Skip to content

VS: Link CUDA binaries with the device runtime library 'cudadevrt'

Brad King requested to merge brad.king/cmake:cuda-vs-cuda-device-runtime into master

According to https://docs.nvidia.com/cuda/nvrtc/index.html there are some cases where a CUDA binary "...must be linked against the CUDA device runtime (cudadevrt) library". When nvcc drives linking it automatically links to runtime libraries as follows:

  • -cudart=none: None
  • -cudart=shared: -lcudadevrt -lcudart
  • -cudart=static: -lcudadevrt -lcudart_static

The cudadevrt library is the cuda device runtime library. It is always static so passing it to the linker when not necessary does not hurt anything.

With Ninja and Makefile generators, we detect cudadevrt and either cudart or cudart_static libraries implied by nvcc and then add them to link lines driven by a host compiler. However, this does not work with the VS generator because the CUDA Toolkit Visual Studio integration does not use nvcc to link binaries and instead uses link.exe directly.

Visual Studio project files (.vcxproj) for CUDA are expected to explicitly list the needed runtime libraries. Our VS generator already adds cudart.lib or cudart_static.lib based on the -cudart= flag. Update it to also add cudadevrt.lib as nvcc does.

Fixes: #17988 (closed)

Merge request reports