What is Thread block?

A group of GPU threads that runs on a single SM. Threads in a block can share data through shared memory and synchronize.

Field: GPU Programming

Japanese name: スレッドブロック

Its place in the grid

In CUDA, all the threads created by one kernel launch form a grid. The grid is divided into thread blocks, and every block has the same number of threads. The number of blocks and the number of threads per block are specified at launch. Launching 4 blocks of 256 threads gives 256 × 4 = 1024 threads. Each thread computes its own global index from its block index and its index within the block.

What threads in a block can do

Threads of the same block can place data in shared memory and read and write it together. With a barrier instruction, no thread proceeds until every thread of the block has reached that point. This enforces an order such as reading only after everyone has finished writing. The threads of one block run on the same SM and share that SM's resources. For this reason there is a limit on the number of threads per block.

Blocks are independent of each other

Blocks must be written so that they can execute independently. The program has to work correctly whatever order they run in, in parallel or one after another. Thanks to this rule, the GPU can assign blocks to whichever SMs are free. The same program runs on GPUs with different numbers of SMs. Synchronization across blocks is available only in limited cases. In many programs the order is therefore created by splitting the work into two kernel launches.

Try it: questions about Thread block

On a GPU whose limit is 1024 threads per thread block, a CUDA kernel is launched with blockDim.x set to 2048. What generally happens?

  1. AThe GPU automatically splits it into two blocks of 1024 threads each and runs them
  2. BOnly the first 1024 threads run and the rest are ignored
  3. CThe launch configuration is treated as invalid, so the kernel does not run and an error is returned
Show answer and explanation

Answer: C. The launch configuration is treated as invalid, so the kernel does not run and an error is returned

All threads of a thread block must reside on one SM at the same time and be able to cooperate through shared memory and __syncthreads(), so the number of threads per block is limited. If a kernel is launched with a configuration above the limit, not a single thread runs, and the launch fails with an error indicating an invalid configuration. A kernel launch returns no value, so unless the error is checked with cudaGetLastError() or similar, it is easy to miss that the result array was never updated. Work for 2048 threads is divided among multiple blocks of 1024 threads or fewer.

FAQ

How does it differ from a warp?

They are defined by different parties. A block is a group of threads whose size the program chooses. A warp is the unit in which an NVIDIA GPU executes instructions, formed by bundling the threads of a block 32 at a time.

Does OpenCL have the same thing?

Yes. An OpenCL work-group corresponds closely to it. Work-items in the same group can share local memory and synchronize at a barrier.

Books on GPU Programming Ad

As an Amazon Associate I earn from qualifying purchases.

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary