Lesson 1 Hello World
来源:互联网 发布:竞价推广账户优化 编辑:程序博客网 时间:2024/05/16 03:15
1.准备好nvcc
装好CUDA后,我们在cmd里面运行
nvcc --version
如果找不到nvcc命令的话,需要自己在环境变量中path添加nvcc.exe的路径
2.接下来需要编写我们的cuda程序
//filename: helloworld.cu// This is the REAL "hello world" for CUDA!// It takes the string "Hello ", prints it, then passes it to CUDA with an array// of offsets. Then the offsets are added in parallel to produce the string "World!"// By Seamanj 04/11/2015 @NCCA #include <stdio.h>const int N = 7;const int blocksize = 7;__global__void hello(char *a, int *b){ printf("block %d thread %d is running!\n", blockIdx.x, threadIdx.x); a[threadIdx.x] += b[threadIdx.x];}int main(){ char a[N] = "Hello "; int b[N] = {15, 10, 6, 0, -11, 1, 0}; char *ad; int *bd; const int csize = N*sizeof(char); const int isize = N*sizeof(int); printf("%s\n", a); cudaMalloc( (void**)&ad, csize ); cudaMalloc( (void**)&bd, isize ); cudaMemcpy( ad, a, csize, cudaMemcpyHostToDevice ); cudaMemcpy( bd, b, isize, cudaMemcpyHostToDevice ); dim3 dimBlock( blocksize, 1 ); dim3 dimGrid( 1, 1 ); hello<<<dimGrid, dimBlock>>>(ad, bd); cudaMemcpy( a, ad, csize, cudaMemcpyDeviceToHost ); cudaFree( ad ); printf("%s\n", a); return EXIT_SUCCESS;}
3.编译helloworld.cu程序
在cmd中转到我们需要编译的文件夹中
输入 nvcc helloworld.cu
结果如下:
哇,坑爹的warning怎么去掉呢?
加选项, -Xcompiler /wd4819
变成
nvcc -Xcompiler /wd4819 helloworld.cu
具体的选项可以参见http://blog.csdn.net/seamanj/article/details/49652649这篇文章里面的pro文件
或者查看官方文档http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/#axzz3qY6vaFLz
由于没有指定输出名字,所以都命令为a.
执行a.exe看看
0 0
- Lesson 1 Hello World
- 从零开始学JAVA - Hello World-Lesson 1
- Lesson: The "Hello World!" Application
- 1-1 Hello World!
- Ext2.1 Hello World.
- 深入浅出Hello World 1
- 1.9.1 Hello,World!
- Hello World 1
- 1、Hello World
- Hello World @Sep 1
- C++(1) Hello world!
- linux hello world 1
- (1)Hello World
- 1、 hello world
- L1-1 Hello World
- mex 1 hello,world
- 1、Hello world
- android(hello world)-1
- poj1577
- 顺序容器--添加及访问元素
- 如何使用标准的java方式获得日期
- npm发布属于自己的开源模块
- 计算机视觉、模式识别学习资源整理
- Lesson 1 Hello World
- js中的数字如何四舍五入
- java多线程之死锁
- Leetcode #200 Number of Islands
- Esri 面试
- exp 使用 sysdba方式
- javascript事件冒泡、捕获及阻止方法终极解答
- CSS中cursor属性汇总
- 什么是CGI、FastCGI、PHP-CGI、PHP-FPM、Spawn-FCGI?