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:
Brad King
2018-05-11 08:37:24 -04:00
parent ad83aa0f3d
commit a170a59a58

View File

@@ -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: