Parallel Computing using the GPU – Tutorial 3: Integrate CUDA 3.2 into Visual Studio 2008


Now that CUDA Toolkit 3.2 was released, the integration with Visual Studio 2008 is a lot easier than before. In this tutorial, we will see how we can create a CUDA application using Visual Studio 2008!


Getting the free version of Visual Studio 2008

Visual C++ 2008 Express is free to download and use, so if you don’t have Visual Studio 2008 and don’t want to buy it, start by downloading it from here:

When the page is loaded, click the Visual Studio 2008 Express link (so you won’t download VS2010, which is not yet supported):

And from the list, select Visual C++ 2008 Express Edition and click Free Download (80mb):

The installation process might take a while.

CUDA in Visual Studio 2008

Start Visual Studio 2008 and create a new Win32 Console Application (C++) project:

Give it a name, like “CUDAinVS2008”, and click OK. The Win32 Application Wizard will start, click “Next >”. On the next screen, set this to be an Empty project and click Finish:

Next, lets add a .cu file and write a simple CUDA application that we will compile.

Right click on the Project and select Add->New Item…:


Now, you get the “Add New Item” screen. Select the C++ File(.cpp) and name it “”. You can name this anything you want, but remember to give it the surname .cu. If not, you can also rename the file by right clicking the .cpp file in the project tree and select Rename.

Click Add to add the new cu file to our project.

The file should now be opened (blank file), but if now, simply double click it to open it in the editor.
Let’s type in a really simple CUDA C program:

int main(void)
        return 0;

Right now, Visual Studio doesn’t recognize the .cu file, so it’s not possible to compile this. To overcome this, CUDA comes with some custom rules that we can apply to our project. Right click the project and select Custom Build Rules…:

A new dialogue pops up, click “Find Existing…” and browse to the \extras\visual_studio_integration\rules-folder in your CUDA installation directory. On my system, this is located here:
C:\Program Files (x86)\NVIDIA GPU Computing Toolkit\CUDA\v3.2\extras\visual_studio_integration\rules.

From here, select NvCudaDriverApi.v3.2.rules and click Open, do the same again to addthe NvCudaRuntimeApi.v3.2.rules. Next, select these two from the Custom Build Rule File dialogue and press OK.


Now that we set the custom build rule to include the CUDA rules, we just need to include the CUDA library in our project, so we get the CUDA functionality!

Again, right click the project and select Properties.


From the Properties window, select Configuration Properties>Linker>General:

On the Additional Library Directory, add the path to the lib folder in your CUDA installation:
C:\Program Files (x86)\NVIDIA GPU Computing Toolkit\CUDA\v3.2\lib\Win32

Next, select Configuration Properties>Linker>Input and add “cudart.lib” in the Additional Dependencies property:


Next, click OK.

Now, the project should be ready for compiling CUDA C projects. Try to compile it and run the application (press image). You should see it compile, and then the console windows flashes. This is because the application starts and then quits as that’s what we programmed our application to do.

But, we got CUDA running from Visual Studio 2008! Now I suggest creating a new project and doing these steps so you remember it, it might seem a lot but it usually just take a few seconds to set up.

This entry was posted in CUDA, Parallel Computing, Tutorial. Bookmark the permalink.

24 Responses to Parallel Computing using the GPU – Tutorial 3: Integrate CUDA 3.2 into Visual Studio 2008

  1. Pingback: Windows Client Developer Roundup 053 for 1/6/2011 - Pete Brown's

  2. Adam says:

    Thanks for the tips! I was having trouble getting this to work with Visual Studio 2010. Going to use Visual C++ 2008 Express as you outlined here.

  3. digitalerr0r says:

    Good that it worked. Please tell me if you get it working in VS2010 🙂

    • Trent says:

      I agree with digital error.

      It seems VS2010 does not like those build customization files you mention.
      Upon clicking “Build Customizations,” there are two already available, but not the ones you mention.

      CUDA 3.1(targets, .props) and CUDA 3.2(targets, .props) .

      When you try to add the .rules files, an unknown error pops up.

      I also did the other steps after this one, but I still get a “1 unresolved externals” error.

  4. Trent says:

    Maybe it does not function in VS2010 because I notice VS2010 wants files with the .target extension while the files you mention have the .rules extension

    After doing some search it seems MS changed these to .target files.
    Will have to look up to see is nVidia made some new ones for VS2010

    If there was already a project solution made, VS2010 would have converted it….maybe

  5. Trent says:

    nVidia gives details on VS2010 how to build a project from scratch.

    • Trent says:

      Oh, as a side note…what the directions fail to mention is the compile will still fail because you still need VS2008 or Windows SDK on your box because VS2010 still wants to use the v90 toolset to compile the CUDA code. VS2010 has v100

    • Trent says:

      This could be now moot since they released version 4 of CUDA. I have not had the time to check if it is fully VS2010 compatable.

  6. Smokey says:

    Oh! Thanks a million for the website. It works! This one should have popped to the top of Google search result.

  7. IonRa says:

    Thank you, very much.

  8. Jackie says:

    thank you, very much.^^

  9. John says:

    Which operating system was this guide run on? If it’s 32 bit windows, what do we change for 64 bit Vista?

  10. Authentic says:

    Welcome to a Facebook Page about mine,I’ve learned a lot from your blog here,Keep on going,my friend,I will keep an eye on it,One more thing,thanks for your post!.

  11. A B-D. says:

    cudart.lib does not appear as you write it above (CUDA 4.0)

  12. Trent says:

    nVidia’s Parallel Nsight integrates right into Visual Studio 2010, which allows you to go right into making a project without the need for doing all these adustments.

  13. vinie says:

    Man, i really thank you so much! Its saved my life.

    WORKS in VS2008 EXPRESS!


  14. Trying on and off for the last 6 months. Finally got it running. Could you please provide some additional projects as a practice or if you know of some links. Your tutorial is really great !!

  15. Ankit Saini says:

    Thanks a lot friend!… u saved a lot of time….

Leave a Reply

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

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

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.