Unable to compile CUDA 13 template project in VS2022

I have installed VS2022 version 17.14.23 and CUDA tool kit 13.1.0

I have also updated my Nvidia driver, currently using NVIDIA GeForce RTX 4060 Laptop GPU, version 591.74

I kept encountering these errors:

I have tried reinstalling VS2022, CUDA toolkit 13.0.0 and tried CUDA tool kit 13.1.0 but they all gave me the same error.

I have also tried changing the code generation from 75 to 89, added additional compiler option “-allow-unsupported-compiler”.

I can compile the project manually via command prompt but not on VS2022.

These are the error output:

1>      Output file "C:\CudaTest\Test\Test\x64\Release\kernel.cu.obj" does not exist.
1>      Task "Message"
1>        Compiling CUDA source file kernel.cu...
1>      Done executing task "Message".
1>      Task "Message" skipped, due to false condition; ('$(__ExcludedFromBuild)' == 'true') was evaluated as ('' == 'true').
1>      Task "MakeDir" skipped, due to false condition; (!Exists('$(CompileOutDir)')) was evaluated as (!Exists('C:\CudaTest\Test\Test\x64\Release')).
1>      Task "MakeDir" skipped, due to false condition; ('$(__Keep)' == 'true' AND !Exists('$(__KeepDir)')) was evaluated as ('false' == 'true' AND !Exists('x64\Release')).
1>      C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\BuildCustomizations\CUDA 13.1.targets(800,13): message : Property reassignment: $(__CommandLineTemplate)=""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\bin\nvcc.exe" [CodeGeneration] --use-local-env -ccbin "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64" -x cu [GenerateRelocatableDeviceCode] [ExtensibleWholeProgramCompilation] [Include] [RequiredIncludes] [InterleaveSourceInPTX] [GPUDebugInfo] [GenerateLineInfo] [Keep] [KeepDir] [FastMath] [MaxRegCount] [PtxAsOptionV] [SplitCompile] [FastCompile] [TargetMachinePlatform] [NvccCompilation] [CudaRuntime] [AdditionalOptions] [HostDebugInfo] [Emulation] [Defines] -Xcompiler "/EHsc [Warning] /nologo [Optimization] /FS [DebugInformationFormat] [RuntimeChecks] [Runtime] [TypeInfo]" -Xcompiler "/Fdx64\Release\vc143.pdb" [CompileOut] "C:\CudaTest\Test\Test\kernel.cu"" (previous value: ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\bin\nvcc.exe" [CodeGeneration] --use-local-env -ccbin "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64" -x cu [GenerateRelocatableDeviceCode] [ExtensibleWholeProgramCompilation] [Include] [RequiredIncludes] [InterleaveSourceInPTX] [GPUDebugInfo] [GenerateLineInfo] [Keep] [KeepDir] [FastMath] [MaxRegCount] [PtxAsOptionV] [SplitCompile] [FastCompile] [TargetMachinePlatform] [NvccCompilation] [CudaRuntime] [AdditionalOptions] [HostDebugInfo] [Emulation] [Defines] -Xcompiler "/EHsc [Warning] /nologo [Optimization] /FS [DebugInformationFormat] [RuntimeChecks] [Runtime] [TypeInfo]" -Xcompiler "/Fd[ProgramDataBaseFileName]" [CompileOut] "C:\CudaTest\Test\Test\kernel.cu"") at C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\BuildCustomizations\CUDA 13.1.targets (800,13)
1>      Initializing task factory "XamlTaskFactory" from assembly "Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
1>      Using "CudaCompile" task from the task factory "XamlTaskFactory".
1>      Task "CudaCompile"
1>        cmd.exe /C "C:\Users\AppData\Local\Temp\tmp71b1d1fc96544bc098a24830a0609bfc.cmd"
1>        "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\bin\nvcc.exe" -gencode=arch=compute_75,code=\"sm_75,compute_75\" --use-local-env -ccbin "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64" -x cu   -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\include"     --keep-dir x64\Release  -maxrregcount=0    --machine 64 --compile -cudart hybrid    -DWIN32 -DWIN64 -DNDEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /O2 /FS   /MD " -Xcompiler "/Fdx64\Release\vc143.pdb" -o C:\CudaTest\Test\Test\x64\Release\kernel.cu.obj "C:\CudaTest\Test\Test\kernel.cu"
1>
1>        C:\CudaTest\Test\Test>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\bin\nvcc.exe" -gencode=arch=compute_75,code=\"sm_75,compute_75\" --use-local-env -ccbin "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64" -x cu   -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\include"     --keep-dir x64\Release  -maxrregcount=0    --machine 64 --compile -cudart hybrid    -DWIN32 -DWIN64 -DNDEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /O2 /FS   /MD " -Xcompiler "/Fdx64\Release\vc143.pdb" -o C:\CudaTest\Test\Test\x64\Release\kernel.cu.obj "C:\CudaTest\Test\Test\kernel.cu"
1>        C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\BuildCustomizations\CUDA 13.1.targets(803,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\bin\nvcc.exe" -gencode=arch=compute_75,code=\"sm_75,compute_75\" --use-local-env -ccbin "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64" -x cu   -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\include"     --keep-dir x64\Release  -maxrregcount=0    --machine 64 --compile -cudart hybrid    -DWIN32 -DWIN64 -DNDEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /O2 /FS   /MD " -Xcompiler "/Fdx64\Release\vc143.pdb" -o C:\CudaTest\Test\Test\x64\Release\kernel.cu.obj "C:\CudaTest\Test\Test\kernel.cu"" exited with code 1.
1>      Done executing task "CudaCompile" -- FAILED.
1>    Done building target "CudaBuildCore" in project "Test.vcxproj" -- FAILED.
1>
1>    Done building project "Test.vcxproj" -- FAILED.
1>  Done executing task "MSBuild" -- FAILED.
1>
1>Done building project "Test.vcxproj" -- FAILED.
1>
1>Build FAILED.
1>
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\BuildCustomizations\CUDA 13.1.targets(803,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\bin\nvcc.exe" -gencode=arch=compute_75,code=\"sm_75,compute_75\" --use-local-env -ccbin "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64" -x cu   -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\include"     --keep-dir x64\Release  -maxrregcount=0    --machine 64 --compile -cudart hybrid    -DWIN32 -DWIN64 -DNDEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /O2 /FS   /MD " -Xcompiler "/Fdx64\Release\vc143.pdb" -o C:\CudaTest\Test\Test\x64\Release\kernel.cu.obj "C:\CudaTest\Test\Test\kernel.cu"" exited with code 1.
1>    0 Warning(s)
1>    1 Error(s)
1>
1>Time Elapsed 00:00:00.89
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 6:24 pm and took 01.590 seconds ==========

Any help is appreciated. Thanks in advance.

This is my pc build sample:

C:\Users\richa\source\repos\CudaRuntime1>“C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\bin\nvcc.exe” -gencode=arch=compute_75,code=“sm_75,compute_75” --use-local-env -ccbin “C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\bin\HostX64\x64” -x cu -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.1\include" -G --keep-dir CudaRuntime1\x64\Debug -maxrregcount=0 --machine 64 --compile -cudart hybrid -g -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /FS /Zi /RTC1 /MDd " -Xcompiler “/FdCudaRuntime1\x64\Debug\vc143.pdb” -o C:\Users\richa\source\repos\CudaRuntime1\CudaRuntime1\x64\Debug\kernel.cu.obj “C:\Users\richa\source\repos\CudaRuntime1\kernel.cu”
1>kernel.cu
1>tmpxft_0000b438_00000000-7_kernel.cudafe1.cpp
1> Creating library C:\Users\richa\source\repos\CudaRuntime1\x64\Debug\CudaRuntime1.lib and object C:\Users\richa\source\repos\CudaRuntime1\x64\Debug\CudaRuntime1.exp
1>LINK : warning LNK4098: defaultlib ‘LIBCMT’ conflicts with use of other libs; use /NODEFAULTLIB:library
1>CudaRuntime1.vcxproj → C:\Users\richa\source\repos\CudaRuntime1\x64\Debug\CudaRuntime1.exe
1>Done building project “CudaRuntime1.vcxproj”.
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
========== Rebuild completed at 8:46 PM and took 01.975 seconds ==========

Compare my side and yours, some setting different, for your setting, there is code=\sm_75,compute_75\, my side without the “\”

I am not sure this can help.

I have a similar problem. (You should remove IntelIisense to accept <<< >>> ?). I get the same error at line 803 but if I copy the command line and run in x64 Native tool it works as you say and then I can run from the IDE with debug. When I enable Verbose in VS2022 it says something I think is problems combining 32-bit compiler (32-bit compiler can be used to generate 64-bit code as required for Cuda 13.1) results with 64-bit compiler results and I don’t know any setting to force them to use the same for both nvcc and VS2022 (although both complie for x64 and I selected 64-bit tools). Maybe to replace the exe files or remove 32-bit tools. I also use 17.14.23, maybe Richard is not?

Microsoft Visual Studio Community 2022
Version 17.14.23
VisualStudio.17.Release/17.14.23+36811.4
Microsoft .NET Framework
Version 4.8.09221

Installed Version: Community

Visual C++ 2022 00482-90000-00000-AA188
Microsoft Visual C++ 2022

ASP.NET and Web Tools 17.14.133.46758
ASP.NET and Web Tools

Azure App Service Tools v3.0.0 17.14.133.46758
Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools 17.14.133.46758
Azure Functions and Web Jobs Tools

C# Tools 4.14.0-3.25412.6+c167adef821b9ba2f1c44c227a5e79ca11876461
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Cookiecutter 17.0.25079.8
Provides tools for finding, instantiating and customizing templates in cookiecutter format.

GitHub Copilot 17.14.1561.44479
GitHub Copilot is an AI pair programmer that helps you write code faster and with less work.

Linux Core Dump Debugging 1.0.9.36414
Enables debugging of Linux core dumps.

Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Mono Debugging for Visual Studio 17.14.11 (f3bc644800)
Support for debugging Mono processes with Visual Studio

NuGet Package Manager 6.14.2
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

NVIDIA CUDA 12.9 Wizards 12.9
Wizards to create new NVIDIA CUDA projects and source files.

NVIDIA CUDA 13.1 Wizards 13.1
Wizards to create new NVIDIA CUDA projects and source files.

@kalle.prorok These are my side setting.

Thank you Richard!

Interesting to see and I’ve heard other made it work in IDE so something strange with my install (I reinstalled several times) -. it seems my VS 2022 opens a command window with 32-bit settings when compiling. It works in x64 native but it is a bit cumbersome.. noticed there is a new version of Cuda (13.1 update 1) to try out as well as github with examples in 13.1-version (they didn’t work in IDE but in x64 native window).

You have some kind of 13.1 Wizard? what is that?

Hello Kalle,

One modify for me is, remove 13.1 inside api file non ascii character.
I am not sure that impact.

Regards,
Richard

Hi @amanpotato788
I am having same issue on cuda 12.9 and rtx 5090 have you succeeded solving the problem?
Can I ask how?

You can use any hex viewer (like hex mode in notepad ++ find the special character, then take off, most you can direct remove.
I did one program, find these characters , unfortunately, I can’t attached in here, gmail block it.

Regards,
Richard

Conv11.txt (817 KB)

Please change this file name to “conv1.exe” then running, enter your directory name. The program will find special chacters.