From a170a59a582ec4e5d65d2e66503a3838982b7de0 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 11 May 2018 08:37:24 -0400 Subject: 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 --- Source/cmVisualStudio10TargetGenerator.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index cfdf2d8..d90d754 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -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: -- cgit v0.12