All posts
    Heterogeneous Inference · 2026-11-01 · 8 min read

    Megakernels, and the layer above them

    Megakernels fuse a model's whole forward pass into one persistent kernel and remove the idle gaps between operations. They are tuned to one chip — which is exactly why a heterogeneous routing layer on top makes them more useful.

    The idle time hiding inside every forward pass

    A conventional inference engine runs a model as a long chain of small GPU programs, called kernels: one for a normalisation, one for attention, one for each matrix multiply, and so on. Each kernel is launched, runs, and finishes before the next one can start.

    At large batch sizes this barely matters, because each kernel has plenty of work. But when an agent asks a small model for one answer at a time, each kernel is tiny and the gaps between them start to dominate. The chip spends a real share of its time waiting: for a launch, for a sync barrier, or for the next layer's weights to arrive from memory.

    Fig. 1Many kernels vs. one megakernel
    KERNEL PER OPERATIONAmber gaps = launch overhead + sync barriers: the chip waitsONE PERSISTENT MEGAKERNELLOAD NEXT WEIGHTSCOMPUTE CURRENT LAYERTIME SAVEDNo boundaries, so loading and computing overlap
    Top: a conventional forward pass launches a separate kernel per operation, and the chip idles at every boundary. Bottom: a megakernel runs the whole pass as one persistent program and loads the next layer's weights while the current one computes. Illustrative, not to scale.

    What a megakernel is

    A megakernel removes the boundaries. Instead of hundreds of separate launches, the entire forward pass runs as one persistent program that stays resident on the chip. Inside it, a scheduler hands out work to the chip's cores and starts loading the next layer's weights while the current layer is still computing.

    The idea moved from research to practice quickly. Hazy Research at Stanford fused the full Llama-1B forward pass into a single megakernel on H100 and reported it outperformed existing systems by over 1.5x on low-latency decode. The Mirage Persistent Kernel (MPK) project followed with a compiler that turns multi-GPU model code into a megakernel automatically, and Cohere has since published a megakernel serving engine for one of its own models. Those are their numbers, on their hardware; links are below.

    The catch: a megakernel belongs to one chip

    A megakernel gets its speed by fitting the exact shape of one accelerator: how many cores it has, how big its on-chip memory is, how its memory system behaves. That fit is the whole point, and it is also the limit. A megakernel built for an NVIDIA H100 does not simply run well on an AMD MI300X, an Intel CPU, or a dataflow accelerator. Each needs its own version, or a compiler that targets it.

    It is also tied to one model. Change the architecture, the context length or the quantisation, and the megakernel has to be rebuilt and retuned. And it pays off most in one regime — small batches where latency matters — while classic batched serving often still wins when the chip is already full of work.

    Adding the heterogeneous layer

    This is where heterogeneous compute comes in. If every chip in a fleet can carry its own best runtime — a megakernel where one exists, a batched engine where that is better — then the question shifts from "how fast is this chip?" to "which chip and which runtime should take this request, right now?"

    That is a three-layer stack. At the bottom, kernels tuned per chip. In the middle, a runtime per chip that handles batching, cache layout and quantisation. On top, a fabric layer that sees all of them and places each request. Megakernels deepen the bottom layer; they don't remove the need for the top one. The more specialised the kernels get, the more the placement decision is worth.

    Fig. 2Three layers of optimisation
    Layer 3 · Fabricmodel="qvolt/route"
    QServe routing picks the chip and runtime per request
    Layer 2 · Runtime per chip
    Batching, KV cache layout, quantisation — tuned separately for each silicon
    NVIDIA GPU
    Layer 1 · Kernel
    Megakernel built for this chip
    AMD GPU
    Layer 1 · Kernel
    Separate megakernel, separate tuning
    CPU
    Layer 1 · Kernel
    Fused loops for tool work
    Dataflow accelerator
    Layer 1 · Kernel
    Whole model mapped onto the chip
    Evaluating
    Megakernels optimise inside one chip. The fabric layer decides which chip, and which compiled runtime, gets each request. SambaNova, Cerebras and D-Matrix systems are under evaluation at QVolt and are not serving traffic.

    What the routing layer decides

    The same model can then be served several ways at once. An interactive agent step on a small model, where a single user is waiting, goes to a megakernel runtime. A busy chat endpoint with many users at once goes to a batched runtime that maximises throughput. A long document goes to a high-compute pool for prefill. And the tool call in between — running code, querying a database — goes to a CPU sandbox, because it involves no model math at all.

    Purpose-built dataflow accelerators push the same idea into hardware: they lay the whole model out across the chip, which is a megakernel in silicon. They are another specialised option for the router to weigh, not a replacement for it.

    Fig. 3Same model, different runtimes
    Interactive agent step, small modelBatch of one, latency mattersMegakernel runtime
    Busy chat endpointMany users at once, throughput mattersBatched runtime
    Long-document promptPrefill-heavy, compute-boundHigh-compute pool
    Tool call or code runNo model math at allCPU sandbox
    A megakernel is one more option the router can choose, not a replacement for the others. Where it wins depends on batch size, model and chip — measure on your own traffic.

    When it is worth it

    Megakernels are not free. Each one is engineering work per model and per chip, and it has to be retested whenever either changes. They are most worth building for models you will serve for a long time, at low batch sizes, on hardware you have a lot of.

    Fig. 4Where megakernels pay off
    Likely to help
    • Low-batch decode where every millisecond counts
    • Small and mid-sized models
    • Agent loops with many short sequential calls
    • A fixed model you will serve for a long time
    Likely to gain less
    • Large batches that already keep the chip busy
    • Models that change every week
    • Moving one chip's megakernel to another vendor
    • Prefill-heavy work bound by raw compute
    A quick screen drawn from published research. Results vary by model, chip and batch size.

    How QVolt approaches it

    QServe already keeps a tuned runtime per chip across the NVIDIA, AMD and Intel capacity in the QVolt fabric, and QServe routing chooses among them per request with model="qvolt/route". Megakernel-style runtimes fit into that design as one more runtime option per chip and model, chosen when the request profile suits it. SambaNova, Cerebras and D-Matrix systems are under evaluation and are not serving traffic.

    We have not published megakernel measurements of our own. When we do, they will follow our published test method, per model and per hardware pairing. Until then, the figures in this post are third-party results, credited to their authors.

    Further reading

    Put this into practice

    Bring us your workload and we will benchmark it on the accelerator and region you are considering.