Automated C/C++ Program Repair for High-Level Synthesis via Large Language Models

📄 arXiv: 2407.03889v1 📥 PDF

作者: Kangwei Xu, Grace Li Zhang, Xunzhao Yin, Cheng Zhuo, Ulf Schlichtmann, Bing Li

分类: eess.SY

发布日期: 2024-07-04


💡 一句话要点

提出基于大语言模型的HLS-C代码自动修复框架,提升修复成功率并优化电路性能。

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 高层次综合 程序修复 大语言模型 检索增强生成 HLS优化

📋 核心要点

  1. HLS-C代码转换需要大量人工,现有脚本修复效果不佳,且直接使用LLM修复易出现幻觉,成本高昂。
  2. 利用检索增强生成(RAG)指导LLM进行代码修复,并结合LLM进行位宽优化和HLS优化策略。
  3. 实验表明,该框架相比传统脚本和直接使用LLM,显著提高了HLS-C代码的自动修复通过率。

📝 摘要(中文)

本文提出了一种基于大语言模型(LLM)的程序修复框架,用于将常规C/C++代码自动转换为可用于高层次综合(HLS)的HLS-C代码,从而减少人工修复工作。该框架利用检索增强生成(RAG)范式来缓解LLM的幻觉问题,并提高提示质量,引导LLM进行正确的修复。此外,还使用LLM创建静态位宽优化程序,以确定变量的最佳位宽。同时,引入了LLM驱动的HLS优化策略,用于在HLS-C程序中添加/调整编译指示,以优化电路。实验结果表明,与传统脚本和直接应用LLM进行程序修复相比,所提出的LLM驱动的自动化框架在24个真实应用中实现了更高的修复通过率。

🔬 方法详解

问题定义:该论文旨在解决将常规C/C++代码转换为HLS-C代码过程中,需要大量人工修复的问题。现有方法,如程序脚本,生成的代码存在诸多问题,需要手动修复。直接使用LLM进行修复,由于缺乏硬件和软件的同步训练,容易产生幻觉,导致编译失败,且迭代修复成本高昂。

核心思路:论文的核心思路是利用LLM的代码生成能力,结合检索增强生成(RAG)范式,引导LLM进行正确的代码修复,并利用LLM进行位宽优化和HLS优化,从而实现HLS-C代码的自动生成,并减少人工干预。

技术框架:该框架主要包含以下几个模块:1) 输入常规C/C++代码;2) 使用RAG范式引导LLM进行代码修复,生成初步的HLS-C代码;3) 使用LLM创建的静态位宽优化程序,确定变量的最佳位宽;4) 应用LLM驱动的HLS优化策略,添加/调整编译指示,优化电路性能;5) 输出最终的HLS-C代码。

关键创新:该论文的关键创新在于:1) 引入RAG范式,缓解LLM在代码修复过程中的幻觉问题,提高修复质量;2) 利用LLM进行静态位宽优化,提升电路性能;3) 提出LLM驱动的HLS优化策略,自动添加/调整编译指示,进一步优化电路。

关键设计:RAG范式的关键在于检索策略和增强方式,具体细节未知。位宽优化程序和HLS优化策略的具体实现方式未知。论文中可能涉及LLM的Prompt设计,但具体内容未知。

🖼️ 关键图片

fig_0
fig_1
fig_2

📊 实验亮点

实验结果表明,该LLM驱动的自动化框架在24个真实应用中实现了比传统脚本和直接应用LLM更高的修复通过率。具体的性能提升数据未知,但整体修复成功率得到了显著提升。

🎯 应用场景

该研究成果可应用于自动化高层次综合流程,降低硬件设计门槛,加速硬件原型验证和产品开发。通过自动将C/C++代码转换为HLS-C代码,可以减少人工工作量,提高开发效率,并优化电路性能,具有广泛的应用前景。

📄 摘要(原文)

In High-Level Synthesis (HLS), converting a regular C/C++ program into its HLS-compatible counterpart (HLS-C) still requires tremendous manual effort. Various program scripts have been introduced to automate this process. But the resulting codes usually contain many issues that should be manually repaired by developers. Since Large Language Models (LLMs) have the ability to automate code generation, they can also be used for automated program repair in HLS. However, due to the limited training of LLMs considering hardware and software simultaneously, hallucinations may occur during program repair using LLMs, leading to compilation failures. Besides, using LLMs for iterative repair also incurs a high cost. To address these challenges, we propose an LLM-driven program repair framework that takes regular C/C++ code as input and automatically generates its corresponding HLS-C code for synthesis while minimizing human repair effort. To mitigate the hallucinations in LLMs and enhance the prompt quality, a Retrieval-Augmented Generation (RAG) paradigm is introduced to guide the LLMs toward correct repair. In addition, we use LLMs to create a static bit width optimization program to identify the optimized bit widths for variables. Moreover, LLM-driven HLS optimization strategies are introduced to add/tune pragmas in HLS-C programs for circuit optimization. Experimental results demonstrate that the proposed LLM-driven automated framework can achieve much higher repair pass rates in 24 real-world applications compared with the traditional scripts and the direct application of LLMs for program repair.