Manual for CUDA Development on Windows Zhengjie Lu
[email protected]
Contents Section 1: Preparation .................................................................................................................................. 2 Section 2: GPU Project Setup ........................................................................................................................ 3 Section 3: Programming Environment Setup.............................................................................................. 11 Section 4: GPU File Setup............................................................................................................................ 26
Section 1: Preparation 1.1 1.2 1.3 1.4
Have Microsoft Visual Studio 2008 Express on Microsoft Windows Vista/XP on your laptop. Install CUDA Driver 2.2 on your laptop. Install CUDA Toolkit 2.2 on your laptop. Install CUDA SDK 2.2 on your laptop.
Section 2: GPU Project Setup 2.1 Open Visual Studio 2008 Express, and create a new project, as shown in figure 2.1.
Fig.2.1
2.2 Click “General” in “Project types” catalogue and then select “Empty Project” in “Visual Studio installed templates” catalogue. After doing the two steps, fill in the name of the program and click “OK”. In this example, the program name is “Lab2_GPU” as shown in figure 2.2.
Fig.2.2
2.3 Obtain the .h files, .cpp files, .ppm files and .pgm files from the assignment website, and place them in the project folder. In this case, it is “Lab2_GPU/Lab2_GPU” and it should look like this as shown in figure 2.3.
Fig.2.3
2.4 Right click the “Header Files” icon in the “Solution Explorer” window and select “Add/Existing Item…”. It is shown in figure 2.4.
Fig.2.4
2.5 Choose all the .h files in the pop up file explorer and click “Add”, as shown in figure 2.5.
Fig.2.5
2.6 Right click the “Source Files” icon in the “Solution Explorer” window and select “Add/Existing Item…”, as shown in figure 2.6.
Fig. 2.6
2.7 Choose all the .cpp files in the pop up file explorer and click “Add”, as shown in figure 2.7.
Fig.2.7
2.8 Right now, your “Solution Explorer” should looks like that shown in figure 2.8.
Fig.2.8
Section 3: Programming Environment Setup 3.1 Click the “Tool” menu and then click the “Option” item, as shown in figure 3.1.
Fig.3.1
3.2 Click the item “VC++ Direction” under “Project and Solutions”, and select “Include files” in the “Show directories for:” catalogue. It is shown in figure 3.2.
Fig.3.2
3.3 Add both the CUDA include files path and the CUDA SDK include files path, as shown in figure 3.3.
Fig.3.3
3.4 Click the item “VC++ Direction” under “Project and Solutions”, and select “Library files” in the “Show directories for:” catalogue. It is shown in figure 3.4.
Fig.3.4
3.5 Add both the CUDA library files path and the CUDA SDK library files path, as shown in figure 3.5.
Fig.3.5
3.6 Click the item “VC++ Direction” under “Project and Solutions”, and select “Source files” in the “Show directories for:” catalogue. It is shown in figure 3.6.
Fig. 3.6
3.7 Add the CUDA SDK source files path, as shown in figure 3.7.
Fig.3.7
3.8 Click the item “VC++ Project Setting” under “Project and Solutions”, and append “*.cu” to the item “C/C++ File Extension”. It is shown in figure 3.8.
Fig.3.8
3.9 Click the item “VC++ Project Setting” under “Project and Solutions”, and then fill in the blank “Rule File Searchg Paths” with the path in which the “Cuda.Rules” exists. It is shown in figure 3.9. After finishing these steps, click “OK”.
Fig.3.9
3.10
Click the “Project” menu and choose the “Properties”, as shown in figure 3.10.
Fig.3.10
3.11 Click “Linker” under the “Configuration Properties” and then click the item “General”. Select “NO/(INCREMENTAL:NO)” in “Enable Incremental Linking”. It is shown in figure 3.11.
Fig.3.11
3.12 Click “Linker” under the “Configuration Properties” and then click the item “Input”. Add two libraries “cudart.lib” and “cutil32.lib” into the blank “Additional Dependencies”. After finishing these steps, click “OK” as shown in figure 3.12.
Fig.3.12
3.13 Right click the project “Lab2_GPU” in the “Solution Explorer” window and then choose the item “Custom Build Rules…”, as shown in figure 3.13.
Fig.3.13
3.14 Select “CUDA Build Rule v2.20” in the catalogue “Available Rule Files” and click OK, as shown in figure 3.14.
Fig.3.14
3.15
A warning window would pop up and just click “OK”, as shown in figure 3.15.
Fig.3.15
Section 4: GPU File Setup 4.1 Now you can develop your own program on CPU. To develop your program on GPU, a new file with the postfix .cu should be used. Right click the “Source Files” icon in the “Solution Explorer” window and choose “Add/New Item…” as shown in figure 4.1.
Fig.4.1
4.2 Click “Code” under “Visual C++” and then select “C++ File (.cpp)” in “Visual Studio installed templates”. Give a name to the GPU file, e.g. “GPU.cu” and click “Add”.
Fig.4.2
4.3 Open the file “main.cpp” and include the file “GPU.cu” in it, as shown in figure 4.3. Now you can develop your GPU program codes in “GPU.cu” and invoke them in “main.cpp”.
Fig.4.3