I had major issues using the CUDA installer and VS integration and the list below is how I overcame those issues.
-
Extract the installer (cuda_12.9.1_576.57_windows.exe) contents to a directory using 7-zip or WinZip so the installer package doesn’t try to extract to a temp location each time you run it. Then run the setup.exe as administrator from the unzipped location.
-
Use the Custom (Advanced) option and NOT the Express (Recommended) option.
-
Do not select features that are already installed that are the same or later version as the installer version. Use the “Current Version” column to see what is already installed and uncheck those items each time you run the installer. A simple custom action in the setup.exe could prevent a user from making this mistake. I’m not sure why the NVIDIA developers didn’t do this? It would save users a ton of frustration. If you attempt to install a component that is already installed that are the same version it will fail out the installer which is frustrating.
-
Incrementally install the components in the installer, running the installer several times, each time select and install the core components first and avoid all the Nsight and Visual Studio options until the end. If the installer fails then rerun the installer and unselect options until you succeed. Again, It seems that the installer has a sequence of installing components that works and if you deviate from the sequence it will fail. A simple custom action in the installer could fix that. Hopefully NVIDIA will fix that in future releases.
-
After successful install I had several problems using the integrated CUDA features in Visual Studio 2022 version 17.14.7 which were:
A. The “Error List” window needs to be set to just “Build Only” and not “Build + IntelliSense”. IntelliSense doesn’t like the <<< brackets used to invoke CUDA Kernel functions.
B. In the Project Properties Dialog under CUDA C/C++ → Common → CUDA Toolkit Custom Dir should be set to $(CUDA_PATH_V12_9) or $(CUDA_PATH) that is added to the system environment variables during installation. Mine would not populate by default when creating a CUDA project.
C. Build would always fail because the custom Property Sheets would aways use the wrong path for the “compile” PDB file location. I fixed this in the “C:\Program Files\Microsoft Visual Studio\2022\Professional\Msbuild\Microsoft\VC\v170\BuildCustomizations\CUDA 12.9.props” file by changing the default value of:
-Xcompiler “/Fd[ProgramDataBaseFileName]” to -Xcompiler “/Fd$(CudaIntDirFullPath)$(TargetName).pdb”
In two places in the file where the XML nodes is specified.
D. Finally, the VS initial project builds and rebuilds still fail for whatever reason, but you can get around that by launching the command line window called “x64 Native Tools Command Prompt for VS 2022” under the Visual Studio 2022 Programs folder and cutting and pasting the call to the NVCC compiler that is dumped to the output window when it fails. The command output for the error message looks something like this:
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\BuildCustomizations\CUDA 12.9.targets(801,9): error MSB3721: The command ““C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.9\bin\nvcc.exe” -gencode=arch=compute_52,code="sm_52,compute_52" --use-local-env -ccbin “C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\bin\HostX64\x64” -x cu -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.9\include” -I"E:\Installs\VCPKG\vcpkg\installed\x64-windows\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.9\include" -G --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile -cudart static -g -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler “/EHsc /W3 /nologo /Od /FS /Zi /RTC1 /MDd " -Xcompiler “/FdF:\projects\sample\CudaRuntime3\CudaRuntime3\x64\Debug\CudaRuntime3.pdb” -o F:\projects\sample\CudaRuntime3\CudaRuntime3\x64\Debug\kernel.cu.obj “F:\projects\sample\CudaRuntime3\CudaRuntime3\kernel.cu”” exited with code 2.
Just paste the NVCC command in that error message into the “x64 Native Tools Command Prompt for VS 2022” command line window and run it manually. Example:
“C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.9\bin\nvcc.exe” -gencode=arch=compute_52,code="sm_52,compute_52" --use-local-env -ccbin “C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.44.35207\bin\HostX64\x64” -x cu -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.9\include" -I"E:\Installs\VCPKG\vcpkg\installed\x64-windows\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.9\include" -G --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile -cudart static -g -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /FS /Zi /RTC1 /MDd " -Xcompiler “/FdF:\projects\sample\CudaRuntime3\CudaRuntime3\x64\Debug\CudaRuntime3.pdb” -o F:\projects\sample\CudaRuntime3\CudaRuntime3\x64\Debug\kernel.cu.obj “F:\projects\sample\CudaRuntime3\CudaRuntime3\kernel.cu”
That would run for me successfully. Then I could do a normal Build from VS to finish the build and run the code successfully.
Finally, I know what you are thinking, this dude’s computer is messed up. While that may be true, I found an ENORMOUS number of similar complaints on the Internet about CUDA Visual Studio integration problems so I hope this helps someone out and I hope the NVIDIA developers can fix these issues in the future since we love NVIDIA hardware and GPU acceleration!!
Also, I thought possibly the command line window and the VS environment PATH, LIBPATH, INCLUDE, etc. was different and that was causing the problem, but after setting both to match the problem still occurs. I think the root of the problem is that there is still an issue with one of the three custom files that NVIDIA adds to Visual Studio (CUDA 12.9.props, CUDA 12.9.targets, and CUDA 12.9.xml). I think because the root problems stem from some of the inherited values in the property sheets and what happens is that the NVCC compiler fails to create some of the binaries in the project Output directory. Possibly the problem relates to referencing the output folder location. Thus, when the command returns and the binaries are not there then VS fails because it is looking for those files. Maybe there are missing files in the temporary linking folder?