CUDA:3D网格中的全局唯一线程索引 [英] CUDA : Global unique thread index in a 3D Grid

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

问题描述

正如问题所述,如果我有3D块网格,则为一个线程获取全局唯一索引的公式是什么?

As the question states, If I have a 3D Grid of Blocks what is the formula to get a global unique index for one thread ?

让块本身保持一维。

推荐答案

// unique block index inside a 3D block grid
const unsigned long long int blockId = blockIdx.x //1D
        + blockIdx.y * gridDim.x //2D
        + gridDim.x * gridDim.y * blockIdx.z; //3D

// global unique thread index, block dimension uses only x-coordinate
const unsigned long long int threadId = blockId * blockDim.x + threadIdx.x;

这篇关于CUDA:3D网格中的全局唯一线程索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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