CUDA的3D矩阵索引 [英] CUDA 3D matrix index

查看:294
本文介绍了CUDA的3D矩阵索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在CUDA是356x896x60一个矩阵中。

I have one matrix in CUDA which is 356x896x60.

在我的节目我编码的三个空间坐标是这样的:

In my program I am coding the three spatial coordinates like this:

voxel[threadIdx.x]= indexx+indexy*(DETECTOR_X_DIM)+indexz*DETECTOR_X_DIM*DETECTOR_Y_DIM;

这是正确的?我看到的是使用了此事的一些话题 X * dimx * dimy + Y * dimx + Z
所以,我真的不知道什么是正确的方法

Is this right? I have seen some topics on the matter that use x*dimx*dimy + y*dimx + z
So I am not really sure what is the right method

推荐答案

取决于你的矩阵元素是如何在内存布局。您正在使用 X + Y * dimx + Z * dimx * dimy 这是有效的,如果你的价值观被映射到内存中的东西,如:

Depends how your matrix elements are laid out in memory. You are using x + y*dimx +z*dimx*dimy which is valid if your values were mapped to memory with something like:

index = 0;
for (z = 0; z<dimz; ++z)
    for(y = 0; y<dimy; ++y)
        for(x = 0; x<dimx; ++x) {
            matrix[index] = value;
            index++;
        }

如果你想像许多小立方体立方体您可以通过改变x走沿立方体的每一行,然后切换为Y线和层立方体以Z。

If you imagine a cube made of many small cubes you walk along each line of cubes by changing x, then you switch lines with y and the layers of cubes with z.

你是在哪里看到 X * dimx * dimy + Y * dimx + Z ?我想不出一个3D矩阵,你可以正确地使用它,除非dimx = dimz的。我不认为这是正确的。

Where did you see x*dimx*dimy + y*dimx + z? I can't think of a 3D matrix where you can use it correctly unless dimx=dimz. I don't think it is correct.

这篇关于CUDA的3D矩阵索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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