The CUDA thread hierarchy consists of two layers: threads organized into blocks, and blocks organized into a grid.

  • Block: A block is an array of threads and can be 1-3 dimensional. Each block in a grid has the same number of threads. Threads within a block can cooperate through synchronization and shared memory, but cooperation is not possible between threads from different blocks.
  • Grid: A grid comprises one or more thread blocks and is also 1-3 dimensional.

Thread ID

ThreadIdx is a built-in variable of CUDA that represents the thread identifier. If it is multi-dimensional, we can expand it to get the flattened id.

Thread Blocks

See: blocks There are two built-in variables for thread block, block indices blockIdx and dimension blockDim.