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
