Introduction
Modern compiler design has increasingly embraced the "separation of concerns," where users define the computational policy and scheduling languages dictate the underlying mechanism. While this provides immense flexibility, it introduces a significant challenge: navigating massive, multi-dimensional search spaces to find optimal configurations. Existing autotuning tools often struggle with the complexity of these spaces, which include mixed parameter types and intricate hardware constraints.
BaCO (Bayesian Compiler Optimization) addresses these limitations by providing a general-purpose, hardware-agnostic autotuner. By specializing Bayesian Optimization for the specific nuances of compiler schedules—such as loop permutations and hidden resource limits—BaCO achieves expert-level performance across CPUs, GPUs, and FPGAs with unprecedented efficiency.
The Complexity of Modern Compiler Search Spaces
The search space for a modern compiler is rarely uniform. It typically consists of RIPOC parameters: Real, Integer, Permutation, Ordinal, and Categorical. For instance, tiling factors are integers, while parallelization strategies are categorical, and loop reordering represents a permutation.
As shown in the comparison above, most existing frameworks fail to support the full breadth of these parameters or lack robust mechanisms for handling constraints. Constraints in compiler optimization are twofold: known constraints, such as a tile size needing to divide a loop bound, and hidden constraints, such as a configuration exceeding a GPU's shared memory, leading to runtime failures. BaCO is uniquely designed to navigate these "minefields" by integrating specialized models for both performance prediction and feasibility.
The BaCO Methodology
At its core, BaCO utilizes Gaussian Processes (GP) as a surrogate model to predict code performance. However, standard Bayesian Optimization (BO) is insufficient for the discrete and structured nature of compiler parameters. BaCO introduces several key innovations to adapt BO for this domain:
- Custom Distance Metrics: BaCO employs specialized kernels for different parameter types. It uses Spearman’s rank correlation for permutations, recognizing the structural similarity between loop orders. For tiling and unrolling factors, it applies log-transforms to reflect the exponential impact of these parameters on performance.
- Chain-of-Trees (CoT): To handle known constraints, BaCO uses a CoT data structure to represent the valid search space. This ensures the optimizer only explores mathematically viable configurations.
- Feasibility Modeling: To manage hidden constraints, BaCO integrates a Random Forest feasibility model. This model predicts the probability that a configuration will execute successfully. By multiplying this probability with the "Expected Improvement" metric, BaCO steers the search toward safe, high-performing regions.
The optimization loop begins with an initial configuration generation phase, followed by an iterative learning phase where runtime statistics from the compiler toolchain inform the prediction and feasibility models.
Experimental Evaluation
BaCO was evaluated across three distinct compiler systems: TACO (sparse tensor algebra on CPUs), RISE & ELEVATE (image processing on GPUs), and HPVM2FPGA (FPGA programming). The benchmarks included 15 critical kernels, such as SpMV and MatMul, tested on a variety of hardware including Intel Xeon CPUs, NVIDIA K80 GPUs, and Intel Arria 10 FPGAs.
Key Results and Insights
The evaluation demonstrated that BaCO significantly outperforms state-of-the-art autotuners like OpenTuner and Ytopt. Key findings include:
- Efficiency: BaCO reached peak performance using only 30% of the evaluation budget required by competing methods.
- Performance Gains: Within a limited budget of 20–40 evaluations, BaCO delivered code that was 1.36× to 1.56× faster than baselines on average.
- Expert Comparison: BaCO reached expert-level performance 2.9× to 3.9× faster than other tuners. In several instances, it discovered non-obvious configurations that outperformed manually handcrafted expert schedules by over 6×.
Conclusion
BaCO represents a significant step forward in making compiler autotuning both fast and portable. By treating permutations and constraints as first-class citizens within a Bayesian framework, it enables developers to achieve high-performance code across diverse hardware without exhaustive manual effort. While current recommendation times (approx. 100 seconds) preclude use in rapid "edit-compile-run" loops, BaCO’s efficiency makes it an ideal solution for complex deployment scenarios and long-running FPGA compilations.
Summary updated