title: Beginner error in CUDA
body: <p>I am writing a small program in CUDA and i have the following errors :</p>
  
  <pre><code>contraste.cu(167): error: calling a host function from a __device__/__global__ function is not allowed
  </code></pre>
  
  <p>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 : </p>
  
  <pre><code> __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);
  
  }
  </code></pre>
  
  <p>Part of my main program :</p>
  
  <pre><code> 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&lt;&lt;&lt;numblocs, nbThreadparBloc &gt;&gt;&gt;(puissance, dimg, dimg_res, h, w);
    cudaThreadSynchronize(); 
    .....
  
  
     cudaFree(dimg);
    cudaFree(dimg_res);
  </code></pre>
  
  <p>The line 167 is the line where i call the printf in function kernel_contraste.</p>
  
  <p>For information, this program takes an image as an input( a sun Rasterfile ) and a power then it calculates the contraste of that image.</p>
  
  <p>Thanks !!</p>