Cuda,3d 块中的执行线程顺序 [英] Cuda, executional thread order in a 3d-block

查看:26
本文介绍了Cuda,3d 块中的执行线程顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为标题,我想知道正确的执行顺序,以防我们有 3d 块

As title, I would like to know the right execution order in case we have a 3d block

我想记得我已经读过一些关于它的东西,但那是前一段时间,我不记得在哪里,但它是由一个看起来不那么可靠的人来的..

I think to remember that I read already something regarding it, but it was some time ago, I dont remember where but it was coming by someone who didnt look so reliable..

无论如何,我想对此进行一些确认.

Anyway I would like to have some confirmations about it.

是不是如下(分经)?

[0, 0, 0]...[blockDim.x, 0, 0] - [0, 1, 0]...[blockDim.x, 1, 0] - (...) - [0, blockDim.y, 0]...[blockDim.x, blockDim.y, 0] - [0, 0, 1]...[blockDim.x, 0, 1] - (...) - [0, blockDim.y, 1]...[blockDim.x, blockDim.y, 1] - (...) - [blockDim.x, blockDim.y, blockDim.z]

[0, 0, 0]...[blockDim.x, 0, 0] - [0, 1, 0]...[blockDim.x, 1, 0] - (...) - [0, blockDim.y, 0]...[blockDim.x, blockDim.y, 0] - [0, 0, 1]...[blockDim.x, 0, 1] - (...) - [0, blockDim.y, 1]...[blockDim.x, blockDim.y, 1] - (...) - [blockDim.x, blockDim.y, blockDim.z]

推荐答案

是的,这是正确的顺序;线程按照块内的 x 维度首先变化,然后是 y,然后是 z(相当于列优先顺序)进行排序.计算可以表示为

Yes, that is the correct ordering; threads are ordered with the x dimension varying first, then y, then z (equivalent to column-major order) within a block. The calculation can be expressed as

int threadID = threadIdx.x + 
               blockDim.x * threadIdx.y + 
               (blockDim.x * blockDim.y) * threadIdx.z;

int warpID = threadID / warpSize;
int laneID = threadID % warpsize;

这里threadID是block内的线程号,warpID是block内的warp,laneID是warp内的线程号.

Here threadID is the thread number within the block, warpID is the warp within the block and laneID is the thread number within the warp.

请注意,线程不一定以与块内此顺序相关的任何可预测顺序执行.执行模型保证同一个warp中的线程被锁步"执行,但是你不能从块内的线程编号推断出更多.

Note that threads are not necessarily executed in any sort of predicable order related to this ordering within a block. The execution model guarantees that threads in the same warp are executed "lock-step", but you can't infer any more than that from the thread numbering within a block.

这篇关于Cuda,3d 块中的执行线程顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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