SystemCインストール(Mac) from GitHub

前回の記事 では、Accelleraの Downloadページから取得したけど、今回は GitHubから。

今回は、ビルドとチェックまでしか実行してません。
最後に make installすればいけると思います。

ビルド&チェック

$ git clone https://github.com/accellera-official/systemc.git
$ cd systemc
# 今回は defaultの masterブランチを使用。
# releaseブランチだと configureがあるので前回通りの実行となる。
# 切替えは $ git checkout release
$ export CXX=clang++
$ vim CMakeLists.txt

コンパイラC98に設定されているため、C++14に変更
※2022/08/17に編集しなくてもできることを確認したため最後に追記してます。

@@ -273,7 +273,7 @@ if (NOT CMAKE_BUILD_TYPE)
        FORCE)
 endif (NOT CMAKE_BUILD_TYPE)

-set (CMAKE_CXX_STANDARD 98 CACHE STRING
+set (CMAKE_CXX_STANDARD 14 CACHE STRING
      "C++ standard to build all targets. Supported values are 98, 11, 14, and 17.")
$ mkdir objdir
$ cd objdir
$ cmake ..
-- The CXX compiler identification is Clang 9.0.1
-- The C compiler identification is Clang 9.0.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
# :
-- ========================================================================
-- Settings to build SystemC 2.3.4_pub_rev_20191203 (20191203) and TLM 2.0.6 (20191203)
-- ------------------------------------------------------------------------
# :
-- Configuring done
-- Generating done
-- Build files have been written to: /{DIR}/systemc/objdir
$ make
Scanning dependencies of target systemc
[  0%] Building CXX object src/CMakeFiles/systemc.dir/sysc/communication/sc_clock.cpp.o
# :
[100%] Linking CXX shared library libsystemc.dylib
[100%] Built target systemc
$ make check
Consolidate compiler generated dependencies of target systemc
[ 31%] Built target systemc
# :

100% tests passed, 0 tests failed out of 33

Total Test time (real) =  12.87 sec
[100%] Built target check
$

とこんな感じでした。

2022/08/17 追記

cmakeコマンドの引数で C++14に指定できることを確認しました。

$ cd objdir
$ cmake .. -DCMAKE_CXX_STANDARD=14

SystemC-2.3.3インストール(Mac)

何年振りかのインストール。

環境

前提

以下がインストールされている状態です。

インストール

こんな感じでインストールしました。

$ wget https://www.accellera.org/images/downloads/standards/systemc/systemc-2.3.3.tar.gz
$ tar xvf systemc-2.3.3.tar.gz
$ cd systemc-2.3.3
$ mkdir objdir
$ cd objdir
$ export CXX=clang++
$ ../configure
#:
---------------------------------------------------------------------
Configuration summary of SystemC 2.3.3 for x86_64-apple-darwin21.6.0
---------------------------------------------------------------------

 Directory setup (based on classic layout):
   Installation prefix (aka SYSTEMC_HOME):
      /{解凍ディレクトリパス}/systemc-2.3.3
   Header files  : <SYSTEMC_HOME>/include
   Libraries     : <SYSTEMC_HOME>/lib-macosx64
   Documentation : <SYSTEMC_HOME>/docs
   Examples      : <SYSTEMC_HOME>/examples

 Architecture    : macosx64
 Compiler        : g++ (C/C++)

 Build settings:
   Enable compiler optimizations  : yes
   Include debugging symbols      : no
   Coroutine package for processes: QuickThreads
   Enable VCD scopes by default   : yes
   Disable async_request_update   : no
   Phase callbacks (experimental) : no

---------------------------------------------------------------------
$ make
$ make check
#:
============================================================================
Testsuite summary for SystemC 2.3.3
============================================================================
# TOTAL: 22
# PASS:  22
# SKIP:  0
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERROR: 0
============================================================================
#:
============================================================================
Testsuite summary for TLM 2.0.5
============================================================================
# TOTAL: 11
# PASS:  11
# SKIP:  0
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERROR: 0
============================================================================
$ make install

動作確認

SYSTEMC_INCLUDE, SYSTEMC_LIBDIR環境変数として設定済み。

CC = clang++
INCDIR = -I. -I$(SYSTEMC_INCLUDE)
LIBDIR = -L. -L$(SYSTEMC_LIBDIR)
LIBS   = -lsystemc -lm
CFLAGS = -O2 -Wall

TARGET = run.exe
SRCS   = sc_main.cpp
OBJS   = $(SRCS:.cpp=.o)

all: $(TARGET)

$(TARGET): $(OBJS)
    $(CC) -o $@ $(LIBDIR) $(LIBS) $(OBJS)

.cpp.o:
    $(CC) $(CFLAGS) $(INCDIR) -c $<

clean:
    @rm -f *.o $(TARGET)
  • sc_main.cpp
#include <systemc.h>

int sc_main(int argc, char* argv[])
{
    std::cout << "Hello, World" << std::endl;

    return 0;
}
$ make
$ ./run.exe

        SystemC 2.3.3-Accellera --- Aug 15 2022 16:07:44
        Copyright (c) 1996-2018 by all Contributors,
        ALL RIGHTS RESERVED
Hello, World

動いた。

余談1

export CXX=clang++

をせずに、g++のまま実行すると make checkのところでエラーが発生しました。

$ make check
#:
To compile and run the examples type
   make check
============================================================================
Testsuite summary for SystemC 2.3.3
============================================================================
# TOTAL: 22
# PASS:  0
# SKIP:  0
# XFAIL: 0
# FAIL:  22
# XPASS: 0
# ERROR: 0

make checkのエラーについては、フォーラムであがっており、C++11以上であれば問題なさそう。

src/sysc/communication/sc_host_semaphore.hを見ると、SC_CPLUSPLUSで判断しており、
src/sysc/kernel/sc_cmnhdr.h で(多少分岐はあるが)最終的には、 __cplusplusを代入している。

__cplusplusは以下のコマンドで出力することが可能です。

$ g++ -dM -E -x c++ /dev/null
#:
#define __cplusplus 199711L

ちなみに、clang++の場合は以下になってます。

$ clang++ -dM -E -x c++ /dev/null
#:
#define __cplusplus 201402L

余談2

2.3.2でよければ、brew install systemcでインストールできるみたい

2.3.3で TLMが同封された。という記憶。

LRMの読み方をご紹介

この記事は SystemVerilog Advent Calendar 2020の 1日目になります。
まだまだ空きがありますので、興味あれば参加してください。

プロローグ

きっかけはこの本が発売されたことから

https://www.kyoritsu-pub.co.jp/app/img/item/9784320124639.jpg

超久しぶりに新しい本が出た気がします。
私も購入したけど忙しくて読めてなく、まだ1章にもたどり着いてないです...orz

っというのも、私の環境も色々変わって今は CUDA書いたり、x86-64や AArch64のアセンブラと格闘したり、Pythonで書かれたプログラムをC++に変換したりと HDLと呼ばれる言語に4〜5年まともに書いてないんじゃないかと(汗

私の環境は変わりましたが、こういう本が世の中に出るのは個人的には嬉しく、できればもっと盛り上げたいなと思って今年 Advent Calendarやることにしました!

SystemVerilogがカバーしている範囲はかなり幅広く、興味があれば一度 LRM(Language Reference Manual)を読むことをおすすめします。
個人的には、こんな感じでした。

  • 知らなかった構文があって、業務に活かせた
  • ツールの挙動がおかしい時の確認に使えた。(問い合わせ時にLRMにこう書いてあるんだけどとか。)
  • UVMやVIPなどのコード見て意味がわかる。(たまにマニアックな記述の塊だったやつもあった)

昔書いてたブログ見たら2013,4年ぐらい

1. LRMをDownloadしよう!

SystemVerilogのLRMは IEEE1800になります。Get programで 無償でDownloadできます。
ただし、IEEEアカウントは作る必要があります。(本記事書くときにIEEEアカウント作ってDownloadしました。今までしてなかった...)

Downloadできる版数は「IEEE1800-2017」です。

この記事見て、まだDownloadしていなかったら、ぜひDownloadしてください。
記事のメインはココです!!!

2. 目次を見てみよう

各パートおよび章立ては以下になってます。

Part One: Design and Verification Constructs
   1. Overview
   2. Normative references
   3. Design and verification building blocks
   4. Scheduling semantics
   5. Lexical Converntions
   6. Data Type
   7. Aggregate data types
   8. Class
   9. Processes
  10. Assignment statements
  11. Operators and expressionsA
  12. Procedural programming statements 
  13. Tasks and functions (subroutines) 
  14. Clocking blocks
  15. Interprocess synchronization and communication
  16. Assertions
  17. Checkers
  18. Constrained random value generation
  19. Functional coverage
  20. Utility system tasks and system functions 
  21. Input/output system tasks and system functions 
  22. Compiler directives

Part Two: Hierarchy Constructs
  23. Modules and hierarhy
  24. Programs
  25. Interfaces
  26. Packages
  27. Generate constructs
  28. Gate-level and switch-level modeling
  29. User-defined primitives
  30. Specify blocks
  31. Timing checks
  32. Backannotation using the standard delay format
  33. Configuring the contents of a design
  34. Protected envelopes

Part Three: Application Programming Interfaces
  35. Direct programming interface
  36. Programming language interface (PLI/VPI) overview
  37. VPI object model diagrams
  38. VPI routine definitions
  39. Assertion API
  40. Code coverage control and API
  41. Data read API

Part Four: Annexes
  Annex A (normative) Formal syntax
  Annex B (normative) Keywords
  Annex C (normative) Deprecation
  Annex D (informative) Optional system tasks and system functions
  Annex E (informative) Optional compiler directives
  Annex F (normative) Formal semantics of concurrent assertions
  Annex G (normative) Std package
  Annex H (normative) DPI C layer
  Annex I (normative) svdpi.h
  Annex J (normative) Inclusion of foreign language code
  Annex K (normative) vpi_user.h
  Annex L (normative) vpi_compatibility.h
  Annex M (normative) sv_vpi_user.h
  Annex N (normative) Algorithm for probabilistic distribution functions
  Annex O (informative) Encryption/decryption flow
  Annex P (informative) Glossary
  Annex Q (informative) Bibliography

1,300ページ以上もあるLRM本なのでそれなりに中身があります...
厳選10章13章をあげると、こんな感じでしょうか。

   3. Design and verification building blocks
   4. Scheduling semantics
   6. Data Type
   7. Aggregate data types
   8. Class
  10. Assignment statements
  14. Clocking blocks
  20. Utility system tasks and system functions 
  21. Input/output system tasks and system functions 
  22. Compiler directives
  25. Interfaces
  26. Packages
  35. Direct programming interface

3. どれか読んでみよう

例えば、21. Input/output system tasks and system functionsだとこんな感じです。
このシステム関数の詳細が記載されている章になります。

f:id:kocha2012:20201130200451p:plain

21.6 Command line input」などは知らないと損しているのではと思ってます。

$test$plusargs ( string )
$value$plusargs ( user_string, variable )

使い方の例も記載されてますので、見てみてください。

分かりづらい部分については exampleとして例が載っているので、
実際に記述したときに、どういう値や挙動になるのかが分かるのでイメージしやすいと思います。

4. おわりに

SystemVerilog Advent Calendar 2020 の初日ということで、LRMについて書いてみました。

過去の自分のブログを見てて、へぇーって思うようなものがあったので羅列しときます。
こんな感じで、LRMを読んで気になったやつを自分で書いてみてるのも楽しいのではないかと思います。

では、良い SystemVerilogライフをお楽しみください!

Vivado/Vitisにて SystemCデザインが非対応に

昨日ふと見てたら、こんなものが、

2020.2 リリース以降、新しいザイリンクス HLS ツール (Vitis HLS) では SystemC がサポートされなくなります。

ということです。
それでも、SystemCのデザインを使い方場合はどうすれば!?っと思った方も安心。こう記載されています。

今後も SystemC を使用して設計する 1 つ方法は、サードパーティ提供の SystemC 高位合成ツールを使用することです。

まとめ:「2020.2」で、SystemCデザインがサポートされなくなります。
時代の流れですね。

gtkwaveをMac(Mojave 10.14.6)にインストール

なんとなくやってみた。
(ここ数年RTL書いてないし、波形も見てない)

環境

前提

以下がインストールされている状態です。

要約

以下のコマンドを実行します。

$ brew cask install xquartz
# passwardを聞かれる場合もあるので、入力
$ brew cask install gtkwave 

インストール完了後にLauchpadにgtkwave.appがあると思うので、ダブルクリックで起動します。

セキュリティの問題で起動しない場合があるので、起動しない場合はこちらを試してください。

「システム環境設定」
  →「セキュリティとプライバシー」
    →「ダウンロードしたアプリケーションの実行許可:」
 があるので、そこで許可すれば画面が立ち上がる。

詳細

やったことをぐだぐたと書いているので、あまり見る価値はないかも。

$ brew install gtkwave
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
==> New Formulae
:
Error: No available formula with the name "gtkwave"
Found a cask named "gtkwave" instead. Try
  brew cask install gtkwave

あらー これではインストール出来ないのね。

$ brew cask install gtkwave
==> Caveats
You may need to install Perl’s Switch module to run gtkwave’s command line tool.

  https://ughe.github.io/2018/11/06/gtkwave-osx

==> Downloading https://downloads.sourceforge.net/gtkwave/gtkwave-3.3.103-osx-app/gtkwave.zip
==> Verifying SHA-256 checksum for Cask 'gtkwave'.
Error: Cask 'gtkwave' requires XQuartz/X11, which can be installed using Homebrew Cask by running:
  brew cask install xquartz

or manually, by downloading the package from:
  https://www.xquartz.org/

まずは、xquartzをインストールしないといけないもよう。
今回、実行したら passwardを聞かれたので入力

$ brew cask install xquartz
==> Downloading https://dl.bintray.com/xquartz/downloads/XQuartz-2.7.11.dmg
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/32e50e8f1e21542b847041711039fa78d44febfed466f834a9281c44d75cd6c3?response-content-disposition=attachment%3Bfilename%3D%22XQuartz-2.7.11.dmg%22&Po
######################################################################## 100.0%
==> Verifying SHA-256 checksum for Cask 'xquartz'.
==> Installing Cask xquartz
==> Running installer for xquartz; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are ignored.
Password:(入力)

installer: Package name is XQuartz 2.7.11
installer: Installing at base path /
installer: The install was successful.
🍺  xquartz was successfully installed!

さて、いよいよ gtkwaveのインストール

$ brew cask install gtkwave
==> Caveats
You may need to install Perl’s Switch module to run gtkwave’s command line tool.

  https://ughe.github.io/2018/11/06/gtkwave-osx

==> Downloading https://downloads.sourceforge.net/gtkwave/gtkwave-3.3.103-osx-app/gtkwave.zip
==> Verifying SHA-256 checksum for Cask 'gtkwave'.
==> Installing Cask gtkwave
==> Moving App 'gtkwave.app' to '/Applications/gtkwave.app'.
==> Linking Binary 'gtkwave_bin_launcher.sh' to '/usr/local/bin/gtkwave'.
🍺  gtkwave was successfully installed!

コマンドラインで起動しようとすると以下のエラーが出る。

$ gtkwave
/usr/local/bin/gtkwave: line 122: test: too many arguments
/usr/local/bin/gtkwave: line 149: test: ==: unary operator expected
find: /share/locale: No such file or directory
/usr/local/bin/gtkwave: line 215: /usr/local/bin/../../../Contents/Resources/bin/: No such file or directory
/usr/local/bin/gtkwave: line 215: exec: /usr/local/bin/../../../Contents/Resources/bin/: cannot execute: No such file or directory

インストール完了後にLauchpadにgtkwave.appがあると思うので、ダブルクリックで起動

セキュリティの問題で起動しない場合があるので、起動しない場合はこちらを試してください。

「システム環境設定」
  →「セキュリティとプライバシー」
    →「ダウンロードしたアプリケーションの実行許可:」
 があるので、そこで許可すれば画面が立ち上がる。

もしかしたら、今後波形見る機会が来るかもしれない。。。
来なくていいけど。