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:
The installation process might take a while.
CUDA in Visual Studio 2008
Next, lets add a .cu file and write a simple CUDA application that we will compile.
Now, you get the “Add New Item” screen. Select the C++ File(.cpp) and name it “CUDAinVs2008.cu”. 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.
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:
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.
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 ). 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.