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.