I have recently installed the CUDA 13.0 toolkit for GPU computation so I can work on physics simulation and other processes. I use Visual Studio 2022 to do this. I have been facing compilation issues when I try to build and run.
Here is the code i used to run the Hello world program:
#include <stdio.h>
int main()
{
printf("Hello, World!\n");
return 0;
}
Whenever I try to compile and run this code, the compiler exits with code 1 and VS provides me with error code MSB3721 with the following description
The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\bin\nvcc.exe" --use-local-env -ccbin "F:\Microsoft Visual Studio\VC\Tools\MSVC\14.44.35207\bin\HostX64\x64" -x cu -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\include" -G --keep-dir Cuda2\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 "/FdCuda2\x64\Debug\vc143.pdb" -o K:\Source\Cuda2\Cuda2\x64\Debug\kernel.cu.obj "K:\Source\Cuda2\kernel.cu"" exited with code 1.
I tried chainging the version of MSVC, adding command line arguments, but nothing worked. It showed the same error every time.
Hi, I am also having this problem and till now have found no solution. It previous years I have been able to compile CUDA programs using VS2022 with no issues on my RTX3070TI but I have since upgraded and tried it out recently but found that the VS2022 seem to have this same issue.
I have posted the issue StackedOverflow but found no solution, in fact I was casually ridicule for asking such a question without knowing the answer - I have resolved to never ask questions there again.
The only way I could compile CUDA programs in windows now is the use Visual studio code using CMAKE with ninja (don’t use the VS2022 settings). It isn’t as elegant as VS2022 but it works and you learn a long more about the NVCC compiler.
I hope this helps.
I use RTX 4070 on a laptop. I just tried calling the cuda functions in a regular .cpp file and it compiled just fine and ran perfectly. The issue I am facing is not being able to compile when I use a .cu file. Is there a difference in those files which I should know in these files, or should I just use a regular .cpp file. If the file extension has no role, then is there a difference between using the default compiler and nvcc.
You know, I never thought of checking the file extension. I only just realized that when i was running my old 3070TI (I don’t have it anymore) I would compile with cpp files - the CU or cuda codes were loaded in the cpp files as well.
But the new CUDA template in VS2022 generate cu files. They should work but it seems what you have just shown (I will also go test later when I get home) could be the real issue.
Thank you for sharing this bit of information.
Hi, did you rename the kernel.cu file to kernel.cpp to get everything working. I tried that but it would still give the same error.
It ran as long as there were no tripple angle brackets, but by this point, I was too frustrated that I reinstalled cuda without the visual studio integration and ran it using vscode, which works much better.