Custom Gstreamer plugin could not find CUDA Driver API function

Hi,
My custom plugin is based on ds-example. I am trying to use EGL-CUDA interoperability to apply my CUDA kernel to an image. Following hints in ds-eample source code I am using CUDA driver API to map data:

if (NvBufSurfaceMapEglImage (&ip_surf, 0) !=0 ) goto error; 

CUgraphicsResource *pCudaResource;
CUeglFrame *pEglFrame;

if (cuGraphicsEGLRegisterImage(pCudaResource,
           ip_surf.surfaceList[0].mappedAddr.eglImage,
           CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE)
           != CUDA_SUCCESS) {
                GST_ERROR("Could n't register EGL image.");
                goto error;
}
if (cuGraphicsResourceGetMappedEglFrame(pEglFrame, *pCudaResource, 0, 0) 
           != CUDA_SUCCESS) {
                GST_ERROR("Could n't get cuda EGL frame.");
                goto error;
}

I use cmake to build plugin:

cuda_add_library(gstdsmyplugin SHARED gstdsmyplugin.cpp)
target_include_directories(gstdsmyplugin PUBLIC
        ${OpenCV_INCLUDE_DIRS}
        ${GST_INCLUDE_DIRS}
        ${DEEPSTREAM_INCLUDE_DIRS}
        ${CUDA_INCLUDE_DIRS}
        )
target_link_libraries(gstdsmyplugin
        frameproc # a lib with my CUDA kernel
        ${OpenCV_LIBS}
        ${GST_LIBRARIES}
        ${DEEPSTREAM_LIBRARIES}
        ${CUDA_LIBRARIES}
        )

When I run my GStreamer app with the custom plugin the problem appears:

(gst-plugin-scanner:20047): GStreamer-WARNING **: 12:22:54.192: Failed to load plugin '/usr/lib/aarch64-linux-gnu/gstreamer-1.0/deepstream/libgstdsmyplugin.so': /usr/lib/aarch64-linux-gnu/gstreamer-1.0/deepstream/libgstdsmyplugin.so: undefined symbol: cuGraphicsEGLRegisterImage

My LD_LIBRARY_PATH contains CUDA libs directory:

user@dev-nano:~$ echo $LD_LIBRARY_PATH 
/usr/local/cuda/lib64

What lib contains the cuGraphicsEGLRegisterImage function?
What am I doing wrong?

I will be grateful for any help :)

Hi,
These is a sample similar to your usecase. Please check

Thank you for the answer!

I had to further study CUDA examples to find a solution.

The problem was in linking. It’s required to explicitly link libcuda, since it’s not placed in common CUDA libraries directory.

I added corresponding line in my CMakeLists.txt:

cuda_add_library(gstdsmyplugin SHARED gstdsmyplugin.cpp)
target_include_directories(gstdsmyplugin PUBLIC
        ${OpenCV_INCLUDE_DIRS}
        ${GST_INCLUDE_DIRS}
        ${DEEPSTREAM_INCLUDE_DIRS}
        ${CUDA_INCLUDE_DIRS}
        )
target_link_libraries(gstdsmyplugin
        frameproc # a lib with my CUDA kernel
        ${OpenCV_LIBS}
        ${GST_LIBRARIES}
        ${DEEPSTREAM_LIBRARIES}
        ${CUDA_LIBRARIES}
        cuda # <----- THIS LINE
        )
1 Like