arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2503.19449cs.SEcs.AIcs.LGcs.PF
收藏

VecTrans:通过LLM辅助的代码变换增强编译器自动向量化

VecTrans: Enhancing Compiler Auto-Vectorization through LLM-Assisted Code Transformations

Huawei(华为);Sun Yat-sen University(中山大学)

Zhongchun Zheng, Kan Wu, Long Cheng, Lu Li, Rodrigo C. O. Rocha, Tianyi Liu, Wei Wei, Jianjiang Zeng, Xianwei Zhang, Yaoqing Gao

AI总结:

VecTrans框架利用LLM重构编译器难以向量化的代码区域,并结合IR级混合验证保证语义正确性,在TSVC测试中实现1.77倍几何平均加速并成功向量化24/51个用例。

摘要:

自动向量化是现代编译器利用SIMD并行性的一项基础优化。然而,最先进的方法仍然难以处理复杂的代码模式,通常需要人工提示或领域专业知识。大型语言模型(LLMs)凭借其捕捉复杂模式的能力,提供了一种有前景的解决方案,但它们在编译器优化中的有效应用仍然是一个开放性挑战,原因在于幻觉问题以及缺乏领域特定推理能力。在本文中,我们提出了VecTrans,这是一个利用LLMs增强基于编译器的代码向量化的新型框架。VecTrans首先使用编译器分析来识别可能可向量化的代码区域。然后,它利用LLM将这些区域重构为更易于编译器自动向量化的模式。为了确保语义正确性,VecTrans进一步在中间表示(IR)层面集成了混合验证机制。通过上述努力,VecTrans将LLMs的适应性与编译器向量化的精确性相结合,从而有效地开辟了向量化机会。实验结果表明,在GCC、ICC、Clang和BiSheng Compiler无法向量化的所有TSVC函数中,VecTrans实现了1.77倍的几何平均加速,并成功向量化了51个测试用例中的24个。这标志着相对于最先进方法的显著进步,同时保持了LLM API使用中每次函数优化0.012美元的成本效率。

英文摘要:

Auto-vectorization is a fundamental optimization for modern compilers to exploit SIMD parallelism. However, state-of-the-art approaches still struggle to handle intricate code patterns, often requiring manual hints or domain-specific expertise. Large language models (LLMs), with their ability to capture intricate patterns, provide a promising solution, yet their effective application in compiler optimizations remains an open challenge due to issues such as hallucinations and a lack of domain-specific reasoning. In this paper, we present VecTrans, a novel framework that leverages LLMs to enhance compiler-based code vectorization. VecTrans first employs compiler analysis to identify potentially vectorizable code regions. It then utilizes an LLM to refactor these regions into patterns that are more amenable to the compilers auto-vectorization. To ensure semantic correctness, VecTrans further integrates a hybrid validation mechanism at the intermediate representation (IR) level. With the above efforts, VecTrans combines the adaptability of LLMs with the precision of compiler vectorization, thereby effectively opening up the vectorization opportunities. experimental results show that among all TSVC functions unvectorizable by GCC, ICC, Clang, and BiSheng Compiler, VecTrans achieves an geomean speedup of 1.77x and successfully vectorizes 24 of 51 test cases. This marks a significant advancement over state-of-the-art approaches while maintaining a cost efficiency of $0.012 per function optimization for LLM API usage.

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

↑