TL;DR
This paper introduces Astra, a novel multi-agent system that leverages Large Language Models (LLMs) to automatically optimize GPU kernels for improved performance. By breaking down the optimization process into specialized LLM agents (coding, testing, profiling, planning), Astra achieves significant speedups on existing CUDA kernels without requiring manual tuning or retraining, demonstrating a promising new direction for high-performance computing.
What Problem Does This Paper Address?
Optimizing GPU kernels for high-performance computing and machine learning, especially for accelerating Large Language Models (LLMs), is a notoriously difficult and time-consuming task. While compiler-based systems and manual tuning have been the traditional approaches, they often fall short of peak performance or require extensive engineering effort. Existing LLM-based methods have primarily focused on generating kernels from high-level code, but this paper tackles the more practical challenge of optimizing existing CUDA kernels, which are already in use in production systems like LLM serving frameworks. The goal is to achieve substantial performance gains without sacrificing correctness, a critical requirement for real-world applications.
Methods
Astra employs a multi-agent system architecture, inspired by the idea that different stages of kernel optimization benefit from specialized expertise. The system comprises four key agents:
- Testing Agent: Generates test cases and validates the functional correctness of candidate kernels.
- Profiling Agent: Measures the execution time of kernels on the test suite to provide performance feedback.
- Planning Agent: Analyzes correctness and performance signals to suggest specific optimizations.
- Coding Agent: Applies the suggested optimizations to generate new kernel implementations.
These agents work in an iterative loop: the planning agent proposes changes, the coding agent implements them, and the testing and profiling agents evaluate the results. This feedback loop allows for systematic exploration and refinement of the optimization space. A key differentiator is that Astra starts with existing CUDA code (extracted from the SGLang framework) rather than translating high-level specifications.
Datasets
The paper evaluates Astra on three kernels extracted from SGLang, a production-grade LLM serving framework. These kernels are: merge_attn_states_lse, fused_add_rmsnorm, and silu_and_mul. The evaluation uses a set of representative tensor shapes derived from actual LLM dimensions (LLaMA-7B, 13B, and 70B models) to ensure realistic performance measurements.
Key Insights and Ideas
- Specialization is Key: Decomposing the complex task of kernel optimization into specialized LLM agents (coding, testing, profiling, planning) leads to better results than a single, all-purpose agent. This acknowledges that different optimization aspects require distinct reasoning capabilities.
- Optimizing Existing Code is Practical: Focusing on optimizing pre-existing CUDA kernels, rather than generating them from scratch, addresses a more immediate and impactful problem in production environments.
- Zero-Shot Prompting Suffices: Astra achieves significant speedups using zero-shot prompting with a relatively small LLM (OpenAI o4-mini), highlighting the potential of LLMs for this task without the need for extensive fine-tuning or reinforcement learning.
- LLMs Can Autonomously Apply Advanced Optimizations: The case studies reveal that LLMs can independently discover and apply sophisticated optimization techniques, such as loop transformations, memory access pattern optimization, CUDA intrinsics, and fast math operations.
Key Results
Astra achieved an average speedup of 1.32x across the three evaluated SGLang kernels using zero-shot prompting. The maximum speedup observed was 1.46x for the silu_and_mul kernel. This performance improvement was achieved while maintaining functional correctness, verified against the original SGLang implementations. A comparison with a single-agent baseline showed that the multi-agent approach yielded a higher speedup (1.32x vs. 1.08x), particularly for more complex kernels. The optimized kernels also saw an increase in lines of code, indicating the addition of more efficient operations.
Limitations and Future Work
The authors acknowledge that the pre-processing (extracting and simplifying kernels) and post-processing (integrating optimized kernels back into the framework) steps are currently manual. Automating these steps is a significant challenge due to the complexity of modern serving frameworks. Future work includes extending Astra to support a broader range of kernels and frameworks (e.g., vLLM, PyTorch, TorchTitan), and exploring more automated pre/post-processing pipelines, potentially with human-in-the-loop guidance, to scale the system to larger codebases.
Summary updated