GPU Programming

To process a 1000-element array with one element per thread and 256 threads per block, how many blocks should be launched?

  1. A3
  2. B4
  3. C1000
Show answer and explanation

Answer: B. 4

1000 ÷ 256 ≈ 3.9, so rounding down to 3 blocks would cover only 256 × 3 = 768 elements and miss the rest. Rounding up to 4 blocks (1024 threads) covers everything, with the 24 extra threads doing nothing. The usual formula is "(n + 256 - 1) / 256" to round up. The kernel must check the index so the extra threads do not read or write beyond the array.

  • A. Three blocks cover only 768 elements.
  • B. Correct. 1000 ÷ 256 rounded up is 4.
  • C. That confuses blocks with threads.
Practice this topic Back to topic

More GPU Programming questions

  1. Why does the CUDA kernel above include "if (i < n)"?
  2. On NVIDIA GPUs, what is the unit of 32 threads bundled together to execute the same instruction in lockstep called?
  3. How does the GPU SIMT (single instruction, multiple threads) model differ from CPU SIMD instructions?
  4. Within one warp, a conditional branch sends half the threads to the if path and half to the else path (warp divergence). How is this generally executed?
  5. Both (1) and (2) above make half the threads run A and the other half run B. Which is correct about warp efficiency (32 threads per warp)?