compile(CUDA + Win7x64 + VS2017) = nvcc fatal: Host compiler targets unsupported OS.

Hi all!
I’m trying compile under VS2017 one simple CUDA project and can’t it successfully.
As I understood from the reports on other forums, at the moment, the CUDA does not support working with VS2017. If someone got it, I ask you to share your experience on how to do it. Or when it becomes possible to compile CUDA projects for VS2017 without tambourine dancing.
Thank you.
— VS2017 Log

1>------ Rebuild All started: Project: CUDATest2, Configuration: Debug Win32 ------
1>
1>D:\VS2017\VC\Projects\CUDATest2>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin\nvcc.exe" -ccbin "D:\VS2017\VC\Tools\MSVC\14.10.25017\bin\HostX86\x86\cl.exe"  -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include"  -G  --keep --keep-dir Debug -maxrregcount=0  --machine 32 --compile   -g  -use_fast_math -DWIN32 -D_DEBUG -D_CONSOLE -D_UNICODE -DUNICODE -Xcompiler "/EHsc /Wall /nologo /Od  /Zi /RTC1 /MDd " -o Debug\bandwidthTest.cu.obj "D:\VS2017\VC\Projects\CUDATest2\bandwidthTest.cu" -clean
1>CUDACOMPILE : nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
1>nvcc fatal   : Host compiler targets unsupported OS.
1>D:\VS2017\Common7\IDE\VC\VCTargets\BuildCustomizations\CUDA 8.0.targets(865,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin\nvcc.exe" -ccbin "D:\VS2017\VC\Tools\MSVC\14.10.25017\bin\HostX86\x86\cl.exe"  -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include"  -G  --keep --keep-dir Debug -maxrregcount=0  --machine 32 --compile   -g  -use_fast_math -DWIN32 -D_DEBUG -D_CONSOLE -D_UNICODE -DUNICODE -Xcompiler "/EHsc /Wall /nologo /Od  /Zi /RTC1 /MDd " -o Debug\bandwidthTest.cu.obj "D:\VS2017\VC\Projects\CUDATest2\bandwidthTest.cu" -clean" exited with code 1.
1>Done building project "CUDATest2.vcxproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

CUDA 9 RC was made available yesterday to registered developers, and it has support for VS2017. You might try that. You need to be a registered developer, then you can download it from developer.nvidia.com. AFAIK no tambourine dancing is involved.

Also, you appear to be building a win32 project. That is generally not recommended anymore with CUDA. I recommend building x64 projects (although it would not resolve this issue for CUDA 8).

txbob, Thank you VERY MUCH! I’ll try it now!

just updated to cuda 9.0 and it got rid of the problem.

but since I am using cmake i also had to do 2 other fixes:

1: make a backup of then delete:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\bin\HostX86

2: make a backup of then delete:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\bin\HostX64\x86

3: if you see: set(CUDA_HOST_COMPILER “$(VCInstallDir)bin”) somewhere in your cmake files then change it to
set(CUDA_HOST_COMPILER “C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\bin\HostX64\x64\cl.exe”

1: and 2: make sure cmake doesnt pick the wrong compiler (in my case cmake was always choosing the wrong compiler, always the same compiler even if I specified)

3: is to correct the incorrect path computed to find cl.exe because msvc 2017 has new path logic than previous msvc’s

I’m sure there’s a better fix but I must move on :) so this quick and dirty will do for now. let me know if it was really necessary to update to cuda 9.0

If I understand correctly, you deleted parts of the MSVC installation to please CMAKE? If so, that seems totally wrong. Presumably CMAKE has a way of choosing the appropriate compiler, and it would be worthwile finding out what that is (IMHO). Alternatively, get rid of CMAKE (that would be my preferred course of action :-).

There is: CMAKE_C_COMPILER and CMAKE_CXX_COMPILER and CMAKE_LINKER, but the build script returned me a nice message saying it had overrode it. Makes sense cuz they can be deduced by other parameters

The following cmake arguments usually work for me with other versions of msvc but couldn’t get the scripts to get it right this time:

-G “Visual Studio 15 2017” -DCMAKE_GENERATOR_PLATFORM=x64 -DCMAKE_GENERATOR_TOOLSET=v141 -DVCToolArchitecture=nativ64

This thing is so convoluted and I’ve fixed so many bugs that I didn’t have time to get into it.
It<s kinda hard to remove CMAKE when the project is open sourced and used by a whole community. Have you ever used hunter?

between cmake, hunter, msvc, build tools, external dependencies, cuda, drivers, the os, host/target architectures blah blah…i’ve done enough debugging for a while i’ll submit a bug report somewhere ;) I agree that cmake is hard to maintain.

like I said it’s quick and dirty… but it gives people the reason for the errors …

It works for me: CUDA 9.0, VS 2017 with latest updates

cmake arguments:

-G “Visual Studio 15 2017 Win64” -DCMAKE_GENERATOR_TOOLSET=v141

cmake file:

list(APPEND CUDA_NVCC_FLAGS --cl-version=2017)

Thank you everyone for your help. I just wanted to supplement this post with the last piece of the puzzle. CUDA v9.0 RC is looking for VS2017 to identify as 1910 but the latest update actually identifies as 1911. To fix open …/CUDA/v9.0/include/crt/host_config.h and change this line:

#if _MSC_VER < 1600 || _MSC_VER > 1910

to this:

#if _MSC_VER < 1600 || _MSC_VER > 1911