CUDA 9 Unsupported Visual Studio Version Error

Today I installed CUDA 9 with the Visual Studio 2017 integration. When creating a new CUDA 9 project and building, I got the error:

Error C1189 #error: – unsupported Microsoft Visual Studio version! Only the versions 2012, 2013, 2015 and 2017 are supported!

With some debugging, I found that on line 131 of file host_config.h in directory “C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\include\crt” only supports a max _MSC_VER of 1910. Since Visual Studio 2017 is reporting version 1911, I changed the line to:

#if _MSC_VER < 1600 || _MSC_VER > 1911

And now the new project will build and run.

I hope this tip is helpful to some. I’m just starting off with CUDA (spent 3 days getting it installed and currently working through some Hello World samples), so I apologize if this tip is very elementary for some.

Very Helpful Kyle! Thanks. Don’t you just love working with the latest versions of these things?

Thanks Kyle! That fixed everything

This method can solve the compiling problem, but the project cannot clean and rebuild now.

I’m confused - does this hack actually fix the problem, as Kyle indicates, or not, as EternalSaga indicates?

Apologies for the difficulties with VS 2017 and CUDA 9 RC.

Microsoft released VS 2017 Update 3 (15.3) on 8/14/2017, right after CUDA 9 RC was published. This update results in an incompatibility with CUDA 9 RC. NVIDIA expects that the CUDA 9 GA (future) release will address this particular incompatibility. In the meantime, if you switch to using VS 2017 RTM (the very first release of VS 2017) with no updates, it should work with CUDA 9 RC. I’m not suggesting this is easy or difficult, or providing exact steps to get VS 2017 RTM at this time.

In other respects, the supported environments should be spelled out in the windows installation guide that ships with CUDA 9 RC, and which is also linked from the CUDA 9 RC download page on developer.nvidia.com.

Just had a chat with MS support. According to them, it is only possible to download the latest RTM of VS 2017. There is no facility to go back to older versions.

Are MS and NVIDIA working on some policy to discourage developers from using CUDA?

As of Visual Studio 2015, Microsoft recommend using >= checks against _MSC_VER. See https://blogs.msdn.microsoft.com/vcblog/2016/10/05/visual-c-compiler-version/

Given that NVIDIA has a vested interest in actively promoting the use of CUDA (as it actually helps them make money these days), I would suggest posing that question to Microsoft.

I wouldn’t exactly characterize that approach as customer friendly.

This fixes compiling, but cleaning is still broken for me:

1>------ Clean started: Project: cuda2GLCore, Configuration: Debug x64 ------
1>
1>D:\jeroenb\Implementation\cuda2GLcore\msvc\vs2017>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\nvcc.exe" -ccbin "C:\Program Files (x86)\Microsoft Visual Studio017\Community\VC\Tools\MSVC4.11.25503\bin\HostX86\x64" -x cu  -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\include"  -G   --keep-dir x64\Debug -maxrregcount=0  --machine 64 --compile   -g   -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /FS /Zi /RTC1 /MDd " -o x64\Debug\kernel.cu.obj "D:\jeroenb\Implementation\cuda2GLcore\src\kernel.cu" -clean
1>CUDACOMPILE : nvcc error : 'C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/HostX86/x64/cl.exe' died with status 0xC0000135
1>C:\Program Files (x86)\Microsoft Visual Studio017\Community\Common7\IDE\VC\VCTargets\BuildCustomizations\CUDA 9.0.targets(883,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\nvcc.exe" -ccbin "C:\Program Files (x86)\Microsoft Visual Studio017\Community\VC\Tools\MSVC4.11.25503\bin\HostX86\x64" -x cu  -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\include"  -G   --keep-dir x64\Debug -maxrregcount=0  --machine 64 --compile   -g   -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /FS /Zi /RTC1 /MDd " -o x64\Debug\kernel.cu.obj "D:\jeroenb\Implementation\cuda2GLcore\src\kernel.cu" -clean" exited with code 53.
1>Done building project "cuda2GLCore.vcxproj" -- FAILED.
========== Clean: 0 succeeded, 1 failed, 0 skipped ==========

There’s another issue:

If you try to compile and execute the most simple CUDA Program with CUDA 9.0 RC and VS2017 latest version, and set -rdc=true, the program will output the following error:

1>C:\Users\Admin\source\repos\Test\Test>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\nvcc.exe" -dlink -o x64\Release\Test.device-link.obj -Xcompiler "/EHsc /W3 /nologo /O2 /Zi  /MD " -L"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\lib\x64" cudart.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  -gencode=arch=compute_50,code=sm_50  --machine 64 x64\Release\kernel.cu.obj
1>nvcc fatal   : Host compiler targets unsupported OS.
1>C:\Program Files (x86)\Microsoft Visual Studio017\Community\Common7\IDE\VC\VCTargets\BuildCustomizations\CUDA 9.0.targets(793,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\nvcc.exe" -dlink -o x64\Release\Test.device-link.obj -Xcompiler "/EHsc /W3 /nologo /O2 /Zi  /MD " -L"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\lib\x64" cudart.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  -gencode=arch=compute_50,code=sm_50  --machine 64 x64\Release\kernel.cu.obj" finished with code 1.
1>Done building project "Test.vcxproj" -- ERROR.

If rdc option is removed, the program will compile without issues.

I changed the _MSC_VER > 1911 to _MSC_VER > 1912, but errors are just postponed:

<<MSVC_DIR>>\VC\Tools\MSVC4.12.25827\include\type_traits(504): error : expression must have a constant value
<<MSVC_DIR>>\VC\Tools\MSVC4.12.25827\include\type_traits(505): error : expression must have a constant value
<<MSVC_DIR>>\VC\Tools\MSVC4.12.25827\include\type_traits(506): error : expression must have a constant value
<<MSVC_DIR>>\VC\Tools\MSVC4.12.25827\include\type_traits(538): error : expression must have a constant value
<<MSVC_DIR>>\VC\Tools\MSVC4.12.25827\include\type_traits(1043): error : expression must have a constant value
<<MSVC_DIR>>\VC\Tools\MSVC4.12.25827\include\type_traits(1558): error : expression must have a constant value
<<MSVC_DIR>>\VC\Tools\MSVC4.12.25827\include\type_traits(2371): error : expression must have a constant value
<<MSVC_DIR>>\VC\Tools\MSVC4.12.25827\include\type_traits(2371): error : expression must have a constant value
<<MSVC_DIR>>\VC\Tools\MSVC4.12.25827\include\xutility(543): error : expression must have a constant value
<<MSVC_DIR>>\VC\Tools\MSVC4.12.25827\include\xtr1common(58): error : class "std::enable_if<<error-constant>, int>" has no member "type"
<<MSVC_DIR>>\VC\Tools\MSVC4.12.25827\include\xmemory0(390): error : expression must have a constant value
<<MSVC_DIR>>\VC\Tools\MSVC4.12.25827\include\xmemory0(1002): error : expression must have a constant value
<<MSVC_DIR>>\VC\Tools\MSVC4.12.25827\include\xmemory0(1322): error : expression must have a constant value
<<MSVC_DIR>>\VC\Tools\MSVC4.12.25827\include\xstring(1693): error : expression must have a constant value
<<MSVC_DIR>>\VC\Tools\MSVC4.12.25827\include\xtr1common(58): error : class "std::enable_if<<error-constant>, void>" has no member "type"
<<MSVC_DIR>>\VC\Tools\MSVC4.12.25827\include\xutility(298): error : expression must have a constant value

What about https://www.visualstudio.com/en-us/productinfo/installing-an-earlier-release-of-vs2017

Did you ask them why they have this unreasonable sounding policy? Why not offer an archive of older versions, like NVIDIA provides for CUDA?

Hello,

I have this problem too. I would like to compile kernels in Visual Studio, to use them in ManagedCuda(probably).I have VS Community ver. 15.5.2 .

The never-praised-enough StackOverflow website provides an answer: install MSVC 2015 toolset

Thanks for reply.
I have installed v140 platform toolset. When I try to apply new project configuration, I get this error:

An error has occurred while saving the edited properties listed below:
Platform Toolset
One or more values are invalid. MSBuild returned the following error: The imported project 'C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\BuildCustomizations\CUDA 9.1.targets' was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

I have first installed CUDA 9. Then I learned that I need CUDA 8 to run Tensorflow, so I installed it. Did I corrupt it?

Very useful. All problems solved. Thank you.

Very helpful!!! Thanks a lot.

hello everyone,

I had the same problem and here is a simple workaround for VS 2017, latest version (15.5.2) with CUDA latest version (9.1.85) that worked for me:

Given that in the beginning, I had only the version VC++ 2017 v142 of the toolset installed, I started the visual studio installer and installed the VC++ 2017 v141 toolset, too.

This alone, didn’t solve the problem, because, for some reason (bug in VS?), even if the project is configured to use the v141 toolset, VS generated the include paths for the v142 toolset.

So I manually changed the project include path in visual studio to point to the v141 toolset:

Project properties -> VC++ Directories -> Include Directories:

Here are the new values:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include;C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\atlmfc\include;C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\VS\include;C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt;C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\VS\UnitTest\include;C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\shared;C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\winrt;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.7\Include\um

Make sure to adapt the paths to your visual studio installation directory.

In case you want to do this for all the sample projects, you can do it once, given that multi-select + modification is allowed in VS

Best,

dorin