TL;DR
Mirage is a novel multi-level superoptimizer for tensor programs that significantly boosts DNN performance on GPUs. It achieves this by unifying algebraic and schedule transformations across kernel, thread block, and thread levels, and by introducing a new hierarchical graph representation called uGraphs. Mirage outperforms existing state-of-the-art methods by up to 3.3x, even on heavily optimized DNNs.
What Problem Does This Paper Address?
Modern deep neural networks (DNNs) demand high-performance execution on GPUs. While existing frameworks like PyTorch and TensorFlow use manually designed rules to map tensor programs to GPU kernels, this approach is labor-intensive and often misses optimization opportunities. Automated approaches exist, but they typically fall into two categories: those that optimize schedules for fixed algorithms (like Halide, TVM) or those that perform algebraic transformations on fixed kernels (like TASO, Grappler). A critical limitation is that these methods often fail to capture optimizations that require coordinated transformations across different levels of the GPU hierarchy (kernel, thread block, thread) or the discovery of entirely new custom kernels. This gap leaves significant performance gains on the table, especially for complex operations like attention mechanisms in LLMs.
Methods
Mirage introduces a multi-level superoptimization approach centered around a novel hierarchical graph representation called uGraphs. uGraphs uniformly represent tensor programs at the kernel, thread block, and thread levels of the GPU compute hierarchy. This unified representation allows Mirage to discover optimizations that combine algebraic transformations (e.g., operator fusion, reordering), schedule transformations (e.g., parallelization strategies), and the generation of new custom kernels.
Key techniques include:
- Expression-Guided µGraph Generator: This component exhaustively searches for possible uGraphs equivalent to a given tensor program. To manage the vast search space, it employs a pruning technique based on abstract expressions. These abstract expressions capture the essence of tensor computations, allowing Mirage to discard unpromising optimization paths early while providing a theoretical guarantee on optimality.
- Probabilistic Equivalence Verifier: To ensure that optimized uGraphs are functionally equivalent to the original program, Mirage uses a probabilistic approach based on random testing over finite fields. This method is shown to provide strong correctness guarantees for the "LAX fragment" of tensor programs (which includes multi-linear operators, division, and limited exponentiation).
- µGraph Optimizer: For each verified uGraph, this component further optimizes performance by considering tensor layouts, operator scheduling, and memory planning across all hierarchy levels.
Datasets
The paper evaluates Mirage on six commonly used DNN benchmarks: GQA (Group-query attention), QKNorm (QK normalization with attention), RMSNorm (RMS normalization with linear), LORA (Low-rank adaptation), GatedMLP (Gated multi-layer perceptron), and nTrans (Normalized Transformer). These benchmarks are representative of components found in large language models and other modern deep learning architectures. No new benchmarks were introduced.
Key Insights and Ideas
- Unified Multi-Level Optimization: The core insight is that significant performance gains are unlocked by jointly optimizing across kernel, thread block, and thread levels, rather than treating them in isolation. uGraphs provide the necessary representation for this unified approach.
- Abstract Expressions for Pruning: The use of abstract expressions to prune the search space is crucial for scalability. This technique allows Mirage to intelligently discard optimization paths that cannot lead to an equivalent and performant solution, making the exhaustive search feasible.
- Probabilistic Equivalence for LAX Programs: The theoretical result that random testing over finite fields provides strong equivalence guarantees for LAX programs is a key enabler for the verification step, making it efficient and reliable.
- Custom Kernel Generation: Mirage doesn't just optimize existing kernels; it can discover and generate entirely new custom kernels that fuse computations in ways not previously considered by manual or existing automated methods.
Key Results
Mirage significantly outperforms existing state-of-the-art tensor program optimizers, achieving speedups of up to 3.3x on NVIDIA A100 and H100 GPUs. For specific benchmarks like GQA, Mirage's generated kernels outperform existing hand-optimized kernels by up to 2.2x by finding better grid dimensions and parallelization strategies. The paper also shows that disabling any single optimization component (thread graph construction, layout optimization, operator scheduling, memory planning) leads to substantial performance degradation, highlighting the importance of Mirage's multi-faceted approach. End-to-end evaluations show Mirage reducing latency by 0.9-1.9x for common DNN models.
Limitations and Future Work
- LAX Program Limitation: The probabilistic equivalence verifier is currently limited to "LAX programs," which include multi-linear operators, division, and limited exponentiation. It does not support certain operators like ReLU. The authors mention developing a solver-based verifier for arbitrary tensor programs as an alternative, which requires more manual effort to specify operator properties.
- Search Time: While Mirage significantly reduces search time compared to naive approaches, optimizing complex LAX programs can still take up to 4 hours. The authors plan to further optimize the search procedure.
- Memory Transfer Overhead: For kernels with light computation, the overhead of transferring data between global and shared memory can dominate runtime. Future work aims to mitigate this by allowing Mirage to bypass shared memory during data loading when beneficial.
- Aeq Axiom Limitations: The abstract expression pruning relies on a set of axioms (Aeq) that, while providing a good balance, do not include cancellation rules. This means Mirage might miss some equivalent uGraphs.
The paper suggests extending Mirage to support new operators and further optimizing the search process.
Summary updated