title: Proper use of cudaMalloc3D with cudaMemcpy
body: <p>I'd like to send a 3D array <code>src</code> of size <code>size</code> in each dimension, flattened into a 1D array of size <code>length = size * size * size</code>, into a kernel, compute a result and store it in <code>dst</code>.  However, at the end, <code>dst</code> improperly contains all 0s.  Here is my code:</p>
  
  <pre><code>int size = 256;
  int length = size * size * size;
  int bytes = length * sizeof(float);
  
  // Allocate source and destination arrays on the host and initialize source array
  
  float *src, *dst;
  cudaMallocHost(&amp;src, bytes);
  cudaMallocHost(&amp;dst, bytes);
  for (int i = 0; i &lt; length; i++) {
      src[i] = i;
  }
  
  // Allocate source and destination arrays on the device
  
  struct cudaPitchedPtr srcGPU, dstGPU;
  struct cudaExtent extent = make_cudaExtent(size*sizeof(float), size, size);
  cudaMalloc3D(&amp;srcGPU, extent);
  cudaMalloc3D(&amp;dstGPU, extent);
  
  // Copy to the device, execute kernel, and copy back to the host
  
  cudaMemcpy(srcGPU.ptr, src, bytes, cudaMemcpyHostToDevice);
  myKernel&lt;&lt;&lt;numBlocks, blockSize&gt;&gt;&gt;((float *)srcGPU.ptr, (float *)dstGPU.ptr);
  cudaMemcpy(dst, dstGPU.ptr, bytes, cudaMemcpyDeviceToHost);
  </code></pre>
  
  <p>I've left out my error checking of <code>cudaMallocHost()</code>, <code>cudaMalloc()</code> and <code>cudaMemcpy()</code> for clarity.  No error is triggered by this code in any case.</p>
  
  <p>What is the correct use of <code>cudaMalloc3D()</code> with <code>cudaMemcpy()</code>?</p>
  
  <p>Please let me know if I should post a minimal test case for the kernel as well, or if the problem can be found in the code above.</p>