CUDA selction with Visual Studio Generator

If I have two CUDA toolkits installed say 12.2 and 12.3 the default Visual Studio behaviour appears to be to use CUDA 12.3, how can I generate a Visual Studio project which uses CUDA toolkit 12.2 when CUDA is a first class language?

If I use the ninja generator then adding C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.2/bin to the begining of the system/user PATH environmental variable will select 12.2, however this does not work for the Visual Studio generator.

If I use Visual Studio generator it seems that the path to CUDA is determined by the CUDA_PATH_V12_3 environmental variable. That is if this is set this to to C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.2 CMake detects CUDA 12.2 and outputs

– Looking for a CUDA compiler
– Looking for a CUDA compiler - C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.2/bin/nvcc.exe
– The CUDA compiler identification is NVIDIA 12.2.128

however if I delete this environmental variable, even if there is a CUDA_PATH and CUDA_PATHV12_2 environmental variable pointing to the same place and the directory containing the compiler is on the PATH the CUDA toolkit is not found.

Cc: @robert.maynard

For Visual Studio Generators you select the CUDA version via the Toolset:

1 Like

That worked perfectly, thank you for the help.

@robert.maynard Is there a recommended way to select the CUDA toolkit when using other generators? Currently in linux I add the location of the CUDA toolkit to the CUDA_PATH environmental variable and in Windows I add it to the start of the system/user PATH.

I’m a very tangential CUDA user (I mainly just compile other people’s code), but setting CUDACC and CUDACXX environment variables has worked well.

1 Like