GPU Programming
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?
- AA matrix transpose
- BA prefix sum (scan, the running total from the start)
- CA fast Fourier transform
Show answer and explanation
Answer: B. A prefix sum (scan, the running total from the start)
Representing whether each thread outputs as 0 or 1 and computing the running total from the start (an exclusive prefix sum) gives each thread "the number of outputting threads before me", which is exactly its write address. A scan can be computed in parallel with a tree structure, like a reduction. It is the basic tool for compacting variable per-element output in parallel.
- A. A transpose does not determine write positions.
- B. Correct. The number of outputs before you is your write position.
- C. Frequency transforms are unrelated.