Skip to content

Commit f17e685

Browse files
tmoreau89sergei-mironov
authored andcommitted
[DOC, EXAMPLE] Updated READMEs, tests, etc. (apache#41)
* bug fix for new drivers in new PYNQ image v2.1 * updating instructions for resnet inference * updated the instructions for starting the RPC server * deriving host/port from env for unit tests
1 parent cfadf5b commit f17e685

File tree

5 files changed

+67
-39
lines changed

5 files changed

+67
-39
lines changed

vta/apps/pynq_rpc/README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
### PYNQ RPC Server for VTA
1+
# PYNQ RPC Server for VTA
22

33
This guide describes how to setup a Pynq-based RPC server to accelerate deep learning workloads with VTA.
44

55
## Pynq Setup
66

77
Follow the getting started tutorial for the [Pynq board](http://pynq.readthedocs.io/en/latest/getting_started.html).
8-
* For this RPC setup make sure to go with the *Connect to a Computer* Ethernet setup.
8+
* This assumes that you've downloaded the latest Pynq image, PYNQ-Z1 v2.1 (released 21 Feb 2018).
9+
* For this RPC setup, follow the ["Connect to a Computer"](http://pynq.readthedocs.io/en/latest/getting_started.html#connect-to-a-computer) Pynq setup instructions.
10+
* To be able to talk to the board, you'll need to make sure that you've followed the steps to [assign a static IP address](http://pynq.readthedocs.io/en/latest/appendix.html#assign-your-computer-a-static-ip)
911

10-
Make sure that you can ssh into your Pynq board successfully:
12+
Make sure that you can talk to your Pynq board successfully:
1113
```bash
12-
ssh xilinx@192.168.2.99
14+
ping 192.168.2.99
1315
```
1416

15-
When ssh-ing onto the board, the default password for the `xilinx` account is `xilinx`.
17+
When ssh-ing onto the board, the password for the `xilinx` username is `xilinx`.
1618

17-
For convenience let's go ahead and mount the Pynq board's file system to easily access it and maintain it:
19+
For convenience let's go ahead and mount the Pynq board's file system to easily access it (this will require sshfs to be installed):
1820
```bash
21+
mkdir <mountpoint>
1922
sshfs xilinx@192.168.2.99:/home/xilinx <mountpoint>
2023
```
2124

@@ -31,7 +34,7 @@ From there, clone the VTA repository:
3134
git clone git@github.com:uwsaml/vta.git --recursive
3235
```
3336

34-
Now, ssh into your **Pynq board** to build the TVM runtime with the following commands:
37+
Now, ssh into your **Pynq board** to build the TVM runtime with the following commands. This build should take about 5 minutes.
3538
```bash
3639
ssh xilinx@192.168.2.99 # ssh if you haven't done so
3740
cd ~/vta/nnvm/tvm
@@ -40,21 +43,18 @@ echo USE_RPC=1 >> config.mk
4043
make runtime -j2
4144
```
4245

43-
## Pynq RPC server setup
44-
45-
We're now ready to build the Pynq RPC server on the Pynq board.
46+
We're now ready to build the Pynq RPC server on the Pynq board, which should take less than 30 seconds.
4647
```bash
4748
ssh xilinx@192.168.2.99 # ssh if you haven't done so
4849
cd ~/vta
49-
make
50+
make -j2
5051
```
5152

52-
The last stage will build the `192.168.2.99:home/xilinx/vta/lib/libvta.so` library file. We are now ready to launch the RPC server on the Pynq. In order to enable the FPGA drivers, we need to run the RPC server with administrator privileges (using `su`, account: `xilinx`, pwd: `xilinx`).
53+
The last stage will build the `vta/lib/libvta.so` library file. We are now ready to launch the RPC server on the Pynq. In order to enable the FPGA drivers, we need to run the RPC server with `sudo` privileges.
5354
```bash
5455
ssh xilinx@192.168.2.99 # ssh if you haven't done so
5556
cd ~/vta
56-
su
57-
./apps/pynq_rpc/start_rpc_server.sh
57+
sudo ./apps/pynq_rpc/start_rpc_server.sh # pw is xilinx
5858
```
5959

6060
You should see the following being displayed when starting the RPC server:
@@ -65,4 +65,4 @@ INFO:root:RPCServer: bind to 0.0.0.0:9091
6565

6666
Note that it should be listening on port `9091`.
6767

68-
To kill the RPC server, just enter the `Ctrl + c` command.
68+
To kill the RPC server, just enter the `Ctrl + c` command.

vta/examples/resnet18/pynq/README.md

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
In order to run this example you'll need to have:
44
* VTA installed
5+
* LLVM 4.0 or newer installed
56
* TVM installed
67
* NNVM installed
78
* MxNet installed
89
* A Pynq-based RPC server running
10+
* Python packages installed
11+
12+
Required setup time from scratch: ~15 mins.
913

1014
## VTA installation
1115

@@ -19,6 +23,23 @@ Update your `~/.bashrc` file to include the VTA python libraries in your `PYTHON
1923
export PYTHONPATH=<vta root>/python:${PYTHONPATH}
2024
```
2125

26+
## LLVM installation
27+
28+
We provide the set of commands to install LLVM 6.0 (stable branch) on Ubuntu Xenial. Note that the [LLVM installation process](apt.llvm.org) can be adapted to different LLVM branches, and operating systems/distros.
29+
30+
```bash
31+
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
32+
sudo apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-6.0 main”
33+
sudo apt-get update
34+
apt-get install clang-6.0 lldb-6.0 lld-6.0
35+
```
36+
37+
To ensure that LLVM 6.0 was properly installed, check that the following command gives the path to your `llvm-config` binary.
38+
39+
```bash
40+
which llvm-config-6.0
41+
```
42+
2243
## TVM installation
2344
2445
Clone the TVM repository in the directory of your choosing:
@@ -29,6 +50,7 @@ git clone git@github.com:dmlc/tvm.git --recursive
2950
TVM is rapidly changing, and to ensure stability, we keep track of working TVM checkpoints.
3051
As of now, the TVM checkpoint `168f099155106d1188dbc54ac00acc02900a3c6f` is known to work with VTA.
3152
```bash
53+
cd <tvm root>
3254
git checkout 168f099155106d1188dbc54ac00acc02900a3c6f
3355
```
3456
@@ -39,13 +61,13 @@ cp make/config.mk .
3961
```
4062
4163
In the 'config.mk' file sure that:
42-
* `LLVM_CONFIG` points to the llvm-config executable (e.g. `LLVM_CONFIG = /usr/bin/llvm-config-4.0`). You'll need to have llvm4.0 installed or later.
64+
* `LLVM_CONFIG` points to the `llvm-config` executable which path was derived in the TVM installation instructions above (e.g. `LLVM_CONFIG = /usr/bin/llvm-config-6.0`)
4365
* `USE_RPC` should be set to 1
4466
45-
Launch the compilation, this takes about 5 minutes.
67+
Launch the compilation, this takes about 5-10 minutes on two threads.
4668
```bash
4769
cd <tvm root>
48-
make -j4
70+
make -j2
4971
```
5072
5173
Finally update your `~/.bashrc` file to include the TVM python libraries in your `PYTHONPATH` (don't forget to source the newly modified `.bashrc` file!):
@@ -60,16 +82,16 @@ Clone the NNVM repository from `tqchen` in the directory of your choosing:
6082
git clone git@github.com:tqchen/nnvm.git --recursive
6183
```
6284
63-
To run this example, we rely on a special branch of NNVM until these changes get merged back into the main repo: `qt`:
85+
To run this example, we rely on a special branch of NNVM `qt`:
6486
```bash
6587
cd <nnvm root>
6688
git checkout qt
6789
```
6890
69-
Launch the compilation, this takes less a minute.
91+
Launch the compilation, this takes about a minute on two threads.
7092
```bash
7193
cd <nnvm root>
72-
make -j4
94+
make -j2
7395
```
7496
7597
Finally update your `~/.bashrc` file to include the NNVM python libraries in your `PYTHONPATH` (don't forget to source the newly modified `.bashrc` file!):
@@ -85,19 +107,33 @@ Follow the [MxNet Installation Instructions](https://mxnet.incubator.apache.org)
85107
86108
Follow the [Pynq RPC Server Guide](https://github.com/uwsaml/vta/tree/master/apps/pynq_rpc/README.md)
87109
110+
## Python packages
111+
112+
You'll need the following packages to be installed for the example to run properly. You can use `pip` to install those packages:
113+
* `decorator` (for TVM)
114+
* `enum34` (for NNVM)
115+
* `Pillow`
116+
* `wget`
117+
88118
## Running the example
89119
120+
Configure your environment with the following:
121+
```bash
122+
export VTA_PYNQ_RPC_HOST=192.168.2.99
123+
export VTA_PYNQ_RPC_PORT=9091
124+
```
125+
90126
Simply run the following python script:
91127
```bash
92128
python imagenet_predict.py
93129
```
94130
95131
This will run imagenet classification using the ResNet18 architecture on a VTA design that performs 8-bit integer inference, to perform classification on a cat image `cat.jpg`.
96132
97-
The script reports runtime measured on the Pynq board, and the top-1 result category:
133+
The script reports runtime measured on the Pynq board (in seconds), and the top-1 result category:
98134
```
99135
('x', (1, 3, 224, 224))
100136
Build complete...
101137
('TVM prediction top-1:', 281, 'tabby, tabby cat')
102138
t-cost=0.41906
103-
```
139+
```

vta/src/pynq/pynq_driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ extern "C" {
2828
void* cma_alloc(size_t size, int cached);
2929
void cma_free(void* buf);
3030
uint32_t cma_get_phy_addr(void* buf);
31+
#endif
3132
void xlnkFlushCache(void* buf, int size);
3233
void xlnkInvalidateCache(void* buf, int size);
33-
#endif
3434

3535
void *VTAMapRegister(uint32_t addr, size_t length);
3636
void VTAUnmapRegister(void *vta, size_t length);

vta/tests/python/pynq/test_benchmark_conv2d.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from tvm.contrib import rpc, util
99
import pandas as pd
1010

11-
host = "pynq"
12-
port = 9091
11+
host = os.environ.get("VTA_PYNQ_RPC_HOST", "pynq")
12+
port = int(os.environ.get("VTA_PYNQ_RPC_PORT", "9091"))
1313
target = "llvm -target=armv7-none-linux-gnueabihf -mattr=+neon"
1414

1515
Workload = namedtuple("Conv2DWorkload",

vta/tests/python/pynq/test_program_rpc.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
from tvm.contrib import rpc
44
from vta import get_bitstream_path, download_bitstream, program_fpga, reconfig_runtime
55

6+
host = os.environ.get("VTA_PYNQ_RPC_HOST", "pynq")
7+
port = int(os.environ.get("VTA_PYNQ_RPC_PORT", "9091"))
8+
69
def program_rpc_bitstream(path=None):
710
"""Program the FPGA on the RPC server
811
@@ -11,26 +14,15 @@ def program_rpc_bitstream(path=None):
1114
path : path to bitstream (optional)
1215
"""
1316
assert tvm.module.enabled("rpc")
14-
host = os.environ.get("VTA_PYNQ_RPC_HOST", None)
15-
if not host:
16-
raise RuntimeError(
17-
"Error: VTA_PYNQ_RPC_HOST environment variable not set.")
18-
# If a path to a bitstream is passed, make sure that it point to a valid bitstream
19-
port = os.environ.get("VTA_PYNQ_RPC_PORT", "9091")
20-
port = int(port)
2117
remote = rpc.connect(host, port)
2218
program_fpga(remote, path)
2319

2420
def reconfig_rpc_runtime():
2521
"""Reconfig the RPC server runtime
2622
"""
2723
assert tvm.module.enabled("rpc")
28-
host = os.environ.get("VTA_PYNQ_RPC_HOST", None)
29-
if host:
30-
port = os.environ.get("VTA_PYNQ_RPC_PORT", "9091")
31-
port = int(port)
32-
remote = rpc.connect(host, port)
33-
reconfig_runtime(remote)
24+
remote = rpc.connect(host, port)
25+
reconfig_runtime(remote)
3426

3527
program_rpc_bitstream()
3628
reconfig_rpc_runtime()

0 commit comments

Comments
 (0)