FPGA開発日記

カテゴリ別記事インデックス https://msyksphinz.github.io/github_pages , English Version https://fpgadevdiary.hatenadiary.com/

NVIDIAのオープンソース ディープラーニングアクセラレータを試す(1. NVDLAのビルドとシミュレーション環境構築)

NVIDIAオープンソースディープラーニングアクセラレータ「NVDLA」について調査したことをまとめる。

ハードウェア・ソフトウェアのイントロダクションについて

  • NVDLA Primer

NVDLA Primer — NVDLA Documentation

msyksphinz.hatenablog.com

msyksphinz.hatenablog.com

NVDLAのシミュレーション環境構築

NVDLAはいくつかのシミュレータでのシミュレーションをサポートしている。 - Synopsys社 VCS - Xilinx社 Vivado Simulator - Verilator (試行中)

github.com

NVDLAの環境構築

NVDLAでの環境を構築し、シミュレーションを実行できるようにするためには、リポジトリをダウンロードした後に環境構築のためのスクリプトを実行する必要がある。

git clone https://github.com/nvdla/hw.git nvdla_hw
cd nvdla_hw

NVDLAの環境を構築するのはちょっと面倒くさい。まずは http://nvdla.org/integration_guide.html を参考に、環境を構築する。

CentOS 7.0で実行しているのだが、まずはPerlのパッケージインストールが必要だ。

sudo yum install perl-IO-Tee
cd nvdla_hw
make

ここでいくつかの質問に答える。GCCの場所とか、Javaの場所、Perlの場所などを入力すればよい。 次に、以下でRTL環境をビルドすることができる。

./tools/bin/tmake -build vmod

outdirというディレクトリができるので、これがおそらくコンフィグレーションを指定している。

$ tree -L 2 outdir/
outdir/
├── build.log
├── nv_large
│   ├── spec
│   └── vmod
└── nv_small
    ├── spec
    └── vmod

6 directories, 1 file

Vivado SimulatorでNVDLAを動作させる

NVDLA version1.0では、Vivado Simulatorがサポートされている。

cd verif/sim_vivado
make run TESTDIR=../traces/traceplayer/googlenet_conv2_3x3_int16

とすると、何やらいろいろアクセスのログを吐き出しながらVivado Simulatorでの実行が始まる。 AXI経由でのアクセスのログが表示されているようだ。

#-----------------------------------------------------------
# xsim v2017.2 (64-bit)
# SW Build 1909853 on Thu Jun 15 18:39:10 MDT 2017
# IP Build 1909766 on Thu Jun 15 19:58:00 MDT 2017
# Start of session at: Tue Nov 21 17:46:20 2017
# Process ID: 4868
# Current directory: /home/masayuki/others/nvdla_hw/verif/sim_vivado/googlenet_conv2_3x3_int16
# Command line: xsim -log test.log -mode tcl -source {xsim.dir/work.top/xsim_script.tcl}
# Log file: /home/masayuki/others/nvdla_hw/verif/sim_vivado/googlenet_conv2_3x3_int16/test.log
# Journal file: /home/masayuki/others/nvdla_hw/verif/sim_vivado/googlenet_conv2_3x3_int16/xsim.jou
#-----------------------------------------------------------
source xsim.dir/work.top/xsim_script.tcl
# xsim {work.top} -testplusarg input_file=/home/masayuki/others/nvdla_hw/verif/sim_vivado/googlenet_conv2_3x3_int16/input.txn -testplusarg input_dir=/home/masayuki/others/nvdla_hw/verif/sim_vivado/googlenet_conv2_3x3_int16 -autoloadwcfg
-runall
Vivado Simulator 2017.2
Time resolution is 1 ps
run -all
10570.00ns MSEQ: Backdoor mem_load of file                           0.raw2 at address 0x50064080 for length 0x0000b480.
10650.00ns MSEQ: Backdoor mem_load of file                           1.raw2 at address 0x5002dfe0 for length 0x00036000.
10730.00ns MSEQ: Backdoor mem_load of file                           2.raw2 at address 0x500000e0 for length 0x0002da80.
10810.00ns MSEQ: write_cmd address 0xffff2c01 with data 0x00000000 (command 4294967295)
11610.00ns MSEQ: Write (command 4294967295) completed (addr: 0xffff2c01, data: 0x00000000.
11690.00ns MSEQ: read_cmd address 0xffff2c01 with data 0x00000000 and mask 0x00010001 (command 0)
12490.00ns MSEQ: Read (command 0) matched (addr: 0xffff2c01, received data: 0x00000000, expected data: 0x00000000.
...

シミュレーションが終了するまでに、Vivado Simulatorでは30分以上かかった。VCSだともっと速いのだろうが。。。

GoogleNet 以外にも、 cc_alexnet_conv5_relu5_int16_dtest_cvsram を指定すればAlexNetを実行するができる、いくつかのSanity Checkも実行できる。

make run TESTDIR=../traces/traceplayer/cc_alexnet_conv5_relu5_int16_dtest_cvsram
make run TESTDIR=../traces/traceplayer/sanity

VerilatorでNVDLAを動作させる

VerilatorでNVDLAを実行することが出来るが、まだ試行的な段階だ。 私の実行環境ではメモリ8GBを食いつぶし、猛烈なHDDアクセスが入るので注意。 VirtualBoxを巻き込んで一度落ちてしまった。

./tools/bin/tmake -build verilator

verif/verilator に移動し、以下のようにしてシミュレーションを実行する。

$ make run TEST=sanity0
rm -rf ../../outdir/nv_full/verilator/test/sanity0/trace.bin
mkdir -p ../../outdir/nv_full/verilator/test/sanity0/
/usr/bin/perl input_txn_to_verilator.pl ../../verif/traces/traceplayer/sanity0 ../../outdir/nv_full/verilator/test/sanity0/trace.bin
converting ../../verif/traces/traceplayer/sanity0/input.txn to ../../outdir/nv_full/verilator/test/sanity0/trace.bin
cd ../../outdir/nv_full/verilator/test/sanity0 && ../../VNV_nvdla trace.bin
CMD: read_reg ffff100b ffffffe0 00000000
CMD: write_reg ffff100b f0a5a500
CMD: read_reg ffff100b ffffffe0 f0a5a500
CMD: done
reset...
letting buffers clear after reset...
running trace...
(8272) read from nvdla: addr ffff100b
(8308) read response from nvdla: 00000000
(8310) write to nvdla: addr ffff100b, data f0a5a500
(8312) read from nvdla: addr ffff100b
(8348) read response from nvdla: f0a5a500
done at 8750 ticks
*** PASS

現状でのシミュレーション結果は以下だ。 Verilatorでは、まだシミュレーションがFailしているものがある。

Test Pattern Verilator Vivado Sim
cc_alexnet_conv5_relu5_int16_dtest_cvsram FAIL PASS
conv_8x8_fc_int16 PASS PASS
googlenet_conv2_3x3_int16 FAIL PASS
pdp_max_pooling_int16 PASS PASS
sanity0 PASS PASS
sanity1 PASS PASS
sanity1_cvsram PASS PASS
sanity2 PASS PASS
sanity2_cvsram PASS PASS
sanity3 PASS PASS
sanity3_cvsram PASS PASS
sdp_relu_int16 PASS PASS