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