CUDA Development Environment Setup Under Windows

This post is from a blog called Adventures in GraphicsLand that I’m writing with two fellow CS grad students, Chris Gibson and Ryan Schmitt. Articles about anything related to my graduate work in graphics or my thesis will be posted there and then cross-posted here. Articles about handy tips (like fixing bugs with VirtualBox or software setup on Fedora) will remain here. This post that I wrote for AIGFX, originally appeared here.

Getting a complete CUDA development environment up and running under Windows can be a bit… daunting. Between all the dev drivers, SDKs, toolkits, and other trimmings it can take several hours to get your workstation up and running. However, the results are pretty nice.

This guide will give you the following setup:

  • Visual Studio 2010 (C/C++ compiler and IDE)
  • CUDA Toolkit 3.2 (CUDA C compiler and runtime)
  • GPU Computing SDK 3.2 (sample code and utility libraries)
  • Parallel Nsight 1.5 (live debugging and performance analysis of CUDA code)
  • Visual Assist X 10.6 (syntax highlighting and completion goodies)

There are, however, some drawbacks that you should be aware of:

  • In addition to Visual Studio 2010, you need Visual Studio 2008. This is because the CUDA compiler (nvcc) only supports the VS 9.0 build tools at the moment. You can still develop in and compile from VS 2010 however.
  • You need two CUDA-capable GPUs in your machine to do CUDA debugging with Parallel Nsight.
  • Installation and setup will take the whole afternoon.

For reference, my machine is running Windows 7 Professional x64. Your mileage may vary.

Step 1: Get everything downloaded.

Make sure you have downloaded installers or installation disks handy for all of the following:

Step 2: Install Visual Studio(s).

Both VS 2008 and 2010 can coexist side-by-side. Install VS 2008, then the SP1 update. Lastly install VS 2010. Be sure to launch Windows Update afterwords to pull down any patches to the dev tools.

Step 3: Install Visual Assist X.

If you haven’t used Visual Assist X before, you’ve been missing out. It has lots of refactoring and code exploration features, but its killer feature for me is how well it complements Visual Studio’s Intellisense. When you run the installer, you’ll be able to select if you want to install it for both versions of VS or just 2010. It’s up to you, but we only needed VS 2008 for the compiler so you can get away with just installing it for VS 2010.

Step 4: Install the CUDA tools.

First install the developer driver. Then the CUDA toolkit, and the GPU Computing SDK. The default installation paths are fine. Lastly, install the Parallel Nsight Host and Parallel Nsight Monitor.

Step 5: Configure Visual Assist X to know about CUDA.

To get full syntax highlighting and include support, we need to tell VAX about our CUDA libraries as well as the fact that it should treat CUDA files as C/C++ files.

Launch VS 2010 and open the Options screen (Tools > Options). Under Projects and Solutions > VC++ Project Settings add the following entries to the Extensions to Include item:

  • .cu
  • .cu.h (or whatever you use for your CUDA headers)

It should look something like this:

Extensions to Include

Now close VS 2010 and open up the registry editor (Start > regedit.exe). Browse to the following folder:

  • HKEY_CURRENT_USER\Software\Whole Tomato\Visual Assist X\VANet10

Now look for the ExtHeader key and add .cu.h to the list. Make sure the whole line ends with a semicolon. It should look something like this:

Regedit ExtHeader

Look a little further down and you should see the ExtSource key. Add .cu to the list in the same way. Again, make sure the line ends with a semicolon.

Regedit Source

Now relaunch VS 2010 and open the VAX options (VAssistX > Visual Assist X Options). Open the Projects group on the left and select C/C++ Directories. Under Platform select Custom. Then, select Stable Include Files from the drop down on the right and add the paths to your CUDA toolkit includes and GPU Computing SDK includes. If you used the default installation directories, these are:

  • C:\Program Files (x86)\NVIDIA GPU Computing Toolkit\CUDA\v3.2\include
  • C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 3.2\C\common\inc

In other words, your screen should look something like this:

Stable Includes

Now switch the drop down to Source files and add the following paths:

  • C:\Program Files (x86)\NVIDIA GPU Computing Toolkit\CUDA\v3.2\src
  • C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 3.2\C\common\src

Source Files

Lastly, select the Performance item from the left and click the Rebuild Symbol Databases button.

Rebuild Symbol Databases

You should be good to go now with Visual Assist X and CUDA.

Step 6: A bare bones CUDA project.

To take you through the process of setting up a new CUDA project in VS 2010, here’s a simple bare bones console application that adds two numbers on the GPU.

First, go to File > New > Project. Select Win32 Console Application from the Visual C++ category. Enter a location and a name and click OK. In the wizard, uncheck Precompiled Headers and check Empty Project.

Now in the Solution Explorer, right click on the name of your project and select Build Customizations. In the box that pops up, select CUDA 3.2 and click OK.

Build Customizations

Now add a new source file to your project. Let’s call it hello.cu. Once it’s added, right click on it in the solution explorer and select Properties. Select the General item on the left and make sure the Item Type is set to CUDA C/C++.

CUDA Item Type

Lastly, we need to make sure we’re including the GPU Computing SDK headers and linking to the CUDA runtime library, as well as tell Visual Studio to use the 2008 (9.0) version of the compiler.

Right click on your project and select Properties. From the Configuration drop down, select All Configurations. Under Configuration Properties > General, select v90 from the Platform Toolset item.

Platform Toolset

Under Configuration Properties > CUDA C/C++ > Common, add the GPU Computing SDK include path to Additional Include Directories. If you chose the default installer path, it will be:

  • C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 3.2\C\common\inc

CUDA Additional Include Directories

Now under Configuration Properties > Linker > Input add cudart.lib to your Additional Dependencies.

Linking CUDArt

Apply the settings and click OK. All we need now is to flesh out our hello.cu file with a sample program and we’re good to go. Here’s a sample program that adds two integers on the GPU and prints the result. (Note that this is not the default VS 2010 or VAX syntax highlighting, I’ve done some heavy customization.)

CUDA Example Program

Hit the run button and away you go. For fun, (and to learn more about Parallel Nsight), try setting a breakpoint in your GPU code and debugging it. :)

9 thoughts on “CUDA Development Environment Setup Under Windows

  1. “Now add a new source file to your project. Let’s call it hello.cu.”
    I don’t understand how to do this. I haven’t used visual studio before.Thanks in advance

  2. OMG! your a life saver!! i spend all of yesterday trying to get this done.. and I did a half-asses job.. But you its perfect! Thank you so much!

  3. thank you sir for your great document. But one problem i am facing that i couldnt find
    HKEY_CURRENT_USER\Software\Whole Tomato\Visual Assist X\VANet10 in my laptop. can u help me about that?

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>