Skip to content

Commit

Permalink
[DOCS] Migrate some markdowns to rst, fix sphinx3 warnings (apache#5416)
Browse files Browse the repository at this point in the history
* [DOCS] Migrate some markdowns to rst, fix sphinx3 warnings

* Add note block
  • Loading branch information
tqchen authored and trevor-m committed Jun 18, 2020
1 parent d7e9393 commit f103631
Show file tree
Hide file tree
Showing 10 changed files with 286 additions and 284 deletions.
25 changes: 0 additions & 25 deletions docs/api/python/runtime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,3 @@ tvm.runtime
:imported-members:
:exclude-members: NDArray
:autosummary:


.. autoclass:: tvm.runtime.PackedFunc
:members:
:inherited-members:

.. autofunction:: tvm.register_func

.. autofunction:: tvm.get_global_func


.. autoclass:: tvm.runtime.Module
:members:

.. autofunction:: tvm.runtime.load_module

.. autofunction:: tvm.runtime.system_lib

.. autofunction:: tvm.runtime.enabled


.. autoclass:: tvm.runtime.Object
:members:

.. autofunction:: tvm.register_object
39 changes: 0 additions & 39 deletions docs/deploy/android.md

This file was deleted.

42 changes: 42 additions & 0 deletions docs/deploy/android.rst
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.
52 changes: 0 additions & 52 deletions docs/deploy/cpp_deploy.md

This file was deleted.

56 changes: 56 additions & 0 deletions docs/deploy/cpp_deploy.rst
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.
67 changes: 0 additions & 67 deletions docs/deploy/integrate.md

This file was deleted.

69 changes: 69 additions & 0 deletions docs/deploy/integrate.rst
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)
Loading

0 comments on commit f103631

Please sign in to comment.