TL;DR
Using Large Language Models (LLMs) to generate low-level hardware description languages like Verilog is notoriously difficult due to severe data scarcity and high token costs. This paper proposes shifting the target to High-Level Synthesis (HLS), introducing a massive dataset of 42,000+ HLS programs alongside a framework that combines fine-tuning, Chain-of-Thought prompting, and automated feedback loops to achieve highly accurate hardware generation.
What Problem Does This Paper Address?
While LLMs excel at generating software code (like Python or C++), applying them to hardware generation faces major roadblocks. Traditional approaches focus on low-level Hardware Description Languages (HDLs) like Verilog or SystemVerilog. However, HDLs suffer from three distinct challenges:
- Data Scarcity: HDL code makes up less than 1% of standard open-source code datasets compared to software languages.
- The Knowledge Gap: Pre-trained LLMs are optimized for software semantics, making their knowledge poorly transferable to the concurrent, hardware-specific nature of HDLs.
- Token Inefficiency: Implementing logic in HDL is highly verbose, requiring 3 to 4 times more tokens than software, which drives up LLM inference costs and latency.
To solve this, the authors explore leveraging LLMs to generate High-Level Synthesis (HLS) code instead. HLS allows developers to describe hardware using C/C++ syntax, directly inheriting the vast software knowledge already embedded within pre-trained LLMs.
Methods
The authors introduce an end-to-end framework divided into two primary stages: model fine-tuning and iterative code generation.
- Supervised Fine-Tuning (SFT): They fine-tune a
Code-Llama-7Bmodel using the low-rank adaptation (QLoRA) technique on a newly compiled HLS dataset. - Chain-of-Thought (CoT) Prompting: The framework injects a structured hardware engineering checklist into the prompt (e.g., considering FPGA characteristics, defining program structure, writing logic, and selecting data types) to guide the model's reasoning step-by-step.
- Two-Step Feedback Loops: During inference, the generated HLS code is automatically evaluated. First, a syntax check is performed via the GCC compiler using the
-fsyntax-onlyflag (enabling rapid verification without full compilation overhead). Second, if the syntax passes, the code runs through functional unit tests. Any discovered errors or defects are fed back into the prompt for iterative self-correction.
Datasets
The paper introduces a substantial benchmark dataset built by collecting 52 open-source HLS designs spanning matrix operations, scientific simulations, and iterative methods. By applying various hardware optimization pragmas (such as PIPELINE, PARALLEL, and TILE), they expanded these base designs into a dataset of over 42,000 valid HLS programs.
To create natural language prompts for training, they used ChatGPT (versions 3.5 and 4) to generate design descriptions. For evaluation, they created two test sets:
- MachineGen: Raw descriptions generated entirely by the LLM.
- HumanRefine: Manually polished, concise, human-like instructions.
Key Insights and Ideas
- The HLS Advantage: Shifting from Verilog to HLS fundamentally bypasses the data scarcity problem. Because HLS relies on C/C++ syntax, the model can effectively reuse its extensive software pre-training.
- The Prompt Disparity: Surprisingly, the model performed significantly worse on human-refined prompts (47.29% syntax correctness) than on machine-generated ones (93.83%). This reveals a strong training bias toward explicit, highly detailed machine-generated text; human prompts often omit repetitive details that LLMs rely on for context.
- Hardware CoT is Linear: While general software generation often requires complex, specialized CoT frameworks, hardware generation benefits immensely from a straightforward, linear engineering checklist built directly into the prompt.
Key Results
The combination of fine-tuning, CoT, and feedback loops yielded dramatic performance improvements:
- Fine-Tuning Impact: The base, non-fine-tuned model failed 100% of functional tests. Fine-tuning skyrocketed syntax correctness from 54.85% to 88.44% and functional pass rates to 53.20%.
- CoT Boost: Adding Chain-of-Thought prompting further raised syntax correctness to 94.33% and functional correctness to 61.45%.
- Feedback Loops: Iterative debugging loops successfully corrected complex code blocks, though the gains showed diminishing returns after the first loop iteration.
The generated HLS designs were successfully synthesized using Xilinx Vivado targeting a Xilinx VCU118 FPGA, demonstrating realistic hardware resource utilization and performance.
Limitations and Future Work
While promising, the authors note several limitations:
- Model Constraints: The evaluation was limited to Code-Llama-7B. Advanced reasoning models (like DeepSeek-R1) and test-time scaling approaches were not explored.
- Dataset Diversity: Although the dataset contains 42,000 programs, they are variations derived from only 52 unique base designs, limiting structural diversity.
- Missing PPA Feedback: The feedback loop currently only checks for syntax and functional correctness. It does not yet optimize for hardware performance metrics like Power, Performance, and Area (PPA).
Summary updated