Skip to main content
QUICK REVIEW

[论文解读] Should AI Optimize Your Code? A Comparative Study of Classical Optimizing Compilers Versus Current Large Language Models

Miguel Romero Rosas, Miguel Torres Sanchez|arXiv (Cornell University)|Jun 17, 2024
Natural Language Processing Techniques被引用 4
一句话总结

该论文评估了大型语言模型(LLMs)如GPT-4.0和CodeLlama-70B是否能在自动代码优化中超越传统优化编译器(CETUS、PLUTO、ROSE)。研究提出了一个自动化验证机制(PCAOT)和一种新型并行计算挑战基准(PCB)v1.0,包含20种复杂优化模式,发现尽管CodeLlama-70B实现了最高达2.1倍的性能提升且优于GPT-4.0,但LLMs在更大代码库上仍表现不佳,由于正确性和可扩展性问题,尚未具备取代编译器的能力。

ABSTRACT

Traditional optimizing compilers have played an important role in adapting to the growing complexity of modern software systems. The need for efficient parallel programming in current architectures requires strong optimization techniques. The beginning of Large Language Models (LLMs) raises intriguing questions about the potential of these AI approaches to revolutionize code optimization methodologies. This work aims to answer an essential question for the compiler community: "Can AI-driven models revolutionize the way we approach code optimization?". To address this question, we present a comparative analysis between three classical optimizing compilers and two recent large language models, evaluating their respective abilities and limitations in optimizing code for maximum efficiency. In addition, we introduce a benchmark suite of challenging optimization patterns and an automatic mechanism for evaluating the performance and correctness of the code generated by LLMs. We used three different prompting strategies to evaluate the performance of the LLMs, Simple Instruction (IP), Detailed Instruction Prompting (DIP), and Chain of Thought (CoT). A key finding is that while LLMs have the potential to outperform current optimizing compilers, they often generate incorrect code on large code sizes, calling for automated verification methods. In addition, expressing a compiler strategy as part of the LLMs prompt substantially improves its overall performance. Our evaluation across three benchmark suites shows CodeLlama-70B as the superior LLM, capable of achieving speedups of up to x1.75. Additionally, CETUS is the best among the current optimizing compilers, achieving a maximum speedup of 1.67x. We also found substantial differences among the three prompting strategies.

研究动机与目标

  • 评估现代LLMs能否作为并行代码优化的有效自动优化工具(AOT),其表现可与传统优化编译器相媲美。
  • 通过开发一种自动化验证机制(PCAOT)来解决LLM生成代码在正确性保证方面的关键缺口,以验证性能和正确性。
  • 创建一个包含20种具有挑战性的优化模式的综合性基准测试套件(PCB v1.0),以系统性地评估和比较AOT。
  • 研究不同提示策略——思维链(CoT)和指令提示(IP)——对LLM优化性能的影响。
  • 确定当前AI驱动代码优化的最先进水平,并识别阻碍LLMs取代传统编译器的关键限制。

提出的方法

  • 开发了PCAOT,一种自动化机制,用于验证AOT生成代码的正确性和性能,从而实现对潜在错误优化的安全评估。
  • 设计了并行计算挑战基准(PCB)v1.0,包含20个针对复杂、难以优化代码模式的真实世界类优化模式的套件。
  • 采用两种提示策略——思维链(CoT)和指令提示(IP)——评估了两种最先进的LLM——GPT-4.0和CodeLlama-70B。
  • 在真实世界基准测试(NPB v3.3、POLYBENCHMARK v4.2和自定义程序)上,将LLM输出与三种传统优化编译器——CETUS、PLUTO和ROSE——进行比较。
  • 通过相对于基线的加速比以及自动化测试和性能回归检查来衡量优化的成功程度。
  • 使用统计分析比较不同提示方法的有效性,以及LLM与编译器在所有基准测试中的相对性能。
Figure 1. Architecture of the PCAOT Environment.
Figure 1. Architecture of the PCAOT Environment.

实验结果

研究问题

  • RQ1LLMs如GPT-4.0和CodeLlama-70B是否能在并行程序的自动代码优化中超越传统优化编译器?
  • RQ2不同提示策略——思维链(CoT)和指令提示(IP)——在引导LLMs生成正确且高效优化代码方面的有效性如何?
  • RQ3LLMs在优化真实世界代码时的关键失败模式是什么,特别是在正确性和可扩展性方面?
  • RQ4自动化验证机制如PCAOT在确保LLM生成优化的正确性方面能起到多大作用?它们如何用于安全探索非安全优化?
  • RQ5LLMs与编译器在优化复杂、非平凡代码模式(如包含函数调用的循环、屏障同步和负载不均)方面的表现如何比较?

主要发现

  • CodeLlama-70B在所有工具中实现了最高加速比,在特定基准测试中最高达到2.1倍,优于GPT-4.0和所有传统编译器。
  • CETUS是表现最佳的传统编译器,最大加速比达到1.9倍,紧随其后的是PLUTO和ROSE。
  • LLMs仅在三种复杂模式中正确优化成功——数组归约、最外层循环并行化和包含函数调用的循环——成功率超过50%。
  • LLMs在更复杂的模式中失败,包括使用NOWAIT消除屏障同步、处理多个并行循环,以及应用动态调度以避免负载不均。
  • 思维链(CoT)与指令提示(IP)之间性能无显著差异,某些情况下CoT表现略差。
  • 尽管潜力巨大,LLMs尚未准备好取代传统编译器,因为其在较大程序(如超过20行)中频繁生成错误代码,凸显了关键的正确性瓶颈。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。