3/09/2015

First CUDA tutorial - CUDA toolkit 6.0 + Visual studio 2012 setting and example simple source


You have already installed Visual studio 2012 or other version.
And, you have to install CUDA toolkit, go to the nvidia homepage -> https://developer.nvidia.com/cuda-downloads
Now cuda 6.5 is available.

Don't worry, In this introduction, version is not important.


After install cuda toolkit and Visual studio.
There is two option to start simple cuda project.

One is little bit complex.
Make win32 console project (empty optioni)
set cuda include and lib directory.
set build option
add cuda file
and coding...

See the this video.
https://www.youtube.com/watch?v=i43dUW4E-fE&feature=youtu.be



Another method is using cuda runtime project.
This is very easy.
See the this video.
https://www.youtube.com/watch?v=j2wV4-IiGh4&feature=youtu.be


This is example source code

#include < iostream>
#include "cuda.h"  
#include "cuda_runtime.h"  
#include "device_launch_parameters.h"  

__global__ void add(int a, int b, int*c)
{
 *c = a+b;
}

int main()
{

 int c;
 int *dev_c;
 cudaMalloc( (void**)&dev_c, sizeof(int) );

 add<<< 1,1>>>(2,7, dev_c);

 cudaMemcpy(&c, dev_c, sizeof(int), cudaMemcpyDeviceToHost);

 printf(" 2+7 = %d \n", c);

 cudaFree(dev_c); 

 return 0;

}

As I am cuda beginner, I don't know which method is good.
But I think first method is more useful for adding cuda code into existing project.

And refer to this youtube channel.
https://www.youtube.com/channel/UCBHcMCGaiJhv-ESTcWGJPcw

cudacast playlist will be efficient.

Thank you.

No comments:

Post a Comment