1.1
通过__global__ 关键字,定义kernel函数,用GPU输出printf
#include <stdio.h>
__global__ void hellofromgpu(void)
{
printf("hello world from gpu\n");
}
int main(void)
{
printf("hello world from cpu\n");
hellofromgpu<<<1,10>>>();
cudaDeviceReset();
return 0;
}
输出
hello world from cpu
hello world from gpu
hello world from gpu
hello world from gpu
hello world from gpu
hello world from gpu
hello world from gpu
hello world from gpu
hello world from gpu
hello world from gpu
hello world from gpu
习题:
2.移除cudaDeviceReset(); 编译,执行没有看到变化
3. cudaDeviceReset(); 替换成cudaDeviceSynchronize(); 未见变化