Dimitri
Dimitri

Reputation: 8280

Beginner error in CUDA

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 !!

Upvotes: 1

Views: 1192

Answers (3)

EnabrenTane
EnabrenTane

Reputation: 7466

look Here for a tutorial on cuprintf(). I think its what you want.

Upvotes: 3

Steve Fallows
Steve Fallows

Reputation: 6424

As the error message says you cannot call a host function (printf in this case) from a kernel function that runs on the GPU.

Upvotes: 2

Anycorn
Anycorn

Reputation: 51465

you are trying to call printf from gpu device. You have to have Fermi card to do that...

Upvotes: 2

Related Questions