title: printf inside CUDA __global__ function
body: <p>I am currently writing a matrix multiplication on a GPU and would like to debug my code, but since I can not use printf inside a device function, is there something else I can do to see what is going on inside that function. This my current function:</p>
  
  <pre><code>__global__ void MatrixMulKernel(Matrix Ad, Matrix Bd, Matrix Xd){
  
      int tx = threadIdx.x;
      int ty = threadIdx.y;
  
      int bx = blockIdx.x;
      int by = blockIdx.y;
  
      float sum = 0;
  
      for( int k = 0; k &lt; Ad.width ; ++k){
          float Melement = Ad.elements[ty * Ad.width + k];
          float Nelement = Bd.elements[k * Bd.width + tx];
          sum += Melement * Nelement;
      }
  
      Xd.elements[ty * Xd.width + tx] = sum;
  }
  </code></pre>
  
  <p>I would love to know if Ad and Bd is what I think it is, and see if that function is actually being called.</p>