cuda: Fix runtime compiler loading with old CUDA tookit

Fallback to PTX if CUBIN symbol is unavailable

Fixes: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/3685
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7220>
This commit is contained in:
Seungha Yang 2024-07-24 02:33:50 +09:00 committed by GStreamer Marge Bot
parent 3e4c8f1b16
commit 0b285fc1a1

View file

@ -45,10 +45,19 @@ GST_DEBUG_CATEGORY_STATIC (gst_cuda_nvrtc_debug);
} \ } \
} G_STMT_END; } G_STMT_END;
#define LOAD_OPTIONAL_SYMBOL(name,func) G_STMT_START { \
if (!g_module_symbol (module, G_STRINGIFY (name), (gpointer *) &vtable->func)) { \
GST_WARNING ("Failed to load '%s', %s", G_STRINGIFY (name), g_module_error()); \
return TRUE; \
} \
} G_STMT_END;
/* *INDENT-OFF* */ /* *INDENT-OFF* */
typedef struct _GstCudaNvrtcVTable typedef struct _GstCudaNvrtcVTable
{ {
gboolean loaded; gboolean loaded;
gboolean have_cubin;
nvrtcResult (*NvrtcCompileProgram) (nvrtcProgram prog, int numOptions, nvrtcResult (*NvrtcCompileProgram) (nvrtcProgram prog, int numOptions,
const char **options); const char **options);
@ -154,6 +163,7 @@ gst_cuda_nvrtc_load_library_once (void)
} }
vtable = &gst_cuda_nvrtc_vtable; vtable = &gst_cuda_nvrtc_vtable;
vtable->have_cubin = FALSE;
LOAD_SYMBOL (nvrtcCompileProgram, NvrtcCompileProgram); LOAD_SYMBOL (nvrtcCompileProgram, NvrtcCompileProgram);
LOAD_SYMBOL (nvrtcCreateProgram, NvrtcCreateProgram); LOAD_SYMBOL (nvrtcCreateProgram, NvrtcCreateProgram);
@ -162,11 +172,12 @@ gst_cuda_nvrtc_load_library_once (void)
LOAD_SYMBOL (nvrtcGetPTXSize, NvrtcGetPTXSize); LOAD_SYMBOL (nvrtcGetPTXSize, NvrtcGetPTXSize);
LOAD_SYMBOL (nvrtcGetProgramLog, NvrtcGetProgramLog); LOAD_SYMBOL (nvrtcGetProgramLog, NvrtcGetProgramLog);
LOAD_SYMBOL (nvrtcGetProgramLogSize, NvrtcGetProgramLogSize); LOAD_SYMBOL (nvrtcGetProgramLogSize, NvrtcGetProgramLogSize);
LOAD_SYMBOL (nvrtcGetCUBINSize, NvrtcGetCUBINSize);
LOAD_SYMBOL (nvrtcGetCUBIN, NvrtcGetCUBIN);
vtable->loaded = TRUE; vtable->loaded = TRUE;
LOAD_OPTIONAL_SYMBOL (nvrtcGetCUBINSize, NvrtcGetCUBINSize);
LOAD_OPTIONAL_SYMBOL (nvrtcGetCUBIN, NvrtcGetCUBIN);
vtable->have_cubin = TRUE;
return TRUE; return TRUE;
error: error:
@ -387,6 +398,11 @@ gst_cuda_nvrtc_compile_cubin (const gchar * source, gint device)
if (!gst_cuda_nvrtc_load_library ()) if (!gst_cuda_nvrtc_load_library ())
return nullptr; return nullptr;
if (!gst_cuda_nvrtc_vtable.have_cubin) {
GST_DEBUG ("CUBIN related symbols are unavailable");
return nullptr;
}
GST_TRACE ("CUDA kernel source \n%s", source); GST_TRACE ("CUDA kernel source \n%s", source);
curet = CuDeviceGetAttribute (&major, curet = CuDeviceGetAttribute (&major,