From c8ffd39dfebcb4c5c0ae352a6e93559dc3255bca Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Sun, 27 Jun 2021 01:15:49 +0900 Subject: [PATCH] nvcodec: Enhance CUDA runtime compiler library loading on Windows 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: --- sys/nvcodec/gstnvrtcloader.c | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/sys/nvcodec/gstnvrtcloader.c b/sys/nvcodec/gstnvrtcloader.c index 0732faf907..0cda03e47c 100644 --- a/sys/nvcodec/gstnvrtcloader.c +++ b/sys/nvcodec/gstnvrtcloader.c @@ -26,6 +26,9 @@ #include +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); -#else - /* (major version * 1000) + (minor version * 10) */ - filename = g_strdup_printf (NVRTC_LIBNAME, cuda_version / 1000, - (cuda_version % 1000) / 10); -#endif - - module = g_module_open (filename, G_MODULE_BIND_LAZY); fname = filename; + module = g_module_open (filename, G_MODULE_BIND_LAZY); +#else + /* 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 } if (module == NULL) {