Click here to Skip to main content
15,867,308 members
Articles / Programming Languages / CUDA
Tip/Trick

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 70.2K   36   14
Compile and run CUDA 3.2 projects from VS2010 in 9 easy steps

Introduction


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). 


Background 


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. 


C++
#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.


History 



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

License

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


Written By
Software Developer
Turkey Turkey
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralThanks, Karem Any changes to the above article now that we'... Pin
Merlin Brasil30-Dec-11 3:24
Merlin Brasil30-Dec-11 3:24 
GeneralHey very nice and very precise explanation. Have a look at t... Pin
GPUToaster™6-May-11 19:00
GPUToaster™6-May-11 19:00 
GeneralBuild Rules Pin
Stefan Popov3-May-11 3:15
Stefan Popov3-May-11 3:15 
GeneralRe: Build Rules Pin
GPUToaster™9-May-11 23:55
GPUToaster™9-May-11 23:55 
GeneralRe: Build Rules Pin
Kerem Kat10-May-11 2:01
Kerem Kat10-May-11 2:01 
GeneralRe: Build Rules Pin
Stefan Popov11-May-11 5:46
Stefan Popov11-May-11 5:46 
GeneralRe: Build Rules Pin
Kerem Kat11-May-11 9:09
Kerem Kat11-May-11 9:09 
QuestionConfused about toolset version Pin
R. Hoffmann29-Apr-11 10:32
professionalR. Hoffmann29-Apr-11 10:32 
AnswerRe: Confused about toolset version Pin
Kerem Kat29-Apr-11 20:08
Kerem Kat29-Apr-11 20:08 
GeneralRe: Confused about toolset version Pin
R. Hoffmann29-Apr-11 21:40
professionalR. Hoffmann29-Apr-11 21:40 
Aha, thanks!
GeneralRe: Confused about toolset version [modified] Pin
Stefan_Lang2-May-11 23:19
Stefan_Lang2-May-11 23:19 
AnswerRe: Confused about toolset version Pin
Kerem Kat28-Jun-13 4:30
Kerem Kat28-Jun-13 4:30 
GeneralNice! Pin
Amro Ibrahim26-Apr-11 22:46
Amro Ibrahim26-Apr-11 22:46 
GeneralRe: Nice! Pin
Kerem Kat27-Apr-11 5:14
Kerem Kat27-Apr-11 5: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.