Threads are numbered in order within blocks so that threadIdx.x
varies the fastest, then threadIdx.y
the second fastest varying, and threadIdx.z
the slowest varying. This is functionally the same as column major ordering in multidimensional arrays. Warps are sequentially constructed from threads in this ordering. So the calculation for a 2d block is
unsigned int tid = threadIdx.x + threadIdx.y * blockDim.x;
unsigned int warpid = tid / warpSize;
This is covered both in the programming guide and the PTX guide.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…