mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-11 00:11:07 -06:00
VS: Link CUDA binaries with the device runtime library 'cudadevrt'
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
This commit is contained in:
@@ -3298,9 +3298,11 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
|
||||
"CUDA") != linkClosure->Languages.end()) {
|
||||
switch (this->CudaOptions[config]->GetCudaRuntime()) {
|
||||
case cmVisualStudioGeneratorOptions::CudaRuntimeStatic:
|
||||
libVec.push_back("cudadevrt.lib");
|
||||
libVec.push_back("cudart_static.lib");
|
||||
break;
|
||||
case cmVisualStudioGeneratorOptions::CudaRuntimeShared:
|
||||
libVec.push_back("cudadevrt.lib");
|
||||
libVec.push_back("cudart.lib");
|
||||
break;
|
||||
case cmVisualStudioGeneratorOptions::CudaRuntimeNone:
|
||||
|
||||
Reference in New Issue
Block a user