From 0b285fc1a1ddbd70bc406b126c2715e964bed5ee Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Wed, 24 Jul 2024 02:33:50 +0900 Subject: [PATCH] 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: --- .../gst-libs/gst/cuda/gstcudanvrtc.cpp | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/cuda/gstcudanvrtc.cpp b/subprojects/gst-plugins-bad/gst-libs/gst/cuda/gstcudanvrtc.cpp index c3851414d3..b82b4c3ac4 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/cuda/gstcudanvrtc.cpp +++ b/subprojects/gst-plugins-bad/gst-libs/gst/cuda/gstcudanvrtc.cpp @@ -45,10 +45,19 @@ GST_DEBUG_CATEGORY_STATIC (gst_cuda_nvrtc_debug); } \ } 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* */ typedef struct _GstCudaNvrtcVTable { gboolean loaded; + gboolean have_cubin; nvrtcResult (*NvrtcCompileProgram) (nvrtcProgram prog, int numOptions, const char **options); @@ -154,6 +163,7 @@ gst_cuda_nvrtc_load_library_once (void) } vtable = &gst_cuda_nvrtc_vtable; + vtable->have_cubin = FALSE; LOAD_SYMBOL (nvrtcCompileProgram, NvrtcCompileProgram); LOAD_SYMBOL (nvrtcCreateProgram, NvrtcCreateProgram); @@ -162,11 +172,12 @@ gst_cuda_nvrtc_load_library_once (void) LOAD_SYMBOL (nvrtcGetPTXSize, NvrtcGetPTXSize); LOAD_SYMBOL (nvrtcGetProgramLog, NvrtcGetProgramLog); LOAD_SYMBOL (nvrtcGetProgramLogSize, NvrtcGetProgramLogSize); - LOAD_SYMBOL (nvrtcGetCUBINSize, NvrtcGetCUBINSize); - LOAD_SYMBOL (nvrtcGetCUBIN, NvrtcGetCUBIN); - vtable->loaded = TRUE; + LOAD_OPTIONAL_SYMBOL (nvrtcGetCUBINSize, NvrtcGetCUBINSize); + LOAD_OPTIONAL_SYMBOL (nvrtcGetCUBIN, NvrtcGetCUBIN); + vtable->have_cubin = TRUE; + return TRUE; error: @@ -387,6 +398,11 @@ gst_cuda_nvrtc_compile_cubin (const gchar * source, gint device) if (!gst_cuda_nvrtc_load_library ()) 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); curet = CuDeviceGetAttribute (&major,