KForge: LLM-Driven Cross-Platform Kernel Generation for AI Accelerators

Taras Sereda, Burak Bartan, Ankita Nayak, Tom St. John, Natalie Serrino, Zain Asgar

TL;DR

This paper introduces KForge, an LLM-powered framework that automates the generation and optimization of high-performance kernels for AI accelerators. By using two collaborating LLM agents—one for generation and one for performance analysis—KForge iteratively refines code to achieve correctness and speed, significantly improving inference performance on diverse hardware.

What Problem Does This Paper Address?

Modern AI inference pipelines are increasingly complex, involving multiple stages like reasoning, data retrieval, and multi-agent coordination. These stages have distinct computational and memory needs, making it crucial to run each on the most suitable hardware accelerator. This heterogeneity presents a significant systems challenge: creating efficient, high-performance code (kernels) for a wide array of hardware backends and programming models. Manually writing these kernels is a time-consuming and expert-intensive task that doesn't scale with growing kernel complexity. While LLMs show promise for code generation, they struggle with the nuances of low-level code, cross-platform generalization, and achieving performance parity with hand-tuned code.

Methods

KForge employs a novel, iterative refinement loop powered by two specialized LLM agents:

  • Generation Agent: This agent takes a prompt (describing the desired kernel and potentially a reference implementation) and generates candidate kernel code. It uses feedback from compilation and correctness checks to iteratively improve the code until it's functionally correct.
  • Performance Analysis Agent: This agent analyzes profiling data (from various tools) and provides specific, actionable recommendations to the generation agent. These recommendations focus on hardware utilization metrics like memory bandwidth, warp occupancy, and arithmetic intensity, guiding the next round of synthesis towards performance improvements.

This loop alternates between:

  1. Functional Passes: Ensuring the generated code compiles, executes without errors, and produces correct output.
  2. Optimization Passes: Using performance feedback to refine the code for speed.

KForge is designed to be cross-platform, supporting four accelerator vendors (NVIDIA, AMD, Intel, Apple) and six programming models (CUDA, Triton, CuTe DSL, HIP, SYCL, Metal) through a unified interface.

Datasets

The paper does not explicitly mention training datasets for the LLMs. However, it uses the following for evaluation:

  • KernelBench Level 2: A benchmark suite containing 37 GEMM + tail-ops workloads, used for evaluating Triton kernel generation on Intel Arc B580.
  • gpt-oss-20b inference speed benchmark: Used for evaluating end-to-end performance on NVIDIA B200, comparing against TensorRT-LLM.

Key Insights and Ideas

  • Collaborative LLM Agents: The separation of concerns between a generation agent and a performance analysis agent is key. This modularity allows each agent to leverage its strengths and addresses the challenge of LLMs struggling with both complex code generation and nuanced performance optimization signals simultaneously.
  • Iterative Refinement Loop: The core idea of an iterative loop, driven by both correctness and performance feedback, mirrors the real-world workflow of a kernel engineer. This cyclical process is crucial for tackling the complexity of low-level code optimization.
  • Cross-Platform Generality: KForge's architecture aims to generate kernels across diverse hardware and programming models, exploring how well LLMs can transfer algorithmic ideas versus needing backend-specific guidance.
  • End-to-End vs. Micro-benchmarking: The paper highlights the importance of evaluating kernel performance not just in isolation (micro-benchmarking) but also within the context of a full inference pipeline (end-to-end performance). A kernel that is fast in isolation might not improve overall performance if it hinders other optimizations.

Key Results

  • NVIDIA B200: KForge achieved a 2.12% improvement in end-to-end throughput compared to TensorRT-LLM on the gpt-oss-20b inference benchmark. This is significant as TensorRT-LLM is a highly optimized, vendor-tuned baseline.
  • Intel Arc B580: KForge generated Triton kernels that achieved a 5.13x geometric mean speedup over the faster of PyTorch eager and torch.compile on 37 GEMM + tail-ops workloads from KernelBench Level 2. This speedup was primarily due to operator fusion and mixed-precision execution.

Limitations and Future Work

  • Reference Implementation Dependency: The current implementation relies on a PyTorch reference implementation for seeding the generation process. Future work aims to synthesize kernels from behavioral specifications and compare against closed-source binaries.
  • Broader Framework Coverage: Extending support beyond PyTorch to other frameworks like JAX and implementing more rigorous verification methods (e.g., differential testing, formal equivalence checking) is planned.
  • Low-Level ISA Targeting: Exploring targeting low-level virtual ISAs like PTX could unlock optimizations beyond source-level programming models, though it presents a more challenging synthesis problem.
  • Joint Optimization: The paper suggests extending KForge to jointly optimize kernels within larger architectural components (e.g., entire attention blocks) rather than optimizing each kernel independently.
  • Autonomous Agentic Approaches: Leveraging recent advances in autonomous agents for more sophisticated long-horizon reasoning in kernel synthesis is a future direction.

Summary updated

BibTeX
@inproceedings{sereda2026kforge,
  author = {Taras Sereda and Burak Bartan and Ankita Nayak and Tom St. John and Natalie Serrino and Zain Asgar},
  title = {{KForge: LLM-Driven Cross-Platform Kernel Generation for AI Accelerators}},
  booktitle = {MLArchSys @ ISCA},
  year = {2026},
  url = {https://openreview.net/forum?id=51fUT6JSzC},
}
Figure