Cuda, executional thread order in a 3d-block

前端 未结 1 1625
盖世英雄少女心
盖世英雄少女心 2021-01-12 14:49

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 t

相关标签:
1条回答
  • 2021-01-12 15:42

    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;
    

    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.

    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.

    0 讨论(0)
提交回复
热议问题