CUDA Tutorial 01 - Windows |
This tutorial is meant to get you up and running with the CUDA computing platform utilizing Microsoft Visual Studio under Windows. Nothing useful will be computed, but the steps necessary to start any meaningful project are explained in detail.
This tutorial has been tested with Windows 7 64bit and Microsoft Visual Studio (MSVS) 2010 Professional, because the optional NSight Debugger only works with MSVS 2010 and 2008 releases. However, CUDA functionality should be possible with MSVS 2008 or newer or even the free Microsoft Visual C++ and the procedure is similar to the one described here.
In order to obtain syntax highlighting for CUDA, navigate to
C
:\
ProgramData
\
NVIDIA
Corporation
\
CUDA
Samples
\
v5
.0\
doc
\
syntax_highlighting
\
visual_studio_8
and append the contents of usertype.dat to the one in
C
:\
Program
Files
\
Microsoft
Visual
Studio
10.0\
Common7
\
IDE
.
If there is none, simply copy the file from the CUDA folder in there.
File → New → Project... → Empty Project → Enter “Tutorial01W” as name → Hit “OK”
Right-click on project “Tutorial01W” → Build Customizations... → Check CUDA 5.0 → Hit “OK”
Right-click on “Source Files” → Add → New Item → C++ File (.cpp) → Enter “main.cpp” as name → Hit “Add”
Enter or copy-and-paste the following source code
Right-click on “Source Files” → Add → under “Installed Templates”, choose NVIDIA→CUDA → CUDA C/C++ File → Enter “cuda_wrapper.cu” as name → Hit “Add”
Enter or copy-and-paste the following source code
Right-click on project “Tutorial01W” → Properties → CUDA C/C++ → Device → Enter compute_x.x, sm_x.x under “Code Generation” and adjust x.x accordingly
While you are already there, change “Verbose PTXAS Output” to “Yes”. This will give some very useful information while compiling your kernels.
Acknowledge by hitting “OK”.
Right-click project “Tutorial01W” → Properties → Linker → Input → Add cuda.lib and cudart.lib to “Additional Dependencies”
Some notes: The printf-command is a host function, that has been added to the CUDA enviroment to help debug programs. Of course data has to be transfered back to the host in order to put it out in the console. It should therefore not be used in any purposeful context, as it probaly slows down computation time significantly
This document was translated from LATEX by HEVEA.