How LLM Inference Operators Approach Hardware Peak Performance
This article explains why LLM inference performance often falls far below an accelerator's theoretical peak, and how operator implementation quality—rather than nominal hardware specs—becomes the primary constraint. It covers the two inference phases (compute-bound Prefill and memory-bound Decode), the overhead of fragmented attention kernels, and four engineering levers for closing the gap: operator fusion, data layout and memory access coalescing, structure-specific operator specialization, and memory bandwidth for Decode. It also provides guidance on benchmarking peak utilization with consistent methodology, plus a practical optimization path from measurement to end-to-end validation.
1. Introduction: From “It Runs” to “It Runs at Full Utilization”
A common misconception in LLM engineering is that once a model runs correctly on a given accelerator, performance can be left to the hardware specifications. In reality, on the same card and the same model, different implementations can differ several-fold in end-to-end throughput. A frequently discussed example is an inference attention operator that reaches roughly 425 TFLOPS on a class of domestic accelerators during the Prefill phase—about 98.5% of the hardware’s theoretical peak—and about 372 TFLOPS during Decode, around 86.1% of peak. The significance of these numbers is not the values themselves, but the engineering fact they reveal: operator implementation quality, not nominal hardware compute, is often the first constraint on inference performance.
Setting aside specific products and models, this article addresses the general technical question of how to make inference operators approach hardware peak performance, covering bottleneck identification, fusion strategies, data layout, and benchmarking methodology.
2. Why Inference Performance Often Falls Far Below Hardware Peak
2.1 Two Phases, Two Bottlenecks
Autoregressive decoding is typically split into two phases:
- Prefill: processes the entire input at once, with large matrix dimensions and high arithmetic intensity. It is compute-bound and, in theory, the phase that is easier to push close to peak.
- Decode: generates one token per step, so the matrices degenerate into “tall and thin” shapes with very low arithmetic intensity. It is memory-bound, with performance determined by memory bandwidth and the amount of KV Cache read.
This explains a common pattern: Prefill can often exceed 95% of peak, while Decode usually stays in the 60%–90% range. Attributing Decode’s low utilization simply to “weak hardware” is a frequent misjudgment.
2.2 The “Fragmentation” Overhead of Attention Operators
Attention computation involves scaled dot product, masking, Softmax, and reading and writing the KV Cache. Implemented naively, it produces many intermediate tensors that land in memory, creating “compute–write back–read again” round trips. The more kernels there are, the higher the launch overhead and the number of memory accesses, which naturally lowers measured utilization.
The following pseudocode shows the difference between a naive and a fused implementation:
# Naive implementation: multiple memory round trips, many kernelsq = layer_norm(x) # kernel 1q = apply_rope(q, pos) # kernel 2scores = q @ k.transpose(-1, -2) * scale # kernel 3scores = mask(scores) # kernel 4p = softmax(scores) # kernel 5out = p @ v # kernel 6out = out.to(dtype) # kernel 7# Fused implementation: done in a single kernel, intermediates stay on-chipout = fused_norm_rope_attention(x, k_cache, v_cache, pos, dtype)
The value of fusion is not just “fewer lines of code,” but keeping intermediate results in on-chip cache (SRAM/registers), avoiding high-latency round trips to memory.
3. Four Engineering Pillars for Approaching Peak
3.1 Operator Fusion: Reducing Memory Access and Launch Overhead
Merging normalization, positional encoding, attention, and type conversion into a single fused operator is the most direct way to raise utilization. A practical indicator of whether fusion is effective is Arithmetic Intensity (FLOPs/Byte): if this value rises significantly after fusion, the compute share increases, making it easier to enter the compute-bound regime and approach peak.
3.2 Data Layout and Memory Access Coalescing
The access pattern to the KV Cache in attention determines bandwidth efficiency. Engineering practice usually focuses on three points:
- Contiguous access: have the same thread block access contiguous addresses to achieve coalesced memory access;
- Tiling: split Q/K/V into blocks that fit on-chip cache, reducing repeated reads;
- Layout alignment: how the head dimension and hidden dimension are aligned directly affects the fill rate of vectorized instructions.
A typical alignment constraint example:
# Pseudo-config: head dimension and block sizes must align to vector widthHEAD_DIM = 128 # aligned to 128 for vectorized loadsBLOCK_M = 128 # tiling along the Q dimensionBLOCK_N = 64 # tiling along the KV dimensionDTYPE = "bf16" # tradeoff between compute precision and bandwidth
3.3 Structure-Specific Specialization
Attention structures differ greatly across models: head dimension, whether grouped-query attention (GQA) is used, RoPE variants, and how the KV Cache is quantized all vary. Generating a specialized instance for a specific structure rather than one general-purpose template lets the compiler perform more aggressive constant folding and instruction scheduling. The cost is binary size growth and higher maintenance overhead, so a supporting pipeline of automated generation and regression testing is needed.
3.4 Memory Bandwidth: The Real Ceiling for Decode
In Decode, generating each token theoretically requires reading the relevant KV Cache once. If bandwidth is insufficient, even abundant compute sits idle. Mitigation includes KV Cache quantization, paged management, prefix reuse, and increasing batch size to improve bandwidth amortization. Industry discussion of higher-bandwidth storage and packaging approaches (for example, custom high-bandwidth memory with wider interfaces and more channels) is essentially about expanding capacity for the Decode phase.
4. How to Scientifically Benchmark “Peak Utilization”
Many teams reach contradictory performance conclusions, rooted in inconsistent methodology. It is advisable to fix the following variables:
- Theoretical peak definition: specify whether it is based on dense or sparse compute;
- Precision mode: peak differs across precisions and must not be mixed;
- Sequence length and batch size: Prefill and Decode must be reported separately;
- Whether warmup is included: first-run compilation and cache warmup should be excluded from the statistics;
- End-to-end vs. single operator: high single-operator utilization does not equal high service throughput.
A reusable recording template:
benchmark:phase: prefill # prefill | decodeseq_len: 4096batch: 16dtype: bf16warmup: 20iters: 100metric: {tflops, peak_ratio, mem_bandwidth_gbps}
5. Practical Recommendations: An Actionable Optimization Path
- Measure first, then optimize: collect operator-level timing via monitoring and logging services to locate the Top-N hotspots;
- Distinguish bottleneck types: for compute-bound cases prioritize fusion and scheduling; for memory-bound cases prioritize layout and bandwidth;
- Establish baseline regression: run a fixed-methodology benchmark on every change to prevent performance regressions;
- Automate specialized instance generation: use templates and code generation to reduce maintenance cost;
- Validate end-to-end: stress-test real traffic on common infrastructure such as container platforms and message queues, focusing on tail latency rather than only the average.
6. Conclusion
The real lesson from numbers like “98.5% of peak” is that the maturity of the domestic compute ecosystem is reflected not only in hardware parameters, but also in the supporting maturity of operator libraries, compiler stacks, benchmarking standards, and engineering methodology. For developers, rather than chasing a single benchmark score, it is better to build a closed-loop method of “bottleneck identification–fusion optimization–layout tuning–unified methodology.” This method does not depend on any specific vendor and can be ported across different acceleration platforms. It is a key capability for maintaining engineering efficiency as compute supply continues to evolve.
