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.

  • 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.
Practice this topic Back to topic

More GPU Programming questions

  1. In CUDA, you want to wait mid-kernel for every other block to finish before moving to the next phase. What is the usual approach?
  2. Building a histogram of pixel values on a GPU can be slow if every thread does atomicAdd directly on 256 bins in global memory. What is a good improvement?
  3. When summing many values on a GPU, why use a tree-shaped reduction (repeatedly adding neighbors to halve the count)?
  4. How many stages does a tree-shaped reduction need to sum 1024 values?
  5. In a program using a discrete GPU, what is generally true about CPU-side and GPU-side memory?