CMake incorrectly links to nvrtc-builtins

Peter Eastman
Tue, 08 Oct 2024 20:45:01 +0000
Code

I have a program that uses CUDA, and more specifically the nvrtc runtime compiler. In my build script, I call find_package(CUDAToolkit), then use target_link_libraries() to link to CUDA::nvrtc.

It is supposed to be binary compatible across minor versions. Its SONAME is, for example, libnvrtc.so.12. You can compile against any 12.x version, then run with any other 12.x version.

There’s another library called libnvrtc-builtins which does not work that way. Its SONAME is, for example, libnvrtc-builtins.so.12.6. Linking to it would break binary compatibility. However, you are never supposed to link to it directly. According to the CUDA documentation, it is only for internal use by the nvrtc library.

When I compile against CUDA 11 this works as expected. I can compile against 11.8 and it works equally well with 11.7. But when I compile against CUDA 12, I find that CMake is incorrectly linking in nvrtc-builtins. That breaks binary compatibility. If I compile against CUDA 12.5, my program can only be used with that exact version, not 12.4 or 12.6.

How can I prevent CMake from incorrectly linking my code to nvrtc-builtins?

Thanks!

6 posts - 3 participants