liveBook · Manning

Block dimension

As explained in Grokking GPU Programming

Block dimensions are the configured extents of a CUDA thread block along its coordinate axes.

A CUDA block’s dimensions specify how many threads it contains along each coordinate axis. For a one-dimensional block, blockDim.x gives the thread count; combined with blockIdx.x and threadIdx.x, it helps each thread find its place in the full grid. section 3.3

Find a thread’s global index

With blockDim.x = 4, blockIdx.x = 3, and threadIdx.x = 2, the global index is 3 × 4 + 2 = 14. Each block covers a contiguous range, so block 2, thread 1 handles index 9. section 3.3

Figure 3.1 Launching <<<3, 4>>>: 12 threads, but only 4 elements touched. With 3 blocks of 4 threads each, every thread uses only threadIdx.x, so all three blocks target the same 4 elements (data[0..3]), leaving data[4..11] untouched. To reach the full array, each thread needs to factor in its block index too.

See why using threadIdx.x alone makes blocks target the same elements instead of covering the full array. section 3.3

Block dimensions also need to fit the work assigned to each thread:

  • A tiled matrix-multiplication kernel uses a TILE_SIZE × TILE_SIZE block so each thread loads one tile element. A smaller block leaves tile slots unfilled; a larger one risks overlapping or out-of-bounds writes. section 12.4

How Grokking GPU Programming covers it

How deep it goes
Explains x and y extents through indexing and a tiled-kernel constraint, without developing other axes.
Examples
Uses a three-block, four-thread launch for index calculations and a 32×32 block for loading a matrix tile.
What you can do after
Apply it via CUDA block configuration to compute global element indices and meet a tiled kernel’s size requirement.
How it connects
Connects threadIdx and blockIdx to global indexing, and ties tile-sized blocks to shared-memory loading.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking GPU Programming. The section links point to the parts of the book it draws on.