CUDA library opened twice?

Hi all.

I’m seeing an issue where libcuda is opened twice. My program does a bunch of CUDA compute work, and then tries to initialize Optix. When initializing the Optix context, libcuda is loaded again (I can see code pages being loaded, etc…). While loading, it tries to bind a socket, but the socket is already in use (from the first time libcuda is loaded). From my strace:

bind(47, {sa_family=AF_UNIX, sun_path=@"cuda-uvmfd-4026531836-29778\0"}, 31) = -1 EADDRINUSE (Address already in use)

and then I get an Unknown exception from Optix.

My code previously worked when I was using system paths and libcuda was found through ld.so.cache. In that case, when Optix tries to load libcuda, it seems to realize that the library is already loaded (code pages are not remapped the second time etc…) Now I have the cuda toolchain copied to another directory and I supply rpath; I don’t quite get why this is failing. Could it be some option supplied to dlopen inside of Optix?

Mystery solved. In the case using rpath, somehow my symlink of libcuda.so got copied to a file libcuda.so. That means that libcudart loads libcuda.so.1, and liboptix loads libcuda.so, which are distinct files, and all hell breaks loose. Maybe one day my troubles will help someone else ;-)