问题描述
我困惑的用途设备指针和 cudaArray
结构之间的差异。可能有人请解释为什么我会用一个与其他?我的基本问题是,翻翻文件和读的书后的示例CUDA,我不明白的API设计者的意图。
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.
这是我所看到的,似乎 cudaArray
应该用于纹理和指针应该用于直接访问内存。这也似乎是3D纹理只能创建使用 cudaArray
。如果所有纹理使用分配 cudaArray
?无数的例子似乎不大。另外,为什么有一个函数 cudaMallocArray
和 cudaMallocArray3D
,但没有类似 cudaMallocArray2D
?相反,有一个 cudaBindTexture
和 cudaBindTexture2D
,但没有 cudaBindTexture3D
?
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
?
推荐答案
cudaArray
是为结合纹理优化的内存块不透明。纹理可以使用存储在一个时,其允许更好的纹理高速缓存的命中率存储器由于更好的2D空间局部性。将数据复制到 cudaArray
将导致它被格式化为这样的曲线。
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.
所以,存储在 cudaArray
是一种优化技术,可以产生更好的纹理缓存命中率的数据。早期CUDA架构中, cudaArray
也不能由内核访问。然而,计算能力的架构> = 2.0可以通过CUDA面访问阵列。
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.
确定是否应使用 cudaArray
或经常在全局内存缓冲区归结于记忆预期的使用情况和访问模式。这将是项目的具体。
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()
实际上分配一个二维数组,所以我觉得这个问题是命名只是不一致。也许这本来是更合乎逻辑称之为 cudaMallocArray2D()
。
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()
.
我没有用3D纹理。希望有人会回答,让我们知道为什么没有必要为 cudaBindTexture3D()
。
I haven't used 3D textures. Hopefully, someone will answer and let us know why there's no need for cudaBindTexture3D()
.
这篇关于cudaArray与设备指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!