cuda上使用printf函数

来源:互联网 发布:淘宝食品如何备案 编辑:程序博客网 时间:2024/06/06 12:55

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

0 0
原创粉丝点击