KatInterview

Design Deterministic Parallel Floating-Point Reduction in CUDA

System DesignModel answer
MediumModel answerSystem Designcudaparallel-programmingfloating-point

Last updated

Architect a GPU reduction pipeline that guarantees bitwise-reproducible floating-point outputs by eliminating non-deterministic thread block contention.

When performing parallel reductions in CUDA (e.g., calculating a total sum across a large array), standard implementations often rely on atomicAdd to accumulate partial results into a single global location. Because the hardware scheduler dispatches thread blocks non-deterministically across Streaming Multiprocessors (SMs), the order in which partial sums are added changes from run to run. Because floating-point addition is non-associative, this leads to non-reproducible results across identical runs.

Design a deterministic parallel reduction framework in CUDA that yields bitwise-identical results across executions.

Address the following key requirements in your design:

  1. Intra-Block Reduction Architecture: Explain how input elements are assigned to threads and reduced within a thread block using a fixed evaluation order.
  2. Inter-Block Accumulation Strategy: Detail how block-level partial results are merged without relying on non-deterministic atomic addition.
  3. Relation to Parallel Prefix Scan: Compare the reduction topology to the up-sweep phase of parallel prefix-scan algorithms (such as the Blelloch scan).
  4. Floating-Point Guarantees & Non-Guarantees: Outline what guarantees this architecture provides regarding numerical precision and reproducibility, and what limitations remain.
  5. Trade-off Analysis: Analyze the trade-offs in execution latency, memory footprint, and hardware utilization compared to atomic reductions or fixed-point exact accumulators.

Hints

Hint 1

Floating-point addition obeys commutativity (a + b = b + a) but violates associativity: (a + b) + c is not guaranteed to bitwise equal a + (b + c).

Hint 2

To enforce determinism, the expression tree must depend only on static configuration factors (array length, block dimension, elements per thread) rather than execution scheduling.

Hint 3

Inter-block merging can be achieved deterministically either using multi-stage kernel launches or via a single-pass flag-based synchronization where the final block processes partials in a strictly ordered tree.