Classification-Based Automatic HDL Code Generation Using LLMs

Wenhao Sun, Bing Li, Grace Li Zhang, Xunzhao Yin, Cheng Zhuo, Ulf SchlichtmannarXiv 2024 · DOI

Abstract

Large Language Models (LLMs) demonstrate significant potential in software engineering but often struggle with hardware description language (HDL) generation due to "hallucinations" and the complexity of multi-hop reasoning in digital logic design. This paper presents a novel, training-free framework that mimics human-expert workflows by first classifying circuits into specific types (combinational, sequential, or behavioral) and then applying structured, type-specific reasoning steps. By integrating symbolic Electronic Design Automation (EDA) tools like PyEDA for logic minimization and employing a search-based iterative refinement process, the proposed method achieves substantial improvements in functional correctness. Evaluation on industry-standard benchmarks shows up to a 14.7% increase in Pass@10 scores, highlighting the effectiveness of structured reasoning in bridging the gap between natural language specifications and reliable hardware implementations.

Introduction

While Large Language Models (LLMs) such as GPT-4 have revolutionized automated code generation, their application to hardware design remains challenging. In digital logic, even minor errors in timing or bit-level logic can render a circuit non-functional. This "hallucination problem" is exacerbated by the "multi-hop reasoning" required for hardware design, where a single specification necessitates a deep chain of logical deductions. Existing solutions often rely on expensive human oversight or computationally intensive fine-tuning. This work proposes a training-free methodology that structures the LLM's reasoning process to align with human engineering practices.

Methodology

The proposed framework introduces a multi-stage pipeline designed to flatten the reasoning depth required from the LLM.

Comparison of the proposed framework against baseline HDL generation approaches.

1. Circuit Classification

The system first identifies the circuit type: Combinational (COMB), Sequential (SEQU), or Behavioral (BEHAV). To improve classification accuracy, the LLM generates an initial "draft" of the code to analyze its structural requirements before finalizing the type.

2. Structured Information Extraction

Instead of direct code generation, the LLM extracts structured data from the natural language specification. For COMB circuits, it generates truth tables; for SEQU circuits, it constructs state-transition tables. This "one-hop" rule ensures that no single prompt requires excessive logical depth.

3. Type-Specific Procedures

  • Combinational Logic: To mitigate LLM errors in logic minimization, the framework utilizes PyEDA, a symbolic EDA tool, to simplify truth tables into Sum-of-Products (SOP) expressions.
  • Sequential Logic: The system enforces the "three-always-block" paradigm—a standard industry practice that separates state registers, next-state logic, and output logic—to ensure clean and reliable Verilog code.

4. Search and Iteration

The framework employs a beam-search-like method to generate and evaluate multiple information lists. These candidates are tested against a functional testbench, allowing the system to iterate on the most promising designs.

Experimental Setup and Datasets

The framework was evaluated using the VerilogEval dataset, comprising:

  • VerilogEval-human: 156 tasks with human-written specifications.
  • VerilogEval-machine: 143 tasks with LLM-generated specifications.

Key Results

Using GPT-4 as the underlying model, the proposed method demonstrated significant performance gains over naive one-shot generation.

Pass@k performance metrics for various configurations on VerilogEval-human (V.H.) and VerilogEval-machine (V.M.) datasets.

On the VerilogEval-human benchmark, Pass@1 improved by 4.7%, Pass@5 by 11.0%, and Pass@10 by 14.7%. Similar gains were observed in the VerilogEval-machine dataset. Notably, the framework significantly outperformed existing feedback-based generators like AutoChip in complex combinational logic tasks, achieving a 70% success rate compared to 0% for the baseline.

Discussion and Conclusion

The success of this framework lies in its ability to offload complex logical calculations to symbolic tools and enforce structured design patterns. By reducing the reasoning depth per step, the system effectively mitigates hallucinations. Future work will focus on addressing highly complex or misleading specifications and further reducing the token costs associated with iterative search. This work demonstrates that a "human-in-the-loop" inspired workflow can dramatically enhance the reliability of LLMs in specialized domains like hardware engineering.

Summary updated

BibTeX
@misc{sun2024classification,
  author = {Wenhao Sun and Bing Li and Grace Li Zhang and Xunzhao Yin and Cheng Zhuo and Ulf Schlichtmann},
  title = {{Classification-Based Automatic HDL Code Generation Using LLMs}},
  year = {2024},
  eprint = {2407.18326},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2407.18326},
}
Figure