Operating Environment:
win7+vs2013+cuda6.5
1. Create a Win32 Empty Project
2. Right-click Project Solution-Build Project Dependencies-Build custom
3. Right-click Project Solutions--Properties---Configuration Properties--general--Platform toolset
Configuration Properties-->vc++ Directory--Include directories, add
$ (Cuda_inc_path)
Connector--general--Additional library directories, adding
$ (Cuda_path)/lib/$ (platformname)
Linker--input-to-attach dependencies, adding
Cudart.lib
Are you sure!
You can now create/use/compile the *.cu file.
4. Right-click the project name, add-new Item-->c++ file--Modify name and suffix =>*.cu
5. Add the following header file to the new file
1 " cuda.h " 2 " cuda_runtime.h " 3 " Device_launch_parameters.h "
6. Create a kernel kernel file, a file that can be executed on the GPU
1#include"cuda.h" 2#include"cuda_runtime.h"3#include"Device_launch_parameters.h"4#include <stdio.h>5 6__global__voidSaxpy (floatAfloat* X_d,float* Y_d,intN)7 {8 if(Threadidx.x <N)9Y_D[THREADIDX.X] = A * x_d[threadidx.x] +y_d[threadidx.x];Ten } One A intMain () - { - intn = -; the floatA =2; - float*x_h, *x_d, *y_h, *Y_d; -X_h = (float*) malloc (n *sizeof(float)); -Y_h = (float*) malloc (n *sizeof(float)); + for(inti =0; I < n; i++) - { +X_h[i] = (float) I; AY_h[i] =1.0; at } -Cudamalloc (&x_d, n *sizeof(float)); -Cudamalloc (&y_d, n *sizeof(float)); -cudamemcpy (X_d, X_h, n *sizeof(float), cudamemcpyhosttodevice); -cudamemcpy (Y_d, Y_h, n *sizeof(float), cudamemcpyhosttodevice); -Saxpy <<<1, ->>>(A, x_d, Y_d, n); incudamemcpy (Y_h, Y_d, n *sizeof(float), cudamemcpydevicetohost); - for(inti =0; I < n; i++) toprintf"%2.1f x[%d] + y[%d] =%f\n", A, I, I, y_h[i]); + Cudafree (x_d); - Cudafree (y_d); the Free (x_h); * Free (y_h); $System"Pause");Panax Notoginseng return 0; -}
7. Start in debug mode and observe the results. To this end.
Self-run File download link
Cuda 6.5 && VS2013 && Win7: Creating Cuda Projects