PYNQ-Z2にAIコンパイラtvmのインストール

tvm
github.com

PYNQへのインストールはここを参考に
tvm.apache.org

git clone --recursive https://github.com/apache/tvm tvm
cd tvm
mkdir build
cp cmake/config.cmake build/.
echo 'set(USE_VTA_FPGA ON)' >> build/config.cmake
cp 3rdparty/vta-hw/config/pynq_sample.json 3rdparty/vta-hw/config/vta_config.json
cd build
cmake ..
make runtime vta -j2
#make clean; make runtime vta -j2
cd ..
sudo ./apps/vta_rpc/start_rpc_server.sh # pw is 'xilinx'

ホスト側にもTVMを入れる必要がある。Dockerで行った。
1. TVMレポジトリのクローン

$ git clone git@github.com:apache/tvm.git
$ cd tvm
$ git submodule init
$ git submodule update

2. dockerイメージの取得

$ docker pull tvmai/demo-cpu

3. dockerコンテナの起動

$ ./docker/bash.sh tvmai/demo-cpu
||< 
4. Jupyter notebookを立ち上げる
>||
$ jupyter notebook --ip=0.0.0.0
[I 12:06:26.811 NotebookApp] Serving notebooks from local directory: /Users/shohei/Downloads/tvm
[I 12:06:26.811 NotebookApp] The Jupyter Notebook is running at:
[I 12:06:26.811 NotebookApp] http://cb83e5afe597:8888/?token=03cd83adb2f74edb51f9f96227b542b6ff16948a18c41036
[I 12:06:26.811 NotebookApp]  or http://127.0.0.1:8888/?token=03cd83adb2f74edb51f9f96227b542b6ff16948a18c41036
[I 12:06:26.811 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 12:06:26.819 NotebookApp] No web browser found: could not locate runnable browser.
[C 12:06:26.819 NotebookApp]

    To access the notebook, open this file in a browser:
        file:///Users/shohei/Downloads/tvm/.local/share/jupyter/runtime/nbserver-7039-open.html
    Or copy and paste one of these URLs:
        http://cb83e5afe597:8888/?token=03cd83adb2f74edb51f9f96227b542b6ff16948a18c41036
     or http://127.0.0.1:8888/?token=03cd83adb2f74edb51f9f96227b542b6ff16948a18c41036
[I 12:06:28.351 NotebookApp] 302 GET /?token=03cd83adb2f74edb51f9f96227b542b6ff16948a18c41036 (172.17.0.1) 1.31ms

で、 トークン付きのURL(http://127.0.0.1:8888/?token=03cd83adb2f74edb51f9f96227b542b6ff16948a18c41036)にアクセスするとJupyterが見えた。
f:id:seinzumtode:20211202210922p:plain
5. ビルド設定
tvm.apache.org

export TVM_PATH=<path to TVM root>
export VTA_HW_PATH=$TVM_PATH/3rdparty/vta-hw
cd $TVM_PATH
mkdir build
cp cmake/config.cmake build/.
echo 'set(USE_VTA_FSIM ON)' >> build/config.cmake
cd build && cmake .. && make -j4

ビルド時に以下のエラーがでたので、CMakeLists.txtの615行目のgtest_discover_testsの行をコメントアウトして再度ビルドした。

CMake Error at CMakeLists.txt:615 (gtest_discover_tests):
  Unknown CMake command "gtest_discover_tests".