HLSDebugger:Identification and Correction of Logic Bugs in HLS Code with LLM Solutions

assets/【论文阅读】HLSDebugger:Identification and Correction of Logic Bugs  in HLS Code with LLM Solutions/file-20260604163646390.png

发表在ICCAD 2025上

摘要

基于LLM进行HLS debug的三个潜在挑战:

  • 高质量的用于训练LLM的电路数据稀缺
  • 进行硬件电路的逻辑bug相较于识别软件bug更为困难
  • 缺乏针对multi-tasking solution的可依赖test cases,用于bug的识别和bug的修正
    HLSDebugger:
    生成大量的labeled dataset,包括300K样本,用于HLS logic bugs
    并基于encoder-decoder架构,实现bug位置定位,bug类型的预测和bug的修复
    超过GPT-4大模型的bug 识别,并且达到3×的bug correction效果

一. Introduction

assets/【论文阅读】HLSDebugger:Identification and Correction of Logic Bugs  in HLS Code with LLM Solutions/file-20260604164715115.png

hardware设计者可能在实现design HLS前引入错误,并且该错误会绕过HLS和静态分析工具
针对logic bug identification和correction,三个关键挑战:

  • 硬件电路稀缺:收集足够的HLS code format是足够困难的,本文生成和扩展到原有benchmark的25倍
  • 逻辑错误修复:编译器难以识别逻辑bug,需要更复杂的功能感知方法识别逻辑错误信息。收集8个类别的已知的逻辑错误。同时,手动构建可依赖的test cases费时,本文仅考虑依赖代码本身识别和修复HLS的错误
  • HLS Debugging的多任务:传统的先定位后修复,容易引起错误累积
    Dataset Generation:收集300K样本,首先收集unlabeled data之后再插入错误
    Encoder-Decoder Debugging Structure:
    设计encoder-decoder LLM架构,其中encoder支持bug定位和bug类型的识别,decoder基于encoder的中间表示实现错误修复
    Debugger Training Scheme:训练模式同时支持bug identification loss,bug correction loss

assets/【论文阅读】HLSDebugger:Identification and Correction of Logic Bugs  in HLS Code with LLM Solutions/file-20260604164829790.png

2.1. LLMs for Software Debugging

QuixBugs和CodeFlows等代表性工作,大多数认为test cases可获取,指导bug correction
问题:没有test case,怎么验证设计是否正确呢?
场景:logic bugs未被提供编译器信息和test cases

2.2. LLMs for RTL Debugging

类似github版本控制的数据,无法保证在prior code正确的修复了错误
场景:进行debug,但是不提供location information

2.3. LLMs for HLS Debugging & Generation

HLS在更高层的抽象级别上运行,隐藏对硬件设计至关重要的信息,同时难以在源代码内查明
前序工作:C2HLSC,HLS dataset 和 HLSPilot

三. Problem Formulation

HLS debugging任务:

  1. 识别错误代码\(C_{buggy}\)的错误代码片段\(s_{buggy}\)
  2. 生成对应的正确的代码样本\(C_{correct}\)
    期望output:
  • Bug Identification:针对每个token,若该token为错误片段token,label为1,否则为0,即$$s_{buggy}={C_{buggy}[I_i]|I==1}$$
  • Bug Correction:生成\(C_{correct}\),基于\(s_{correct}\)替换\(s_{buggy}\)
    最大化如下的准确度:

\[LLM{C_{buggy}} \rightarrow {I_1,I_2,...,I_N},C_{correct} \]

四. Methodolgy

assets/【论文阅读】HLSDebugger:Identification and Correction of Logic Bugs  in HLS Code with LLM Solutions/file-20260604164854559.png

4.1 Dataset Generation

包括两个步骤,1)Unsupervised dataset collection 和 2)Supervised bug dataset generation
首先基于Github和GPT-3.5 generation收集正确的HLS code,之后基于GPT-3.5 COT插入bug
构建数据集包括:\(C_{buggy}\)\(C_{correct}\),和bug information
assets/【论文阅读】HLSDebugger:Identification and Correction of Logic Bugs  in HLS Code with LLM Solutions/file-20260604164926167.png
Unsupervised Data Collection
基于Github收集HLS codes,并基于规则过滤,共收集30K代码样本,之后基于GPT-3.5将原有的部分代码改写,共收集到40K样本

Supervised Bug Dataset Generation
在每个original correct code sample查明可能的潜在错误,并进行插入,通过COT prompt
主要分为如下三个步骤

  1. function analysis:基于\((p_i || C_{correct})\) 至GPT-3.5,得到功能说明\(f_i =G_1(p_i||C_{correct})\)
  2. bug insertion procedure:基于指令,插入18种可能的逻辑错误$${s_{correct},s_{buggy},b_t}=G_2(p_b||C_{correct}||f_i)$$
  3. debugging strategy:构建较小的数据集,涵盖错误分析和debugging策略,$$b_a,o_s=G_3(p_c||C_{buggy}||s_{correct}||s_{buggy})$$
    最终的数据集包括:$${s_{correct},s_{buggy},b_t},{b_a,o_s}=G_3|G_2|G_1(p_i|C_{correct})$$

4.2 Encoder-Decoder Structure of HLSDebugger

assets/【论文阅读】HLSDebugger:Identification and Correction of Logic Bugs  in HLS Code with LLM Solutions/file-20260604165017578.png

问题:decoder-only模型中,存在错误累积现象,即LLM错误识别buggy code locations,incorrect corrections。
基于encoder-only架构实现更为准确的定位bug,同时encoder提供了bug location的软表示,而不是潜在的误导性字符串,支撑HLS Decoder
HLS Encoder. 将HLS code映射为包括语义的高维向量,用于分类和指明潜在的错误代码
输入:\([CLS]||C_{buggy}\),其中\([CLS]\)包括了完整的code functionality和bug information,经encoding后:

\[E_{cls},E_1,...,E_{N}=Encoder([CLS]||C_{buggy}) \]

之后送入prediction head,包括\((H_{type},H_{bug})\)

\[\hat{I_1},...,\hat{I_N}=H_{bug}(E_1,...,E_N); \hat{T}=H_{type}(E_{cls}) \]

HLS Decoder. 生成错误矫正的\(C_{gen}\),最后一层生成对应的修复后的代码

\[c_j = Decoder(<start/>||\{c_i^{i<k}\},{E_{cls},E_1,...,E_N}) \]

其中encoder的embeddings会作为K,V,decoder layer的embedding作为Q

4.3 Training Schema for Encoder-Decoder Structure

基于encoder-decoder 架构,提出针对性的loss
assets/【论文阅读】HLSDebugger:Identification and Correction of Logic Bugs  in HLS Code with LLM Solutions/file-20260604165203061.png
Encoder Training Loss. 分类Loss, \(L_{encoder}=\alpha_{type} \cdot L_{type} + \alpha_{bug} \cdot L_{bug}\)
Decoder Training Loss.

\[L_{decoder}=-\sum_{k=1}^KlogDecoder(<start/>||\{c_i^{<k}\}) \]

最终是二者加权相加

五. Experimental Setup

5.1 Experimental Benchmark and Task

Evaluation Benchmark. 包括8个类别的bug,主要如下:
assets/【论文阅读】HLSDebugger:Identification and Correction of Logic Bugs  in HLS Code with LLM Solutions/file-20260604165349849.png
bug location在token-wise,line-wise和code-wise粒度上评估
bug correction基于ground truth correct code snippet 和 generated outputs匹配

5.2 HLSDebugger Implementation in Experiment

HLSDebugger Structure Details. 基于CodeT5-Large
HLSDebugger Training Details. Rouge-L指标剔除可能的在训练集内的测试集代码

5.3 Evaluation Metrics

Bug Identification Metrics. 基于三种不同的粒度
1)Token-wise classification. 视为token的分类问题
2)Line-wise string classification. 评估line-wise的predicted 和 actual locations
3)Code-wise evaluation based on top-k line predictions. 基于每个code sample的top-1和top-5 line predictions
基于Precision,Recall,F1 Score 和 AUC
Bug Correction Generation Metrics. 基于string match

六. Experimental Result

assets/【论文阅读】HLSDebugger:Identification and Correction of Logic Bugs  in HLS Code with LLM Solutions/file-20260604165404748.png

assets/【论文阅读】HLSDebugger:Identification and Correction of Logic Bugs  in HLS Code with LLM Solutions/file-20260604165437775.png

总结: 核心是构建HLS领域的错误修复数据,并基于此训练encoder-decoder model,encoder用于错误的识别,decoder用于错误的修复,缺点在于数据集规模虽然足够,但是涉及的错误种类较少,不符合真实世界的错误分布,同时该方法也很难说是专用于HLS的,也算是一个通用的method搬过来(可能是bug种类是适配HLS的?),算是比较初步的

posted @ 2026-06-04 16:27  zjz2333  阅读(25)  评论(0)    收藏  举报