Skip to content

Commit 1e36f30

Browse files
tqchenzhiics
authored andcommitted
Update legacy places from nnvm to relay. (apache#4535)
* Update legacy places from nnvm to relay. This PR prepares the current mainline to remove nnvm compiler dep. * remove legacy stage
1 parent 5a0301e commit 1e36f30

File tree

28 files changed

+133
-185
lines changed

28 files changed

+133
-185
lines changed

Jenkinsfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,15 @@ stage('Integration Test') {
309309
}
310310
}
311311
},
312-
'legacy: GPU': {
312+
'docs: GPU': {
313313
node('GPU') {
314-
ws(per_exec_ws("tvm/legacy-python-gpu")) {
314+
ws(per_exec_ws("tvm/docs-python-gpu")) {
315315
init_git()
316316
unpack_lib('gpu', tvm_multilib)
317317
timeout(time: max_time, unit: 'MINUTES') {
318-
sh "${docker_run} ${ci_gpu} ./tests/scripts/task_python_legacy.sh"
318+
sh "${docker_run} ${ci_gpu} ./tests/scripts/task_python_docs.sh"
319319
}
320+
pack_lib('mydocs', 'docs.tgz')
320321
}
321322
}
322323
}

apps/benchmark/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def get_network(name, batch_size, dtype='float32'):
3434
3535
Returns
3636
-------
37-
net: nnvm.symbol
38-
The NNVM symbol of network definition
37+
net: relay.Module
38+
The relay function of network definition
3939
params: dict
4040
The random parameters for benchmark
4141
input_shape: tuple

apps/bundle_deploy/Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
# under the License.
1717

1818
# Makefile Example to bundle TVM modules.
19+
1920
TVM_ROOT=$(shell cd ../..; pwd)
20-
NNVM_PATH=nnvm
2121
DMLC_CORE=${TVM_ROOT}/3rdparty/dmlc-core
22-
PKG_CFLAGS = -std=c++14 -Oz -fPIC\
22+
PKG_CFLAGS = -std=c++14 -O2 -fPIC\
2323
-I${TVM_ROOT}/include\
2424
-I${DMLC_CORE}/include\
25-
-I${TVM_ROOT}/3rdparty/dlpack/include\
25+
-I${TVM_ROOT}/3rdparty/dlpack/include
2626

27-
PKG_LDFLAGS = -L${TVM_ROOT}/build
27+
PKG_LDFLAGS = -pthread
2828

2929
build_dir := build
3030

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

3434
$(build_dir)/demo: demo.cc
3535
@mkdir -p $(@D)
36-
$(CXX) $(PKG_CFLAGS) -o $@ $^
36+
$(CXX) $(PKG_CFLAGS) -o $@ $^ -ldl
3737

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

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

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

5555
clean:
5656
rm -r $(build_dir)

apps/bundle_deploy/build_model.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818

1919
import argparse
2020
import os
21-
import nnvm.compiler
22-
import nnvm.testing
21+
from tvm import relay
2322
import tvm
2423
import logging
2524

@@ -34,22 +33,24 @@ def main():
3433
dshape = (1, 3, 224, 224)
3534
from mxnet.gluon.model_zoo.vision import get_model
3635
block = get_model('mobilenet0.25', pretrained=True)
37-
net, params = nnvm.frontend.from_mxnet(block)
38-
net = nnvm.sym.softmax(net)
36+
shape_dict = {'data': dshape}
37+
mod, params = relay.frontend.from_mxnet(block, shape_dict)
38+
func = mod["main"]
39+
func = relay.Function(func.params, relay.nn.softmax(func.body), None, func.type_params, func.attrs)
40+
41+
with relay.build_config(opt_level=3):
42+
graph, lib, params = relay.build(
43+
func, 'llvm --system-lib', params=params)
3944

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

4849
lib.save(os.path.join(build_dir, 'model.o'))
4950
with open(os.path.join(build_dir, 'graph.json'), 'w') as f_graph_json:
50-
f_graph_json.write(graph.json())
51+
f_graph_json.write(graph)
5152
with open(os.path.join(build_dir, 'params.bin'), 'wb') as f_params:
52-
f_params.write(nnvm.compiler.save_param_dict(params))
53+
f_params.write(relay.save_param_dict(params))
5354

5455

5556
if __name__ == '__main__':

apps/bundle_deploy/bundle.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* to you under the Apache License, Version 2.0 (the
77
* "License"); you may not use this file except in compliance
88
* with the License. You may obtain a copy of the License at
9-
*
9+
*
1010
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
11+
*
1212
* Unless required by applicable law or agreed to in writing,
1313
* software distributed under the License is distributed on an
1414
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -26,7 +26,9 @@ extern unsigned int build_graph_json_len;
2626
extern unsigned char build_params_bin[];
2727
extern unsigned int build_params_bin_len;
2828

29-
#define TVM_BUNDLE_FUNCTION __attribute__((visibility("default"))) extern "C"
29+
#define TVM_BUNDLE_FUNCTION __attribute__((visibility("default")))
30+
31+
extern "C" {
3032

3133
TVM_BUNDLE_FUNCTION void *tvm_runtime_create() {
3234
const std::string json_data(&build_graph_json[0],
@@ -64,3 +66,4 @@ TVM_BUNDLE_FUNCTION void tvm_runtime_get_output(void *handle, int index,
6466
reinterpret_cast<tvm::runtime::Module *>(handle)->GetFunction("get_output")(
6567
index, reinterpret_cast<DLTensor *>(tensor));
6668
}
69+
}

apps/bundle_deploy/runtime.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
#include "../../src/runtime/c_runtime_api.cc"
2626
#include "../../src/runtime/cpu_device_api.cc"
2727
#include "../../src/runtime/workspace_pool.cc"
28-
#include "../../src/runtime/module_util.cc"
28+
#include "../../src/runtime/library_module.cc"
2929
#include "../../src/runtime/module.cc"
3030
#include "../../src/runtime/registry.cc"
3131
#include "../../src/runtime/file_util.cc"
3232
#include "../../src/runtime/threading_backend.cc"
3333
#include "../../src/runtime/thread_pool.cc"
3434
#include "../../src/runtime/ndarray.cc"
3535
#include "../../src/runtime/object.cc"
36-
#include "../../src/runtime/system_lib_module.cc"
36+
#include "../../src/runtime/system_library.cc"
3737
#include "../../src/runtime/graph/graph_runtime.cc"

apps/howto_deploy/Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717

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

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

28-
PKG_LDFLAGS = -L${TVM_ROOT}/build -ldl -lpthread
27+
PKG_LDFLAGS = -L${TVM_ROOT}/build -ldl -pthread
2928

3029
.PHONY: clean all
3130

@@ -39,7 +38,7 @@ lib/libtvm_runtime_pack.o: tvm_runtime_pack.cc
3938
# The code library built by TVM
4039
lib/test_addone_sys.o: prepare_test_libs.py
4140
@mkdir -p $(@D)
42-
python prepare_test_libs.py
41+
python3 prepare_test_libs.py
4342

4443
# Deploy using the all in one TVM package library
4544
lib/cpp_deploy_pack: cpp_deploy.cc lib/test_addone_sys.o lib/libtvm_runtime_pack.o

apps/rocm_rpc/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
ROCM_PATH=/opt/rocm
2020

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

2524
PKG_CFLAGS = -std=c++11 -O2 -fPIC\

apps/sgx/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ mkdir build && cd build
4949
cmake .. -DUSE_LLVM=ON -DUSE_SGX=/opt/sgxsdk -DRUST_SGX_SDK=/opt/rust-sgx-sdk
5050
make -j4
5151
cd ..
52-
pip install -e python -e topi/python -e nnvm/python
52+
pip install -e python -e topi/python
5353
cd apps/sgx
5454
```
5555

apps/sgx/enclave/src/build_model.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import os
2121
from os import path as osp
2222

23-
import nnvm.compiler
24-
import nnvm.testing
23+
from tvm import relay
24+
from tvm.relay import testing
2525
import tvm
2626

2727

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

33-
# from tutorials/nnvm_quick_start.py
3433
dshape = (1, 3, 224, 224)
35-
net, params = nnvm.testing.resnet.get_workload(
34+
net, params = relay.testing.resnet.get_workload(
3635
layers=18, batch_size=dshape[0], image_shape=dshape[1:])
3736

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

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

4645
lib.save(osp.join(build_dir, 'model.bc'))
4746
with open(osp.join(build_dir, 'graph.json'), 'w') as f_graph_json:
48-
f_graph_json.write(graph.json())
47+
f_graph_json.write(graph)
4948
with open(osp.join(build_dir, 'params.bin'), 'wb') as f_params:
50-
f_params.write(nnvm.compiler.save_param_dict(params))
49+
f_params.write(relay.save_param_dict(params))
5150

5251

5352
if __name__ == '__main__':

0 commit comments

Comments
 (0)