code:
#include <stdio.h>
__global__ void helloCUDA(float f)
{
printf("Hello thread %d, f=%f\n", threadIdx.x, f);
}
int main()
{
helloCUDA<<<1, 5>>>(1.2345f);
cudaDeviceReset();
return 0;
}
设置:
打开vs项目属性图,将code generation设置为compute_20,sm_20。否则,报如下错误:calling a __host__ function("printf") from a __global__ function("kk") is not allowed
本文详细介绍了如何使用CUDA进行GPU并行计算,包括设置VS项目属性、编写CUDA代码及注意事项,旨在帮助开发者掌握CUDA编程技巧。
2937

被折叠的 条评论
为什么被折叠?



