CUDA 5.0 and Visual Studio 2012 Configuration

Note that CUDA 5.5 fully supports Visual Studio 2012..

I will explain in this article how to set your environment in order to successfully write and run CUDA 5 programs with Visual Studio 2012. It takes time to figure out how to get it done and there is very little information on the internet, so hopefully, I will make life a little easier for some of you. When you study GPGPU programming it helps to understand cross-platform programming paradigms and technologies, such as AMP, CUDA, OpenCL, and DirectCompute because all of them target the same hardware and consequently have similar limitations.

Prerequisites for the attached project are CUDA 5.0, NSight 3.0 RC1, Visual Studio 2012. The code is extremely simple (just under 100 lines in one file) and serves more to give you a complete configured Visual Studio custom project that works. You can build on it.

The main idea in parallel programming is to write code as if you were writing a program that will execute on one thread only, then specifying that you want to run that program simultaneously on as many threads as necessary.

Start with installing CUDA 5.0 and NSight software. You can download everything from the following links:

NVIDIA CUDA Getting Started Guide for Microsoft Windows

CUDA Zone

Nsight Visual Studio

You have to be registered with NVidia to install the software.

Please read the rest as well as access the code on MSDN here.

12 comments

  1. Thanks for your notes on this. It is very helpful. However, I produced the following error:

    Error: The project file could not be loaded. Name cannot begin with the ‘$’ character, hexadecimal value 0x24. Line 626, position 35. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\BuildCustomizations\CUDA 5.0.targets

    Do you have any suggestions on why this may be?

    1. I found that using a single quote, rather than double quotes on the following line solved my problem:
      CommandLineTemplate=”‘$(CudaToolkitNvccPath)’ %(CudaCompile.BuildCommandLineTemplate) %(CudaCompile.ApiCommandLineTemplate) %(CudaCompile.CleanCommandLineTemplate)”

  2. Great! You figured that out before I could reply. I should have uploaded configuration files. I’ll try to do that.

    1. I may have spoken too soon. Before that change, the project file would load because of the formatting error in the targets file. Now I got past that, but the project does not seem to recognize that I’m trying to compile CUDA code… even though the file is named souce.cu, and “CUDA 5.0” is checked in the Build Customizations menu. My code fails to compile with this output:

      >—— Build started: Project: cubeKernel, Configuration: Debug x64 ——
      1>Build started 2/28/2013 2:39:02 PM.
      1>InitializeBuildStatus:
      1> Touching “x64\Debug\cubeKernel.unsuccessfulbuild”.
      1>ClCompile:
      1> Source.cu
      1>Source.cu(5): error C2144: syntax error : ‘void’ should be preceded by ‘;’
      etc…

      where line (5) is: __global__ void saxpy(int n, float a, float *x, float *y)

      so it is not recognizing __global__. I can get a result using nvcc on the command line, but that is less ideal.

      Thanks for replying!

  3. It says saxpy in your printout, I did not include that sample with cubeKernel: where line (5) is: __global__ void saxpy(int n, float a, float *x, float *y). Start very simple, remove all code but main and headers, re-run several times adding a little at a time. Make sure your environment variables are set correctly, check project and cu file properties. Probably start from scratch and go through the setup one more time. Also, after installing NVidia CUDA SDK, run samples from the sample browser. Exclude your own errors in configuring your machine.

  4. Jules Bushell · · Reply

    Hi Alan,

    Does this work with Nsight 3.0 RC2? And does debugging the CUDA code then work with Nsight?

    Thanks for any reply,
    Jules

  5. I have not installed RC2 yet. From what I hear, it works the same way to described here. It does not provide intellisense, debugging, or project templates. Not yet. But it works.

  6. OK, started installing it and the first observation is that RC2 requires 301.42 win7/vista driver. Latest available driver from NVidia for my card is 311.35 win8/win7 driver. Sounds like NVidia is not integrating with VS2012 just yet.

  7. guglielmo · · Reply

    I think I set up everything correctly but that’s what I got :

    LINK : fatal error LNK1181: cannot open input file ‘Debug\Program.cu.obj’

    Seems it’s compiling correctly but there’s no .obj! And no errors in no log.
    I don’t know what to investigate.

  8. This could be that your PATH environment variables point to incorrect bitness libraries. I provided instructions for 64-bit compilation only. Open program.cu file properties and click on Common Output, is that what you see there: $(IntDir)%(Filename)%(Extension).obj? I have seen that error before but I do not remember how to reproduce it. I believe it is environment/bitness related, but I just do not remember.

    Start with a blank solution, modify include and lib path for the project (be careful with the platform, i.e. 32- or 64-bit path), change build customizations, add blank program.cu file and under file properties change compiler to CUDA/C++, add empty main function and build.

    Let me know what happens.

    Also, can you run CUDA SDK samples? Do not build, just run..

  9. Haitao Fan · · Reply

    Hi, Allan:

    Can you tell us how to enable intellisense in .cu files in VS 2010 for CUDA 5.5?

  10. Haitao, sorry, I have not touched VS 2010 since 2012 came out, I do not remember.. Try to upgrade to the latest environment. 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: