An Attempt At Using CUDA 8 With Visual Studio 2017

I don’t think this is all that useful, but at least it documents my attempt to get CUDA to use the Visual Studio 2017 build tools, which is something at NVIDIA don’t support at this time.

If you want to see a more successful attempt at getting CUDA to work with something it wasn’t supposed to, see my earlier post relating to CUDA and Visual Studio 2015 Express Edition here.

Again, I’m happy to build from the command line. I don’t find the debugger all that useful when building highly threaded systems anyway since the idea that you can step through the code one line at a time and follow the logic of the program has limited relevance to parallel programming, and I usually end up falling back on logs or attempts to visualize what programs are doing.

1. Setup the VS 2017 Envionment

I stuck the following line of code into a batch file called env.bat so I could quickly setup the environment needed to access the build tools. Just run env.bat from the command line once this is in place…

call “D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build” x86_amd64

2. Add vcvars64.bat

The CUDA compiler, nvcc, looks for this file before launching the various Visual Studio tools. After spending a bit of time looking at what nvcc does via Windows Process Monitor I figured out that we need to create the following path under Program Files, or wherever VS2017 was installed…

\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\VC\bin\amd64

Note the the folder with three numbers relates to the specific version of the build tools and I expect Microsoft to change or add variations of the Build tools during the life of VS2017, so this number won’t always be correct. Microsoft do provide a way to query the location of the build tools, but as this requires the use of a COM interface it’s not that easy to integrate into a simple test like this and so I’m happy to hard code it. Once the path is there, make a file called vcvars64.bat containing the text “CALL setenv /x64”.

3. Build Something

A typical command line to CUDA under VS2015 looked like this, where we all we’ve changed for 2017 is the path to cl.exe, and we can’t set the cl-version parameter to 2017 because if we do it throws an error back at us, but this seems to at last find the correct tools.

nvcc main.cu -o main.exe –gpu-architecture=compute_50 –gpu-code=sm_50,sm_52 –machine 64 –cl-version 2015 -ccbin “D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\bin\HostX64\x64”

One more problem is that in my sample app I hit a compile time check in host_config.h that the version of Visual Studio was not recognized, where I found that locating and commenting out the offending line of code seemed to clear the error.

host_config.h(133): fatal error C1189: #error: — unsupported Microsoft Visual Studio version! Only the versions 2012, 2013, and 2015 are supported!

After that it seems to work, at least in my simple Hello World app.

Note that I do get a lot of warnings like this… but that they don’t appear to affect the output of the program.

math_functions.h(7691): warning: a __host__ function("fmodf") redeclared with __host__ __device__,
 hence treated as a __host__ __device__ function

Generally I wouldn’t advise doing this for any serious attempt at CUDA coding. I’m sure official Visual Studio 2017 support is just around the corner.

Leave a Reply

Your email address will not be published. Required fields are marked *