Fused Operators and Memory Bandwidth Optimization for Domestic AI Accelerators
A practical look at how model-specific kernels, operator fusion, and memory-system optimization can improve large language model inference on domestic AI accelerators. The article explains why Prefill and Decoding need different strategies, how to evaluate performance claims, and how to build a reproducible validation process.
As large language model infrastructure evolves, performance depends not only on model size and training data, but also on how effectively the software stack is adapted to the underlying hardware. Recent public code from a large-model team includes implementations tailored to domestic AI accelerators, covering operator fusion, optimization for specific tensor shapes, and kernel scheduling for different inference stages. These changes point to a broader shift: coordination between domestic models and domestic computing hardware is moving beyond basic compatibility toward more effective use of hardware capabilities.
Published performance figures depend on factors such as the model under test, input length, batch size, precision, compiler options, device frequency, and test environment. They should not be treated as representative of every production workload. A more useful approach is to examine the code structure and optimization techniques for reusable engineering lessons.
1. Why Prefill and Decoding Need Different Optimization Strategies
LLM inference is generally divided into two stages: Prefill and Decoding.
Prefill processes the full user context. Because many tokens can be computed in parallel, matrix operations are relatively large and compute units are more likely to remain well utilized. Prefill is therefore typically compute-bound. Key optimization goals include:
- Increasing matrix multiplication throughput.
- Reducing reads and writes of intermediate tensors between operators.
- Using low-precision data types appropriately.
- Improving on-chip cache hit rates.
- Overlapping computation with memory access where possible.
Decoding has a different profile. The model typically generates one or a small number of tokens at a time while accessing the historical KV Cache. Each step involves less computation, so memory access, cache layout, and scheduling overhead often become more significant. Decoding is therefore more likely to be memory-bound. Its optimization priorities include:
- Reducing the cost of reading the KV Cache.
- Minimizing launches of small kernels.
- Optimizing thread-block configuration and work partitioning.
- Improving access to non-contiguous memory.
- Increasing batch-level concurrency where possible.
A single kernel and parameter configuration is unlikely to be optimal for both stages. Providing dedicated implementations for each stage, as seen in public code, reflects this engineering reality.
2. Operator Fusion as a Way to Improve Hardware Utilization
Attention computation can involve normalization, positional encoding, attention, and data type conversion as separate operators. A conventional execution flow may look like this:
Input↓Normalization↓Positional encoding↓Attention↓Data type conversion↓Output
Each operator may write intermediate results to global memory for the next operator to read, and each may require a separate kernel launch. In large-scale inference workloads, these costs can have a noticeable impact on end-to-end performance.
Operator fusion combines multiple logical steps in a single device kernel:
Input → Normalization + positional encoding + attention + data type conversion → Output
This approach can help in three main ways.
1. Fewer Trips to Global Memory
If intermediate results can be passed through on-chip registers or shared memory rather than written back to device memory, memory bandwidth pressure is reduced. For long-context Prefill workloads, cutting intermediate data movement can be more effective than simply increasing compute frequency.
2. Lower Kernel Launch Overhead
Each operator requires task submission, parameter preparation, and synchronization. When individual operations are small but invoked frequently, launch overhead can become a bottleneck. Fusion allows multiple stages to be handled in one dispatch, improving overall efficiency.
3. Better Pipeline Coordination
A fused kernel can more precisely coordinate loading, computation, and writeback, reducing synchronization delays between operators. When compute units, caches, and memory channels can operate as a pipeline, the workload is more likely to approach the hardware’s theoretical performance limits.
Fusion is not beneficial without limit. Combining too many operations can increase register usage, reduce thread-level parallelism, or cause spills to local memory. Kernel design must balance reduced memory traffic against resource consumption and parallelism.
3. Specialized Kernels Reflect Deeper Hardware Adaptation
Public implementations that include many specializations for particular head dimensions, data layouts, and model variants indicate that optimization has moved beyond general-purpose kernels toward model-level tuning.
Specializations commonly account for:
- Attention head dimensions.
- The relationship between query and key-value counts.
- Tensor layout.
- Sequence-length ranges.
- Data type combinations.
- Batch size and concurrency strategy.
- The different access patterns of Prefill and Decoding.
General-purpose kernels support a wide range of inputs, but may need to retain more branches and runtime checks. Specialized kernels can resolve more parameters at compile time, reducing runtime decisions and improving instruction layout and memory access efficiency.
A practical design is to use a general implementation as a fallback and specialized implementations for acceleration:
if shape and precision meet specialized conditions:call the specialized fused kernelelse:call the general-purpose kernel
This approach can handle varied production inputs while delivering better performance for common model configurations. Specialized kernels should always have a complete fallback path. Otherwise, changes in input length, batch size, or model structure may cause a sharp performance drop or even execution failures.
4. How to Interpret “Near-Peak Hardware Performance”
Hardware peak utilization is commonly expressed as measured compute throughput divided by theoretical peak throughput. If the device’s theoretical peak is P and the benchmark’s effective throughput is T, then:
Peak utilization = T / P × 100%
A result close to the theoretical peak indicates that compute units were well utilized for that particular workload. It does not mean the entire inference system achieves the same level of utilization. Reasons include:
- Theoretical peak figures are often based on ideal matrix shapes.
- Real models also incur communication, cache, scheduling, and synchronization costs.
- Different input lengths change arithmetic intensity.
- Decoding is often more constrained by memory access.
- End-to-end latency includes framework and serving-layer overhead.
Performance reports should therefore include operator-level throughput, stage-level throughput, and end-to-end metrics. A peak result for one kernel alone cannot fully represent the capacity of an online service.
5. The Role of High-Bandwidth Memory in LLM Inference
Model parameters, activations, and the KV Cache all consume substantial memory capacity and bandwidth. As context length grows, bottlenecks are increasingly likely to shift from computation to data movement.
High-bandwidth memory can help in three main ways.
1. Wider Data Paths
Increasing interface width can raise data throughput per unit of time at a given transfer rate. Wider interfaces also introduce challenges involving packaging, power consumption, signal integrity, and cost.
2. Greater Stacking Density
Stacking multiple layers of wafers or chips can provide greater capacity and bandwidth within a limited package area. Advanced bonding techniques can shorten interconnect distances, but they also place higher demands on manufacturing processes and yield.
3. Better Support for Cache-Intensive Workloads
During Decoding, frequent KV Cache reads can make higher bandwidth useful for easing memory bottlenecks. However, bandwidth is not the only factor that determines performance. Cache layout, access continuity, compression strategy, and cross-device communication also affect the realized benefit.
In other words, hardware bandwidth improvements must be matched by software optimization to translate into effective throughput. Non-contiguous kernel access patterns or frequent transfers between memory levels can prevent the system from using its theoretical bandwidth fully.
6. Building a Reusable Performance Validation Process
Teams working with domestic accelerators or other heterogeneous devices should establish a standardized validation process.
First, fix the test environment. Record the device model, driver version, compiler configuration, frequency state, precision format, and thread settings.
Second, test Prefill and Decoding separately. Do not combine them into a single metric. Cover short inputs, long contexts, multiple batch sizes, and different concurrency levels.
Third, collect a broad set of measurements, including:
- Operator latency.
- Memory bandwidth utilization.
- Compute-unit utilization.
- Number of kernel launches.
- On-chip cache hit rates.
- Device memory usage.
- End-to-end time to first token.
- Per-token generation latency.
- Steady-state throughput.
Fourth, verify correctness. Faster fused kernels must still be tested for numerical error across different input lengths, boundary shapes, precision modes, and edge-case inputs.
Fifth, maintain regression tests. After changes to kernels, compiler options, or scheduling strategies, compare results with a baseline to ensure that local improvements do not degrade other workloads.
7. Engineering Takeaways
Several broadly applicable lessons emerge from these public code changes.
First, hardware adaptation should be part of the model development process from the outset, rather than postponed until the model is complete.
Second, optimization should not focus only on individual matrix multiplications. The full inference path matters, including data layout, cache management, operator fusion, and scheduling.
Third, stable model structures are better candidates for specialized kernels that target high performance. When model structures change frequently, stronger generality is more important.
Fourth, performance results must include their test conditions. Metrics without input size, precision, batch size, and software version are difficult to reproduce and unsuitable for direct comparison.
Finally, the maturity of a domestic accelerator ecosystem depends not only on chip peak performance, but also on the completeness of its compiler, runtime, operator libraries, debugging tools, and model frameworks. Stable production performance requires joint optimization across software and hardware.
Deep hardware adaptation for LLMs is evolving beyond basic instruction compatibility and operator porting. It increasingly involves co-design around model structure, memory systems, and inference stages. Fused operators, specialized kernels, and high-bandwidth memory are important ways to improve the practical utilization of domestic compute. For developers, the most useful measure is not an isolated peak number, but a complete methodology spanning model-graph analysis, kernel design, compiler optimization, and end-to-end validation.
