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?
- ABoth paths run simultaneously, so speed is unaffected
- BThe else threads are discarded without executing
- 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.