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

查看:24
本文介绍了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.

当我阅读一些书籍和帖子时,并且我只是从结构中读取值,我认为如果可以将我的数组存储在纹理内存中,我会很有趣.我在内核之外使用了以下代码:

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
",tex1Dfetch(textureNode, 0 ));

但我确实有一个编译错误,通过在第一行中使用node"但是如果我用 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天全站免登陆