Accelerating the Domestic AI Compute Ecosystem: Prefill Performance Optimization Through Deep Hardware Adaptation

    This article examines how deep adaptation between open-source large language models and domestic AI accelerators can push Prefill-stage compute utilization close to theoretical hardware limits. It breaks down the core techniques behind a reported 98.5% peak utilization, including operator fusion, attention head dimension alignment, and specialized kernels, and explains how to measure peak utilization rigorously. It then outlines the full engineering chain from operators to system-level deployment, covering memory layout, precision strategy, performance regression, and cloud integration, before discussing memory subsystem bottlenecks and a transferable optimization checklist for engineering teams.

    1. Introduction: Why the Prefill Stage Is the Key Battleground for Compute Efficiency

    In the large model inference pipeline, computation is typically divided into two distinct phases: Prefill and Decoding. The Prefill phase processes the entire input context at once, mapping all prompt tokens in parallel into the KV Cache. Its computational profile is characterized by large matrix multiplications, high parallelism, and compute-intensive workloads. The Decoding phase, by contrast, generates output autoregressively token by token, processing only one position per step, which makes it a typical memory-access-intensive workload.

    This difference means the two phases have entirely different performance bottlenecks. Prefill is often constrained by the actual throughput of the matrix multiplication units, while Decoding is more limited by memory bandwidth and cache access patterns. Therefore, when the industry discusses a platform’s inference efficiency approaching hardware peak, it is essential to specify which phase it refers to, and under what precision and sequence length conditions it was measured. Otherwise, the numbers are not comparable.

    A set of engineering data that has recently drawn widespread attention in the technical community illustrates this point: a new version of a domestic open-source large model, after deep adaptation on a domestic accelerator card, achieved a measured Prefill compute throughput of 98.5% of the hardware’s theoretical peak, and 86.1% in the Decoding phase. The significance of these numbers lies not in the figures themselves, but in the engineering methodology they validate—when model structure, operator implementation, and hardware characteristics are co-designed, general-purpose hardware utilization can be pushed close to the theoretical upper limit.

    2. Technical Breakdown: How 98.5% Peak Utilization Is Achieved

    2.1 Operator Fusion: Reducing the Overhead of Moving Intermediate Tensors

    In a naive implementation, normalization, positional encoding, attention computation, and data type conversion are often written as four separate operators. Each time execution crosses an operator boundary, the intermediate result must be written back to memory and then read out by the next operator. In Prefill scenarios with large tensors, this memory-access overhead can significantly consume effective compute.

    The core idea of operator fusion is to combine multiple steps into a single kernel, keeping intermediate results in on-chip high-speed cache or registers and outputting only the final result. Taking the fusion of “normalization + rotary positional encoding + attention + type conversion” as an example, the benefits come from three levels:

    • Reduced memory access: intermediate tensors no longer travel back and forth to memory, greatly easing bandwidth pressure;
    • Reduced launch overhead: the number of kernel launches drops from several to one, with especially noticeable gains in short-sequence scenarios;
    • Fuller pipelines: instructions within the merged kernel are more continuous, reducing idle bubbles in the compute units.

    The following illustrative pseudocode shows the scheduling difference before and after fusion:

    1. # Without fusion: four round trips to memory
    2. x = rms_norm(x) # read/write memory
    3. q, k, v = apply_rope(x) # read/write memory
    4. out = attention(q, k, v) # read/write memory
    5. out = out.to(dtype) # read/write memory
    6. # With fusion: single kernel, intermediates stay on-chip
    7. out = fused_norm_rope_attn_cast(x, cache, dtype)

    2.2 Attention Head Dimension Alignment: Why 128 Is the Performance Threshold

    Hardware matrix multiplication units have a natural preference for specific dimension sizes. When the attention head dimension aligns evenly with the hardware’s vectorization width and tile size, every tile can be fully filled. Once misaligned, edge tiles require masking or zero-padding, and compute is immediately wasted.

    Unifying the head dimension to 128 is a common alignment choice in engineering practice: it is divisible by both mainstream vector widths and common tile sizes, so tiled matrix multiplication incurs almost no edge loss. This is also the key step in adaptation work to “get the loop closed in code”—not relying on tuning and luck, but making the model structure actively conform to the hardware’s tiling constraints.

    2.3 Specialized Kernel Instances: Generating Dedicated Paths for Specific Model Shapes

    General-purpose kernels must accommodate a wide variety of shapes and configurations, and the branch judgments and shape inference themselves consume instruction cycles. The engineering approach is to generate a set of specialized kernel instances for well-defined model shapes (for example, fixed head dimensions, fixed layer structure, fixed cache layout), and dispatch directly to the specialized path at runtime, skipping all general-purpose checks.

    This kind of specialization is typically organized as independent implementation files by model identifier, combined with explicit type markers for compile-time or load-time selection. The benefit is twofold: it reduces control overhead and allows the compiler to perform more aggressive loop unrolling and instruction scheduling.

    2.4 How to Measure Peak Utilization Correctly

    The statement “98.5% of hardware peak” needs rigorous grounding, otherwise it easily becomes marketing talk. A reproducible measurement should at least include the following elements:

    1. Specify the precision: theoretical hardware peak can differ by several times across data formats, so the format used for computation must be stated;
    2. Specify the source of the theoretical peak: use the dense compute in the hardware’s public specifications as the denominator, not sparse compute;
    3. Specify the workload shape: sequence length, batch size, and context length all significantly affect utilization;
    4. Specify the statistical method: whether the mean over a steady-state interval or the instantaneous peak value is used must be declared in advance.

    The formula can be expressed as:

    1. Utilization = Measured effective compute (TFLOPS) / Hardware theoretical dense peak (TFLOPS) × 100%
    2. Effective compute = Model-required floating-point operations / Measured elapsed time

    It is worth noting that the required compute in the Prefill phase is mainly composed of attention and linear layers. If the implementation introduces redundant computation (such as unnecessary reordering or repeated normalization), the numerator is artificially inflated, leading to overstated utilization. Therefore, a rigorous evaluation reports two sets of data: the “required-compute measure” and the “actually executed instructions measure.”

    3. From Operators to System: The Complete Engineering Chain of Deep Adaptation

    Single-point operator optimization is only the starting point. To reliably reproduce high utilization in real workloads, a complete engineering chain is needed.

    3.1 Co-Design of Compute Graph and Memory Layout

    The prerequisite for high utilization is that the arrangement of data in memory matches the computation order. Common practices include: organizing weights by tile order, changing the KV Cache layout to a form friendly to contiguous access, and placing variable-length tensors in a specific memory pool to reduce fragmentation. Layout adjustments often do not change the mathematical result, yet can bring double-digit throughput differences.

    3.2 Precision Strategy and Numerical Stability

    Low precision can directly raise the theoretical peak, but the boundary of numerical stability must be held. Engineering practice usually adopts a layered strategy: matrix multiplication uses low precision, normalization and accumulation use higher precision, and sensitive small operators retain high precision; meanwhile, techniques such as stochastic rounding and loss scaling control error accumulation. The difficulty of adaptation work is that performance optimization and precision regression must pass simultaneously—degradation on either side means it cannot be shipped.

    3.3 Performance Regression and Continuous Validation

    Hardware adaptation is not a one-time delivery but long-term maintenance. A workable mechanism is to build a benchmark suite covering different sequence lengths and batch sizes, automatically run and compare against the baseline after each kernel change, and block the merge if the regression exceeds a threshold. Combined with layered performance profiling (operator-level, inter-layer, and end-to-end), the source of a regression can be quickly located.

    An illustrative benchmark configuration structure:

    1. benchmark:
    2. seq_lengths: [512, 2048, 8192]
    3. batch_sizes: [1, 8, 32]
    4. metrics:
    5. - prefill_tflops
    6. - decode_tflops
    7. - utilization_ratio
    8. - p99_latency_ms
    9. baseline_tolerance: 0.03 # block merge if regression exceeds 3%

    3.4 Integration with General Cloud Capabilities

    In real deployments, model services rarely run in isolation, but are combined with general cloud capabilities such as container platforms, object storage, message queues, logging services, and monitoring and alerting. For example: model weights are stored in object storage and distributed through image pre-warming; requests are peak-shaved through a message queue; inference metrics are integrated into monitoring and alerting to enable auto-scaling. Baidu AI Cloud provides standardized infrastructure support for such general capabilities, based on which enterprises can turn optimization results into stable online services.

    4. The Memory Subsystem: The Long-Underestimated Second Ceiling

    Once compute utilization is pushed high, the bottleneck quickly shifts to the memory subsystem. Directions the industry is exploring include higher-width memory interfaces, wafer-on-wafer hybrid bonding across multiple layers, and bandwidth improvements from shorter interconnect distances. The technical essence of hybrid bonding is to increase interconnect density by shrinking the bonding pitch; its advantages are high bandwidth and short interconnect distance, while the cost is difficult yield control and limits on the number of stacked layers and single-die capacity, requiring more compute chips to interconnect collaboratively.

    For developers, this means two things. First, bandwidth gains do not automatically translate into business benefits; they must be paired with memory-access-friendly operators and caching strategies. Second, the topology of multi-chip interconnects directly affects collective communication efficiency, and the model parallelism partitioning scheme must match the topology, otherwise communication overhead will offset the bandwidth gains.

    5. A Transferable Practice Checklist

    Regardless of how the underlying hardware changes, the following methods have general applicability:

    • Profile before optimizing: use operator-level time breakdown to locate the real bottleneck, avoiding optimizing non-hot paths based on intuition;
    • Prioritize eliminating memory access: the gains from operator fusion and reusing on-chip cache usually exceed simply increasing parallelism;
    • Align shapes to hardware: align key dimensions to the hardware tile size to eliminate edge waste;
    • Specialization over generalization: generate specialized kernels for stable shapes to reduce control and judgment overhead;
    • Define the measure first: label any performance conclusion with precision, workload, and statistical method to ensure reproducibility;
    • Dual gates for precision and performance: optimization must not come at the cost of numerical stability degradation;
    • Establish long-term regression: embed benchmarks into continuous integration to prevent performance from silently regressing.

    6. Conclusion

    Prefill performance approaching hardware peak is essentially not the credit of any single technique, but the result of four layers working together: model structure, operator implementation, memory layout, and hardware characteristics. For engineering teams, what is truly worth accumulating is this reproducible methodology: defining metrics with rigorous measures, compressing overhead with fusion and specialization, holding stability with layout and precision strategies, and safeguarding long-term gains with continuous regression. When domestic models and domestic compute achieve this two-way fit at the code level, the ecosystem loop gains a foundation for sustainable evolution.