GPU Programming

In CUDA, what is the relationship between blocks and SMs (streaming multiprocessors)?

  1. AA block's threads are spread across all SMs
  2. BThe number of blocks must always equal the number of SMs
  3. CEach block is assigned to one SM and runs there to completion, and one SM may hold several blocks at once
Show answer and explanation

Answer: C. Each block is assigned to one SM and runs there to completion, and one SM may hold several blocks at once

A GPU has many SMs and assigns a kernel's blocks to free SMs in turn. A block runs on one SM, so its threads can use that SM's shared memory and synchronize. Launching many more blocks than SMs keeps every SM busy regardless of the GPU's size, with the next block assigned to whichever SM finishes.

GPU thread hierarchy and assignment to SMs Grid B0 B1 B2 B3 B4 B5 Block Warp 0 Warp 1 Warp 2 Warp (32 threads) Same instruction in lockstep Threads grouped by 32 Each block goes to an SM SM0 B0 B3 Shared memory SM1 B1 B4 Shared memory SM2 B2 B5 Shared memory Global memory (read/write from all blocks) A block runs on one SM and cooperates via shared memory
GPU thread hierarchy and assignment to SMs · View in diagrams
  • A. A block runs within a single SM.
  • B. There can be far more blocks than SMs.
  • C. Correct. That is why shared memory works within a block.