title: Why does NVENC sample use both cuMemcpyHtoD and cuMemcpy2D to copy YUV data?
body: <p>I am learning <a href="https://developer.nvidia.com/nvidia-video-codec-sdk" rel="nofollow noreferrer">NVIDIA NVENC</a> API.The SDK supplies a sampled called "NvEncoderCudaInterop" .There is a chunk of code which copies YUV plane arrays from CPU to GPU buffers.
  This is the code:</p>
  
  <pre><code> // copy luma
   CUDA_MEMCPY2D copyParam;
  memset(&amp;copyParam, 0, sizeof(copyParam));
  copyParam.dstMemoryType = CU_MEMORYTYPE_DEVICE;
  copyParam.dstDevice = pEncodeBuffer-&gt;stInputBfr.pNV12devPtr;
  copyParam.dstPitch = pEncodeBuffer-&gt;stInputBfr.uNV12Stride;
  copyParam.srcMemoryType = CU_MEMORYTYPE_HOST;
  copyParam.srcHost = yuv[0];
  copyParam.srcPitch = width;
  copyParam.WidthInBytes = width;
  copyParam.Height = height;
  __cu(cuMemcpy2D(&amp;copyParam));
  
  // copy chroma
  
  __cu(cuMemcpyHtoD(m_ChromaDevPtr[0], yuv[1], width*height / 4));
  __cu(cuMemcpyHtoD(m_ChromaDevPtr[1], yuv[2], width*height / 4));
  </code></pre>
  
  <p>I do understand the rationale behind the procedure.The memory is copied to GPU  for the kernel to process it.What I don't understand is why,in order to copy Y plane, cuMemcpy2D is used and for UV <a href="http://developer.download.nvidia.com/compute/cuda/4_1/rel/toolkit/docs/online/group__CUDA__MEM_g4d32266788c440b0220b1a9ba5795169.html" rel="nofollow noreferrer">cuMemcpyHtoD</a>?Why Y can't be copied using cuMemcpyHtoD as well?As far as I understand,YUV planes have the same linear memory layout.The only difference is their size.</p>
  
  <p>PS:I asked this question originally on <a href="https://computergraphics.stackexchange.com/questions/1555/cuda-cumemcpuhtod-vs-cumemcpy2d">Computer Graphics</a> site but got no answers.</p>