Skip to content

tanshie05/Verilog-AI-Agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Verilog-AI-Agent

This is a Python-based AI tool that takes natural language prompts and generates Verilog hardware modules and testbenches using OpenAI GPT-4. It then automatically compiles, simulates, and visualizes the resulting design using Icarus Verilog and waveform generation.

You can either:

  • Use the Streamlit web interface, or
  • Use the command-line script (CLI)

Features

  • Natural Language to Verilog
    Enter prompts like "4-bit full adder" and get clean, syntactically correct Verilog modules.

  • Powered by GPT-4 via OpenAI API
    Uses your OpenAI key to generate both the module and a corresponding testbench.

  • Testbench Enhancement
    Injects $monitor, $dumpfile, $dumpvars, and $finish if missing — making testbenches simulation-ready.

  • Automatic Simulation
    Compiles and simulates the design using Icarus Verilog (iverilog + vvp).

  • Waveform Generation
    Dumps simulation data to a VCD file (wave.vcd) viewable in GTKWave or as a PNG (via matplotlib — still improving).

  • Modular Design Comes with both a Streamlit GUI and a lightweight CLI script.

How It Works

Option 1: Streamlit Web Interface

  1. Run the app locally (streamlit run streamlit_app.py)
  2. Enter your OpenAI API key and hardware prompt
  3. App:
    • Calls GPT-4 to generate module and testbench
    • Validates and patches testbench if needed
    • Lets you view, download, and simulate your design
  4. After simulation:
    • Shows console output
    • Generates wave.vcd
    • Plots waveform as a PNG (basic version)
    • Optionally download waveform file to open in GTKWave

Option 2: CLI Script

  1. Add your OpenAI API key in the script (openai.api_key = "sk-...")
  2. Run the script (python verilog_cli_generator.py)
  3. Flow:
    • Asks you for a hardware design prompt
    • GPT returns module + testbench
    • Automatically saves .v files in current directory
    • Asks if you want to simulate using iverilog
    • If yes, runs simulation and creates wave.vcd
    • Asks if you want to open waveform in GTKWave

Getting Started

Requirements

Tool Required Description
Python 3.8+ Yes For both CLI and Streamlit
OpenAI API key Yes To access GPT-4 via OpenAI API
Icarus Verilog Yes Icarus Verilog compiler and simulator
gtkwave Optional For viewing wave.vcd (CLI + Streamlit)
matplotlib Optional For waveform plotting in Streamlit app
vcdvcd Optional VCD parsing library for PNG generation

OpenAI API Key Setup

To use either version, you'll need an OpenAI API key.

  1. Go to https://platform.openai.com/account/api-keys
  2. Click Create new secret key
  3. Copy the key
  • In Streamlit: Paste the key into the app when prompted
  • In CLI: Replace "sk-..." in the script:
    openai.api_key = "sk-..."

Note: GPT-4 access requires a paid account

Installation

Streamlit Version

  1. Clone the repository:
    git clone https://github.com/YOUR_USERNAME/verilog-ai-agent.git
    cd verilog-ai-agent/streamlit_app
    
  2. Install Python dependencies:
    pip install -r requirements.txt
    
  3. Run the app:
    streamlit run streamlit_app.py
    

Once running:

  • Enter your OpenAI API key
  • Enter a prompt like "3-bit up counter"
  • Click Generate
  • Click Run Simulation
  • View results, waveform, and download files

CLI Version

  1. Clone the repository:
    git clone https://github.com/YOUR_USERNAME/verilog-ai-agent.git
    cd verilog-ai-agent/cli_version
    

2.Add your API key to the script

  1. Install Python dependencies:
    pip install -r requirements.txt
    
  2. Run the script:
    python verilog_cli_generator.py
    

Once running, you will be prompted to:

  • Hardware prompt
  • Simulation option
  • Whether to view waveform in GTKWave

Project Stucture

├── streamlit_app/
│   ├── streamlit_app.py       # Main Streamlit code
│   ├── requirements.txt       # Python dependencies
│   ├── waveform.png           # Rendered waveform (optional)
│   ├── wave.vcd               # Simulation output
│   └── *.v                    # Generated Verilog + Testbench
│
├── cli_version/
│   └── verilog_cli_generator.py # Simple CLI version

Notes

  • Waveform visualization is a work in progress — matplotlib rendering is still being improved.
  • Use GTKWave (gtkwave wave.vcd) for detailed signal visualization
  • The tool assumes a valid module/testbench is generated; please check logs if simulation fails

Why I Built This

As a student passionate about both AI and hardware design, I built this tool to explore hardware-software co-design. It reflects my interest in bridging LLMs with digital design and using Python to streamline RTL workflows.
It lets me:

  • Apply generative AI in an EDA context
  • Automate repetitive design + simulation tasks
  • Build practical AI tooling for Verilog users

About

Use GPT-4 to generate, simulate, and visualize Verilog modules from natural language prompts.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages