-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DOCS] How to deploy TVM Modules (#499)
* [DOCS] How to deploy TVM Modules * More comments
- Loading branch information
Showing
14 changed files
with
183 additions
and
45 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 was deleted.
Oops, something went wrong.
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,34 @@ | ||
# Makefile Example to deploy TVM modules. | ||
TVM_ROOT=$(shell cd ../..; pwd) | ||
NNVM_PATH=nnvm | ||
DMLC_CORE=${TVM_ROOT}/dmlc-core | ||
|
||
PKG_CFLAGS = -std=c++11 -O2 -fPIC\ | ||
-I${TVM_ROOT}/include\ | ||
-I${DMLC_CORE}/include\ | ||
-I${TVM_ROOT}/dlpack/include\ | ||
|
||
PKG_LDFLAGS = -L${TVM_ROOT}/lib -ldl -lpthread | ||
|
||
.PHONY: clean all | ||
|
||
all: lib/cpp_deploy_pack lib/cpp_deploy_normal | ||
|
||
# Build rule for all in one TVM package library | ||
lib/libtvm_runtime_pack.o: tvm_runtime_pack.cc | ||
@mkdir -p $(@D) | ||
$(CXX) -c $(PKG_CFLAGS) -o $@ $^ | ||
|
||
# The code library built by TVM | ||
lib/test_addone_sys.o: prepare_test_libs.py | ||
python prepare_test_libs.py | ||
|
||
# Deploy using the all in one TVM package library | ||
lib/cpp_deploy_pack: cpp_deploy.cc lib/test_addone_sys.o lib/libtvm_runtime_pack.o | ||
@mkdir -p $(@D) | ||
$(CXX) $(PKG_CFLAGS) -o $@ $^ $(PKG_LDFLAGS) | ||
|
||
# Deploy using pre-built libtvm_runtime.so | ||
lib/cpp_deploy_normal: cpp_deploy.cc lib/test_addone_sys.o | ||
@mkdir -p $(@D) | ||
$(CXX) $(PKG_CFLAGS) -o $@ $^ $(PKG_LDFLAGS) -ltvm_runtime |
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,11 @@ | ||
How to Deploy TVM Modules | ||
========================= | ||
This folder contains an example on how to deploy TVM modules. | ||
It also contains an example code to deploy with C++. | ||
|
||
Type the following command to run the sample code under the current folder(need to build TVM first). | ||
```bash | ||
./run_example.sh | ||
``` | ||
|
||
Checkout [How to Deploy TVM Modules](http://docs.tvmlang.org/how_to/deploy.html) for more information. |
File renamed without changes.
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 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,13 @@ | ||
#!/bin/bash | ||
echo "Build the libraries.." | ||
mkdir -p lib | ||
make | ||
echo "Run the example" | ||
export LD_LIBRARY_PATH=../../lib:${LD_LIBRARY_PATH} | ||
export DYLD_LIBRARY_PATH=../../lib:${DYLD_LIBRARY_PATH} | ||
|
||
echo "Run the deployment with all in one packed library..." | ||
lib/cpp_deploy_pack | ||
|
||
echo "Run the deployment with all in normal library..." | ||
lib/cpp_deploy_normal |
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,53 @@ | ||
/*! | ||
* \brief This is an all in one TVM runtime file. | ||
* | ||
* You only have to use this file to compile libtvm_runtime to | ||
* include in your project. | ||
* | ||
* - Copy this file into your project which depends on tvm runtime. | ||
* - Compile with -std=c++11 | ||
* - Add the following include path | ||
* - /path/to/tvm/include/ | ||
* - /path/to/tvm/dmlc-core/include/ | ||
* - /path/to/tvm/dlpack/include/ | ||
* - Add -lpthread -ldl to the linked library. | ||
* - You are good to go. | ||
* - See the Makefile in the same folder for example. | ||
* | ||
* The include files here are presented with relative path | ||
* You need to remember to change it to point to the right file. | ||
* | ||
*/ | ||
#include "../../src/runtime/c_runtime_api.cc" | ||
#include "../../src/runtime/cpu_device_api.cc" | ||
#include "../../src/runtime/workspace_pool.cc" | ||
#include "../../src/runtime/module_util.cc" | ||
#include "../../src/runtime/module.cc" | ||
#include "../../src/runtime/registry.cc" | ||
#include "../../src/runtime/file_util.cc" | ||
#include "../../src/runtime/thread_pool.cc" | ||
|
||
// NOTE: all the files after this are optional modules | ||
// that you can include remove, depending on how much feature you use. | ||
|
||
// Likely we only need to enable one of the following | ||
// If you use Module::Load, use dso_module | ||
// For system packed library, use system_lib_module | ||
#include "../../src/runtime/dso_module.cc" | ||
#include "../../src/runtime/system_lib_module.cc" | ||
|
||
// Graph runtime | ||
#include "../../src/runtime/graph/graph_runtime.cc" | ||
|
||
// Uncomment the following lines to enable RPC | ||
// #include "../../src/runtime/rpc/rpc_session.cc" | ||
// #include "../../src/runtime/rpc/rpc_event_impl.cc" | ||
// #include "../../src/runtime/rpc/rpc_server_env.cc" | ||
|
||
// Uncomment the following lines to enable Metal | ||
// #include "../../src/runtime/metal/metal_device_api.mm" | ||
// #include "../../src/runtime/metal/metal_module.mm" | ||
|
||
// Uncomment the following lines to enable OpenCL | ||
// #include "../../src/runtime/opencl/opencl_device_api.cc" | ||
// #include "../../src/runtime/opencl/opencl_module.cc" |
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,36 @@ | ||
How to Deploy TVM Modules | ||
========================= | ||
We provide an example on how to deploy TVM modules in [apps/howto_deploy](https://github.com/dmlc/tvm/tree/master/apps/howto_deploy) | ||
|
||
To run the example, you can use the following command | ||
|
||
```bash | ||
cd apps/howto_deploy | ||
./run_example.sh | ||
``` | ||
|
||
Get TVM Runtime Library | ||
----------------------- | ||
|
||
![](http://www.tvmlang.org/images/release/tvm_flexible.png) | ||
|
||
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/dmlc/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/dmlc/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/dmlc/tvm/tree/master/apps/howto_deploy/prepare_test_libs.py) | ||
on how to generate the library and [cpp_deploy.cc](https://github.com/dmlc/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 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 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 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,26 @@ | ||
# pylint: disable=invalid-name, exec-used | ||
"""Setup TOPI package.""" | ||
from __future__ import absolute_import | ||
import sys | ||
|
||
from setuptools import find_packages | ||
from setuptools.dist import Distribution | ||
|
||
if "--inplace" in sys.argv: | ||
from distutils.core import setup | ||
from distutils.extension import Extension | ||
else: | ||
from setuptools import setup | ||
from setuptools.extension import Extension | ||
|
||
__version__ = "0.1.0" | ||
|
||
setup(name='topi', | ||
version=__version__, | ||
description="TOPI: TVM operator index", | ||
install_requires=[ | ||
"numpy", | ||
"decorator", | ||
], | ||
packages=find_packages(), | ||
url='https://github.com/dmlc/tvm') |