我有一个包含两个元素的结构的数组,将其发送到全局内存中的CUDA,然后从全局内存中读取值.
I have an array containing a structure of two elements, that I send to CUDA in global memory, and I read the values from global memory.
当我阅读一些书籍和帖子时,因为我只是从结构中读取值,所以我认为如果可以将数组存储在Texture内存中,我会很有趣.我在内核外部使用了以下代码:
As I read through some books and posts, and as I am only reading values from the structure, I thought i would be interesting if it was possible to store my array in Texture memory. I used the following code outside the kernel :
texture<node, cudaTextureType1D, cudaReadModeElementType> textureNode;和main()中的以下行
and the following lines in main()
gpuErrchk(cudaMemcpy(tree_d, tree, n * sizeof(node), cudaMemcpyHostToDevice)); gpuErrchk(cudaBindTexture( (size_t)0,textureNode, tree_d, n*sizeof(node) ));在我的内核中,我使用了以下内容:
and in my kernel I used the following :
printf("Here %d\n",tex1Dfetch(textureNode, 0 ));但是我确实存在编译错误,通过在第一行中使用节点",但是如果我将它替换为int,它将编译,但是我要指出的是通过使用类似以下内容的方法访问结构数组中的元素:
but I do have a compilation error, by using "node" in the first line however it compiles if I replace it by int but my point would be access elements in my array of structures by using something like :
tree[i].left;我已经尝试了多种方法,但是无法使其正常工作,所以我想知道这是否有可能.
I have tried multiple things, but haven't been able to make it work, so I'm wondering if this is possible.
谢谢
推荐答案纹理仅支持CUDA内置类型.不可能将用户结构绑定到纹理.
Textures only support CUDA built in types. it is not possible to bind user structures to textures.
如果您的结构恰好具有与CUDA内置向量类型相同的大小和对齐方式,则可能会假装它是内置类型并绑定它,但这只是闲置的推测
if you have a structure which happens to have the same size and alignment as a CUDA built-in vector type, it might be possible to pretend it is a built-in type.and bind it, but that is just idle speculation.
更多推荐
CUDA上纹理存储器中的结构
发布评论