arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2512.15766cs.PLcs.AIcs.DCcs.PF
收藏

LOOPRAG:通过检索增强的大语言模型增强循环变换优化

LOOPRAG: Enhancing Loop Transformation Optimization with Retrieval-Augmented Large Language Models

Zhejiang University(浙江大学);Zhejiang Institute of Administration(浙江行政研究院);Beijing ShenZhou Aerospace Software Technology Ltd.(北京神舟航天软件技术有限公司)

Yijie Zhi, Yayu Cao, Jianhua Dai, Xiaoyang Han, Jingwen Pu, Qingran Wu, Sheng Cheng, Ming Cai

AI总结:

LOOPRAG通过检索增强大语言模型提升循环变换优化效率,实现代码生成的准确性和性能提升。

摘要:

循环变换是保持语义的优化技术,广泛用于最大化诸如并行性等目标。尽管几十年的研究,应用最优的循环变换组合仍然具有挑战性,由于内在的复杂性,包括优化目标的成本建模。最近的研究探讨了大语言模型(LLMs)在代码优化中的潜力。然而,我们的关键观察是,LLMs在有效的循环变换优化中经常表现不佳,经常导致错误或次优优化,从而错过性能改进的机会。为弥合这一差距,我们提出了LOOPRAG,一种新颖的检索增强生成框架,旨在指导LLMs在静态控制部分进行有效的循环优化。我们引入了一种参数驱动的方法来利用循环属性,触发各种循环变换,并生成多样但合法的示例代码作为演示来源。为了有效获取最有信息量的演示,我们提出了一种基于循环特征的循环感知算法,该算法在相似性和多样性之间进行平衡,用于代码检索。为了增强正确和高效的代码生成,我们引入了一种基于反馈的迭代机制,将编译、测试和性能结果作为反馈来指导LLMs。每段优化的代码都经过突变、覆盖和差异测试进行等价性检查。我们评估了LOOPRAG在PolyBench、TSVC和LORE基准套件上的性能,并将其与编译器(GCC-Graphite、Clang-Polly、Perspective和ICX)和代表性的LLMs(DeepSeek和GPT-4)进行了比较。结果表明,LOOPRAG在PolyBench、TSVC和LORE上的平均加速分别为11.20×、14.34×和9.29×,在基础LLMs上分别达到11.97×、5.61×和11.59×的加速。

英文摘要:

Loop transformations are semantics-preserving optimization techniques, widely used to maximize objectives such as parallelism. Despite decades of research, applying the optimal composition of loop transformations remains challenging due to inherent complexities, including cost modeling for optimization objectives. Recent studies have explored the potential of Large Language Models (LLMs) for code optimization. However, our key observation is that LLMs often struggle with effective loop transformation optimization, frequently leading to errors or suboptimal optimization, thereby missing opportunities for performance improvements. To bridge this gap, we propose LOOPRAG, a novel retrieval-augmented generation framework designed to guide LLMs in performing effective loop optimization on Static Control Part. We introduce a parameter-driven method to harness loop properties, which trigger various loop transformations, and generate diverse yet legal example codes serving as a demonstration source. To effectively obtain the most informative demonstrations, we propose a loop-aware algorithm based on loop features, which balances similarity and diversity for code retrieval. To enhance correct and efficient code generation, we introduce a feedback-based iterative mechanism that incorporates compilation, testing and performance results as feedback to guide LLMs. Each optimized code undergoes mutation, coverage and differential testing for equivalence checking. We evaluate LOOPRAG on PolyBench, TSVC and LORE benchmark suites, and compare it against compilers (GCC-Graphite, Clang-Polly, Perspective and ICX) and representative LLMs (DeepSeek and GPT-4). The results demonstrate average speedups over base compilers of up to 11.20$\times$, 14.34$\times$, and 9.29$\times$ for PolyBench, TSVC, and LORE, respectively, and speedups over base LLMs of up to 11.97$\times$, 5.61$\times$, and 11.59$\times$.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑