Click here to Skip to main content
15,169,508 members
Articles / Programming Languages / CUDA
Posted 25 Apr 2011


36 bookmarked

CUDA 3.2 on VS2010 in 9 steps

Rate me:
Please Sign up or sign in to vote.
4.56/5 (14 votes)
11 May 2011CPOL2 min read
Compile and run CUDA 3.2 projects from VS2010 in 9 easy steps


This article is accompanied by somewhat large images to make an easy following. 

In this short article, we will be enjoying entering GPU programming world with nVidia CUDA SDK v3.2. With CUDA, we can
write programs that can run on the graphical processing unit(GPU). 


Programs written as CUDA *.cu files that run in GPU are called kernels. A kernel is a unit of structure that runs parallel on the GPU. Thousands, even millions of threads that the kernel is running on is not uncommon in the GPU world. But to be able to write them, you have to be able to compile them, duh!

Nine Easy Steps  

Follow the steps to create a CUDA 3.2 capable VS2010 project.
Make sure CUDA 3.2 SDK is installed from here, fire up Visual Studio 2010 and... 

1. Create a new Win32 Console Project  

2. Choose 'Empty Project' 

Choose 'Empty Project' setting from new project window. We will add our source files later on. 

3. Add your CU file  

Add a new C++ file with the extension .cu. Files with cu extension are processed with nvcc.exe nvidia compiler driver and are sent to VS2008 C compiler after processing.

4. Check Build Customizations

CUDA SDK setup installs build customizations for VS2010. They are installed in program files\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations. If the selected files are not there, you can download them from my blog: CUDA 3.2 Build Rules

5. Change Platform Toolset

Change Platform Toolset to v90. With CUDA SDK 3.2, VS2010 IDE is supported through custom build targets which in turn use the C/C++ compiler distributed with VS2008. When you are using VS2010 and compiling a CUDA project, using the .NET4 compiler is not supported (yet) by nVidia. So you need to have the C/C++ compiler distributed with VS2008.

 Change toolset for the project from project property page. 

6. Change CU File Type

Change Item Type of the added CU file to CUDA C/C++ from file property page. 

7. Select Build Customization 

Select build customization from Project menu. Check CUDA 3.2. 

8. Add CUDA Libraries 

Add libraries that are used with CUDA run-time. In Project Property Page, add cuda.lib and cudart.lib to
Linker->Input->Additional Dependencies.

9. Compile Your First CUDA Capable Program 

Enter the following code in the cu file and then compile the project. 

#include <stdio.h>
#include <assert.h>
#include <cuda.h>
#include <cuda_runtime.h>
int main( int argc, char** argv )
        float* d_A;
        cudaMalloc( (void**) &d_A, 100 * sizeof(float) );
        cudaFree( d_A );
        return 0;

Points of Interest 

There should be VS2010 project and item templates for CUDA 3.2 in the SDK. Maybe there will be in the future versions.


Initial article. 24.04.2011 - This article is also available at my blog, albeit Turkish: 


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Kerem Kat
Software Developer
Turkey Turkey
No Biography provided

Comments and Discussions

GeneralThanks, Karem Any changes to the above article now that we'... Pin
Merlin Brasil30-Dec-11 4:24
MemberMerlin Brasil30-Dec-11 4:24 
GeneralHey very nice and very precise explanation. Have a look at t... Pin
GPUToaster™6-May-11 20:00
MemberGPUToaster™6-May-11 20:00 
GeneralBuild Rules Pin
Stefan Popov3-May-11 4:15
MemberStefan Popov3-May-11 4:15 
GeneralRe: Build Rules Pin
GPUToaster™10-May-11 0:55
MemberGPUToaster™10-May-11 0:55 
GeneralRe: Build Rules Pin
Kerem Kat10-May-11 3:01
MemberKerem Kat10-May-11 3:01 
GeneralRe: Build Rules Pin
Stefan Popov11-May-11 6:46
MemberStefan Popov11-May-11 6:46 
GeneralRe: Build Rules Pin
Kerem Kat11-May-11 10:09
MemberKerem Kat11-May-11 10:09 
QuestionConfused about toolset version Pin
R. Hoffmann29-Apr-11 11:32
professionalR. Hoffmann29-Apr-11 11:32 
AnswerRe: Confused about toolset version Pin
Kerem Kat29-Apr-11 21:08
MemberKerem Kat29-Apr-11 21:08 
GeneralRe: Confused about toolset version Pin
R. Hoffmann29-Apr-11 22:40
professionalR. Hoffmann29-Apr-11 22:40 
GeneralRe: Confused about toolset version [modified] Pin
Stefan_Lang3-May-11 0:19
mveStefan_Lang3-May-11 0:19 
AnswerRe: Confused about toolset version Pin
Kerem Kat28-Jun-13 5:30
MemberKerem Kat28-Jun-13 5:30 
Actually, it does support the VS2010 IDE but not the compilers that come with VS2010. VS2008 compilers are needed, that's why even if you are using VS2010 IDE, you have to set the platform toolset to v90 (VS2008).

Now that CUDA 5.5 is out, this information might be rendered irrelevant.
GeneralNice! Pin
Amro Ibrahim26-Apr-11 23:46
MemberAmro Ibrahim26-Apr-11 23:46 
GeneralRe: Nice! Pin
Kerem Kat27-Apr-11 6:14
MemberKerem Kat27-Apr-11 6:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.