通过编译器-LLM协作实现代理代码优化
Agentic Code Optimization via Compiler-LLM Cooperation
AI总结:
本文提出编译器-LLM协作方法,结合传统编译优化与LLM生成,提升代码性能,实验显示比现有方法快1.25倍。
摘要:
从高级语言生成高性能可执行文件对软件性能至关重要。现代编译器通过一系列优化步骤逐步降低抽象层次,但可能错过需要高层面程序目的推理的优化机会。最近的研究提出了使用LLM来填补这一空白。虽然LLM在某些程序上能带来显著加速,但生成的代码经常不正确。本文提出一种方法,平衡传统编译器优化的正确性与LLM生成代码的“创造性”:编译器-LLM协作。我们的方法整合现有的编译器优化步骤与LLM生成代码在多个抽象层次上,保留两种优化方式的最佳特性。我们通过一个多智能体系统实现该方法,包括(1)每个抽象层次的LLM优化代理,(2)单独的编译器组件作为工具,(3)一个LLM生成的测试生成代理用于探测生成代码的正确性和性能,以及(4)一个指导LLM协调其他组件。该策略使LLM能够在多个抽象层次上优化输入程序,并引入一种在不同层次之间分配计算预算的方法。我们的广泛评估显示,编译器-LLM协作优于现有的编译器优化和特定层次的LLM基线方法,产生高达1.25倍的加速。
英文摘要:
Generating performant executables from high level languages is critical to software performance across a wide range of domains. Modern compilers perform this task by passing code through a series of well-studied optimizations at progressively lower levels of abstraction, but may miss optimization opportunities that require high-level reasoning about a program's purpose. Recent work has proposed using LLMs to fill this gap. While LLMs can achieve large speedups on some programs, they frequently generate code that is incorrect. In this work, we propose a method to balance the correctness of conventional compiler optimizations with the ``creativity'' of LLM-based code generation: compiler-LLM cooperation. Our approach integrates existing compiler optimization passes with LLM-based code generation at multiple levels of abstraction, retaining the best features of both types of code optimization. We realize our approach with a multi-agent system that includes (1) LLM-based optimization agents for each level of abstraction, (2) individual compiler constituents as tools, (3) an LLM-based test generation agent that probes the correctness and performance of generated code, and (4) a guiding LLM that orchestrates the other components. The strategy enables LLM-based optimization of input programs at multiple levels of abstraction and introduces a method for distributing computational budget between levels. Our extensive evaluation shows that compiler-LLM cooperation outperforms both existing compiler optimizations and level-specific LLM-based baselines, producing speedups up to 1.25x.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。