Vengineerの妄想(準備期間)

人生は短いけど、長いです。人生を楽しみましょう!

UHDM と UHDM-Verilator Integrationのビルド

@Vengineerの戯言 : Twitter SystemVerilogの世界へようこそすべては、SystemC v0.9公開から始まった 

はじめに

ASIC や FPGA の開発にも下記のようなオープンソースのソフトウェアを使う動きが活発になってきました。

これらのソフトウェアとは別に、SystemVerilog をサポートするソフトウェア間のモデルを共通化という UHDM (Universal hardware Data Model) というプロジェクトがあります。

UHDM とは?

UHDM (Universal Hardware Data Model) は、IEEE standard の SystemVerilog 2017 の 976~1050頁で詳細に記述されているオブジェクトモデルに準拠したものです。このオブジェクトモデルは、SystemVerilog の VPI (Verilog Procedural Interface) を使ったものです。VPI は、Verilog HDL の PLI 2.0 (Programming Language Interface version 2.0) と同じもので、IEEE 1364 Programming Language Interface standard から IEEE 1800 (SystemVerilog) に取り込まれたものです。

UHDM に関する資料

UHDM は名前が示すようにモデルです。Antmicro が このUHDMを論理合成ツールである YosysVerilog HDL/SystemVerilog シミュレータである Verilator に統合するプロジェクトを行っています。

AntMicroのVerilator

Verilator は本家のVerilatorではなく、AntMicroのVerilator with a dynamic schedulerです。 Veriator with a dynamic scheduler は、本家のVerilatorに対して、

  • # 遅延
  • initial 文
  • wait 文
  • event
  • fork
  • Randomize class function with constraints

をサポートしています。

UHDM-Verilator Integration

UHDM と AntMicro の Verilator with a dynamic scheduler の統合は、uhdm-verilator branch に行われています。

ビルド

Verilator で UHDM を使えるようにした、UHDM-Verilator Integration をビルドします。

準備として、下記のパッケージをインストールします。

$ sudo apt install g++-7 cmake build-essential tclsh \
 ant default-jre swig google-perftools libgoogle-perftools-dev \
 python3 python3-dev

また、Surelog のビルド時に、"No package 'uuid' build というメッセージが表示され、cmake が失敗するので、uu-dev パッケージをインストールします。

$ sudo apt install uuid-dev

UHDM-Verilator のビルドです。

$ git clone -b uhdm-verilator https://github.com/antmicro/verilator.git uhdm-verilator
$ cd uhdm-verilator
$ git submodule update --init --recursive
$ ./build_binaries.sh
$ cd uhdm-integration
$ make

WSL2 (WSL)のビルドでエラーが発生した

WSL2 でビルドすると、third_party/capnproto/c++src/capnp のところで次のようなエラーが発生する場合があります

[ 46%] Generating ../src/UHDM.capnp.h, ../src/UHDM.capnp.c++
UHDM MODEL GENERATION
Working dir: /home/vengineer/home/verilator/UHDM/build; codegen_base: /home/vengineer/home/verilator/UHDM
capnp_path = /home/vengineer/home/verilator/UHDM/build/third_party/capnproto/c++/src/capnp/capnpc-c++
sh: 1: export: Files/WindowsApps/CanonicalGroupLimited.Ubuntu20.04onWindows_2004.2021.610.0_x64__79rhkp1fndgsc:/mnt/c/Program: bad variable name
child process exited abnormally
    while executing
"exec -ignorestderr sh -c "export PATH=$capnp_path:\$PATH; $capnp_path/capnp compile -oc++:. $myProjetPathNoNormalize/src/UHDM.capnp""
    (procedure "generate_code" line 393)
    invoked from within
"generate_code $models"
    (file "/home/vengineer/home/verilator/UHDM/model_gen/model_gen.tcl" line 1704)
make[3]: *** [CMakeFiles/GenerateCode.dir/build.make:349: ../src/UHDM.capnp.h] Error 1
make[3]: Leaving directory '/mnt/c/Users/haray/home/verilator/UHDM/build'
make[2]: *** [CMakeFiles/Makefile2:403: CMakeFiles/GenerateCode.dir/all] Error 2
make[2]: Leaving directory '/mnt/c/Users/haray/home/verilator/UHDM/build'
make[1]: *** [Makefile:141: all] Error 2
make[1]: Leaving directory '/mnt/c/Users/haray/home/verilator/UHDM/build'
make: *** [Makefile:16: release] Error 2

このエラーの原因は、PATH にスペースが入っているためのようです。PATH を 下記のように再設定することでエラーが無くなりました。 この対策が分かるまで、4時間ぐらいかかちゃいましたよ。

$ export PATH=/usr/bin:/usr/local/bin

おわりに

今回は、UHDMとUHDM-Verilator Integration の ビルドまで行いました。