nvcodec: Enhance CUDA runtime compiler library loading on Windows
authorSeungha Yang <seungha@centricular.com>
Sat, 26 Jun 2021 16:15:49 +0000 (01:15 +0900)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 29 Jun 2021 17:40:37 +0000 (17:40 +0000)
The name of installed CUDA runtime compiler library is formed like
nvrtc64_{major-version}{minor-version}_0.dll on Windows
(which is differnt from documented in https://docs.nvidia.com/cuda/nvrtc/index.html)

And minor version might not be exactly same as that of CUDA.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2362>

sys/nvcodec/gstnvrtcloader.c

index 0732faf..0cda03e 100644 (file)
@@ -26,6 +26,9 @@
 
 #include <gmodule.h>
 
+GST_DEBUG_CATEGORY_EXTERN (gst_nvcodec_debug);
+#define GST_CAT_DEFAULT gst_nvcodec_debug
+
 #ifndef G_OS_WIN32
 #define NVRTC_LIBNAME "libnvrtc.so"
 #else
@@ -80,14 +83,33 @@ gst_nvrtc_load_library (void)
   if (!module) {
 #ifndef G_OS_WIN32
     filename = g_strdup (NVRTC_LIBNAME);
+    fname = filename;
+    module = g_module_open (filename, G_MODULE_BIND_LAZY);
 #else
-    /* (major version * 1000) + (minor version * 10) */
-    filename = g_strdup_printf (NVRTC_LIBNAME, cuda_version / 1000,
-        (cuda_version % 1000) / 10);
+    /* XXX: On Windows, minor version of nvrtc library might not be exactly
+     * same as CUDA library */
+    {
+      gint cuda_major_version = cuda_version / 1000;
+      gint cuda_minor_version = (cuda_version % 1000) / 10;
+      gint minor_version;
+
+      for (minor_version = cuda_minor_version; minor_version >= 0;
+          minor_version--) {
+        g_free (filename);
+        filename = g_strdup_printf (NVRTC_LIBNAME, cuda_major_version,
+            minor_version);
+        fname = filename;
+
+        module = g_module_open (filename, G_MODULE_BIND_LAZY);
+        if (module) {
+          GST_INFO ("%s is available", filename);
+          break;
+        }
+
+        GST_DEBUG ("Couldn't open library %s", filename);
+      }
+    }
 #endif
-
-    module = g_module_open (filename, G_MODULE_BIND_LAZY);
-    fname = filename;
   }
 
   if (module == NULL) {