forked from neo-ai/tvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DOCS] Migrate some markdowns to rst, fix sphinx3 warnings (apache#5416)
* [DOCS] Migrate some markdowns to rst, fix sphinx3 warnings * Add note block
- Loading branch information
Showing
10 changed files
with
286 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
.. 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. | ||
Deploy to Android | ||
================= | ||
|
||
Build model for Android Target | ||
------------------------------ | ||
|
||
Relay compilation of model for android target could follow same approach like android_rpc. | ||
The code below will save the compilation output which is required on android target. | ||
|
||
|
||
.. code:: python | ||
lib.export_library("deploy_lib.so", ndk.create_shared) | ||
with open("deploy_graph.json", "w") as fo: | ||
fo.write(graph.json()) | ||
with open("deploy_param.params", "wb") as fo: | ||
fo.write(relay.save_param_dict(params)) | ||
deploy_lib.so, deploy_graph.json, deploy_param.params will go to android target. | ||
|
||
TVM Runtime for Android Target | ||
------------------------------ | ||
|
||
Refer `here <https://github.com/apache/incubator-tvm/blob/master/apps/android_deploy/README.md#build-and-installation>`_ to build CPU/OpenCL version flavor TVM runtime for android target. | ||
From android java TVM API to load model & execute can be referred at this `java <https://github.com/apache/incubator-tvm/blob/master/apps/android_deploy/app/src/main/java/org/apache/tvm/android/demo/MainActivity.java>`_ sample source. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
.. 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. | ||
Deploy TVM Module using C++ API | ||
=============================== | ||
|
||
We provide an example on how to deploy TVM modules in `apps/howto_deploy <https://github.com/apache/incubator-tvm/tree/master/apps/howto_deploy>`_ | ||
|
||
To run the example, you can use the following command | ||
|
||
|
||
.. code:: bash | ||
cd apps/howto_deploy | ||
./run_example.sh | ||
Get TVM Runtime Library | ||
----------------------- | ||
|
||
The only thing we need is to link to a TVM runtime in your target platform. | ||
TVM provides a minimum runtime, which costs around 300K to 600K depending on how much modules we use. | ||
In most cases, we can use ``libtvm_runtime.so`` that comes with the build. | ||
|
||
If somehow you find it is hard to build ``libtvm_runtime``, checkout | ||
`tvm_runtime_pack.cc <https://github.com/apache/incubator-tvm/tree/master/apps/howto_deploy/tvm_runtime_pack.cc>`_. | ||
It is an example all in one file that gives you TVM runtime. | ||
You can compile this file using your build system and include this into your project. | ||
|
||
You can also checkout `apps <https://github.com/apache/incubator-tvm/tree/master/apps/>`_ for example applications build with TVM on iOS, Android and others. | ||
|
||
Dynamic Library vs. System Module | ||
--------------------------------- | ||
TVM provides two ways to use the compiled library. | ||
You can checkout `prepare_test_libs.py <https://github.com/apache/incubator-tvm/tree/master/apps/howto_deploy/prepare_test_libs.py>`_ | ||
on how to generate the library and `cpp_deploy.cc <https://github.com/apache/incubator-tvm/tree/master/apps/howto_deploy/cpp_deploy.cc>`_ on how to use them. | ||
|
||
- Store library as a shared library and dynamically load the library into your project. | ||
- Bundle the compiled library into your project in system module mode. | ||
|
||
Dynamic loading is more flexible and can load new modules on the fly. System module is a more ``static`` approach. We can use system module in places where dynamic library loading is banned. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
.. 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. | ||
Integrate TVM into Your Project | ||
=============================== | ||
|
||
TVM's runtime is designed to be lightweight and portable. | ||
There are several ways you can integrate TVM into your project. | ||
|
||
This article introduces possible ways to integrate TVM | ||
as a JIT compiler to generate functions on your system. | ||
|
||
|
||
DLPack Support | ||
-------------- | ||
|
||
TVM's generated function follows the PackedFunc convention. | ||
It is a function that can take positional arguments including | ||
standard types such as float, integer, string. | ||
The PackedFunc takes DLTensor pointer in `DLPack <https://github.com/dmlc/dlpack>`_ convention. | ||
So the only thing you need to solve is to create a corresponding DLTensor object. | ||
|
||
|
||
|
||
Integrate User Defined C++ Array | ||
-------------------------------- | ||
|
||
The only thing we have to do in C++ is to convert your array to DLTensor and pass in its address as | ||
``DLTensor*`` to the generated function. | ||
|
||
|
||
## Integrate User Defined Python Array | ||
|
||
Assume you have a python object ``MyArray``. There are three things that you need to do | ||
|
||
- Add ``_tvm_tcode`` field to your array which returns ``tvm.TypeCode.ARRAY_HANDLE`` | ||
- Support ``_tvm_handle`` property in your object, which returns the address of DLTensor in python integer | ||
- Register this class by ``tvm.register_extension`` | ||
|
||
.. code:: python | ||
# Example code | ||
import tvm | ||
class MyArray(object): | ||
_tvm_tcode = tvm.TypeCode.ARRAY_HANDLE | ||
@property | ||
def _tvm_handle(self): | ||
dltensor_addr = self.get_dltensor_addr() | ||
return dltensor_addr | ||
# You can put registration step in a separate file mypkg.tvm.py | ||
# and only optionally import that if you only want optional dependency. | ||
tvm.register_extension(MyArray) |
Oops, something went wrong.