我正在用 CUDA 编写一个小程序,但出现以下错误:
contraste.cu(167): error: calling a host function from a __device__/__global__ function is not allowed
我不明白为什么。你能帮我看看我的错误吗?看来我的程序是正确的。这是导致问题的一堆代码:
__global__ void kernel_contraste(float power,
unsigned char tab_in[],
unsigned char tab_out[],
int nbl, int nbc) {
int x = threadIdx.x;
printf("I am the thread %d\n", x);
}
我的主要程序的一部分:
unsigned char *dimg, *dimg_res;
.....
cudaMalloc((void **)dimg, h * w * sizeof(char));
cudaMemcpy(dimg, r.data, h*w*sizeof(char), cudaMemcpyHostToDevice);
cudaMalloc((void **)dimg_res, h*w*sizeof(char));
dim3 nbThreadparBloc(256);
dim3 numblocs(1);
kernel_contraste<<<numblocs, nbThreadparBloc >>>(puissance, dimg, dimg_res, h, w);
cudaThreadSynchronize();
.....
cudaFree(dimg);
cudaFree(dimg_res);
第 167 行是我在函数 kernel_contraste 中调用 printf 的行。
有关信息,该程序将图像作为输入(太阳光栅文件)和功率,然后计算该图像的对比度。
谢谢!!
最佳答案
看Here有关 cuprintf()
的教程。我认为这就是您想要的。
关于c - CUDA 初学者错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4535157/