【CUDA开发】CUDA面内存拷贝用法总结
标签(空格分隔): 【CUDA开发】
主要是在调试CUDA硬解码并用D3D9或者D3D11显示的时候遇到了一些代码,如下所示:
CUdeviceptr g_pRgba = 0;
CUDA_MEMCPY2D memcpy2D = { 0 };
memcpy2D.srcMemoryType = CU_MEMORYTYPE_DEVICE;
memcpy2D.srcDevice = g_pRgba;
memcpy2D.srcPitch = nWidth * 4;
memcpy2D.dstMemoryType = CU_MEMORYTYPE_ARRAY;
memcpy2D.dstArray = array;
memcpy2D.dstPitch = nWidth * 4;
memcpy2D.WidthInBytes = nWidth * 4;
memcpy2D.Height = nHeight;
// clear the surface to solid white
checkCudaErrors(cuMemcpy2D(&memcpy2D));
将设备内存g_pRgba中的数据拷贝到面内存中;还有另外一种情况:
src GMEM pointer : dpSrc
src GMEM layout : 100x100
dst GMEM pointer : dpDst
dst GMEM layout : 50*50
将src GMEM按行序初始化为:0~9999的值
CUDA_MEMCPY2D planeMem;
memset(&planeMem,0,sizeof(planeMem));
planeMem.srcMemoryType=CU_MEMORYTYPE_DEVICE;
planeMem.srcDevice =dpSrc;
planeMem.srcXInBytes =25*sizeof(float);
planeMem.srcY =25;
planeMem.srcPitch =100*sizeof(float);
planeMem.dstMemoryType=CU_MEMORYTYPE_DEVICE;
planeMem.dstDevice =dpDst;
planeMem.dstXInBytes =0;
planeMem.dstY =0;
planeMem.dstPitch =50*sizeof(float);
planeMem.WidthInBytes =planeMem.dstPitch;
planeMem.Height =50;
cuMemcpy2DUnaligned(&planeMem); //如果数据已经对齐则最好使用cuMemcpy2D,否则必须使用该函数,另外当内存是使用cuMemAllocPitch分配的时候,如果内存布局本事不是2的次幂,则需要将planeMem的srcPitch和dstPitch设置为通过cuMemAllocPitch得到的pitch参数,而不是内存本身的布局大小*sizeof(TYPE)
2017-01-26 23:28
张朋艺 pyZhangBIT2010@126.com