verilator 安装和使用


Verilator 是一个轻量仿真工具。

Verilator 安装

Verilator 主要是在 Ubuntu 上进行开发和测试,也额外在 FreeBSD、Apple OS-X、Red Hat Linux和 GNU/Linux-ish 其他平台上进行了测试。Verilator 还可用于 Windows 上的 Linux 子系统 (WSL2) ,Cygwin 下的 Windows 和 Mingw(GCC-MNO-Cygwin) 下的 Windows。

Windows 比较推荐使用 WSL2 安装。安装时一定要使用 Git 仓库自己构建安装,不要使用 `apt install verilator

注意:在现代仿真中,Verilator 版本需要 4.2 以上。目前Debian系的Linux发行版(含Ubuntu 22.10)的软件包中Verilator版本较老,仅为4.0,因此请勿apt install verilator进行安装。否则可能会出现编译错误!

例如:

../testbench.cpp: In function ‘int main(int, char**, char**)’:
../testbench.cpp:57:24: error: request for member ‘at’ in ‘dut->VTensorCore::matrix_a0’, which is of non-class type ‘WData [4]{aka ‘unsigned int [4]}
   57 |         dut->matrix_a0.at(i) = A[i*4+0];

安装前需要配置的环境:


# 构建和运行

sudo apt-get install git help2man perl python3 make autoconf g++ flex bison ccache
sudo apt-get install libgoogle-perftools-dev numactl perl-doc
sudo apt-get install libfl2  # Ubuntu only (ignore if gives error)
sudo apt-get install libfl-dev  # Ubuntu only (ignore if gives error)
sudo apt-get install zlibc zlib1g zlib1g-dev  # Ubuntu only (ignore if gives error) zlibc 已经废弃,报错不用管

# 如果想要进行开发工作
sudo apt-get install clang clang-format-14 cmake gdb gprof graphviz lcov
sudo apt-get install python3-clang yapf3 bear jq
sudo pip3 install sphinx sphinx_rtd_theme sphinxcontrib-spelling breathe ruff
sudo pip3 install git+https://github.com/antmicro/astsee.git
cpan install Pod::Perldoc

安装命令:


git clone https://github.com/verilator/verilator   # Only first time

# Every time you need to build:
unsetenv VERILATOR_ROOT  # For csh; ignore error if on bash
unset VERILATOR_ROOT  # For bash
cd verilator
git pull         # Make sure git repository is up-to-date
git tag          # See what versions exist
#git checkout master      # Use development branch (e.g. recent bug fixes)
#git checkout stable      # Use most recent stable release
#git checkout v{version}  # Switch to specified release version

autoconf         # Create ./configure script
./configure      # Configure and create Makefile
make -j `nproc`  # Build Verilator itself (if error, try just 'make')
sudo make install

Verilator 使用和运行

这里给出一个常用的 make 脚本:

all:
	-rm -r ./obj_dir
	-rm ./waveform.vcd
	verilator --trace -top-module topmodulename --cc *.v --exe testbench.cpp
	make -C ./obj_dir/ -f Vtopmodulename.mk
	./obj_dir/Vtopmodulename
	gtkwave ./waveform.vcd waveconfig.gtkw

执行后即可查看波形,效果如下图所示:

查看波形

参考:

verilator 官网:https://verilator.org/guide/latest/install.html

重庆大学硬件综合设计实验文档:https://co.ccslab.cn/env/tools/


Author: Yixiang Zhang
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source Yixiang Zhang !
评论
  TOC