LoginSignup
7
5

More than 5 years have passed since last update.

DeepLearning ハードウェアアクセラレータ:VTAをPYNQ-Z1 で動くようにセットアップして見た

Last updated at Posted at 2019-01-05

MacからsshfsでPYNQのファイルをリモートアクセスするための設定

最初は、VivadoをWindows10で動作させていて、そこからPYNQ-Z1にbitstreamファイルを
送り込んでいたので、WindowsのWSL(Windows Subscribe for Linux)のUbuntu16.04から
sshfsしてみようと試みたのですが、なんか色々モジュールが足りないとのことで、接続出来なかったので、
Macからやってみたら出来た。

brew install osxfuse
brew install sshfs
mkdir mountp
sshfs xilinx@192.168.2.99:/home/xilinx mountp

として、ローカルのmountpに移動して、中身を見ると、PYNQ-z1のファイルがみれていますね。
素晴らしい。

cd mountp
kinomacpro-4:mountp kinoca77$ ls
REVISION        jupyter_notebooks   pynq

これで、PYNQからはインターネットに繋がらないのですが、git cloneしてきたソースファイルなどを
取り込んで、コンパイルが出来ます!
では早速、TVMのソースをcloneします。

git clone --recursive https://github.com/dmlc/tvm

この状態で、PYNQにログインして、ビルドしましょう。
本家の手順はこちら。

ssh xilinx@192.168.2.99
cd /home/xilinx/tvm
mkdir build
cp cmake/config.cmake build/.
cp vta/config/pynq_sample.json build/vta_config.json
cd build
cmake ..
make runtime vta -j2
cd ..
sudo ./apps/pynq_rpc/start_rpc_server.sh # pw is 'xilinx'

/tvm/vta/config/pynq_sample.jsonには、PYNQ用の以下のような推論パラメータ(各種演算に利用する計算資源の量を、対象の計算資源に合わせて調整できる)が参照できます。

{
  "TARGET" : "pynq",
  "HW_FREQ" : 100,
  "HW_CLK_TARGET" : 8,
  "HW_VER" : "0.0.0",
  "LOG_INP_WIDTH" : 3,
  "LOG_WGT_WIDTH" : 3,
  "LOG_ACC_WIDTH" : 5,
  "LOG_OUT_WIDTH" : 3,
  "LOG_BATCH" : 0,
  "LOG_BLOCK_IN" : 4,
  "LOG_BLOCK_OUT" : 4,
  "LOG_UOP_BUFF_SIZE" : 15,
  "LOG_INP_BUFF_SIZE" : 15,
  "LOG_WGT_BUFF_SIZE" : 18,
  "LOG_ACC_BUFF_SIZE" : 17
}

手順の詳細結果は、以下。

xilinx@pynq:~$ ls
jupyter_notebooks  pynq  REVISION  tvm
xilinx@pynq:~$ pwd
/home/xilinx
xilinx@pynq:~$ cd tvm
xilinx@pynq:~/tvm$ mkdir build
xilinx@pynq:~/tvm$ cp cmake/config.cmake build/.
xilinx@pynq:~/tvm$ ls
3rdparty  cmake           CONTRIBUTORS.md  golang       jvm       NEWS.md  python     src    tutorials  web
apps      CMakeLists.txt  docker           include      LICENSE   nnvm     README.md  tests  verilog
build     conda           docs             Jenkinsfile  Makefile  NOTICE   rust       topi   vta
xilinx@pynq:~/tvm$ cd build
xilinx@pynq:~/tvm/build$ ls
config.cmake
xilinx@pynq:~/tvm/build$ cmake ..
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test SUPPORT_CXX11
-- Performing Test SUPPORT_CXX11 - Success
-- Build with RPC support...
-- Build with Graph runtime support...
-- Build VTA runtime with target: sim
-- Configuring done
-- Generating done
-- Build files have been written to: /home/xilinx/tvm/build

TVMをビルドします。

xilinx@pynq:~/tvm/build$ make runtime vta -j2

[100%] Built target vta

が表示されればビルドは成功です。
ここでPYNQ上でRPCサーバーを起動します。(パスワードは、xilinx)

xilinx@pynq:~$ cd tvm
xilinx@pynq:~/tvm$ sudo ./apps/pynq_rpc/start_rpc_server.sh # pw is 'xilinx'
[sudo] password for xilinx: 
INFO:RPCServer:bind to 0.0.0.0:9091

Mac(Host)からRPCサーバーを使用するための設定

ホストPC側で以下の設定をします。

export VTA_PYNQ_RPC_HOST=192.168.2.99
export VTA_PYNQ_RPC_PORT=9091

tvmのルートフォルダに,PYNQのファイルからTARGETがpynqとしたファイルをコピーします。

cd mountp/tvm
cp vta/config/pynq_sample.json vta_config.json

PYNQで設定したものと同じものを、ホスト側でも置く訳です。

{
  "TARGET" : "pynq",
  "HW_FREQ" : 100,
  "HW_CLK_TARGET" : 8,
  "HW_VER" : "0.0.0",
  "LOG_INP_WIDTH" : 3,
  "LOG_WGT_WIDTH" : 3,
  "LOG_ACC_WIDTH" : 5,
  "LOG_OUT_WIDTH" : 3,
  "LOG_BATCH" : 0,
  "LOG_BLOCK_IN" : 4,
  "LOG_BLOCK_OUT" : 4,
  "LOG_UOP_BUFF_SIZE" : 15,
  "LOG_INP_BUFF_SIZE" : 15,
  "LOG_WGT_BUFF_SIZE" : 18,
  "LOG_ACC_BUFF_SIZE" : 17
}
import os
import tvm
from tvm import rpc
from vta import get_bitstream_path, download_bitstream, program_fpga, reconfig_$

host = os.environ.get("VTA_PYNQ_RPC_HOST", "pynq")
port = int(os.environ.get("VTA_PYNQ_RPC_PORT", "9091"))

def program_rpc_bitstream(path=None):
    """Program the FPGA on the RPC server

    Parameters
    ----------
    path : path to bitstream (optional)
    """
    assert tvm.module.enabled("rpc")
    remote = rpc.connect(host, port)
    program_fpga(remote, path)

def reconfig_rpc_runtime():
    """Reconfig the RPC server runtime
    """
    assert tvm.module.enabled("rpc")
    remote = rpc.connect(host, port)
    reconfig_runtime(remote)

program_rpc_bitstream()
reconfig_rpc_runtime()

Mac(host side)側でも、TVMをインストール

git clone --recursive https://github.com/dmlc/tvm

Macで必要なライブラリは以下。

On OSX the target library are libtvm.dylib, libtvm_topi.dylib
7
5
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
7
5