Skip to content

Commit 1f6c498

Browse files
authored
[DOCS] Migrate some markdowns to rst, fix sphinx3 warnings (#5416)
* [DOCS] Migrate some markdowns to rst, fix sphinx3 warnings * Add note block
1 parent d81a4fa commit 1f6c498

File tree

10 files changed

+286
-284
lines changed

10 files changed

+286
-284
lines changed

docs/api/python/runtime.rst

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,3 @@ tvm.runtime
2323
:imported-members:
2424
:exclude-members: NDArray
2525
:autosummary:
26-
27-
28-
.. autoclass:: tvm.runtime.PackedFunc
29-
:members:
30-
:inherited-members:
31-
32-
.. autofunction:: tvm.register_func
33-
34-
.. autofunction:: tvm.get_global_func
35-
36-
37-
.. autoclass:: tvm.runtime.Module
38-
:members:
39-
40-
.. autofunction:: tvm.runtime.load_module
41-
42-
.. autofunction:: tvm.runtime.system_lib
43-
44-
.. autofunction:: tvm.runtime.enabled
45-
46-
47-
.. autoclass:: tvm.runtime.Object
48-
:members:
49-
50-
.. autofunction:: tvm.register_object

docs/deploy/android.md

Lines changed: 0 additions & 39 deletions
This file was deleted.

docs/deploy/android.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
Deploy to Android
19+
=================
20+
21+
Build model for Android Target
22+
------------------------------
23+
24+
Relay compilation of model for android target could follow same approach like android_rpc.
25+
The code below will save the compilation output which is required on android target.
26+
27+
28+
.. code:: python
29+
30+
lib.export_library("deploy_lib.so", ndk.create_shared)
31+
with open("deploy_graph.json", "w") as fo:
32+
fo.write(graph.json())
33+
with open("deploy_param.params", "wb") as fo:
34+
fo.write(relay.save_param_dict(params))
35+
36+
deploy_lib.so, deploy_graph.json, deploy_param.params will go to android target.
37+
38+
TVM Runtime for Android Target
39+
------------------------------
40+
41+
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.
42+
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.

docs/deploy/cpp_deploy.md

Lines changed: 0 additions & 52 deletions
This file was deleted.

docs/deploy/cpp_deploy.rst

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
19+
Deploy TVM Module using C++ API
20+
===============================
21+
22+
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>`_
23+
24+
To run the example, you can use the following command
25+
26+
27+
.. code:: bash
28+
29+
cd apps/howto_deploy
30+
./run_example.sh
31+
32+
33+
Get TVM Runtime Library
34+
-----------------------
35+
36+
The only thing we need is to link to a TVM runtime in your target platform.
37+
TVM provides a minimum runtime, which costs around 300K to 600K depending on how much modules we use.
38+
In most cases, we can use ``libtvm_runtime.so`` that comes with the build.
39+
40+
If somehow you find it is hard to build ``libtvm_runtime``, checkout
41+
`tvm_runtime_pack.cc <https://github.com/apache/incubator-tvm/tree/master/apps/howto_deploy/tvm_runtime_pack.cc>`_.
42+
It is an example all in one file that gives you TVM runtime.
43+
You can compile this file using your build system and include this into your project.
44+
45+
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.
46+
47+
Dynamic Library vs. System Module
48+
---------------------------------
49+
TVM provides two ways to use the compiled library.
50+
You can checkout `prepare_test_libs.py <https://github.com/apache/incubator-tvm/tree/master/apps/howto_deploy/prepare_test_libs.py>`_
51+
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.
52+
53+
- Store library as a shared library and dynamically load the library into your project.
54+
- Bundle the compiled library into your project in system module mode.
55+
56+
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.

docs/deploy/integrate.md

Lines changed: 0 additions & 67 deletions
This file was deleted.

docs/deploy/integrate.rst

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
Integrate TVM into Your Project
19+
===============================
20+
21+
TVM's runtime is designed to be lightweight and portable.
22+
There are several ways you can integrate TVM into your project.
23+
24+
This article introduces possible ways to integrate TVM
25+
as a JIT compiler to generate functions on your system.
26+
27+
28+
DLPack Support
29+
--------------
30+
31+
TVM's generated function follows the PackedFunc convention.
32+
It is a function that can take positional arguments including
33+
standard types such as float, integer, string.
34+
The PackedFunc takes DLTensor pointer in `DLPack <https://github.com/dmlc/dlpack>`_ convention.
35+
So the only thing you need to solve is to create a corresponding DLTensor object.
36+
37+
38+
39+
Integrate User Defined C++ Array
40+
--------------------------------
41+
42+
The only thing we have to do in C++ is to convert your array to DLTensor and pass in its address as
43+
``DLTensor*`` to the generated function.
44+
45+
46+
## Integrate User Defined Python Array
47+
48+
Assume you have a python object ``MyArray``. There are three things that you need to do
49+
50+
- Add ``_tvm_tcode`` field to your array which returns ``tvm.TypeCode.ARRAY_HANDLE``
51+
- Support ``_tvm_handle`` property in your object, which returns the address of DLTensor in python integer
52+
- Register this class by ``tvm.register_extension``
53+
54+
.. code:: python
55+
56+
# Example code
57+
import tvm
58+
59+
class MyArray(object):
60+
_tvm_tcode = tvm.TypeCode.ARRAY_HANDLE
61+
62+
@property
63+
def _tvm_handle(self):
64+
dltensor_addr = self.get_dltensor_addr()
65+
return dltensor_addr
66+
67+
# You can put registration step in a separate file mypkg.tvm.py
68+
# and only optionally import that if you only want optional dependency.
69+
tvm.register_extension(MyArray)

0 commit comments

Comments
 (0)