BaCO: A Fast and Portable Bayesian Compiler Optimization Framework

Erik Hellsten, Artur Souza, Johannes Lenfers, Rubens Lacouture, Olivia Hsu, Adel Ejjeh, Fredrik Kjolstad, Michel Steuwer, Kunle Olukotun, Luigi Nardi

TL;DR

BaCO (Bayesian Compiler Optimization) is a fast, portable, and general-purpose autotuner that optimizes code across diverse hardware backends like CPUs, GPUs, and FPGAs. By customizing Bayesian Optimization to handle complex parameter types (including permutations) and both known and hidden constraints, BaCO delivers up to 1.56x faster code execution while reaching expert-level performance nearly 4x faster than existing state-of-the-art autotuners.

What Problem Does This Paper Address?

Modern compilers are increasingly separating what to compute (policy) from how to compute it (mechanism) by utilizing high-level scheduling languages. While this separation makes compilers more flexible, it shifts the massive burden of optimization onto an "autoscheduler."

The resulting search space for an optimal schedule is incredibly complex. It consists of mixed-variable types—abbreviated as RIPOC (Real, Integer, Ordinal, Categorical)—as well as permutation parameters (such as loop reordering). Furthermore, these spaces are heavily constrained. Some constraints are known beforehand (e.g., loop tiling factors must divide loop bounds), while others are "hidden" and only discovered at runtime (e.g., a configuration causing an out-of-memory error on a GPU).

Prior autotuning frameworks fail to support all of these parameter types and constraint variations simultaneously, making them difficult to port across different compilers and hardware backends.

Methods

BaCO tackles this challenge by introducing a highly customized Bayesian Optimization (BO) framework designed to treat compilers as black-box systems.

Figure 2: Overview of the BaCO framework.

Key methodological innovations include:

  • Unified Distance Metric: To handle mixed-variable spaces in its Gaussian Process (GP) surrogate model, BaCO employs a weighted Euclidean norm over individual distance metrics tailored to each parameter type.
  • Structural Permutation Modeling: Instead of treating loop reorderings as simple categorical variables, BaCO models their underlying structure using semimetrics like Spearman’s rank correlation, which captures the magnitude of element movements.
Illustration of similarity metrics between two permutations
  • Unbiased Chain-of-Trees (CoT): To navigate sparse search spaces dictated by known constraints, BaCO utilizes a Chain-of-Trees data structure. Unlike prior implementations that suffer from structural bias, BaCO samples uniformly from the leaves of the trees to ensure a fair exploration of the valid search space.
Figure 4: Chain-of-Trees with 5 parameters, p1 to p5.
  • Hidden Constraints Feasibility Model: BaCO pairs its GP value predictor with a Random Forest classification model that estimates the probability of a configuration being valid. The framework multiplies the Expected Improvement (EI) acquisition function by this feasibility probability to steer the search away from invalid regions.

Datasets

The authors evaluated BaCO across 15 distinct kernels spanning three modern compiler frameworks:

  1. TACO (Tensor Algebra Compiler): Evaluated on sparse matrix-vector multiply (SpMV), sparse matrix multiply (SpMM), sampled dense-dense matrix multiplication (SDDMM), and others. Tensors were sourced from the SuiteSparse matrix collection, the Facebook Activities graph, the FROSTT collection, and synthetic generators.
  2. RISE & ELEVATE: Evaluated on dense linear algebra and image processing workloads (e.g., Matrix Multiplication, K-means, Harris Corner Detection) targeting both Intel CPUs and NVIDIA K80 GPUs.
  3. HPVM2FPGA: Evaluated on hardware-agnostic FPGA programs including Breadth-First Search (BFS), a 3D Spatial Audio Encoder, and computational fluid dynamics (PreEuler), targeting an Intel Arria 10 FPGA.

Key Insights and Ideas

  • Permutations Matter Structurally: Treating loop reordering as a structured permutation (using Spearman's rank correlation) rather than an unordered categorical variable provides a massive boost to optimization efficiency, especially in early iterations.
  • Bias-Free Sampling is Essential: Standard tree-based constraint sampling naturally over-samples less dense parts of a configuration tree. Sampling uniformly from the leaves eliminates this bias, leading to more robust performance across diverse compiler spaces.
  • Data-Driven over Analytical Models: By learning entirely from online runtime observations rather than relying on rigid, handcrafted analytical cost models, BaCO achieves true portability across wildly different architectures (CPUs vs. FPGAs).

Key Results

  • Tiny Budget Efficiency: With a tiny search budget of just 20–40 evaluations, BaCO delivered code that was on average 1.36x to 1.56x faster than state-of-the-art baselines (such as ATF/OpenTuner and Ytopt).
  • Speed to Expert Performance: BaCO reached or exceeded handcrafted expert-level configurations 2.9x to 3.9x faster than competing autotuners.
  • Generality: BaCO was the only framework tested that successfully outperformed expert configurations across all three compiler ecosystems without requiring any manual hyperparameter tuning or custom constraint filtering.

Limitations and Future Work

The primary limitation acknowledged by the authors is wall-clock time. Although BaCO finds high-performing schedules in fewer iterations (often under 100 seconds total), this overhead is still too slow to be integrated directly into a developer's immediate interactive compilation loop.

Future work aims to further optimize the internal mechanics of the autotuner to enable an "autotuning-in-the-development-loop" paradigm. Additionally, incorporating multi-task and meta-learning strategies could allow BaCO to leverage knowledge from previous tuning runs to accelerate optimization on new, unseen programs.

Summary updated

BibTeX
@inproceedings{hellsten2022baco,
  author = {Erik Hellsten and Artur Souza and Johannes Lenfers and Rubens Lacouture and Olivia Hsu and Adel Ejjeh and Fredrik Kjolstad and Michel Steuwer and Kunle Olukotun and Luigi Nardi},
  title = {{BaCO: A Fast and Portable Bayesian Compiler Optimization Framework}},
  booktitle = {ASPLOS},
  year = {2022},
}
Figure