Skip to content

Commit

Permalink
Update legacy places from nnvm to relay. (#4535)
Browse files Browse the repository at this point in the history
* Update legacy places from nnvm to relay.

This PR prepares the current mainline to remove nnvm compiler dep.

* remove legacy stage
  • Loading branch information
tqchen authored and icemelon committed Dec 18, 2019
1 parent c44b7bf commit 9384353
Show file tree
Hide file tree
Showing 28 changed files with 129 additions and 193 deletions.
11 changes: 0 additions & 11 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -310,17 +310,6 @@ stage('Integration Test') {
}
}
},
'legacy: GPU': {
node('GPU') {
ws(per_exec_ws("tvm/legacy-python-gpu")) {
init_git()
unpack_lib('gpu', tvm_multilib)
timeout(time: max_time, unit: 'MINUTES') {
sh "${docker_run} ${ci_gpu} ./tests/scripts/task_python_legacy.sh"
}
}
}
},
'docs: GPU': {
node('GPU') {
ws(per_exec_ws("tvm/docs-python-gpu")) {
Expand Down
4 changes: 2 additions & 2 deletions apps/benchmark/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def get_network(name, batch_size, dtype='float32'):
Returns
-------
net: nnvm.symbol
The NNVM symbol of network definition
net: relay.Module
The relay function of network definition
params: dict
The random parameters for benchmark
input_shape: tuple
Expand Down
14 changes: 7 additions & 7 deletions apps/bundle_deploy/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
# under the License.

# Makefile Example to bundle TVM modules.

TVM_ROOT=$(shell cd ../..; pwd)
NNVM_PATH=nnvm
DMLC_CORE=${TVM_ROOT}/3rdparty/dmlc-core
PKG_CFLAGS = -std=c++14 -Oz -fPIC\
PKG_CFLAGS = -std=c++14 -O2 -fPIC\
-I${TVM_ROOT}/include\
-I${DMLC_CORE}/include\
-I${TVM_ROOT}/3rdparty/dlpack/include\
-I${TVM_ROOT}/3rdparty/dlpack/include

PKG_LDFLAGS = -L${TVM_ROOT}/build
PKG_LDFLAGS = -pthread

build_dir := build

Expand All @@ -33,7 +33,7 @@ test: $(build_dir)/demo $(build_dir)/bundle.so

$(build_dir)/demo: demo.cc
@mkdir -p $(@D)
$(CXX) $(PKG_CFLAGS) -o $@ $^
$(CXX) $(PKG_CFLAGS) -o $@ $^ -ldl

# Serialize our graph.json file.
$(build_dir)/graph.json.cc: $(build_dir)/graph.json
Expand All @@ -44,13 +44,13 @@ $(build_dir)/params.bin.cc: $(build_dir)/params.bin
xxd -i $^ > $@

$(build_dir)/model.o $(build_dir)/graph.json $(build_dir)/params.bin: build_model.py
python $< -o $(build_dir)
python3 $< -o $(build_dir)

# Build our bundle against the serialized bundle.cc API, the runtime.cc API, and
# the serialized graph.json and params.bin
$(build_dir)/bundle.so: bundle.cc runtime.cc $(build_dir)/model.o $(build_dir)/graph.json.cc $(build_dir)/params.bin.cc
@mkdir -p $(@D)
$(CXX) $(PKG_CFLAGS) -fvisibility=hidden -o $@ $^ $(PKG_LDFLAGS) -shared
$(CXX) -shared $(PKG_CFLAGS) -fvisibility=hidden -o $@ $^ $(PKG_LDFLAGS)

clean:
rm -r $(build_dir)
21 changes: 11 additions & 10 deletions apps/bundle_deploy/build_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

import argparse
import os
import nnvm.compiler
import nnvm.testing
from tvm import relay
import tvm
import logging

Expand All @@ -34,22 +33,24 @@ def main():
dshape = (1, 3, 224, 224)
from mxnet.gluon.model_zoo.vision import get_model
block = get_model('mobilenet0.25', pretrained=True)
net, params = nnvm.frontend.from_mxnet(block)
net = nnvm.sym.softmax(net)
shape_dict = {'data': dshape}
mod, params = relay.frontend.from_mxnet(block, shape_dict)
func = mod["main"]
func = relay.Function(func.params, relay.nn.softmax(func.body), None, func.type_params, func.attrs)

with relay.build_config(opt_level=3):
graph, lib, params = relay.build(
func, 'llvm --system-lib', params=params)

with nnvm.compiler.build_config(opt_level=3):
graph, lib, params = nnvm.compiler.build(
net, 'llvm --system-lib', shape={'data': dshape}, params=params)
print(graph.symbol().debug_str())
build_dir = os.path.abspath(opts.out_dir)
if not os.path.isdir(build_dir):
os.makedirs(build_dir)

lib.save(os.path.join(build_dir, 'model.o'))
with open(os.path.join(build_dir, 'graph.json'), 'w') as f_graph_json:
f_graph_json.write(graph.json())
f_graph_json.write(graph)
with open(os.path.join(build_dir, 'params.bin'), 'wb') as f_params:
f_params.write(nnvm.compiler.save_param_dict(params))
f_params.write(relay.save_param_dict(params))


if __name__ == '__main__':
Expand Down
9 changes: 6 additions & 3 deletions apps/bundle_deploy/bundle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* 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
Expand All @@ -26,7 +26,9 @@ extern unsigned int build_graph_json_len;
extern unsigned char build_params_bin[];
extern unsigned int build_params_bin_len;

#define TVM_BUNDLE_FUNCTION __attribute__((visibility("default"))) extern "C"
#define TVM_BUNDLE_FUNCTION __attribute__((visibility("default")))

extern "C" {

TVM_BUNDLE_FUNCTION void *tvm_runtime_create() {
const std::string json_data(&build_graph_json[0],
Expand Down Expand Up @@ -64,3 +66,4 @@ TVM_BUNDLE_FUNCTION void tvm_runtime_get_output(void *handle, int index,
reinterpret_cast<tvm::runtime::Module *>(handle)->GetFunction("get_output")(
index, reinterpret_cast<DLTensor *>(tensor));
}
}
4 changes: 2 additions & 2 deletions apps/bundle_deploy/runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
#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/library_module.cc"
#include "../../src/runtime/module.cc"
#include "../../src/runtime/registry.cc"
#include "../../src/runtime/file_util.cc"
#include "../../src/runtime/threading_backend.cc"
#include "../../src/runtime/thread_pool.cc"
#include "../../src/runtime/ndarray.cc"
#include "../../src/runtime/object.cc"
#include "../../src/runtime/system_lib_module.cc"
#include "../../src/runtime/system_library.cc"
#include "../../src/runtime/graph/graph_runtime.cc"
5 changes: 2 additions & 3 deletions apps/howto_deploy/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@

# Makefile Example to deploy TVM modules.
TVM_ROOT=$(shell cd ../..; pwd)
NNVM_PATH=nnvm
DMLC_CORE=${TVM_ROOT}/3rdparty/dmlc-core

PKG_CFLAGS = -std=c++11 -O2 -fPIC\
-I${TVM_ROOT}/include\
-I${DMLC_CORE}/include\
-I${TVM_ROOT}/3rdparty/dlpack/include\

PKG_LDFLAGS = -L${TVM_ROOT}/build -ldl -lpthread
PKG_LDFLAGS = -L${TVM_ROOT}/build -ldl -pthread

.PHONY: clean all

Expand All @@ -39,7 +38,7 @@ lib/libtvm_runtime_pack.o: tvm_runtime_pack.cc
# The code library built by TVM
lib/test_addone_sys.o: prepare_test_libs.py
@mkdir -p $(@D)
python prepare_test_libs.py
python3 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
Expand Down
1 change: 0 additions & 1 deletion apps/rocm_rpc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
ROCM_PATH=/opt/rocm

TVM_ROOT=$(shell cd ../..; pwd)
NNVM_PATH=nnvm
DMLC_CORE=${TVM_ROOT}/3rdparty/dmlc-core

PKG_CFLAGS = -std=c++11 -O2 -fPIC\
Expand Down
2 changes: 1 addition & 1 deletion apps/sgx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ mkdir build && cd build
cmake .. -DUSE_LLVM=ON -DUSE_SGX=/opt/sgxsdk -DRUST_SGX_SDK=/opt/rust-sgx-sdk
make -j4
cd ..
pip install -e python -e topi/python -e nnvm/python
pip install -e python -e topi/python
cd apps/sgx
```

Expand Down
17 changes: 8 additions & 9 deletions apps/sgx/enclave/src/build_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import os
from os import path as osp

import nnvm.compiler
import nnvm.testing
from tvm import relay
from tvm.relay import testing
import tvm


Expand All @@ -30,24 +30,23 @@ def main():
parser.add_argument('-o', '--out-dir', default='.')
opts = parser.parse_args()

# from tutorials/nnvm_quick_start.py
dshape = (1, 3, 224, 224)
net, params = nnvm.testing.resnet.get_workload(
net, params = relay.testing.resnet.get_workload(
layers=18, batch_size=dshape[0], image_shape=dshape[1:])

with nnvm.compiler.build_config(opt_level=3):
graph, lib, params = nnvm.compiler.build(
net, 'llvm --system-lib', shape={'data': dshape}, params=params)
with relay.build_config(opt_level=3):
graph, lib, params = relay.build(
net, 'llvm --system-lib', params=params)

build_dir = osp.abspath(opts.out_dir)
if not osp.isdir(build_dir):
os.makedirs(build_dir, exist_ok=True)

lib.save(osp.join(build_dir, 'model.bc'))
with open(osp.join(build_dir, 'graph.json'), 'w') as f_graph_json:
f_graph_json.write(graph.json())
f_graph_json.write(graph)
with open(osp.join(build_dir, 'params.bin'), 'wb') as f_params:
f_params.write(nnvm.compiler.save_param_dict(params))
f_params.write(relay.save_param_dict(params))


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ members = [
"runtime",
"runtime/tests/test_tvm_basic",
"runtime/tests/test_tvm_dso",
"runtime/tests/test_nnvm",
"runtime/tests/test_nn",
"frontend",
"frontend/tests/basics",
"frontend/tests/callback",
Expand Down
2 changes: 1 addition & 1 deletion rust/frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ description = "Rust frontend support for TVM"
repository = "https://github.com/apache/incubator-tvm"
homepage = "https://github.com/apache/incubator-tvm"
readme = "README.md"
keywords = ["rust", "tvm", "nnvm"]
keywords = ["rust", "tvm"]
categories = ["api-bindings", "science"]
authors = ["TVM Contributors"]
edition = "2018"
Expand Down
16 changes: 7 additions & 9 deletions rust/frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ Here's a Python snippet for downloading and building a pretrained Resnet18 via A

```python
block = get_model('resnet18_v1', pretrained=True)

sym, params = nnvm.frontend.from_mxnet(block)
# add the softmax layer for prediction
net = nnvm.sym.softmax(sym)

sym, params = relay.frontend.from_mxnet(block, shape_dict)
# compile the model
with nnvm.compiler.build_config(opt_level=opt_level):
graph, lib, params = nnvm.compiler.build(
net, target, shape={"data": data_shape}, params=params)
with relay.build_config(opt_level=opt_level):
graph, lib, params = relay.build(
net, target, params=params)
# same the model artifacts
lib.save(os.path.join(target_dir, "deploy_lib.o"))
cc.create_shared(os.path.join(target_dir, "deploy_lib.so"),
Expand All @@ -51,7 +49,7 @@ cc.create_shared(os.path.join(target_dir, "deploy_lib.so"),
with open(os.path.join(target_dir, "deploy_graph.json"), "w") as fo:
fo.write(graph.json())
with open(os.path.join(target_dir,"deploy_param.params"), "wb") as fo:
fo.write(nnvm.compiler.save_param_dict(params))
fo.write(relay.save_param_dict(params))
```

Now, we need to input the artifacts to create and run the *Graph Runtime* to detect our input cat image
Expand Down Expand Up @@ -113,7 +111,7 @@ and the model correctly predicts the input image as **tiger cat**.

Please follow TVM [installations](https://docs.tvm.ai/install/index.html), `export TVM_HOME=/path/to/tvm` and add `libtvm_runtime` to your `LD_LIBRARY_PATH`.

*Note:* To run the end-to-end examples and tests, `tvm`, `nnvm` and `topi` need to be added to your `PYTHONPATH` or it's automatic via an Anaconda environment when it is installed individually.
*Note:* To run the end-to-end examples and tests, `tvm` and `topi` need to be added to your `PYTHONPATH` or it's automatic via an Anaconda environment when it is installed individually.

## Supported TVM Functionalities

Expand Down
6 changes: 3 additions & 3 deletions rust/frontend/examples/resnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
## Resnet example

This end-to-end example shows how to:
* build `Resnet 18` with `tvm` and `nnvm` from Python
* build `Resnet 18` with `tvm` from Python
* use the provided Rust frontend API to test for an input image

To run the example with pretrained resnet weights, first `tvm`, `nnvm` and `mxnet` must be installed for the python build. To install mxnet for cpu, run `pip install mxnet`
and to install `tvm` and `nnvm` with `llvm` follow the [TVM installation guide](https://docs.tvm.ai/install/index.html).
To run the example with pretrained resnet weights, first `tvm` and `mxnet` must be installed for the python build. To install mxnet for cpu, run `pip install mxnet`
and to install `tvm` with `llvm` follow the [TVM installation guide](https://docs.tvm.ai/install/index.html).

* **Build the example**: `cargo build

Expand Down
2 changes: 1 addition & 1 deletion rust/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ license = "Apache-2.0"
description = "A static TVM runtime"
repository = "https://github.com/apache/incubator-tvm"
readme = "README.md"
keywords = ["tvm", "nnvm"]
keywords = ["tvm"]
categories = ["api-bindings", "science"]
authors = ["TVM Contributors"]
edition = "2018"
Expand Down
2 changes: 1 addition & 1 deletion rust/runtime/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ named!(
)
);

/// Loads a param dict saved using `nnvm.compiler.save_param_dict`.
/// Loads a param dict saved using `relay.save_param_dict`.
pub fn load_param_dict(bytes: &[u8]) -> Result<HashMap<String, Tensor>, GraphFormatError> {
if let Ok((remaining_bytes, param_dict)) = parse_param_dict(bytes) {
if remaining_bytes.len() == 0 {
Expand Down
2 changes: 1 addition & 1 deletion rust/runtime/src/threading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ pub(crate) fn sgx_join_threads() {
ocall_packed!("__sgx_thread_group_join__", 0);
}

// @see https://github.com/apache/incubator-tvm/issues/988 for information on why this function is used.
// @see issue 988 for information on why this function is used.
#[no_mangle]
pub extern "C" fn TVMBackendParallelBarrier(_task_id: usize, penv: *const TVMParallelGroupEnv) {
let barrier: &Arc<Barrier> = unsafe { &*((*penv).sync_handle as *const Arc<Barrier>) };
Expand Down

0 comments on commit 9384353

Please sign in to comment.