问题
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