title: CUDA "Unknown error" for unknown reasons
body: <p>In my current project, a call to <code>cudaGetLastError()</code> is returning <code>unknown error</code> and I don't know why. The code compiles just fine, but it is not behaving how I would like it to.</p>
  
  <p>Below is a brief, <em>not</em> compilable example of what the relevant code consists of:</p>
  
  <h2>CU_Main.cu</h2>
  
  <h3>Below is the CUDA kernel:</h3>
  
  <pre><code>//My CUDA kernel
  __global__ void CU_KernelTest(Kernel* matrix){
      int idx = blockIdx.x * blockDim.x + threadIdx.x;  
      int idy = blockIdx.y * blockDim.y + threadIdx.y;  
  
      if(idx == 0 &amp;&amp; idy == 0){
              printf("ID is: %d\n", idx);
              matrix-&gt;set(1,1, 16.0f);
      }
  }
  </code></pre>
  
  <h3>Here is the host code:</h3>
  
  <pre><code>//A host function which is called when a button is clicked
  int HOST_OnbuttonClick(){
      Kernel* matrix = new Kernel(3,3,2);
      Kernel* device_matrix;
  
      cudaMalloc(&amp;device_matrix, sizeof(Kernel));
      cudaMemcpy(device_matrix, matrix, sizeof(Kernel), cudaMemcpyHostToDevice);
  
      CU_KernelTest&lt;&lt;&lt;256, 256&gt;&gt;&gt;(device_matrix);
      cudaDeviceSynchronize();
  
      cudaError_t err = cudaGetLastError();
      if (err != cudaSuccess) {
          printf("Error: %s\n", cudaGetErrorString(err));
      }
  
  
      cudaFree(device_matrix);
      return 0.0f;
  }
  </code></pre>
  
  <p>When <code>matrix-&gt;set(1,1, 16.0f);</code> is included in the cuda kernel, <code>(err != cudaSuccess)</code> returns true and prints out <code>UNKNOWN ERROR</code>, whereas if I comment <code>set</code> out, i get no error.</p>
  
  <p>The other <code>struct</code> relevant to this is my own helper for a convolution kernel design I'm going for, naturally called <code>Kernel</code>.</p>
  
  <h2>Kernel.cuh</h2>
  
  <pre><code>struct Kernel {
      private :
          float* kernel;
          int rows;
          int columns;
  
      public :
  
          __device__ __host__
          Kernel(int _rows, int _columns, float _default) {
              rows = _rows;
              columns = _columns;
              kernel = new float[rows * columns];
  
              for(int r = 0; r &lt; rows; r++){
                  for(int c = 0; c &lt; columns; c++){
                      kernel[r * rows + c] = _default;
                  }
              }
          }
  
          __device__ __host__
          void set(int row, int col, float value){
              kernel[row * rows + col] = value;
          }
  }
  </code></pre>
  
  <p>The goal of this design is to be able to set all values for the kernel on the host, send it to the CUDA kernel, set values there and then retrieve the updated object back at the host.</p>
  
  <p>So, there are two issues really, why would I get an <code>unknown error</code> message, and is the code syntactically correct that it should work?
  Let me know if more information is needed.</p>
  
  <h3>Here are the results of the memory checker:</h3>
  
  <pre><code>Nsight Debug
  ================================================================================
  CUDA Memory Checker detected 1 threads caused an access violation:
  Launch Parameters
      CUcontext    = 071c7340
      CUstream     = 08f3e3b8
      CUmodule     = 08fa97a8
      CUfunction   = 08fdbbe8
      FunctionName = _Z13CU_KernelTestP6Kernel
      gridDim      = {1,1,1}
      blockDim     = {256,1,1}
      sharedSize   = 128
      Parameters:
          matrix = 0x06b60000  {kernel = 0x07a31718  ???, rows = 3, columns = 3}
      Parameters (raw):
           0x06b60000
  GPU State:
     Address  Size      Type  Mem       Block  Thread         blockIdx  threadIdx      PC  Source
  -----------------------------------------------------------------------------------------------
    07a31728     4    adr st    g           0       0          {0,0,0}    {0,0,0}  000260  c:\users
  
  Summary of access violations:
  c:\users....kernel.cuh(26): error MemoryChecker: #misaligned=0  #invalidAddress=2
  </code></pre>