forked from huajsj/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.
[BUILD] Enable RTTI of most part of library, example extension pkg. (a…
- Loading branch information
Showing
15 changed files
with
138 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,7 @@ ENV/ | |
*~ | ||
build | ||
config.mk | ||
config.cmake | ||
build_* | ||
Win32 | ||
*.dir | ||
|
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
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 @@ | ||
lib |
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 @@ | ||
# Minimum Makefile for the extension package | ||
TVM_ROOT=$(shell cd ../..; pwd) | ||
PKG_CFLAGS = -std=c++11 -O2 -fPIC\ | ||
-I${TVM_ROOT}/include\ | ||
-I${TVM_ROOT}/dmlc-core/include\ | ||
-I${TVM_ROOT}/dlpack/include\ | ||
-I${TVM_ROOT}/HalideIR/src | ||
|
||
PKG_LDFLAGS =-L${TVM_ROOT}/lib | ||
|
||
lib/libtvm_ext.so: src/tvm_ext.cc | ||
@mkdir -p $(@D) | ||
$(CXX) $(PKG_CFLAGS) -shared -o $@ $^ $(PKG_LDFLAGS) -ltvm |
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,7 @@ | ||
Example Extension Library | ||
========================= | ||
This folder contains an example extension library of TVM. | ||
It demonstrates how can other library extend TVM in both C++ and python API. | ||
|
||
- The library extends TVM's functionality by link libtvm | ||
- The python module load the new shared library and can interpolate with TVM's python API. |
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,31 @@ | ||
|
||
/*! | ||
* Copyright (c) 2017 by Contributors | ||
* \brief Example package that uses TVM. | ||
* \file tvm_ext.cc | ||
*/ | ||
#include <tvm/runtime/packed_func.h> | ||
#include <tvm/runtime/module.h> | ||
#include <tvm/runtime/registry.h> | ||
#include <tvm/packed_func_ext.h> | ||
|
||
namespace tvm_ext { | ||
using namespace tvm; | ||
using namespace tvm::runtime; | ||
|
||
TVM_REGISTER_GLOBAL("tvm_ext.bind_add") | ||
.set_body([](TVMArgs args_, TVMRetValue *rv_) { | ||
PackedFunc pf = args_[0]; | ||
int b = args_[1]; | ||
*rv_ = PackedFunc([pf, b](TVMArgs args, TVMRetValue *rv) { | ||
*rv = pf(b, args[0]); | ||
}); | ||
}); | ||
|
||
TVM_REGISTER_GLOBAL("tvm_ext.sym_add") | ||
.set_body([](TVMArgs args, TVMRetValue *rv) { | ||
Var a = args[0]; | ||
Var b = args[1]; | ||
*rv = a + b; | ||
}); | ||
} // namespace tvm_ext |
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,18 @@ | ||
import tvm_ext | ||
import tvm | ||
|
||
def test_bind_add(): | ||
def add(a, b): | ||
return a + b | ||
f = tvm_ext.bind_add(add, 1) | ||
assert f(2) == 3 | ||
|
||
def test_sym_add(): | ||
a = tvm.var('a') | ||
b = tvm.var('b') | ||
c = tvm_ext.sym_add(a, b) | ||
assert c.a == a and c.b == b | ||
|
||
if __name__ == "__main__": | ||
test_bind_add() | ||
test_sym_add() |
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,19 @@ | ||
"""Example extension package of TVM.""" | ||
from __future__ import absolute_import | ||
import os | ||
import ctypes | ||
|
||
def load_lib(): | ||
"""Load library, the functions will be registered into TVM""" | ||
curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__))) | ||
lib = ctypes.CDLL(os.path.join(curr_path, "../lib/libtvm_ext.so"), | ||
ctypes.RTLD_GLOBAL) | ||
return lib | ||
|
||
_LIB = load_lib() | ||
|
||
import tvm | ||
# Expose two functions into python | ||
bind_add = tvm.get_global_func("tvm_ext.bind_add") | ||
sym_add = tvm.get_global_func("tvm_ext.sym_add") | ||
|
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
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 |
---|---|---|
@@ -1,7 +1,14 @@ | ||
#!/bin/bash | ||
export PYTHONPATH=python:examples/extension | ||
export LD_LIBRARY_PATH=lib:${LD_LIBRARY_PATH} | ||
|
||
export PYTHONPATH=python | ||
# Test extern package package | ||
cd examples/extension | ||
make || exit -1 | ||
cd ../.. | ||
python -m nose -v examples/extension/tests || exit -1 | ||
|
||
# Test TVM | ||
make cython || exit -1 | ||
TVM_FFI=cython python -m nose -v tests/python/integration || exit -1 | ||
TVM_FFI=ctypes python3 -m nose -v tests/python/integration || exit -1 |