tmoreau89 commented on a change in pull request #5:
URL: https://github.com/apache/incubator-tvm-vta/pull/5#discussion_r418425846



##########
File path: apps/deploy/Makefile
##########
@@ -0,0 +1,71 @@
+#licensed to the Apache Software Foundation (ASF) under one

Review comment:
       `#licensed` -> `# Licensed`

##########
File path: apps/deploy/Makefile
##########
@@ -0,0 +1,71 @@
+#licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Makefile Example to deploy TVM modules.
+TVM_ROOT=$(shell cd ../../../../; pwd)
+CUR_DIR=$(shell pwd)
+DMLC_CORE=${TVM_ROOT}/3rdparty/dmlc-core
+
+TARGET := ${shell python3 ../../config/vta_config.py --target}
+
+
+VTA_LIB=vta
+ifeq (${TARGET}, sim)
+       VTA_LIB=vta_fsim
+endif
+
+#packages:

Review comment:
       cleanup commented out lines?

##########
File path: apps/deploy/Makefile
##########
@@ -0,0 +1,71 @@
+#licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Makefile Example to deploy TVM modules.
+TVM_ROOT=$(shell cd ../../../../; pwd)

Review comment:
       We can use TVM_PATH and VTA_HW_PATH env vars, see 
https://docs.tvm.ai/vta/install.html

##########
File path: apps/deploy/Makefile
##########
@@ -0,0 +1,71 @@
+#licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Makefile Example to deploy TVM modules.
+TVM_ROOT=$(shell cd ../../../../; pwd)
+CUR_DIR=$(shell pwd)
+DMLC_CORE=${TVM_ROOT}/3rdparty/dmlc-core
+
+TARGET := ${shell python3 ../../config/vta_config.py --target}
+
+
+VTA_LIB=vta
+ifeq (${TARGET}, sim)
+       VTA_LIB=vta_fsim
+endif
+
+#packages:
+#      [ -z `dpkg -l | grep libboost-all-dev` ] && sudo apt-get install 
libboost-all-dev
+
+#.PHONY: packages
+
+#p2:
+#      [ -z `dpkg -l | grep libpng-dev` ] && sudo apt-get install libpng-dev
+#.PHONY: p2
+
+PKG_CFLAGS = -std=c++11 -O0 -g -fPIC\
+                                                -I${TVM_ROOT}/include\
+                                                -I${TVM_ROOT}/vta/include\
+                                                -I${DMLC_CORE}/include\
+                                                
-I${TVM_ROOT}/3rdparty/dlpack/include\
+                                                
-I${TVM_ROOT}/3rdparty/vta-hw/include\
+                                                -I${TVM_ROOT}/\
+
+PKG_LDFLAGS = -L${TVM_ROOT}/build  -L${CUR_DIR} -ldl -pthread -l${VTA_LIB} 
-ltvm_runtime
+
+.PHONY: clean all
+
+all:./build/deploy copylib
+
+./build/deploy: ./build/deploy.o ./build/model/lib.so
+       $(CXX) $(PKG_CFLAGS) -o $@  $^ $(PKG_LDFLAGS)
+       # Build rule for all in one TVM package library

Review comment:
       Move comment up

##########
File path: apps/deploy/ReadME.md
##########
@@ -0,0 +1,123 @@
+<!--- Licensed to the Apache Software Foundation (ASF) under one -->
+<!--- or more contributor license agreements.  See the NOTICE file -->
+<!--- distributed with this work for additional information -->
+<!--- regarding copyright ownership.  The ASF licenses this file -->
+<!--- to you under the Apache License, Version 2.0 (the -->
+<!--- "License"); you may not use this file except in compliance -->
+<!--- with the License.  You may obtain a copy of the License at -->
+
+<!---   http://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!--- Unless required by applicable law or agreed to in writing, -->
+<!--- software distributed under the License is distributed on an -->
+<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
+<!--- KIND, either express or implied.  See the License for the -->
+<!--- specific language governing permissions and limitations -->
+<!--- under the License. -->
+
+
+How to Deploy TVM-VTA Modules
+=========================

Review comment:
       `==` width to match title

##########
File path: apps/deploy/ReadME.md
##########
@@ -0,0 +1,123 @@
+<!--- Licensed to the Apache Software Foundation (ASF) under one -->

Review comment:
       Change ReadME.md to README.md 

##########
File path: apps/deploy/ReadME.md
##########
@@ -0,0 +1,123 @@
+<!--- Licensed to the Apache Software Foundation (ASF) under one -->
+<!--- or more contributor license agreements.  See the NOTICE file -->
+<!--- distributed with this work for additional information -->
+<!--- regarding copyright ownership.  The ASF licenses this file -->
+<!--- to you under the Apache License, Version 2.0 (the -->
+<!--- "License"); you may not use this file except in compliance -->
+<!--- with the License.  You may obtain a copy of the License at -->
+
+<!---   http://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!--- Unless required by applicable law or agreed to in writing, -->
+<!--- software distributed under the License is distributed on an -->
+<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
+<!--- KIND, either express or implied.  See the License for the -->
+<!--- specific language governing permissions and limitations -->
+<!--- under the License. -->
+
+
+How to Deploy TVM-VTA Modules
+=========================
+This folder contains an example on how to deploy TVM-VTA modules.
+It also contains an example code to deploy with C++ and Python.
+
+1. In host machine tvm project enable vta fsim or FPGA and compile tvm 
successfully.
+
+2. In target FPGA machine, flash bitstream into FPGA, following are example on 
pynq board
+
+   Run following command, "/home/xilinx/vta.bit" is the bitstream file
+
+       ```bash
+        xilinx@pynq:~$ sudo python3

Review comment:
       it would be nice to have a simple python with a CLI that takes a file 
and downloads it. e.g. `python3 program.py --bit="/home/xilinx/vta.bit"`

##########
File path: apps/deploy/ReadME.md
##########
@@ -0,0 +1,123 @@
+<!--- Licensed to the Apache Software Foundation (ASF) under one -->
+<!--- or more contributor license agreements.  See the NOTICE file -->
+<!--- distributed with this work for additional information -->
+<!--- regarding copyright ownership.  The ASF licenses this file -->
+<!--- to you under the Apache License, Version 2.0 (the -->
+<!--- "License"); you may not use this file except in compliance -->
+<!--- with the License.  You may obtain a copy of the License at -->
+
+<!---   http://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!--- Unless required by applicable law or agreed to in writing, -->
+<!--- software distributed under the License is distributed on an -->
+<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
+<!--- KIND, either express or implied.  See the License for the -->
+<!--- specific language governing permissions and limitations -->
+<!--- under the License. -->
+
+
+How to Deploy TVM-VTA Modules
+=========================
+This folder contains an example on how to deploy TVM-VTA modules.
+It also contains an example code to deploy with C++ and Python.
+
+1. In host machine tvm project enable vta fsim or FPGA and compile tvm 
successfully.
+
+2. In target FPGA machine, flash bitstream into FPGA, following are example on 
pynq board
+
+   Run following command, "/home/xilinx/vta.bit" is the bitstream file
+
+       ```bash
+        xilinx@pynq:~$ sudo python3
+       >>> from pynq import Bitstream
+       >>> file="/home/xilinx/vta.bit"
+       >>> bt = Bitstream(file)
+       >>> bt.download()
+       ```
+
+3. Compile and Deploy with C++
+
+   3.1 Deploy with FPGA
+
+       3.1.1 in host machine change ./vta-hw/config/vta_config.json TARGET 
into FPGA type
+             for example "ultra96"
+
+       3.1.2 in host machine run resnet_export.py, this script would compile 
mxnet resnet18
+             into vta library, and compute graph, parameter and save into 
./build/model folder.
+       
+       ```bash
+       python3 ./resnet_export.py
+       ```
+
+       3.1.3 from host machine, copy './build/' folder(generate by #2) into 
target FPGA board folder 

Review comment:
       `folder(generate` -> `folder (generated`

##########
File path: apps/deploy/resnet_export.py
##########
@@ -0,0 +1,132 @@
+#licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+""" Compile And Export MXNET Resnet18 Model With VTA As Backend """
+from __future__ import absolute_import, print_function
+
+import os
+from os.path import exists
+import numpy as np
+from mxnet.gluon.model_zoo import vision
+
+import tvm
+from tvm import autotvm, relay
+from tvm.relay import op, transform
+
+import vta
+from vta.top import graph_pack
+from vta.top.graphpack import run_opt_pass
+
+# Load VTA parameters from the vta/config/vta_config.json file
+ENV = vta.get_env()
+assert ENV.target.device_name == "vta"
+# Dictionary lookup for when to start/end bit packing
+PACK_DICT = {"resnet18_v1": ["nn.max_pool2d", "nn.global_avg_pool2d", None, 
None],}
+
+# Name of Gluon model to compile
+MODEL = "resnet18_v1"
+assert MODEL in PACK_DICT
+
+def merge_transform_to_mxnet_model(mod):
+    """ Add Image Transform Logic Into Model """
+    svalue = np.array([123., 117., 104.])
+    sub_data = relay.Constant(tvm.nd.array(svalue)).astype("float32")
+    dvalue = np.array([58.395, 57.12, 57.37])
+    divide_data = relay.Constant(tvm.nd.array(dvalue)).astype("float32")
+
+    data_shape = (224, 224, 3)
+    data = relay.var("data", relay.TensorType(data_shape, "float32"))
+
+    simple_net = relay.expand_dims(data, axis=0, num_newaxis=1)
+    # to do, relay not support dynamic shape now, future need to add resize 
logic

Review comment:
       `to do` -> TODO

##########
File path: apps/deploy/ReadME.md
##########
@@ -0,0 +1,123 @@
+<!--- Licensed to the Apache Software Foundation (ASF) under one -->
+<!--- or more contributor license agreements.  See the NOTICE file -->
+<!--- distributed with this work for additional information -->
+<!--- regarding copyright ownership.  The ASF licenses this file -->
+<!--- to you under the Apache License, Version 2.0 (the -->
+<!--- "License"); you may not use this file except in compliance -->
+<!--- with the License.  You may obtain a copy of the License at -->
+
+<!---   http://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!--- Unless required by applicable law or agreed to in writing, -->
+<!--- software distributed under the License is distributed on an -->
+<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
+<!--- KIND, either express or implied.  See the License for the -->
+<!--- specific language governing permissions and limitations -->
+<!--- under the License. -->
+
+
+How to Deploy TVM-VTA Modules
+=========================
+This folder contains an example on how to deploy TVM-VTA modules.
+It also contains an example code to deploy with C++ and Python.
+
+1. In host machine tvm project enable vta fsim or FPGA and compile tvm 
successfully.
+
+2. In target FPGA machine, flash bitstream into FPGA, following are example on 
pynq board
+
+   Run following command, "/home/xilinx/vta.bit" is the bitstream file
+
+       ```bash
+        xilinx@pynq:~$ sudo python3
+       >>> from pynq import Bitstream
+       >>> file="/home/xilinx/vta.bit"
+       >>> bt = Bitstream(file)
+       >>> bt.download()
+       ```
+
+3. Compile and Deploy with C++
+
+   3.1 Deploy with FPGA
+
+       3.1.1 in host machine change ./vta-hw/config/vta_config.json TARGET 
into FPGA type
+             for example "ultra96"
+
+       3.1.2 in host machine run resnet_export.py, this script would compile 
mxnet resnet18
+             into vta library, and compute graph, parameter and save into 
./build/model folder.
+       
+       ```bash
+       python3 ./resnet_export.py
+       ```
+
+       3.1.3 from host machine, copy './build/' folder(generate by #2) into 
target FPGA board folder 
+             "tvm/3rdparty/vta-hw/apps/deploy/"
+
+       3.1.4 in target FPGA board, enable FPGA in config file and run 
following command
+
+             to build libvta.so and libtvm_runtime.so
+       ```bash
+       make runtime vta
+       ```
+
+       3.1.5 in target FPGA board goto "tvm/3rdparty/vta-hw/apps/deploy/"
+       ```bash
+       cd tvm/3rdparty/vta-hw/apps/deploy/
+       ```
+
+       3.1.6 int FPGA board Run "make" command, the script would build 
"lib.so" and cop libtvm_runtime.so
+             and "libvta*.so" into "./build" folder and compile execute file 
"./deploy"
+      ```bash
+      make
+      ```
+  
+      3.1.7. in FPGA board use following command to convert a image into 
correct image size that match 

Review comment:
       an image into the size that matches mxnet resnet18 requirements.

##########
File path: apps/deploy/ReadME.md
##########
@@ -0,0 +1,123 @@
+<!--- Licensed to the Apache Software Foundation (ASF) under one -->
+<!--- or more contributor license agreements.  See the NOTICE file -->
+<!--- distributed with this work for additional information -->
+<!--- regarding copyright ownership.  The ASF licenses this file -->
+<!--- to you under the Apache License, Version 2.0 (the -->
+<!--- "License"); you may not use this file except in compliance -->
+<!--- with the License.  You may obtain a copy of the License at -->
+
+<!---   http://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!--- Unless required by applicable law or agreed to in writing, -->
+<!--- software distributed under the License is distributed on an -->
+<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
+<!--- KIND, either express or implied.  See the License for the -->
+<!--- specific language governing permissions and limitations -->
+<!--- under the License. -->
+
+
+How to Deploy TVM-VTA Modules
+=========================
+This folder contains an example on how to deploy TVM-VTA modules.
+It also contains an example code to deploy with C++ and Python.
+
+1. In host machine tvm project enable vta fsim or FPGA and compile tvm 
successfully.
+
+2. In target FPGA machine, flash bitstream into FPGA, following are example on 
pynq board
+
+   Run following command, "/home/xilinx/vta.bit" is the bitstream file
+
+       ```bash
+        xilinx@pynq:~$ sudo python3
+       >>> from pynq import Bitstream
+       >>> file="/home/xilinx/vta.bit"
+       >>> bt = Bitstream(file)
+       >>> bt.download()
+       ```
+
+3. Compile and Deploy with C++
+
+   3.1 Deploy with FPGA
+
+       3.1.1 in host machine change ./vta-hw/config/vta_config.json TARGET 
into FPGA type
+             for example "ultra96"
+
+       3.1.2 in host machine run resnet_export.py, this script would compile 
mxnet resnet18
+             into vta library, and compute graph, parameter and save into 
./build/model folder.
+       
+       ```bash
+       python3 ./resnet_export.py
+       ```
+
+       3.1.3 from host machine, copy './build/' folder(generate by #2) into 
target FPGA board folder 
+             "tvm/3rdparty/vta-hw/apps/deploy/"
+
+       3.1.4 in target FPGA board, enable FPGA in config file and run 
following command
+
+             to build libvta.so and libtvm_runtime.so
+       ```bash
+       make runtime vta
+       ```
+
+       3.1.5 in target FPGA board goto "tvm/3rdparty/vta-hw/apps/deploy/"
+       ```bash
+       cd tvm/3rdparty/vta-hw/apps/deploy/
+       ```
+
+       3.1.6 int FPGA board Run "make" command, the script would build 
"lib.so" and cop libtvm_runtime.so

Review comment:
       `int FPGA board Run` -> `On the FPGA board run`

##########
File path: apps/deploy/ReadME.md
##########
@@ -0,0 +1,123 @@
+<!--- Licensed to the Apache Software Foundation (ASF) under one -->
+<!--- or more contributor license agreements.  See the NOTICE file -->
+<!--- distributed with this work for additional information -->
+<!--- regarding copyright ownership.  The ASF licenses this file -->
+<!--- to you under the Apache License, Version 2.0 (the -->
+<!--- "License"); you may not use this file except in compliance -->
+<!--- with the License.  You may obtain a copy of the License at -->
+
+<!---   http://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!--- Unless required by applicable law or agreed to in writing, -->
+<!--- software distributed under the License is distributed on an -->
+<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
+<!--- KIND, either express or implied.  See the License for the -->
+<!--- specific language governing permissions and limitations -->
+<!--- under the License. -->
+
+
+How to Deploy TVM-VTA Modules
+=========================
+This folder contains an example on how to deploy TVM-VTA modules.
+It also contains an example code to deploy with C++ and Python.
+
+1. In host machine tvm project enable vta fsim or FPGA and compile tvm 
successfully.
+
+2. In target FPGA machine, flash bitstream into FPGA, following are example on 
pynq board
+
+   Run following command, "/home/xilinx/vta.bit" is the bitstream file
+
+       ```bash
+        xilinx@pynq:~$ sudo python3
+       >>> from pynq import Bitstream
+       >>> file="/home/xilinx/vta.bit"
+       >>> bt = Bitstream(file)
+       >>> bt.download()
+       ```
+
+3. Compile and Deploy with C++
+
+   3.1 Deploy with FPGA
+
+       3.1.1 in host machine change ./vta-hw/config/vta_config.json TARGET 
into FPGA type

Review comment:
       Can we capitalize all sentences `in host` -> `In host`; and do the same 
for all paragraphs below

##########
File path: apps/deploy/ReadME.md
##########
@@ -0,0 +1,123 @@
+<!--- Licensed to the Apache Software Foundation (ASF) under one -->
+<!--- or more contributor license agreements.  See the NOTICE file -->
+<!--- distributed with this work for additional information -->
+<!--- regarding copyright ownership.  The ASF licenses this file -->
+<!--- to you under the Apache License, Version 2.0 (the -->
+<!--- "License"); you may not use this file except in compliance -->
+<!--- with the License.  You may obtain a copy of the License at -->
+
+<!---   http://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!--- Unless required by applicable law or agreed to in writing, -->
+<!--- software distributed under the License is distributed on an -->
+<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
+<!--- KIND, either express or implied.  See the License for the -->
+<!--- specific language governing permissions and limitations -->
+<!--- under the License. -->
+
+
+How to Deploy TVM-VTA Modules
+=========================
+This folder contains an example on how to deploy TVM-VTA modules.
+It also contains an example code to deploy with C++ and Python.
+
+1. In host machine tvm project enable vta fsim or FPGA and compile tvm 
successfully.
+
+2. In target FPGA machine, flash bitstream into FPGA, following are example on 
pynq board
+
+   Run following command, "/home/xilinx/vta.bit" is the bitstream file
+
+       ```bash
+        xilinx@pynq:~$ sudo python3
+       >>> from pynq import Bitstream
+       >>> file="/home/xilinx/vta.bit"
+       >>> bt = Bitstream(file)
+       >>> bt.download()
+       ```
+
+3. Compile and Deploy with C++
+
+   3.1 Deploy with FPGA
+
+       3.1.1 in host machine change ./vta-hw/config/vta_config.json TARGET 
into FPGA type
+             for example "ultra96"
+
+       3.1.2 in host machine run resnet_export.py, this script would compile 
mxnet resnet18
+             into vta library, and compute graph, parameter and save into 
./build/model folder.
+       
+       ```bash
+       python3 ./resnet_export.py
+       ```
+
+       3.1.3 from host machine, copy './build/' folder(generate by #2) into 
target FPGA board folder 
+             "tvm/3rdparty/vta-hw/apps/deploy/"
+
+       3.1.4 in target FPGA board, enable FPGA in config file and run 
following command
+
+             to build libvta.so and libtvm_runtime.so
+       ```bash
+       make runtime vta
+       ```
+
+       3.1.5 in target FPGA board goto "tvm/3rdparty/vta-hw/apps/deploy/"
+       ```bash
+       cd tvm/3rdparty/vta-hw/apps/deploy/
+       ```
+
+       3.1.6 int FPGA board Run "make" command, the script would build 
"lib.so" and cop libtvm_runtime.so
+             and "libvta*.so" into "./build" folder and compile execute file 
"./deploy"
+      ```bash
+      make
+      ```
+  
+      3.1.7. in FPGA board use following command to convert a image into 
correct image size that match 
+             mxnet resnet18 requirement.
+      ```bash
+      ./img_data_help.py <image path>
+      ```
+      the said command would output a file name 'img_data'
+
+      3.1.8. in FPGA board run following command to get the image type
+      ```bash
+      ./deploy img_data
+      ```
+
+   3.2 Deploy with vta simulator(all steps happen in host machine)
+
+       3.2.1 change ./vta-hw/config/vta_config.json TARGET into "sim"
+
+       3.2.2 run resnet_export.py, this script would compile mxnet resnet18 
into vta library, 
+            and compute graph, parameter and save into ./build/model folder.
+
+       ```bash
+       python3 ./resnet_export.py
+       ```
+       
+       3.2.3 Run "make" command, the script would build "lib.so" and copy 
libtvm_runtime.so
+             and libvta*.so into ./build folder and compile execute file 
./deploy
+       ```bash
+       make
+       ```
+
+4. python deploy
+
+      4.1 Deploy with FPGA.
+
+          4.1.1 From host machine Copy "./vta-hw/apps/deploy/build" folder 
into 

Review comment:
       `copy` instead of `Copy`

##########
File path: apps/deploy/ReadME.md
##########
@@ -0,0 +1,123 @@
+<!--- Licensed to the Apache Software Foundation (ASF) under one -->
+<!--- or more contributor license agreements.  See the NOTICE file -->
+<!--- distributed with this work for additional information -->
+<!--- regarding copyright ownership.  The ASF licenses this file -->
+<!--- to you under the Apache License, Version 2.0 (the -->
+<!--- "License"); you may not use this file except in compliance -->
+<!--- with the License.  You may obtain a copy of the License at -->
+
+<!---   http://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!--- Unless required by applicable law or agreed to in writing, -->
+<!--- software distributed under the License is distributed on an -->
+<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
+<!--- KIND, either express or implied.  See the License for the -->
+<!--- specific language governing permissions and limitations -->
+<!--- under the License. -->
+
+
+How to Deploy TVM-VTA Modules
+=========================
+This folder contains an example on how to deploy TVM-VTA modules.
+It also contains an example code to deploy with C++ and Python.
+
+1. In host machine tvm project enable vta fsim or FPGA and compile tvm 
successfully.
+
+2. In target FPGA machine, flash bitstream into FPGA, following are example on 
pynq board
+
+   Run following command, "/home/xilinx/vta.bit" is the bitstream file
+
+       ```bash
+        xilinx@pynq:~$ sudo python3
+       >>> from pynq import Bitstream
+       >>> file="/home/xilinx/vta.bit"
+       >>> bt = Bitstream(file)
+       >>> bt.download()
+       ```
+
+3. Compile and Deploy with C++
+
+   3.1 Deploy with FPGA
+
+       3.1.1 in host machine change ./vta-hw/config/vta_config.json TARGET 
into FPGA type
+             for example "ultra96"
+
+       3.1.2 in host machine run resnet_export.py, this script would compile 
mxnet resnet18
+             into vta library, and compute graph, parameter and save into 
./build/model folder.
+       
+       ```bash
+       python3 ./resnet_export.py
+       ```
+
+       3.1.3 from host machine, copy './build/' folder(generate by #2) into 
target FPGA board folder 
+             "tvm/3rdparty/vta-hw/apps/deploy/"
+
+       3.1.4 in target FPGA board, enable FPGA in config file and run 
following command
+
+             to build libvta.so and libtvm_runtime.so
+       ```bash
+       make runtime vta
+       ```
+
+       3.1.5 in target FPGA board goto "tvm/3rdparty/vta-hw/apps/deploy/"
+       ```bash
+       cd tvm/3rdparty/vta-hw/apps/deploy/
+       ```
+
+       3.1.6 int FPGA board Run "make" command, the script would build 
"lib.so" and cop libtvm_runtime.so
+             and "libvta*.so" into "./build" folder and compile execute file 
"./deploy"
+      ```bash
+      make
+      ```
+  
+      3.1.7. in FPGA board use following command to convert a image into 
correct image size that match 
+             mxnet resnet18 requirement.
+      ```bash
+      ./img_data_help.py <image path>
+      ```
+      the said command would output a file name 'img_data'
+
+      3.1.8. in FPGA board run following command to get the image type
+      ```bash
+      ./deploy img_data
+      ```
+
+   3.2 Deploy with vta simulator(all steps happen in host machine)
+
+       3.2.1 change ./vta-hw/config/vta_config.json TARGET into "sim"
+
+       3.2.2 run resnet_export.py, this script would compile mxnet resnet18 
into vta library, 
+            and compute graph, parameter and save into ./build/model folder.
+
+       ```bash
+       python3 ./resnet_export.py
+       ```
+       
+       3.2.3 Run "make" command, the script would build "lib.so" and copy 
libtvm_runtime.so
+             and libvta*.so into ./build folder and compile execute file 
./deploy
+       ```bash
+       make
+       ```
+
+4. python deploy

Review comment:
       Capitalize title. Deploy with Python?

##########
File path: apps/deploy/cpp_deploy.cc
##########
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include <cstdio>
+#include <dlpack/dlpack.h>
+#include <tvm/runtime/module.h>
+#include <tvm/runtime/registry.h>
+#include <tvm/runtime/packed_func.h>
+#include <fstream>
+#include <iterator>
+#include <algorithm>
+#include <vta/runtime/runtime.h>
+void graph_test(std::string img,
+                std::string model_path,
+                std::string lib,
+                std::string graph,
+                std::string params) {
+  tvm::runtime::Module mod_dylib =
+        tvm::runtime::Module::LoadFromFile((model_path+lib).c_str()) ;
+  std::ifstream json_in((model_path + graph).c_str());
+  if(json_in.fail())
+  {
+    throw std::runtime_error("could not open json file");
+  }
+
+  std::ifstream params_in((model_path + params).c_str(), std::ios::binary);
+  if(params_in.fail())
+  {
+    throw std::runtime_error("could not open json file");
+  }
+
+  const std::string json_data((std::istreambuf_iterator<char>(json_in)),
+                               std::istreambuf_iterator<char>());
+  json_in.close();
+  const std::string params_data((std::istreambuf_iterator<char>(params_in)),
+                                 std::istreambuf_iterator<char>());
+  params_in.close();
+
+  TVMByteArray params_arr;
+  params_arr.data = params_data.c_str();
+  params_arr.size = params_data.length();
+
+  int dtype_code = kDLFloat;
+  int dtype_bits = 32;
+  int dtype_lanes = 1;
+  int device_type = kDLExtDev;
+  int device_id = 0;
+
+  // get global function module for graph runtime
+  tvm::runtime::Module mod = 
+    (*tvm::runtime::Registry::Get("tvm.graph_runtime.create"))(json_data,
+                                                                mod_dylib,
+                                                                device_type,
+                                                                device_id);
+  DLTensor* x;
+  tvm::runtime::PackedFunc get_input = mod.GetFunction("get_input");
+  x = get_input(0);
+  VTACommandHandle cmd;
+  char * vta_ptr = (char *)VTABufferCPUPtr(cmd, static_cast<void*>(x->data));
+
+  int in_ndim = 4;
+  int64_t in_shape[4] = {1, 3, 224, 224};
+  // load image data saved in binary
+  std::ifstream data_fin(img.c_str(), std::ios::binary);
+  data_fin.read(static_cast<char*>(vta_ptr), 3 * 224 * 224 * 4);
+  // get the function from the module(load patameters)

Review comment:
       parameters

##########
File path: apps/deploy/ReadME.md
##########
@@ -0,0 +1,123 @@
+<!--- Licensed to the Apache Software Foundation (ASF) under one -->
+<!--- or more contributor license agreements.  See the NOTICE file -->
+<!--- distributed with this work for additional information -->
+<!--- regarding copyright ownership.  The ASF licenses this file -->
+<!--- to you under the Apache License, Version 2.0 (the -->
+<!--- "License"); you may not use this file except in compliance -->
+<!--- with the License.  You may obtain a copy of the License at -->
+
+<!---   http://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!--- Unless required by applicable law or agreed to in writing, -->
+<!--- software distributed under the License is distributed on an -->
+<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
+<!--- KIND, either express or implied.  See the License for the -->
+<!--- specific language governing permissions and limitations -->
+<!--- under the License. -->
+
+
+How to Deploy TVM-VTA Modules
+=========================
+This folder contains an example on how to deploy TVM-VTA modules.
+It also contains an example code to deploy with C++ and Python.
+
+1. In host machine tvm project enable vta fsim or FPGA and compile tvm 
successfully.
+
+2. In target FPGA machine, flash bitstream into FPGA, following are example on 
pynq board
+
+   Run following command, "/home/xilinx/vta.bit" is the bitstream file
+
+       ```bash
+        xilinx@pynq:~$ sudo python3
+       >>> from pynq import Bitstream
+       >>> file="/home/xilinx/vta.bit"
+       >>> bt = Bitstream(file)
+       >>> bt.download()
+       ```
+
+3. Compile and Deploy with C++
+
+   3.1 Deploy with FPGA
+
+       3.1.1 in host machine change ./vta-hw/config/vta_config.json TARGET 
into FPGA type
+             for example "ultra96"
+
+       3.1.2 in host machine run resnet_export.py, this script would compile 
mxnet resnet18
+             into vta library, and compute graph, parameter and save into 
./build/model folder.
+       
+       ```bash
+       python3 ./resnet_export.py
+       ```
+
+       3.1.3 from host machine, copy './build/' folder(generate by #2) into 
target FPGA board folder 
+             "tvm/3rdparty/vta-hw/apps/deploy/"
+
+       3.1.4 in target FPGA board, enable FPGA in config file and run 
following command
+
+             to build libvta.so and libtvm_runtime.so
+       ```bash
+       make runtime vta
+       ```
+
+       3.1.5 in target FPGA board goto "tvm/3rdparty/vta-hw/apps/deploy/"
+       ```bash
+       cd tvm/3rdparty/vta-hw/apps/deploy/
+       ```
+
+       3.1.6 int FPGA board Run "make" command, the script would build 
"lib.so" and cop libtvm_runtime.so
+             and "libvta*.so" into "./build" folder and compile execute file 
"./deploy"
+      ```bash
+      make
+      ```
+  
+      3.1.7. in FPGA board use following command to convert a image into 
correct image size that match 
+             mxnet resnet18 requirement.
+      ```bash
+      ./img_data_help.py <image path>
+      ```
+      the said command would output a file name 'img_data'
+
+      3.1.8. in FPGA board run following command to get the image type
+      ```bash
+      ./deploy img_data
+      ```
+
+   3.2 Deploy with vta simulator(all steps happen in host machine)

Review comment:
       space before bracket `(`

##########
File path: apps/deploy/ReadME.md
##########
@@ -0,0 +1,123 @@
+<!--- Licensed to the Apache Software Foundation (ASF) under one -->
+<!--- or more contributor license agreements.  See the NOTICE file -->
+<!--- distributed with this work for additional information -->
+<!--- regarding copyright ownership.  The ASF licenses this file -->
+<!--- to you under the Apache License, Version 2.0 (the -->
+<!--- "License"); you may not use this file except in compliance -->
+<!--- with the License.  You may obtain a copy of the License at -->
+
+<!---   http://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!--- Unless required by applicable law or agreed to in writing, -->
+<!--- software distributed under the License is distributed on an -->
+<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
+<!--- KIND, either express or implied.  See the License for the -->
+<!--- specific language governing permissions and limitations -->
+<!--- under the License. -->
+
+
+How to Deploy TVM-VTA Modules
+=========================
+This folder contains an example on how to deploy TVM-VTA modules.
+It also contains an example code to deploy with C++ and Python.
+
+1. In host machine tvm project enable vta fsim or FPGA and compile tvm 
successfully.
+
+2. In target FPGA machine, flash bitstream into FPGA, following are example on 
pynq board
+
+   Run following command, "/home/xilinx/vta.bit" is the bitstream file
+
+       ```bash
+        xilinx@pynq:~$ sudo python3
+       >>> from pynq import Bitstream
+       >>> file="/home/xilinx/vta.bit"
+       >>> bt = Bitstream(file)
+       >>> bt.download()
+       ```
+
+3. Compile and Deploy with C++
+
+   3.1 Deploy with FPGA
+
+       3.1.1 in host machine change ./vta-hw/config/vta_config.json TARGET 
into FPGA type
+             for example "ultra96"
+
+       3.1.2 in host machine run resnet_export.py, this script would compile 
mxnet resnet18
+             into vta library, and compute graph, parameter and save into 
./build/model folder.
+       
+       ```bash
+       python3 ./resnet_export.py
+       ```
+
+       3.1.3 from host machine, copy './build/' folder(generate by #2) into 
target FPGA board folder 
+             "tvm/3rdparty/vta-hw/apps/deploy/"
+
+       3.1.4 in target FPGA board, enable FPGA in config file and run 
following command
+
+             to build libvta.so and libtvm_runtime.so
+       ```bash
+       make runtime vta
+       ```
+
+       3.1.5 in target FPGA board goto "tvm/3rdparty/vta-hw/apps/deploy/"
+       ```bash
+       cd tvm/3rdparty/vta-hw/apps/deploy/
+       ```
+
+       3.1.6 int FPGA board Run "make" command, the script would build 
"lib.so" and cop libtvm_runtime.so
+             and "libvta*.so" into "./build" folder and compile execute file 
"./deploy"
+      ```bash
+      make
+      ```
+  
+      3.1.7. in FPGA board use following command to convert a image into 
correct image size that match 
+             mxnet resnet18 requirement.
+      ```bash
+      ./img_data_help.py <image path>
+      ```
+      the said command would output a file name 'img_data'

Review comment:
       the command outputs a file named ...

##########
File path: apps/deploy/cpp_deploy.cc
##########
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include <cstdio>
+#include <dlpack/dlpack.h>
+#include <tvm/runtime/module.h>
+#include <tvm/runtime/registry.h>
+#include <tvm/runtime/packed_func.h>
+#include <fstream>
+#include <iterator>
+#include <algorithm>
+#include <vta/runtime/runtime.h>
+void graph_test(std::string img,

Review comment:
       add two spaces here. when in doubt run source code through C linter

##########
File path: apps/deploy/run_python_deploy.sh
##########
@@ -0,0 +1,22 @@
+#!/bin/bash
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+PROJROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../../../../" && pwd )"

Review comment:
       again here we can use the env variables from 
https://docs.tvm.ai/vta/install.html#vta-simulator-installation




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to