将纹理内存绑定到 GPU 分配的矩阵

发布于 2024-11-27 01:38:20 字数 1071 浏览 2 评论 0原文

我在 GPU 上创建了一个大小为 (p7P_NXSTATES)x(p7P_NXTRANS) 的浮点矩阵,如下所示:

// Special Transitions
// Host pointer to array of device pointers
float **tmp_xsc = (float**)(malloc(p7P_NXSTATES * sizeof(float*)));
// For every alphabet in scoring profile...
for(i = 0; i < p7P_NXSTATES; i++)
{
    // Allocate memory for device for every alphabet letter in protein sequence
    cudaMalloc((void**)&(tmp_xsc[i]), p7P_NXTRANS * sizeof(float));
    // Copy over arrays
    cudaMemcpy(tmp_xsc[i], gm.xsc[i], p7P_NXTRANS * sizeof(float), cudaMemcpyHostToDevice);
}
// Copy device pointers to array of device pointers on GPU (matrix)
float **dev_xsc;
cudaMalloc((void***)&dev_xsc, p7P_NXSTATES * sizeof(float*));
cudaMemcpy(dev_xsc, tmp_xsc, p7P_NXSTATES * sizeof(float*), cudaMemcpyHostToDevice);

该内存一旦复制到 GPU,就永远不会更改,只能读取。因此,我决定将其绑定到纹理内存。问题是,当使用 2D 纹理内存时,绑定到它的内存实际上只是一个使用偏移量充当矩阵的数组。

我知道我需要使用 cudaBindTexture2D() 和 cudaCreateChannelDesc() 绑定此 2D 内存才能访问它

tex2D(texXSC,x,y)

- 但我只是不知道如何。有什么想法吗?

I created a float point matrix on the GPU of size (p7P_NXSTATES)x(p7P_NXTRANS) like so:

// Special Transitions
// Host pointer to array of device pointers
float **tmp_xsc = (float**)(malloc(p7P_NXSTATES * sizeof(float*)));
// For every alphabet in scoring profile...
for(i = 0; i < p7P_NXSTATES; i++)
{
    // Allocate memory for device for every alphabet letter in protein sequence
    cudaMalloc((void**)&(tmp_xsc[i]), p7P_NXTRANS * sizeof(float));
    // Copy over arrays
    cudaMemcpy(tmp_xsc[i], gm.xsc[i], p7P_NXTRANS * sizeof(float), cudaMemcpyHostToDevice);
}
// Copy device pointers to array of device pointers on GPU (matrix)
float **dev_xsc;
cudaMalloc((void***)&dev_xsc, p7P_NXSTATES * sizeof(float*));
cudaMemcpy(dev_xsc, tmp_xsc, p7P_NXSTATES * sizeof(float*), cudaMemcpyHostToDevice);

This memory, once copied over to the GPU, is never changed and is only read from. Thus, I've decided to bind this to texture memory. Problem is that when working with 2D texture memory, the memory being bound to it is really just an array that uses offsets to function as a matrix.

I'm aware I need to use cudaBindTexture2D() and cudaCreateChannelDesc() to bind this 2D memory in order to access it as such

tex2D(texXSC,x,y)

-- but I'm just not sure how. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你没皮卡萌 2024-12-04 01:38:20

简而言之,您不能将指针数组绑定到纹理。您可以创建 CUDA 数组并将数据从线性源内存复制到其中,也可以使用直接绑定到纹理的倾斜线性内存。但指针数组不起作用。

The short answer is that you cannot bind arrays of pointers to textures. You can either create a CUDA array and copy data to it from linear source memory, or use pitched linear memory directly bound to a texture. But an array of pointers will not work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文