Structure in Texture memory on CUDA

痞子三分冷 提交于 2021-02-04 08:28:25

问题


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.

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;

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 ));

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.

Thanks


回答1:


Textures only support CUDA built in types. it is not possible to bind user structures to textures.

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.



来源:https://stackoverflow.com/questions/18831235/structure-in-texture-memory-on-cuda

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!