Beginner error in CUDA

Posted by Dimitri on Stack Overflow See other posts from Stack Overflow or by Dimitri
Published on 2010-12-26T19:42:18Z Indexed on 2010/12/26 19:53 UTC
Read the original article Hit count: 174

Filed under:
|
|

Hi folks, first all i want to wish you a merry christmas. I am writing a small program in CUDA and i have the following errors :

contraste.cu(167): error: calling a host function from a __device__/__global__ function is not allowed

I don't understand why. Can you please help me and show me my errors. It seems that my program is correct. Here is a the bunch of code causing the problems :

 __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);

}

Part of my main program :

 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);

The line 167 is the line where i call the printf in function kernel_contraste.

For information, this program takes an image as an input( a sun Rasterfile ) and a power then it calculates the contraste of that image.

Thanks !!

© Stack Overflow or respective owner

Related posts about c

    Related posts about cuda