Make Every Move Count: LLM-based High-Quality RTL Code Generation Using MCTS

Matthew DeLorenzo, Animesh Basak Chowdhury, Vasudev Gohil, Shailja Thakur, Ramesh Karri, Siddharth Garg, Jeyavijayan RajendranarXiv 2024 · DOI

Introduction

Large Language Models (LLMs) have demonstrated remarkable proficiency in software engineering, yet they frequently stumble when tasked with Register Transfer Level (RTL) code generation for hardware design. Unlike general-purpose software, hardware description languages like Verilog demand absolute functional correctness and strict adherence to Power, Performance, and Area (PPA) constraints. A single logic error renders a chip non-functional, and "naive" LLMs—which typically predict the most probable next token—often produce suboptimal, "PPA-agnostic" designs that are either too large or too slow.

The VeriGen+MCTS Framework

To bridge this gap, researchers introduced VeriGen+MCTS, a framework that treats Verilog generation as a strategic search problem within a Markov Decision Process (MDP). By integrating Monte Carlo Tree Search (MCTS) with an LLM, the system moves beyond simple probabilistic guessing to a deliberate "lookahead" search.

The four stages of the MCTS-based code generation process: Selection, Expansion, Rollout, and Backpropagation.

The MCTS cycle consists of four key stages:

  1. Selection: Navigating the existing search tree to find promising partial code sequences.
  2. Expansion: Adding new potential tokens to the tree based on LLM suggestions.
  3. Rollout: Using the LLM to complete the code sequence to a terminal state.
  4. Backpropagation: Updating the value of nodes based on the rewards received from the completed code.

Reward-Driven Optimization

The core of this approach is a sophisticated reward function that evaluates generated code based on three criteria: compilability, functional correctness, and hardware efficiency. By utilizing tools like Icarus Verilog for simulation and Yosys for hardware synthesis, the framework calculates an Area-Delay Product (ADP). This allows the search agent to prioritize code paths that result in smaller, faster circuits. To maintain efficiency, the search space is pruned by skipping non-functional tokens such as comments, allowing the model to focus entirely on hardware logic.

Scaling with Modularity

Generating complex designs, such as 64-bit Multiply-Accumulate (MAC) units, presents a significant challenge due to the exponential growth of the search space. The framework addresses this through a hierarchical modularity strategy.

The modularity workflow for handling large hardware modules by modifying input prompts to reuse optimized sub-modules.

When the system identifies a "Large Module," it modifies the input prompt to encourage the reuse of previously optimized smaller modules (e.g., using 8-bit units to build a 64-bit unit). This approach not only mimics human engineering practices but also increased the MCTS iteration rate by 3x for large-scale designs.

Results and Impact

The VeriGen+MCTS framework was evaluated against a baseline VeriGen-2B model on a suite of 15 Verilog benchmarks. While vanilla LLMs and standard beam search failed on the majority of cases, VeriGen+MCTS achieved a 100% success rate, generating functionally correct code for all modules.

Beyond mere correctness, the framework delivered substantial hardware optimizations. For a 16-bit adder, the MCTS-guided search achieved a 31.8% improvement in ADP compared to the best baseline. These results demonstrate that combining the "intuition" of LLMs with the "deliberation" of MCTS can effectively navigate the complex trade-offs inherent in hardware design.

Conclusion

While the computational cost of running synthesis and simulation in the loop remains a challenge, the high-quality RTL generated by this method provides a valuable dataset for future work. The authors suggest that this optimized code can be used to fine-tune LLMs, potentially embedding PPA-awareness directly into the models and enabling high-quality, single-pass hardware generation in the future.

Summary updated

BibTeX
@misc{delorenzo2024make,
  author = {Matthew DeLorenzo and Animesh Basak Chowdhury and Vasudev Gohil and Shailja Thakur and Ramesh Karri and Siddharth Garg and Jeyavijayan Rajendran},
  title = {{Make Every Move Count: LLM-based High-Quality RTL Code Generation Using MCTS}},
  year = {2024},
  eprint = {2402.03289},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2402.03289},
}
Figure