Abstract
Performance optimization is an increasingly challenging but often repetitive task. While each platform has its quirks, the underlying code transformations rely on data movement and computational characteristics that recur across applications. This paper proposes to leverage those similarities by constructing an embedding space for subprograms. The continuous space captures both static and dynamic properties of loop nests via symbolic code analysis and performance profiling, respectively. Performance embeddings enable direct knowledge transfer of performance tuning between applications, which can result from autotuning or tailored improvements. We demonstrate this transfer tuning approach on case studies in deep neural networks, dense and sparse linear algebra compositions, and numerical weather prediction stencils. Transfer tuning reduces the search complexity by up to four orders of magnitude and outperforms the MKL library in sparse-dense matrix multiplication. The results exhibit clear correspondences between program characteristics and optimizations, outperforming prior specialized state-of-the-art approaches and generalizing beyond their capabilities.
Introduction
Performance optimization is frequently described as a "black art," a process that grows exponentially more difficult as hardware architectures increase in complexity. Traditionally, developers have relied on two primary paths: manual engineering, which utilizes expert intuition and profiling tools like the Roofline model, or automated schedulers. While tools like the Polyhedral model can automate scheduling, they are often restricted to mathematically "clean" affine loop nests and struggle with data-dependent applications, such as sparse linear algebra.
This paper introduces Performance Embeddings, a novel method for representing code snippets in a continuous vector space that captures both their structural "DNA" and their runtime behavior. By mapping programs into this space, we enable transfer tuning: the ability to automatically apply successful optimization strategies from known programs to new, similar ones, effectively bridging the gap between static code analysis and dynamic runtime profiling.
Methodology: The Transfer Tuning Workflow
The proposed framework operates through a dual-phase process: an offline database construction phase and an online optimization workflow.
In the offline phase, a diverse set of programs is analyzed to create an Optimization Database. Each entry consists of a performance embedding (the "key") and its corresponding optimal transformations (the "values"), such as tiling, vectorization, or buffering. During the online phase, a new program source is embedded into the same space. A similarity search identifies its $k$-nearest neighbors in the database, and the best-performing transformations from these neighbors are transferred and tuned for the new application.
The Encoding Network Architecture
The core of this approach is a dual-input neural network architecture designed to generate a 128-dimensional embedding for any given parallel loop nest.
The network processes two distinct types of information:
- Static Encoding: The code is represented as a Stateful Dataflow Multigraph (SDFG). This graph is processed by a Graph Neural Network (GNN) using a graph transformer operator to capture structural relationships between data accesses and computations.
- Dynamic Encoding: The program is executed once on a "canonical" schedule to collect 19 hardware performance counters (e.g., cache misses, branch mispredictions, bandwidth). These 95 features are passed through a linear embedding layer.
These two branches are concatenated and passed through a Multi-Layer Perceptron (MLP) trained to predict 20 standard performance metrics. Once trained, the internal bottleneck layer serves as the Performance Embedding, a representation that captures physical reality with high correlation (up to 0.98 Pearson correlation for predicted metrics).
Evaluation and Key Results
The system was evaluated using a mix of synthetic data (~8,500 loop nests) and real-world benchmarks, including NPBench and the SuiteSparse collection.
Search Space Reduction: Transfer tuning achieved performance within 5% of exhaustive auto-scheduling while testing only a tiny fraction of the configurations. This resulted in a reduction of search complexity by up to 10,000x. For the Daubechies Wavelet benchmark, the system found an optimization that state-of-the-art search methods missed, leading to a 92% better runtime.
Library Comparison: In sparse-dense matrix multiplication (SpMM), the system's ability to choose between static and dynamic scheduling based on the matrix's embedding allowed it to outperform the Intel MKL library in 8 out of 10 test cases.
Explainability and Generalization: Unlike "black-box" auto-tuners, transfer tuning is inherently explainable; developers can inspect "neighbor" programs to understand why specific optimizations were suggested. Furthermore, the model treats data-dependent aspects as "gaps" filled by dynamic profiling, allowing it to generalize to non-polyhedral code that traditional tools cannot handle.
Conclusion and Future Work
Performance embeddings provide a robust mechanism for transferring optimization knowledge across disparate applications. While the current framework focuses on individual loop nests on CPUs, future work aims to extend this to Loop Fusion via subgraph embeddings and to improve the transfer of complex transformation sequences using sequence alignment techniques. Additionally, the framework is designed to be portable to other architectures, such as GPUs or FPGAs, through architecture-specific retraining.
Summary updated