6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Verilator 5をGitHub Actionsで動かす方法〜self-hosted runnerで高速化

Last updated at Posted at 2023-01-31

SystemVerilogのCI環境の構築で,今度はself-hosted runnerを使ってみたいと思います.

Verilator 5 を使う利点について

Verilatorのいいところは,macOSでも使える点と,GitHub ActionsでCIを組める点です.
Verilator 5になって,--timingオプションが使えるようになり,テストベンチで #10; すなわち10クロック待つ,みたいな記述ができるようになり,SystemVerilogでテストベンチが完結できるみたいです.それ以前のVerilatorだとCプログラムでテストベンチを書く必要がありました.(とはいえ,記述できるのは,ディジタル回路設計とコンピュータアーキテクチャ第2版にあるような,自己点検テストベンチまでで,テストベクタファイル付きテストベンチは意図通りにファイルを読み込めなかったのですけど)

下記のようにDockerを使って高速化しましたが,CIで常用するにはまだまだ速度が足りないと思っていました.

Self-hosted runnerを使うことで,プライベートネットワーク上のリソースを使うことができます.今回の場合だと,環境をあらかじめセットアップしてDockerイメージ取得の時間を削減するのと,CPU資源とメモリ資源を潤沢に使って並列コンパイルをすることで,ビルドを高速化できる期待を持っています.

Self-hosted runnerに関する公式ドキュメント

今回参考にした記事はこちらです.

GitHubレポジトリ上の Settings > Actions > Runners でNew self-hosted runnerボタンを押し,その手順にしたがって,環境を構築します.

ただし,最後の ./run.sh をするかわりに,次のコマンドを入力します.

sudo ./svc.sh install $USER
sudo ./svc.sh start $USER

これでバックグラウンドでランナーが起動します.

今回,Ubuntu20.04に環境を構築しました.Verilator 5をインストールする手順は基本的には次の手順です.

ただし,不足しているのは,まずhelp2manのインストールです.

sudo apt install help2man

それから,Clang 9を用いるようにしないとエラーになります.Clang 9のインストールは下記です.

sudo apt install clang-9

./configure を実行する際に,次のようにして Clang-9 を用いるように設定します.

CXX=clang++-9 LINK=clang++-9 ./configure

あとは前述の手順の通りです.

GitHub Actionsのymlは次のようにします.

verilator_on_local.yml
# This is a basic workflow to help you get started with Actions

name: Verilator on Rigel

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the "main" branch
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: self-hosted

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v3

      # Run compiling and testing
      - name: Run compiling and testing
        run: |
          make -j$(nproc) -f Makefile.verilator clean test

make -j$(nproc)とすることで,マシンのポテンシャルをめいいっぱい使い切って並列ビルドします.また,Verilator 5環境構築済みなので,Dockerイメージの取得が不要です.

この変更により,ビルドとテストが数倍高速化され,ほとんど待たずに終了するようになりました!

20240210追記:

本記事から大幅アップデートした手法について,FPGAマガジン特別版No.2で紹介しております https://fpga.tokyo/no2-2/

大変光栄なことに,トップを飾っております.

第1章 Verilator 5とGitHub Actionsによるテストベンチ自動検証

他にも有用な記事が満載ですので,ぜひこの機会にInterfaceを定期購読ください!

6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?