网上的资料讲了不少了,在此,先感谢各位铺路的大牛,偶记录一下测试和遇到的各种问题,同时做一下比较。如有出入,欢迎指正!
二维数据,转一维再传比较好。这句话是我开始探索二维数组传递听到最多的了。
CUDA本身提供的二维数据传递为下面两个函数
cudaMallocPitch()
cudaMemcpy2D()
Library Document里面的原文是这样子的:
http://developer.download.nvidia.com/compute/cuda/4_1/rel/toolkit/docs/online/group__CUDART__MEMORY_g80d689bc903792f906e49be4a0b6d8db.html
cudaError_t cudaMallocPitch( void** devPtr, size_t * pitch, size_t width, size_t height )
Allocates at least width
(in bytes) * height
bytes of linear memory on the device and returns in *devPtr
a pointer to the allocated memory. The function may pad the allocation to ensure that corresponding pointers in any given row will continue to meet the alignment requirements for coalescing as the address is updated from row to row. The pitch returned in *pitch
by cudaMallocPitch() is the width in bytes of the allocation. The intended usage of pitch
is as a separate parameter of the allocation, used to compute addresses within the 2D array. Given the row and column of an array element of typ