Implement a Work-Efficient Parallel Exclusive Prefix Sum
Last updated: November 29, 2026
Quick Overview
Implement an exclusive prefix sum using the up-sweep and down-sweep (Blelloch) structure that a GPU kernel would use, simulated sequentially in Python. Pad to a power of two internally and return a result of the original length.
AMD
November 29, 20260
0
0 solved
Implement an exclusive prefix sum using the up-sweep and down-sweep (Blelloch) structure that a GPU kernel would use, simulated sequentially in Python. Pad to a power of two internally and return a result of the original length.
An onsite question in the style of AMD ROCm library teams (rocPRIM, hipCUB), where scan is a building block for stream compaction, radix sort and sparse kernels. The interviewer checks that you know why a naive parallel scan does O(n log n) work, can reproduce the tree structure, and can reason about synchronization between levels.
What the Interviewer Expects
- Contrast the O(n log n) work Hillis-Steele scan with O(n) work Blelloch
- Implement the up-sweep reduction tree correctly
- Clear the root and implement the down-sweep swap-and-add
- Pad to a power of two and trim the result
- Point out that each level needs a barrier on the GPU
- Discuss multi-block scans for large inputs
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How do you scan an array much larger than one work group's LDS?
- Where do LDS bank conflicts appear in this pattern and how does padding fix them?
- How would you turn this into an inclusive scan?
- How does a single-pass decoupled look-back scan improve on the three-kernel approach?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
Input: list of numbers. Output: exclusive scan, where out[i] is the sum of values[0..i-1] and out[0] = 0. Use the tree structure so each inner loop corresponds to one parallel step across thread...
High-Level Design
Up-sweep builds partial sums in a binary tree in place: at stride s, element i (with i + 1 a multiple of 2s) adds element i - s. After log n levels the last slot holds the total. Down-sweep ...