Something More for Research

Explorer of Research #HEMBAD

CUDA Tutorial 04


Getting up and running with CUDA and Visual Studio 2010 under Windows 7

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.

1  Download and install the following ressources in that order:

  1. Microsoft Visual Studio 2010 Professional (or similar)
    consult Windows Update now and get MSVS up-to-date.
  2. CUDA Toolkit 5.0
    https://developer.nvidia.com/cuda-downloads

    • do not install drivers for the GPU device, that is to be done in the next step
    • Sample package is not required, but recommended because of tools which can help during development
    • use the default installation path, otherwise there might be configuration problems later on
  3. (optional) NSight Visual Studio Edition (free registration required)
    https://developer.nvidia.com/rdp/nsight-visual-studio-edition-downloads
  4. Install the latest drivers for your CUDA device
    http://www.geforce.com/drivers

2  Setting up MSVS

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.

3  Create your first CUDA project

  1. Start MSVS (choose C++ enviroment if asked)
  2. Open new blank project:File → New → Project… → Empty Project → Enter “Tutorial01W” as name → Hit “OK”
  3. ActivateCUDA build customization:Right-click on project “Tutorial01W” → Build Customizations… → Check CUDA 5.0 → Hit “OK”
  4. Add host part of the program: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

    #include extern void cuda_doStuff(void); int main( int argc, const char* argv[] ) { cuda_doStuff(); }
  5. AddCUDA part of the program: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

    #include #include #include __global__ void someKernel(int N) { int idx = blockIdx.x*blockDim.x + threadIdx.x; if (idx<n) printf(“hello=”” from=”” thread=”” #=”” %i=”” (block=”” #:=”” %i)\n”,=”” idx,=”” blockidx.x);=”” }=”” extern=”” void=”” cuda_dostuff(void)=”” {=”” int=”” numberofblocks=”2;” threadsperblock=”5;” maxnumberofthreads=”10;” somekernel<<<numberofblocks,=””>>>(maxNumberOfThreads); cudaDeviceSynchronize(); }
  6. Adjust the compute capability according to your device. See, e.g.,
    http://en.wikipedia.org/wiki/CUDA for a detailed list of supportedCUDA devices (for theGTX 480, choose compute capability 2.0, forGTX Titan choose 3.5, or below). This tutorial requires at least compute capability 2.0.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”.

  7. Add Library LinksRight-click project “Tutorial01W” → Properties → Linker → Input → Add cuda.lib and cudart.lib to “Additional Dependencies”
  8. Compile the program by pressing F7
  9. Run the program by opening a command window and navigating to the Debug folder of your project. Type “Tutorial01W” and hit enter (you might as well run it from inside MSVS, but that window vanishes very fast so you won’t see much). Congratulations, you have programmed and executed your first CUDA program.

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

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Extracts from a Personal Diary

dedicated to the life of a silent girl who eventually learnt to open up

Num3ri v 2.0

I miei numeri - seconda versione

ThuyDX

Just another WordPress.com site

Algunos Intereses de Abraham Zamudio Chauca

Matematica, Linux , Programacion Serial , Programacion Paralela (CPU - GPU) , Cluster de Computadores , Software Cientifico

josephdung

thoughts...

Tech_Raj

A great WordPress.com site

Travel tips

Travel tips

Experience the real life.....!!!

Shurwaat achi honi chahiye ...

Ronzii's Blog

Just your average geek's blog

Karan Jitendra Thakkar

Everything I think. Everything I do. Right here.

VentureBeat

News About Tech, Money and Innovation

Chetan Solanki

Helpful to u, if u need it.....

ScreenCrush

Explorer of Research #HEMBAD

managedCUDA

Explorer of Research #HEMBAD

siddheshsathe

A great WordPress.com site

Ari's

This is My Space so Dont Mess With IT !!

%d bloggers like this: