Skip to content

Commit b86add3

Browse files
committed
Merge branch 'pers-upstream' of https://github.com/dchauhan-arm/tvm into pers-upstream
2 parents 6706248 + 203cfd2 commit b86add3

File tree

89 files changed

+3085
-1030
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+3085
-1030
lines changed

.asf.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ github:
4646
# cycle. PMC may review and recycle slots when necessary.
4747
collaborators:
4848
- denise-k
49+
- tvm-bot # For automated feedback in PR review.

apps/cpp_rpc/rpc_server.cc

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,24 +86,33 @@ static std::string getNextString(std::stringstream* iss) {
8686

8787
/*!
8888
* \brief RPCServer RPC Server class.
89+
*
8990
* \param host The hostname of the server, Default=0.0.0.0
90-
* \param port The port of the RPC, Default=9090
91-
* \param port_end The end search port of the RPC, Default=9099
92-
* \param tracker The address of RPC tracker in host:port format e.g. 10.77.1.234:9190 Default=""
93-
* \param key The key used to identify the device type in tracker. Default=""
94-
* \param custom_addr Custom IP Address to Report to RPC Tracker. Default=""
91+
*
92+
* \param port_search_start The low end of the search range for an
93+
* available port for the RPC, Default=9090
94+
*
95+
* \param port_search_end The high search the search range for an
96+
* available port for the RPC, Default=9099
97+
*
98+
* \param tracker The address of RPC tracker in host:port format
99+
* (e.g. "10.77.1.234:9190")
100+
*
101+
* \param key The key used to identify the device type in tracker.
102+
*
103+
* \param custom_addr Custom IP Address to Report to RPC Tracker.
95104
*/
96105
class RPCServer {
97106
public:
98107
/*!
99108
* \brief Constructor.
100109
*/
101-
RPCServer(std::string host, int port, int port_end, std::string tracker_addr, std::string key,
102-
std::string custom_addr, std::string work_dir)
110+
RPCServer(std::string host, int port_search_start, int port_search_end, std::string tracker_addr,
111+
std::string key, std::string custom_addr, std::string work_dir)
103112
: host_(std::move(host)),
104-
port_(port),
113+
port_search_start_(port_search_start),
105114
my_port_(0),
106-
port_end_(port_end),
115+
port_search_end_(port_search_end),
107116
tracker_addr_(std::move(tracker_addr)),
108117
key_(std::move(key)),
109118
custom_addr_(std::move(custom_addr)),
@@ -126,7 +135,7 @@ class RPCServer {
126135
*/
127136
void Start() {
128137
listen_sock_.Create();
129-
my_port_ = listen_sock_.TryBindHost(host_, port_, port_end_);
138+
my_port_ = listen_sock_.TryBindHost(host_, port_search_start_, port_search_end_);
130139
LOG(INFO) << "bind to " << host_ << ":" << my_port_;
131140
listen_sock_.Listen(1);
132141
std::future<void> proc(std::async(std::launch::async, &RPCServer::ListenLoopProc, this));
@@ -140,7 +149,7 @@ class RPCServer {
140149
* \brief ListenLoopProc The listen process.
141150
*/
142151
void ListenLoopProc() {
143-
TrackerClient tracker(tracker_addr_, key_, custom_addr_, port_);
152+
TrackerClient tracker(tracker_addr_, key_, custom_addr_, my_port_);
144153
while (true) {
145154
support::TCPSocket conn;
146155
support::SockAddr addr("0.0.0.0", 0);
@@ -340,9 +349,9 @@ class RPCServer {
340349
}
341350

342351
std::string host_;
343-
int port_;
352+
int port_search_start_;
344353
int my_port_;
345-
int port_end_;
354+
int port_search_end_;
346355
std::string tracker_addr_;
347356
std::string key_;
348357
std::string custom_addr_;

cmake/config.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ set(USE_ETHOSN_HW OFF)
231231
# Whether to build with Arm(R) Ethos(TM)-U NPU codegen support
232232
set(USE_ETHOSU OFF)
233233

234+
# Whether to build with CMSIS-NN external library support.
235+
# See https://github.com/ARM-software/CMSIS_5
236+
set(USE_CMSISNN OFF)
237+
234238
# Whether to build with TensorRT codegen or runtime
235239
# Examples are available here: docs/deploy/tensorrt.rst.
236240
#

docker/install/ubuntu_install_vela.sh

100644100755
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,4 @@ set -e
2020
set -u
2121
set -o pipefail
2222

23-
# In a refactor between v2.1.1 and v3.0.0, find_block_configs <appropriate function name> was removed from Vela.
24-
# Since this is still required for the TVM port, it will be reinstated in Vela in a future release.
25-
# Until then, it needs to be pinned to v2.1.1.
26-
pip3 install ethos-u-vela==2.1.1
23+
pip3 install ethos-u-vela==3.2.0

docs/arch/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,4 +423,5 @@ microTVM
423423
:maxdepth: 1
424424

425425
microtvm_design
426+
microtvm_project_api
426427
model_library_format

docs/arch/microtvm_project_api.rst

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
.. Licensed to the Apache Software Foundation (ASF) under one
2+
or more contributor license agreements. See the NOTICE file
3+
distributed with this work for additional information
4+
regarding copyright ownership. The ASF licenses this file
5+
to you under the Apache License, Version 2.0 (the
6+
"License"); you may not use this file except in compliance
7+
with the License. You may obtain a copy of the License at
8+
9+
.. http://www.apache.org/licenses/LICENSE-2.0
10+
11+
.. Unless required by applicable law or agreed to in writing,
12+
software distributed under the License is distributed on an
13+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
KIND, either express or implied. See the License for the
15+
specific language governing permissions and limitations
16+
under the License.
17+
18+
.. _microtvm_project_api:
19+
20+
microTVM Project API
21+
====================
22+
23+
About microTVM Project API
24+
--------------------------
25+
26+
The microTVM Project API allows TVM to automatically run models on
27+
unconventional or embedded platforms. It allows platforms to define a standard
28+
function to integrate TVM compiler output with boilerplate platform-specific
29+
code, producing a runnable **Project**. Project API then further defines
30+
functions to build that project, program compatible devices accessible from the
31+
TVM machine, and communicate with the running code so that TVM can perform
32+
host-driven inference and autotuning.
33+
34+
There are many cases where it might be desirable simply to invoke microTVM as a
35+
tool from your platform's build process. Indeed, for the average firmware
36+
developer, this is likely to be all they need. However, there are a couple of
37+
use cases when you may want to teach microTVM how to build firmware using your
38+
platform's build tool:
39+
40+
1. To enable AutoTVM and AutoScheduling on your platform. Defining a Project
41+
API implementation allows TVM to tune models for peak performance on your
42+
platform.
43+
2. To enable engineers without firmware expertise to experiment with models on
44+
your platform. Defining a Project API implementation allows these engineers
45+
to leverage the standard TVM Python workflows to perform host-driven
46+
inference on your platform.
47+
3. Integration Testing. Defining a Project API implementation allows you to
48+
create Continuous Integration Tests which verify model correctness and
49+
performance on your platform.
50+
51+
API Definition
52+
--------------
53+
54+
The full API is the ``abstractmethod`` defined on ``ProjectAPIHandler`` in
55+
`python/tvm/micro/project_api/server.py <https://github.com/apache/tvm/blob/main/python/tvm/micro/project_api/server.py>`_.
56+
Rather than duplicate the documentation here, we simply refer you to that class.
57+
58+
How TVM uses Project API
59+
------------------------
60+
61+
This section explains how the Project API should be used with TVM. Project API
62+
is defined around the *Project* as the buildable unit of firmware. TVM expects
63+
to be provided initially with a directory containing a *Template Project*, which
64+
together with a :ref:`Model Library Format <model_library_format>` file can be
65+
built into a runnable project.
66+
67+
Inside the Template Directory is (typically) a Python script implementing the
68+
API server. TVM launches this script in a subprocess and sends commands to the
69+
server to perform each of the actions outlined above.
70+
71+
The typical usage flow is as follows:
72+
73+
1. Launch Project API server in Template Project.
74+
2. Verify the API server is version-compatible with TVM, plus read properties
75+
of the implementation, by sending ``server_info_query`` command.
76+
3. Generate a new project by sending command ``generate_project`` to create a
77+
new project. The arguments to this command is a Model Library Format and a
78+
non-existent directory which should be populated with the generated
79+
project. The Template Project API server should copy itself into the
80+
newly-generated project.
81+
4. Terminate the Template Project API server.
82+
5. Launch Project API server in Generated Project.
83+
6. Verify the API server is version-compatible with TVM, plus read properties
84+
of the implementation, by sending ``server_info_query`` command.
85+
7. Build and flash the projec by sending commands ``build`` and ``flash`` to the
86+
API server.
87+
8. Communicate with the target. Send command ``open_transport`` followed by
88+
commands ``write_transport`` and ``read_transport`` to write and read from
89+
e.g. a serial port attached to the target. Upon completion,
90+
``close_transport`` is sent.
91+
9. Terminate Project API server.
92+
93+
Disk Layout of the Project
94+
--------------------------
95+
96+
In the root directory of a project (template or generated), one of the following
97+
two files must exist:
98+
99+
- ``microtvm_api_server.py`` - the suggested approach. Place a
100+
python3-compatible Python script in the root directory. TVM will execute this
101+
script in its own process using the same interpreter used to execute TVM.
102+
- ``microtvm_api_server.sh`` (on Windows, ``microtvm_api_server.bat``) -
103+
alternate approach. When a different Python interpreter is necessary, or
104+
when you want to implement the server in a different language, create this
105+
executable file. TVM will launch this file in a separate process.
106+
107+
Aside from these two files, no other restrictions are made on the layout.
108+
109+
Communication between TVM and Project API Server
110+
------------------------------------------------
111+
112+
TVM communicates with the Project API server using `JSON-RPC 2.0
113+
<https://www.jsonrpc.org/specification>`_. TVM always launches API servers using
114+
the following command-line:
115+
116+
``microtvm_api_server.py --read-fd <n> --write-fd <n>``
117+
118+
Commands are sent from TVM to the server over the file descriptor given by
119+
``--read-fd`` and replies are received by TVM from the server over the file
120+
descriptor given by ``--write-fd``.
121+
122+
Helpers for Implementing the API server in Python
123+
-------------------------------------------------
124+
125+
TVM provides helper utilities that make it easy to implement the server in Python.
126+
To implement the server in Python, create ``microtvm_api_server.py`` and add
127+
``from tvm.micro.project_api import server`` (or, copy this file into your template
128+
project--there are no dependencies--and import it there instead). Next, subclass
129+
``ProjectAPIHander``::
130+
131+
class Handler(server.ProjectAPIHandler):
132+
def server_info_query(self, tvm_version):
133+
# Implement server_info_query
134+
135+
def generate_project(self, model_library_format_path, standalone_crt_dir, project_dir, options):
136+
# Implement generate_project
137+
138+
# ...
139+
140+
Finally, invoke the helper ``main()``::
141+
142+
if __name__ == "__main__":
143+
server.main(Handler())
144+
145+
Using Project API from ``tvmc``
146+
-------------------------------
147+
148+
Each major Project API command is available through the ``tvmc micro``
149+
sub-command to make debugging interactions simple. Invoke ``tvmc micro --help``
150+
for more information.

docs/arch/model_library_format.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
specific language governing permissions and limitations
1616
under the License.
1717
18+
.. _model_library_format:
19+
1820
Model Library Format
1921
====================
2022

docs/legacy_redirect.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
["vta/dev/index.html", "../../topic/vta/dev/index.html"],
105105
["vta/index.html", "../topic/vta/index.html"],
106106
["vta/install.html", "../topic/vta/install.html"],
107+
["tutorials/index.html", "../tutorial/index.html"],
107108
["tutorials/frontend/from_caffe2.html", "../../how_to/compile_models/from_caffe2.html"],
108109
["tutorials/frontend/from_coreml.html", "../../how_to/compile_models/from_coreml.html"],
109110
["tutorials/frontend/from_darknet.html", "../../how_to/compile_models/from_darknet.html"],

include/tvm/tir/usmp/utils.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,45 @@ class BufferInfo : public ObjectRef {
153153
TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(BufferInfo, ObjectRef, BufferInfoNode);
154154
};
155155

156+
/*!
157+
* \brief This is a composite node that is produced by extract_buffer_info
158+
* analysis pass that contains useful global information that could be useful
159+
* for memory planning algorithms.
160+
*/
161+
struct BufferInfoAnalysisNode : public Object {
162+
/*! \brief The BufferInfo object and its associated TIR statement */
163+
Map<BufferInfo, tir::Stmt> buffer_info_stmts;
164+
/*! \brief This represent maximum amount of memory being used at
165+
* any point of time in the inference. This value is largely the
166+
* best allocation an algorithm could achieve. Due to
167+
* the complexities of conflict graphs, it would not be feasible
168+
* to achieve this value, practically. However, it can be useful
169+
* for iterative algorithms to know this value to define termination
170+
* criteria.*/
171+
Integer memory_pressure;
172+
173+
void VisitAttrs(tvm::AttrVisitor* v) {
174+
v->Visit("buffer_info_stmts", &buffer_info_stmts);
175+
v->Visit("memory_pressure", &memory_pressure);
176+
}
177+
178+
bool SEqualReduce(const BufferInfoAnalysisNode* other, SEqualReducer equal) const {
179+
return equal(buffer_info_stmts, other->buffer_info_stmts) &&
180+
equal(memory_pressure, other->memory_pressure);
181+
}
182+
183+
void SHashReduce(SHashReducer hash_reduce) const {
184+
hash_reduce(buffer_info_stmts);
185+
hash_reduce(memory_pressure);
186+
}
187+
};
188+
189+
class BufferInfoAnalysis : public ObjectRef {
190+
public:
191+
TVM_DLL BufferInfoAnalysis(Map<BufferInfo, tir::Stmt> buffer_info_stmts, Integer memory_pressure);
192+
TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(BufferInfoAnalysis, ObjectRef, BufferInfoAnalysisNode);
193+
};
194+
156195
/*!
157196
* \brief The pool allocation produced after the USMP algorithm
158197
*/

python/gen_requirements.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
[
110110
"future", # Hidden dependency of torch.
111111
"onnx",
112+
"onnxoptimizer",
112113
"onnxruntime",
113114
"torch",
114115
"torchvision",
@@ -146,6 +147,7 @@
146147
"ethos-u-vela",
147148
"future", # Hidden dependency of torch.
148149
"onnx",
150+
"onnxoptimizer",
149151
"onnxruntime",
150152
"paddlepaddle",
151153
"tensorflow",
@@ -233,13 +235,14 @@
233235
"docutils",
234236
"<0.17",
235237
), # Work around https://github.com/readthedocs/sphinx_rtd_theme/issues/1115
236-
("ethos-u-vela", "==2.1.1"),
238+
("ethos-u-vela", "==3.2.0"),
237239
("future", None),
238240
("h5py", "==2.10.0"),
239241
("image", None),
240242
("matplotlib", None),
241243
("numpy", None),
242244
("onnx", None),
245+
("onnxoptimizer", None),
243246
("onnxruntime", None),
244247
("opencv-python", None),
245248
("paddlepaddle", None),

0 commit comments

Comments
 (0)