CUDA上纹理存储器中的结构 [英] Structure in Texture memory on CUDA

查看:102
本文介绍了CUDA上纹理存储器中的结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含两个元素的结构的数组,将其发送到全局内存中的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上纹理存储器中的结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆