GPU Programming

What is a common guideline for choosing the number of threads per block in CUDA?

  1. AMake it a multiple of the warp size, 32 (such as 128 or 256)
  2. BAlways use 1
  3. CAlways use a prime number
Show answer and explanation

Answer: A. Make it a multiple of the warp size, 32 (such as 128 or 256)

A block's threads are divided into warps of 32, so with, say, 100 threads the last warp uses only 4 lanes and the slots of the other 28 are wasted. A multiple of 32 keeps every warp full. In practice 128 to 256 threads are common, tuned while watching occupancy and shared-memory use.

  • A. Correct. It avoids partially filled warps.
  • B. With one thread, 31 lanes of the warp are wasted.
  • C. A prime number creates a partially filled warp.
Practice this topic Back to topic

More GPU Programming questions

  1. What is the advantage of writing a kernel with a loop like the one above (a grid-stride loop)?
  2. For what kind of access does CUDA constant memory perform especially well?
  3. In general, how do GPU caches compare with CPU caches?
  4. Which is an example of a parallel-programming framework for GPUs that also works on GPUs other than NVIDIA's?
  5. On a GPU you want to compact only the elements meeting a condition into another array (each thread outputs 0 or 1 items). Which parallel computation is commonly used to determine each thread's write position?