CUDA编程_HellowGPU
几点心得:
- vs2017写cuda程序,源文件为.cu后缀,头文件为.cuh后缀,且不能在头文件中同时声明和定义函数,必须在源文件里定义
- 使用__global__修饰的函数必须返回空
- 核函数仅支持printf(),不支持std::cout();
#include "cuda_runtime.h"
__global__ void hellow_from_gpu()
{
printf("Hellow from GPU");
}
int main()
{
//此处hellow_from_gpu是一个核函数,一个核函数对应一个GPU网格,一个GPU网格里有多个线程块,一个线程块包含多个线程,此核函数有2*2个线程。
hellow_from_gpu<<<2,2>>>();//会打印4个Hellow from GPU
return 0;
}