Abstract
The development of high-performance computation kernels is a critical yet labor-intensive task in modern AI systems, often requiring deep expertise in both algorithms and hardware architectures. This paper introduces AKG Kernel Agent, a multi-agent framework that automates kernel synthesis and optimization across diverse hardware backends (GPUs, NPUs, and CPUs). By utilizing a "Unified Sketch" intermediate representation to decouple optimization strategies from implementation details, the system bridges the performance-portability gap. AKG Kernel Agent achieves a 1.46× average speedup over PyTorch Eager baselines while ensuring high functional correctness through an iterative, conductor-led verification loop.
Introduction
Modern AI models, particularly Large Language Models (LLMs) and multimodal systems, rely on high-performance "kernels"—the low-level code that executes mathematical operations on hardware. However, developing these kernels is a major bottleneck. Manual optimization requires rare expertise in both algorithms and specific hardware architectures, such as memory hierarchies and instruction sets.
Furthermore, the "performance-portability gap" is widening: a kernel optimized for an NVIDIA GPU won't run efficiently on a Huawei Ascend NPU or an Intel CPU. While LLMs show promise in coding, they often struggle with the precision required for high-performance kernels, frequently producing code with compilation errors or suboptimal performance.
The AKG Kernel Agent Framework
The authors propose a multi-agent system designed to mimic a professional engineering workflow. The architecture centers on four specialized agents:
- The Designer: Analyzes hardware specs and operator requirements to create a Unified Sketch. This is a hardware-agnostic intermediate representation (IR) that captures the "intent" of the optimization (tiling strategies, parallelization, data flow) without committing to a specific programming language.
- The Coder: Translates the Unified Sketch into executable code for a target Domain-Specific Language (DSL) like Triton, CUDA-C, or TileLang.
- The Verifier: Acts as the quality gate, performing numerical accuracy checks against a reference (like NumPy) and profiling performance on actual hardware.
- The Conductor: The orchestrator. It analyzes failure logs from the Verifier and "routes" the task back to the right agent—sending syntax errors to the Coder and algorithmic flaws back to the Designer.
Key Innovations
- Document-Driven Integration (DDI): Instead of hard-coding hardware knowledge, the system ingests structured manuals and API references. This allows it to support new chips or languages just by "reading" the documentation.
- Hierarchical Code Retrieval: A multi-stage RAG (Retrieval-Augmented Generation) process that matches candidates based on computational logic first, then filters by hardware/DSL, and finally ranks by "shape compatibility."
- Iterative Search (Island Model): To find the fastest version of a kernel, the system runs a parallel search across multiple "islands" of candidates, allowing successful optimization strategies to "migrate" and evolve over several rounds.
The Conductor and Iterative Optimization
Unlike traditional fixed pipelines that may stall upon encountering errors, the Conductor diagnoses the root cause of failures. It distinguishes between syntax errors (routed to the Coder) and algorithmic flaws (routed to the Designer), significantly improving the efficiency of the optimization loop. This adaptive routing ensures that the system doesn't just retry the same prompt but actively learns from execution feedback.
Evaluation and Results
The researchers evaluated their system using KernelBench (Level 1) and a new, more rigorous suite comprising nearly 400 operators for dynamic and static shapes. This new benchmark specifically targets "fused" operators common in production environments.
- Performance: On the Triton-Ascend (NPU) backend, the agent achieved an average 1.46× geometric mean speedup over PyTorch Eager. On CPU backends, it reached up to a 9.00× speedup for specific "Scan & Loss" kernels.
- Correctness: The system achieved 100% correctness on KernelBench Level 1 for Triton-CUDA and between 85–91% on the more challenging dynamic shape benchmark.
- Efficiency: The iterative evolution module successfully fused operations (like LayerNorm), eliminating intermediate memory accesses that typically slow down standard framework implementations.
Conclusion and Future Work
AKG Kernel Agent demonstrates that decoupling optimization strategy from implementation through a multi-agent system can effectively automate high-performance kernel synthesis. While the system handles common fusions well, extremely complex or highly specialized kernels remain a challenge. Future directions include incorporating Reinforcement Learning to guide the search process based on performance feedback and extending the Unified Sketch language to support advanced hardware features like asynchronous execution and specialized tensor core utilization.
Summary updated