Commit 240be55b by Tianqi Chen Committed by GitHub

[DOCS] API doc update (#1136)

parent ad01a66c
Framework Bridge APIs
---------------------
tvm.contrib.mxnet
~~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.mxnet
:members:
Contrib APIs
------------
Additional Contrib APIs
-----------------------
.. automodule:: tvm.contrib
tvm.contrib.nvcc
~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.nvcc
tvm.contrib.cblas
~~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.cc
:members:
tvm.contrib.cc
~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.cc
:members:
tvm.contrib.xcode
~~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.xcode
tvm.contrib.cublas
~~~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.cublas
:members:
tvm.contrib.rpc
tvm.contrib.emscripten
~~~~~~~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.emscripten
:members:
tvm.contrib.miopen
~~~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.miopen
:members:
tvm.contrib.ndk
~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.rpc
.. automodule:: tvm.contrib.ndk
:members:
tvm.contrib.nnpack
~~~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.nnpack
:members:
tvm.contrib.nvcc
~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.nvcc
:members:
tvm.contrib.graph_runtime
~~~~~~~~~~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.graph_runtime
tvm.contrib.pickle_memoize
~~~~~~~~~~~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.pickle_memoize
:members:
tvm.contrib.random
~~~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.random
:members:
tvm.contrib.rocblas
~~~~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.rocblas
:members:
tvm.contrib.rocm
~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.rocm
:members:
tvm.contrib.spirv
~~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.spirv
:members:
tvm.contrib.tar
~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.tar
:members:
tvm.contrib.util
~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.util
:members:
tvm.contrib.cblas
tvm.contrib.xcode
~~~~~~~~~~~~~~~~~
.. automodule:: tvm.contrib.cblas
.. automodule:: tvm.contrib.xcode
:members:
tvm.contrib.graph_runtime
-------------------------
.. automodule:: tvm.contrib.graph_runtime
:members:
......@@ -14,6 +14,9 @@ Python API
ndarray
container
function
graph_runtime
rpc
bridge
contrib
dev
topi
tvm.contrib.rpc
---------------
.. automodule:: tvm.contrib.rpc
.. autofunction:: tvm.contrib.rpc.connect
.. autofunction:: tvm.contrib.rpc.connect_tracker
.. autoclass:: tvm.contrib.rpc.TrackerSession
:members:
:inherited-members:
.. autoclass:: tvm.contrib.rpc.RPCSession
:members:
:inherited-members:
.. autoclass:: tvm.contrib.rpc.LocalSession
:members:
:inherited-members:
.. autoclass:: tvm.contrib.rpc.Server
:members:
:inherited-members:
tvm.target
----------
.. automodule:: tvm.target
.. autofunction:: tvm.target.generic_func
.. autoclass:: tvm.target.Target
:members:
.. autofunction:: tvm.target.cuda
.. autofunction:: tvm.target.rocm
.. autofunction:: tvm.target.rasp
.. autofunction:: tvm.target.create
......@@ -9,16 +9,33 @@ Index
.. autosummary::
topi.identity
topi.negative
topi.exp
topi.tanh
topi.log
topi.sqrt
topi.sigmoid
topi.clip
topi.cast
topi.transpose
topi.expand_dims
topi.reshape
topi.squeeze
topi.concatenate
topi.split
topi.full
topi.full_like
topi.greater
topi.less
topi.nn.relu
topi.nn.leaky_relu
topi.nn.dilate
topi.nn.pool
topi.nn.global_pool
topi.nn.upsampling
topi.nn.softmax
topi.nn.log_softmax
topi.nn.conv2d_nchw
topi.nn.conv2d_hwcn
topi.nn.depthwise_conv2d_nchw
......@@ -31,6 +48,8 @@ Index
topi.broadcast_sub
topi.broadcast_mul
topi.broadcast_div
topi.broadcast_maximum
topi.broadcast_minimum
**List of schedules**
......@@ -45,13 +64,25 @@ Index
topi
~~~~
.. autofunction:: topi.negative
.. autofunction:: topi.identity
.. autofunction:: topi.exp
.. autofunction:: topi.tanh
.. autofunction:: topi.log
.. autofunction:: topi.sqrt
.. autofunction:: topi.sigmoid
.. autofunction:: topi.clip
.. autofunction:: topi.cast
.. autofunction:: topi.transpose
.. autofunction:: topi.expand_dims
.. autofunction:: topi.reshape
.. autofunction:: topi.squeeze
.. autofunction:: topi.concatenate
.. autofunction:: topi.split
.. autofunction:: topi.full
.. autofunction:: topi.full_like
.. autofunction:: topi.greater
.. autofunction:: topi.less
.. autofunction:: topi.max
.. autofunction:: topi.sum
.. autofunction:: topi.min
......@@ -60,6 +91,8 @@ topi
.. autofunction:: topi.broadcast_sub
.. autofunction:: topi.broadcast_mul
.. autofunction:: topi.broadcast_div
.. autofunction:: topi.broadcast_maximum
.. autofunction:: topi.broadcast_minimum
topi.nn
......@@ -67,6 +100,11 @@ topi.nn
.. autofunction:: topi.nn.relu
.. autofunction:: topi.nn.leaky_relu
.. autofunction:: topi.nn.dilate
.. autofunction:: topi.nn.pool
.. autofunction:: topi.nn.global_pool
.. autofunction:: topi.nn.upsampling
.. autofunction:: topi.nn.softmax
.. autofunction:: topi.nn.log_softmax
.. autofunction:: topi.nn.conv2d_nchw
.. autofunction:: topi.nn.conv2d_hwcn
.. autofunction:: topi.nn.depthwise_conv2d_nchw
......
......@@ -15,6 +15,7 @@ The user facing API for computation declaration.
tvm.extern
tvm.decl_buffer
tvm.reduce_axis
tvm.select
tvm.thread_axis
tvm.comm_reducer
tvm.sum
......@@ -33,6 +34,7 @@ The user facing API for computation declaration.
.. autofunction:: tvm.extern
.. autofunction:: tvm.decl_buffer
.. autofunction:: tvm.reduce_axis
.. autofunction:: tvm.select
.. autofunction:: tvm.thread_axis
.. autofunction:: tvm.comm_reducer
.. autofunction:: tvm.sum
......
......@@ -189,6 +189,7 @@ subsection_order = ExplicitOrder(
'../tutorials/optimize',
'../tutorials/deployment'])
def generate_doxygen_xml(app):
"""Run the doxygen make commands if we're on the ReadTheDocs server"""
run_doxygen('..')
......
......@@ -35,7 +35,27 @@ on how to generate the library and [cpp_deploy.cc](https://github.com/dmlc/tvm/t
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.
Deploy to Android
-----------------
### Build model for Android Target
How to Deploy on Android
------------------------
- [How to deploy on android](deploy_android.md)
\ No newline at end of file
NNVM compilation of model for android target could follow same approach like android_rpc.
An reference exampe can be found at [chainer-nnvm-example](https://github.com/tkat0/chainer-nnvm-example)
Above example will directly run the compiled model on RPC target. Below modification at [rum_mobile.py](https://github.com/tkat0/chainer-nnvm-example/blob/5b97fd4d41aa4dde4b0aceb0be311054fb5de451/run_mobile.py#L64) will save the compilation output which is required on android target.
```
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(nnvm.compiler.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/dmlc/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 refered at this [java](https://github.com/dmlc/tvm/blob/master/apps/android_deploy/app/src/main/java/ml/dmlc/tvm/android/demo/MainActivity.java) sample source.
# How to deploy and use compiled model on Android
This tutorial explain below aspects (Unlike the android_rpc approach we already have)
* Build a model for android target
* TVM run on Android using Java API
As an example here is a reference block diagram.
![](http://www.tvmlang.org/images/release/tvm_flexible.png)
## Build model for Android Target
NNVM compilation of model for android target could follow same approach like android_rpc.
An reference exampe can be found at [chainer-nnvm-example](https://github.com/tkat0/chainer-nnvm-example)
Above example will directly run the compiled model on RPC target. Below modification at [rum_mobile.py](https://github.com/tkat0/chainer-nnvm-example/blob/5b97fd4d41aa4dde4b0aceb0be311054fb5de451/run_mobile.py#L64) will save the compilation output which is required on android target.
```
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(nnvm.compiler.save_param_dict(params))
```
deploy_lib.so, deploy_graph.json, deploy_param.params will go to android target.
## TVM run on Android using Java API
### TVM Runtime for android Target
Refer [here](https://github.com/dmlc/tvm/blob/master/apps/android_deploy/README.md#build-and-installation) to build CPU/OpenCL version flavor TVM runtime for android target.
### Android Native API Reference
From android java TVM API to load model & execute can be refered at this [java](https://github.com/dmlc/tvm/blob/master/apps/android_deploy/app/src/main/java/ml/dmlc/tvm/android/demo/MainActivity.java) sample source.
......@@ -10,4 +10,4 @@ upload and run remote RPC server, get the result back to verify correctness.
"""
from .server import Server
from .client import RPCSession, LocalSession, connect, connect_tracker
from .client import RPCSession, LocalSession, TrackerSession, connect, connect_tracker
......@@ -155,6 +155,7 @@ class GenericFunc(NodeBase):
key_list = [key_list] if isinstance(key_list, str) else key_list
_api_internal._GenericFuncRegisterFunc(self, func, key_list, allow_override)
def get_native_generic_func(name):
"""Get a generic function from the global registry. If no
function is registered under the given name, a new generic
......@@ -172,6 +173,7 @@ def get_native_generic_func(name):
"""
return _api_internal._GenericFuncGetGlobal(name)
def override_native_generic_func(func_name):
"""Override a generic function defined in C++
......@@ -193,20 +195,20 @@ def override_native_generic_func(func_name):
-------
.. code-block:: python
import tvm
# wrap function as target generic
@tvm.target.override_native_generic_func("my_func")
def my_func(a):
return a + 1
# register specialization of my_func under target cuda
@my_func.register("cuda")
def my_func_cuda(a):
return a + 2
# displays 3, because my_func is called
print(my_func(2))
# displays 4, because my_func_cuda is called
with tvm.target.cuda():
print(my_func(2))
import tvm
# wrap function as target generic
@tvm.target.override_native_generic_func("my_func")
def my_func(a):
return a + 1
# register specialization of my_func under target cuda
@my_func.register("cuda")
def my_func_cuda(a):
return a + 2
# displays 3, because my_func is called
print(my_func(2))
# displays 4, because my_func_cuda is called
with tvm.target.cuda():
print(my_func(2))
"""
generic_func_node = get_native_generic_func(func_name)
......@@ -346,6 +348,7 @@ def generic_func(fdefault):
fdecorate.register = register
return fdecorate
def cuda(options=None):
"""Returns a cuda target.
......
......@@ -27,6 +27,7 @@ def elemwise_sum(xs, num_args):
return tvm.compute(xs[0].shape, _compute)
@tvm.tag_scope(tag=tag.ELEMWISE)
def full(shape, dtype, fill_value):
"""Fill tensor with fill_value
......@@ -47,6 +48,7 @@ def full(shape, dtype, fill_value):
"""
return tvm.compute(shape, lambda *i: tvm.const(fill_value, dtype))
@tvm.tag_scope(tag=tag.ELEMWISE)
def full_like(x, fill_value):
"""Construct a tensor with same shape as input tensor,
......@@ -67,6 +69,7 @@ def full_like(x, fill_value):
dtype = x.dtype
return tvm.compute(x.shape, lambda *i: tvm.const(fill_value, dtype))
@tvm.tag_scope(tag=tag.ELEMWISE)
def greater(lhs, rhs, out_type=tvm.int8):
"""Compare two input tensors element-wise and return an mask tensor
......
......@@ -254,7 +254,7 @@ def split(ary, indices_or_sections, axis=0):
"Should be sorted, recieved %s" % str(indices_or_sections)
begin_ids = [0] + list(indices_or_sections)
else:
raise NotImplementedError
raise NotImplementedError()
out_shapes = []
for i in range(len(begin_ids)):
if i == len(begin_ids) - 1:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment