CUDA has taken the computing world with storm. This seems a lot exaggerated but this is where all indicators are pointing to. Introduced in late 2006 by NimageVIDIA, CUDA which is short for Compute Unified Device Architecture allows programmers with minimal extra effort to code massively parallel algorithms on GPUs. So why GPU when we have been running the same tasks on CPU for ages now? The answer is pretty simple: Massively parallel tasks run best in parallel and GPU offers upto 512 cores (latest NVIDIA’s card) which means you can run 512*512 = almost quarter of a million threads (of course theoretically) in parallel whereas that’s still a dream for any given CPU.

For those who have already started and facing problems running their CUDA code on Visual Studio 2008 (this applies of the earlier versions too but with minute modifications) here’s a quick starter guide:

What you require:

1) Visual Studio 2008
2) CUDA SDK
3) CUDA Toolkit

The best thing is that you can code and run CUDA apps without CUDA enabled Graphics Card installed but your applications will run on emulator which of course won’t show any improvement from your previously coded sequential code.

Step 1: Adding cuda.rules to your project

Right click on your project –> Custom Build Rules
image

Click on New Rule File and browse to your %CUDA Folder%cuda_build_rule/cuda.rules
image

Step 2: Now setup your BIN, INCLUDE and LIB directories.

Goto Tools –> Options –> Projects and Solutions –> VC++ Directories
image

First, lets specify the INCLUDE directories. Select Include Directories from the “Show Directories for” dropdown menu.

Create a new line by clicking the new file button and specify  %CUDA Directory%include
image

Similarly, select Library files from the dropdown and specify: %CUDA%lib directory
image

Similarly, select Executable files from the dropdown and specify: %CUDA%bin directory
image

Final Step: Specify the CUDA Runtime and CUTIL32D Linkers

Linkers work during compilation when your code is linked to external libraries that you use.

Goto Project –> Properties –> Configuration Properties –> Linker –> Input and specify two few files in the Additional Dependencies field: CUDART.lib and CUTIL32D.lib
image

Now goto Project –> Properties –> Configuration Properties –> Linker –> General and paste this line in the Additional Library Directories field: $(CUDA_LIB_PATH);../../common/lib
image

Alas! You’re done! Now you can try Rebuilding the sample code that comes with CUDA SDK. Simply open the project folder and then  open the .sln file in it to open it in VS08 and then Right click on the project and click Rebuild and run it for yourself!
image

If everything has been properly setup, The Rebuild should be Successful and if not then don’t hesitate to comment on here with your specific problem.

My successful run: (This is my own code not any sample)
image

Note: Kindly specify your CUDA Toolkit version, CUDA SDK Version and your OS in your questions.

P.S: Since CUDA Toolkit version 3.2 the Cuda.rules file is now shipped with the toolkit. In the older versions the rules file was shipped with the SDK and not the Toolkit so you had to download the both to write CUDA programs.