Cuda 6.5 && VS2013 && Win7: Creating Cuda Projects

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.