Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cudaArray vs. device pointer

I am confused about the difference between the intended use of device pointers and cudaArray structures. Could someone please explain why I would use one versus the other? My basic problem is that after looking through documentation and reading the book "CUDA by Example," I do not understand the intent of the API designers.

From what I have seen, it seems that cudaArray should be used for textures and pointers should be used for directly accessing memory. It also seems that 3D textures can only be created using a cudaArray. Should all textures be allocated using cudaArray? Numerous examples seem not to. Also, why is there a function cudaMallocArray and cudaMallocArray3D, but no equivalent for cudaMallocArray2D? Conversely, there is a cudaBindTexture and cudaBindTexture2D, but no cudaBindTexture3D?

like image 654
Joe Avatar asked Jan 22 '13 01:01

Joe


1 Answers

cudaArray is an opaque block of memory that is optimized for binding to textures. Textures can use memory stored in a space filling curve, which allows for a better texture cache hit rate due to better 2D spatial locality. Copying data to a cudaArray will cause it to be formatted to such a curve.

So, storing data in a cudaArray is an optimization technique which can yield better texture cache hit rates. On early CUDA architectures, the cudaArray also cannot be accessed by a kernel. However, architectures of compute capability >= 2.0 can access the array via CUDA surfaces.

Determining if you should use a cudaArray or a regular buffer in global memory comes down to the intended usage and access patterns for the memory. It will be project specific.

cudaMallocArray() actually allocates a 2D array, so I think the issue is just inconsistent naming. Maybe it would have been more logical to call it cudaMallocArray2D().

I haven't used 3D textures. Hopefully, someone will answer and let us know why there's no need for cudaBindTexture3D().

like image 172
Roger Dahl Avatar answered Oct 06 '22 11:10

Roger Dahl