NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Mirage Persistent Kernel: A Compiler and Runtime for Mega-Kernelizing Tensor Programs

Xinhao Cheng, Zhihao Zhang, Yu Zhou, Jianan Ji, Jinchen Jiang, Zepeng Zhao, Ziruo Xiao, Zihao Ye, Yingyi Huang, Ruihang Lai, Hongyi Jin, Bohan Hou, Mengdi Wu, Yixin Dong, Anthony Yip, Songting Wang, Wenqin Yang, Xupeng Miao, Tianqi Chen, Zhihao JiaarXiv 2025 · DOI

Introduction

Modern machine learning frameworks, such as PyTorch, typically execute models using a "kernel-per-operator" paradigm. In this model, each operation—such as a matrix multiplication or an attention layer—is launched as a discrete GPU kernel. While this modularity simplifies development, it introduces significant performance bottlenecks in high-performance inference, particularly for Large Language Models (LLMs).

Mirage Persistent Kernel (MPK) is a novel compiler and runtime system designed to overcome these limitations. MPK automatically transforms multi-GPU model inference programs into a single, highly optimized "mega-kernel." By managing data dependencies at the granularity of individual Streaming Multiprocessors (SMs) rather than whole kernels, MPK eliminates launch overheads and unlocks previously impossible optimizations like cross-operator pipelining, speeding up LLM inference by up to 1.7x over state-of-the-art systems.

The Bottlenecks of Traditional Execution

The standard execution model suffers from three primary flaws that hinder hardware utilization:

  1. Implicit Kernel Barriers: GPU architectures force a global synchronization point between kernels. All threads of a preceding kernel must complete before any thread of the subsequent kernel can begin. This prevents cross-operator software pipelining, where data for a future operation could be fetched while the current operation is still processing.
  2. Lack of Fine-Grained Overlap: In multi-GPU setups, communication steps (like AllReduce) must wait for the entire preceding computation kernel to finish. Ideally, communication should begin as soon as the first chunks of data are ready, overlapping compute and transfer.
  3. Launch Overheads: Launching thousands of kernels per inference iteration incurs significant CPU-side overhead. While technologies like CUDA Graphs attempt to mitigate this, they are often too static to handle the dynamic sequence lengths and branching logic inherent in LLM decoding.

While "mega-kernels"—persistent kernels that fuse an entire model into one program—can solve these issues, they traditionally require heroic manual engineering effort. MPK automates this process, providing the performance of hand-tuned code with the ease of a standard compiler.

The MPK Architecture

MPK achieves automatic mega-kernelization through a specialized compiler and an embedded runtime.

The MPK Compiler and tGraph Representation

Instead of a standard computation graph where nodes represent high-level operators, MPK compiles programs into a tGraph (Task Graph). In a tGraph, nodes represent sub-operator tasks assigned to individual SMs, and edges represent fine-grained synchronization events. The compiler optimizes this graph by fusing redundant events and linearizing the structure for compact storage in GPU memory. It then utilizes superoptimization techniques to generate highly efficient CUDA code for each specific task.

In-Kernel Parallel Runtime

MPK executes the tGraph using a runtime embedded entirely within the mega-kernel itself, consisting of several key innovations:

  • Workers and Schedulers: Physical SMs are partitioned into "workers," which execute the computational tasks, and "schedulers," which track dependencies and dispatch tasks. This decentralized approach avoids the overhead of global GPU synchronization.
  • Hybrid Task Launch: To balance efficiency and flexibility, MPK employs a hybrid scheduling strategy. It uses Just-In-Time (JIT) scheduling for unpredictable tasks, such as attention mechanisms with variable sequence lengths, and Ahead-Of-Time (AOT) scheduling for predictable, static tasks.
  • Paged Shared Memory: Standard GPU programming models assume a kernel owns all of an SM's shared memory (SRAM) for its duration. MPK introduces a paged abstraction for shared memory, allowing a worker to pre-fetch data for a subsequent task into a free page while the current task is still computing, enabling true cross-operator pipelining.

Evaluation and Results

The researchers evaluated MPK on LLM serving workloads, simulating batched-inference requests with a fixed prompt length of 64 and a decoding phase of 1024 tokens. The evaluation covered several models, including Qwen3 (0.6B to 30B) and Llama-3.2-1B, across NVIDIA A100, H100, and B200 GPUs.

Performance Highlights

  • End-to-End Speedups: MPK reduced inference latency by 1.0x to 1.7x compared to highly optimized systems like vLLM and SGLang.
  • Hardware Efficiency: For the Qwen3-8B model on an A100, MPK achieved a per-token decoding latency of 12.5 ms. This is remarkably close to the theoretical memory-bandwidth lower bound of approximately 10 ms, indicating near-optimal hardware utilization.
  • Multi-GPU Scaling: In 8-GPU H100 configurations using tensor parallelism, MPK achieved 1.1x to 1.4x throughput improvements over vLLM and up to 10x over native PyTorch.
  • Ablation Studies: The results showed that cross-task pipelining alone improved individual task runtimes by 20-30%, while fine-grained compute-communication overlap reduced per-iteration latency by roughly 10%.

Conclusion and Future Work

MPK demonstrates that compiler-driven mega-kernels are a viable and highly effective path for optimizing LLM inference. By moving scheduling and dependency management onto the GPU itself and operating at the SM level, MPK bypasses the rigid constraints of traditional kernel execution.

Current limitations include a decentralized scheduling strategy that may miss global optimization opportunities. Future work will explore globally coordinated scheduling strategies with minimal overhead and extending the runtime to support increasingly dynamic workloads and diverse model architectures.

Summary updated

BibTeX
@misc{cheng2025mirage,
  author = {Xinhao Cheng and Zhihao Zhang and Yu Zhou and Jianan Ji and Jinchen Jiang and Zepeng Zhao and Ziruo Xiao and Zihao Ye and Yingyi Huang and Ruihang Lai and Hongyi Jin and Bohan Hou and Mengdi Wu and Yixin Dong and Anthony Yip and Zihao Ye and Songting Wang and Wenqin Yang and Xupeng Miao and Tianqi Chen and Zhihao Jia},
  title = {{Mirage Persistent Kernel: A Compiler and Runtime for Mega-Kernelizing Tensor Programs}},
  year = {2025},
  eprint = {2512.22219},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2512.22219},
}
Figure