title: cudaMallocPitch and cudaMemcpy2D
body: <p>I have an error when transfering C++ 2D array into CUDA 1D array.
  Let me show my source code.</p>
  
  <pre><code>int main(void)
  {
        float h_arr[1024][256];
        float *d_arr;
  
        // --- Some codes to populate h_arr
  
        // --- cudaMallocPitch
        size_t pitch;
        cudaMallocPitch((void**)&amp;d_arr, &amp;pitch, 256, 1024);
  
        // --- Copy array to device
        cudaMemcpy2D(d_arr, pitch, h_arr, 256, 256, 1024, cudaMemcpyHostToDevice);
  }
  </code></pre>
  
  <p>I tried to run the code, but it pops up an error.</p>
  
  <p>How to use <code>cudaMallocPitch()</code> and <code>cudaMemcpy2D()</code> properly?</p>