liveBook · Manning

Thread block

As explained in Fast Python: High performance techniques for large datasets

A thread block is a group of GPU threads scheduled as a unit that can cooperate through shared memory and synchronization.

A thread block groups GPU threads for execution on the same streaming multiprocessor. Threads in a block can share memory and synchronization; separate blocks can run on different multiprocessors. section 9.1.4

Block sizing determines how GPU work is distributed:

  • Choose threads per block and enough blocks to cover the data; when the product exceeds the array size, guard against out-of-bounds threads. section 9.2.2
  • For two-dimensional work, round block counts up so the grid covers every image point. section 9.2.3
import numpy as np
 
blocks_per_grid = 50
threads_per_block = 20
 
my_array = np.ones(1000)
double[blocks_per_grid, threads_per_block](my_array)   #1
assert (my_array == 2).all()                           #2

A Numba CUDA launch assigns 20 threads to each block and uses 50 blocks to cover 1,000 array elements. section 9.2.2

How Fast Python: High performance techniques for large datasets covers it

How deep it goes
Explains block placement and cooperation, then demonstrates launch sizing and bounds checks; it defers shared-memory algorithms as advanced.
Examples
Uses matrix scaling, array doubling, and two-dimensional Mandelbrot image generation to illustrate block sizing.
What it assumes
Builds from CPU-driven GPU execution and array operations, while pointing new Numba users to separate introductory material.
What you can do after
Apply Numba CUDA launch configurations to distribute array or image work across blocks and guard excess threads.
How it connects
Connects GPU kernels, streaming multiprocessors, shared memory, synchronization, grids, and CUDA thread indexing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Fast Python: High performance techniques for large datasets. The section links point to the parts of the book it draws on.