Integrating CUDA with Visual Studio 2017

Published by moxlotus on

Recently, I was tasked to speed up an algorithm using the CUDA framework. And I ran into issues getting the CUDA project to compile in the VS2017. After spending all the time searching all over the internet for the solutions/guides, I have decided to put up a guide myself so that someone else will benefit from it. Let's get started!

Software

So first of all, you will need to download all the softwares that I have listed below:
Visual Studio 2017
CUDA 9.0/9.1

CUDA Library Setup

Copy the files
from C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\extras\visual_studio_integration\MSBuildExtensions

to C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v140\BuildCustomizations

Visual Studio 2017 Setup

After you have installed visual studio 2017, you will realize that a new CUDA project is not able to compile. That is because there are still some missing dependencies. At the point of writing this article, the latest CUDA versions 9.0/9.1 are not compatible with Visual Studio 2017 by default. For it to be able to compile, it requires the VS2015 toolset and an older version of Win 10 SDK.


First, Select VC++ 2015.3 v140 toolset for desktop (x86,x64) from the list

Next, scroll to the bottom and select Windows 10 SDK(10.0.15063.0) for Desktop C++ [x86 and x64]
After we have installed the VS2015 toolset and Win10 SDK, we will need to update our project settings to use the VS2015 toolset instead of the VS2017 toolset.
Right click your project and go to Properties. Under the General tab, change the platform toolset to Visual Studio 2015(v140)
Now you may press Ctrl+F5 to run your project. And it should compile and run successfully.

Share it with others
Categories: Tools

2 Comments

Fatima · May 28, 2020 at 6:43 PM

I have windows 10 and i install cuda 10.2 and visual studio 2017 but cuda not work please help me how i combine betwee cuda 10.2 and vs 2017

    moxlotus · June 19, 2020 at 10:14 PM

    You may want to try a different platform tool set. The one that I have documented in the guide is for cuda 9. I am pretty sure the one for cuda 10 has changed to a higher version.

Leave a Reply

Avatar placeholder

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