Simplifying Multiple-Statement Reductions with the Polyhedral Model

Cambridge Yang, Eric Atkinson, Michael Carbin

Abstract

This paper presents a novel approach to optimizing "dependent reductions"—complex accumulation patterns where subsequent calculations depend on previous results—within the Polyhedral Model. By formalizing the selection of reuse vectors as an integer bilinear program (IBP) and introducing a practical heuristic algorithm (SDR), the authors enable the automatic simplification of these patterns. The SDR heuristic leverages affine sequential schedules to ensure that optimizations do not introduce dependency cycles. Evaluation across 11 probabilistic inference benchmarks demonstrates that this technique can reduce algorithmic complexity from $O(N^2)$ to $O(N)$, yielding wall-clock speedups of up to $10^6$x.

Introduction

Reductions, such as summing elements of an array, are ubiquitous in high-performance computing. Compilers frequently utilize the Polyhedral Model, a mathematical framework for loop optimization, to simplify these operations. A classic example is the optimization of a prefix sum: by reusing the result of a previous iteration, the computational complexity can be reduced from $O(N^2)$ to $O(N)$. However, existing automated techniques, notably "Simplifying Reductions" (SR), are primarily designed for independent reductions. In many real-world applications, particularly in probabilistic machine learning, reductions are interdependent, creating a significant challenge for automated optimization.

The Challenge of Dependent Reductions

In complex inference workloads, reductions often exhibit interdependencies where the input for one step depends on the accumulated result of a previous step. Applying standard SR techniques to these patterns is hazardous; it often results in "dependence cycles," where the program attempts to use a value before it has been computed.

Initial dependency graph of a reduction operation showing reduction, use, and update dependencies.

Historically, optimizing these dependent patterns required manual intervention by expert programmers—a process that is tedious, error-prone, and difficult to scale. The primary difficulty lies in choosing a "reuse vector" (the direction of data reuse) that does not violate the fundamental execution order of the program.

Methodology: The SDR Algorithm

The authors bridge the gap between loop simplification and dependency management through two primary contributions. First, they formalize the selection of an optimal reuse vector as an Integer Bilinear Program (IBP). This represents a significant increase in complexity over the standard Integer Linear Programming (ILP) typically used in compiler scheduling.

To address the NP-hard nature of IBPs, the authors propose the SDR (Simplifying Dependent Reductions) heuristic. The key insight is the use of a valid affine sequential schedule of the original program as a safety guide. If a proposed reuse vector aligns with the original execution order, the optimization is guaranteed not to create a dependency cycle.

The optimization of a prefix sum with dependent reduction: (a) illustrates the iteration space after a shift, and (b) shows the simplified computation after the transformation.

The algorithm operates by breaking down the iteration space (the polyhedron) into its geometric faces and applying the simplification transformation to each face individually. This ensures that no optimization opportunities are missed while maintaining correctness. Furthermore, the authors prove that for operators with an inverse (e.g., addition and subtraction), their heuristic is optimal, matching the complexity reduction of expert manual implementations.

Evaluation and Results

The SDR technique was evaluated on a benchmark suite of 11 probabilistic inference algorithms, including Latent Dirichlet Allocation (LDA), Gaussian Mixture Models (GMM), and Loopy Belief Propagation (LBP). These models are characterized by highly nested and dependent reductions that are notoriously difficult to optimize.

The results were transformative:

  • Complexity Reduction: 10 out of 11 benchmarks achieved a reduction in algorithmic complexity by at least a factor of $N$.
  • Massive Speedups: Wall-clock speedups ranged from 1.1x to over 1,000,000x, with a median speedup of 37x.
  • Practical Impact: For the LDA benchmark, unoptimized versions timed out after 12 hours, whereas the SDR-optimized versions completed in seconds or milliseconds.

Conclusion

This work significantly advances the state-of-the-art in polyhedral compilation by automating the optimization of dependent reductions. By combining formal optimization theory with practical heuristics, the authors provide a tool that matches the performance of expert-tuned code while maintaining the safety and generality of automated compiler passes. Future work will focus on extending these techniques to operators without inverses, such as min and max, and exploring the interplay between simplification and parallelization.

Summary updated

BibTeX
@article{yang2021simplifying,
  author = {Cambridge Yang and Eric Atkinson and Michael Carbin},
  title = {{Simplifying Multiple-Statement Reductions with the Polyhedral Model}},
  journal = {Proc. ACM Program. Lang.},
  year = {2021},
  doi = {10.1145/3434301},
}
Figure