GPU Programming

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?

  1. ABoth paths run simultaneously, so speed is unaffected
  2. BThe else threads are discarded without executing
  3. CThe if and else paths run one after the other, with non-participating threads idle each time, lowering efficiency
Show answer and explanation

Answer: C. The if and else paths run one after the other, with non-participating threads idle each time, lowering efficiency

A warp's 32 threads execute the same instruction, so on divergence the if-path instructions run first with only the if threads active, and then the else path runs with the rest. Results are correct, but half the threads are idle each time, so the cost is the sum of both paths. Arranging data or threads so that branches agree within each warp improves efficiency.

  • A. A warp executes only one instruction at a time.
  • B. Both sets of threads execute correctly.
  • C. Correct. It takes the time of both paths.
Practice this topic Back to topic

More GPU Programming questions

  1. 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)?
  2. Which describes memory coalescing on a GPU?
  3. With i as each thread's index, reading the array every 32 elements as above is slower than reading a[i]. What is the main reason?
  4. When processing particle data with positions x, y and z on a GPU, which layout is better for memory coalescing?
  5. What is a characteristic of CUDA shared memory?