KernelFoundry: Hardware-Aware Evolutionary GPU Kernel Optimization
Abstract
GPU kernel optimization challenges LLMs beyond standard coding tasks, as it requires an understanding of hardware architecture, parallel computing optimization strategies, and profiling outputs. However, most existing approaches leveraging LLMs for kernel generation apply standard prompting and feedback loops, considering hardware only through profiling feedback. We introduce KernelFoundry, an evolutionary framework that efficiently explores the space of GPU kernels through (1) MAP-Elites quality-diversity search with kernel-specific behavioral dimensions to sustain exploration; (2) meta-prompt evolution that co-evolves prompts with kernels to uncover task-specific optimization strategies, and (3) a template-based parameter optimization approach to tune kernels to inputs and hardware. We evaluate this framework on KernelBench, robust-kbench and custom tasks, generating SYCL kernels as a cross-platform GPU programming paradigm, and CUDA kernels for comparison to prior work. Our approach consistently outperforms the baseline methods and achieves an average speedup of 2.3 on KernelBench for SYCL. Moreover, KernelFoundry is implemented as a distributed framework with remote access to diverse hardware, allowing quick benchmarking and featuring a flexible user input layer to support kernel generation for a wide range of real use cases beyond benchmarking.
Lay Summary
Modern AI applications are only as fast as the low-level code — called GPU kernels — that runs beneath them. While AI coding assistants can help with general programming tasks, they struggle with kernel optimization because it demands hardware-specific intuition that goes far beyond writing correct code. We built KernelFoundry, a framework that uses large language models (LLMs) to automatically optimize GPU kernels. Rather than simply asking an LLM to write code and checking the result, KernelFoundry runs an evolutionary process: it keeps a diverse population of kernels, combining and mutating the best ones — similar to natural selection, but for code. Crucially, it also evolves the instructions given to the LLM, so the system gradually learns how to ask better questions to get better kernels. KernelFoundry achieves higher kernel speedups than prior methods, supports multiple GPU platforms, and is designed as a distributed framework that is efficient for real-world kernel generation tasks.