Thread: CUDA Tutorial
View Single Post
Old 10-14-11, 04:05 PM   #2
ViN86
 
Join Date: Mar 2004
Posts: 15,486
Default Re: Adventures in CUDA on Windows 7 x64

Setup/Installation

When I first started, I had many issues getting code to compile and getting CUDA setup. The runtimes are included in drivers from NVIDIA, but the CUDA SDK and toolkit needs to be downloaded.

You will need these files from the CUDA downloads page: http://developer.nvidia.com/cuda-toolkit-40

CUDA Toolkit (in 32-bit or 64-bit, if you use an express version you must use 32-bit)
CUDA SDK
CUDA Toolkit 4.0 Build Customization BUG Fix (follow instructions inside)
NVIDIA Parallel Nsight (recommended) from http://developer.nvidia.com/nvidia-parallel-nsight (you need to register)

Please note if you decide to use an express version of Visual Studio, you need to use the 32-bit CUDA Toolkit and SDK. For 64-bit, make sure you use the Full option when installing Visual Studio 2008. Furthermore, install the Windows 7 SDK from the following: http://www.microsoft.com/download/en...en&id=3138Also, make sure you follow their guide (link below) as you need the following environmental variables described below.

Hit Start, then right-click on Computer and select properties. Then click Advanced System Settings and select the Advanced tab. Hit the Environmental Variables button. Under User Variables, click New. For installation, check this PDF from NVIDIA: http://developer.download.nvidia.com...tedWindows.pdf. However, use the following variables.

CUDA_BIN_PATH
Set the value to C:\Program Files (x86)\NVIDIA GPU Computing Toolkit\CUDA\v4.0\bin

CUDA_INC_PATH
Set the value to C:\Program Files (x86)\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include

CUDA_LIB_PATH
Set the value to C:\Program Files (x86)\NVIDIA GPU Computing Toolkit\CUDA\v4.0\lib

I recommend using Nsight from NVIDIA (you need to register to download it). But note that it is only compatible with Visual Studio 2008 SP1 and 2010 (not Express versions). You should be able to open project files that are located in C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.0\C\src. Please be sure you open the correct file for your respective version of Visual Studio (2008 or 2010).

You can test the samples they provide which are located in the C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.0\C\bin directory.

Now I wasn't able to get Visual Studio Express versions to recognize the CUDA project type. However, with Visual Studio 2008, I do have a CUDA project option, which creates a basic project you can edit to your liking.

The sample project demonstrates how to add a kernel and it should compile and run a simple matrix addition example. I will be learning more about CUDA as I go, so I will post examples/explanations I come across as I learn them.

It's a lot easier to use the command prompt to compile .cu files. Compiling is quite simple really. The NVIDIA CUDA Toolkit installs the nvcc compiler linker. It's compatible with Visual Studio 8.0 and 9.0 C compilers. If you have Visual Studio 2008 SP1, you can compile a file via the following:
  1. Click Start, then go to Programs, expand the Visual Studio tools folder in the Visual Studio 2008 folder, then open the Visual Studio 2008 x64 Command Prompt (this sets all the necessary variables needed by the compiler cl.exe)
  2. Navigate to your directory where your mysamplecudaprogram.cu file is located (obviously use your own file name, note that Tab auto complete makes life much easier when navigating)
  3. Type the following and hit enter: nvcc mycudaprogram.cu (you can also specify output options and pass other parameters to the compiler, including any include directories containing any headers you may need)
  4. Run the program (which by default is a.exe) by typing the following and pressing Enter: a.exe

This should output your program in the command prompt.

Last edited by ViN86; 10-18-11 at 01:47 AM.
ViN86 is offline