本文介绍了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 矩阵索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-09 12:04