Skip to content

Commit 0e65606

Browse files
authored
[Enhancement] Support tvm 1.x (#1531)
* support tvm 1.x * fix tvm sdk export
1 parent 6e91614 commit 0e65606

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2316
-45
lines changed

.codespell_ignore.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
cann
22
CANN
3+
nd

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,18 @@ The supported Device-Platform-InferenceBackend matrix is presented as following,
5858

5959
The benchmark can be found from [here](docs/en/03-benchmark/benchmark.md)
6060

61-
| Device / Platform | Linux | Windows | macOS | Android |
62-
| ----------------- | --------------------------------------------------------------- | --------------------------------------- | -------- | ---------------- |
63-
| x86_64 CPU | ✔️ONNX Runtime<br>✔️pplnn<br>✔️ncnn<br>✔️OpenVINO<br>✔️LibTorch | ✔️ONNX Runtime<br>✔️OpenVINO | - | - |
64-
| ARM CPU | ✔️ncnn | - | - | ✔️ncnn |
65-
| RISC-V | ✔️ncnn | - | - | - |
66-
| NVIDIA GPU | ✔️ONNX Runtime<br>✔️TensorRT<br>✔️pplnn<br>✔️LibTorch | ✔️ONNX Runtime<br>✔️TensorRT<br>✔️pplnn | - | - |
67-
| NVIDIA Jetson | ✔️TensorRT | ✔️TensorRT | - | - |
68-
| Huawei ascend310 | ✔️CANN | - | - | - |
69-
| Rockchip | ✔️RKNN | - | - | - |
70-
| Apple M1 | - | - | ✔️CoreML | - |
71-
| Adreno GPU | - | - | - | ✔️ncnn<br>✔️SNPE |
72-
| Hexagon DSP | - | - | - | ✔️SNPE |
61+
| Device / Platform | Linux | Windows | macOS | Android |
62+
| ----------------- | ------------------------------------------------------------------------ | --------------------------------------- | -------- | ---------------- |
63+
| x86_64 CPU | ✔️ONNX Runtime<br>✔️pplnn<br>✔️ncnn<br>✔️OpenVINO<br>✔️LibTorch<br>✔️TVM | ✔️ONNX Runtime<br>✔️OpenVINO | - | - |
64+
| ARM CPU | ✔️ncnn | - | - | ✔️ncnn |
65+
| RISC-V | ✔️ncnn | - | - | - |
66+
| NVIDIA GPU | ✔️ONNX Runtime<br>✔️TensorRT<br>✔️pplnn<br>✔️LibTorch<br>✔️TVM | ✔️ONNX Runtime<br>✔️TensorRT<br>✔️pplnn | - | - |
67+
| NVIDIA Jetson | ✔️TensorRT | ✔️TensorRT | - | - |
68+
| Huawei ascend310 | ✔️CANN | - | - | - |
69+
| Rockchip | ✔️RKNN | - | - | - |
70+
| Apple M1 | - | - | ✔️CoreML | - |
71+
| Adreno GPU | - | - | - | ✔️ncnn<br>✔️SNPE |
72+
| Hexagon DSP | - | - | - | ✔️SNPE |
7373

7474
### Efficient and scalable C/C++ SDK Framework
7575

README_zh-CN.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,18 @@ MMDeploy 是 [OpenMMLab](https://openmmlab.com/) 模型部署工具箱,**为
5656

5757
支持的设备平台和推理引擎如下表所示。benchmark请参考[这里](docs/zh_cn/03-benchmark/benchmark.md)
5858

59-
| Device / Platform | Linux | Windows | macOS | Android |
60-
| ----------------- | --------------------------------------------------------------- | --------------------------------------- | -------- | ---------------- |
61-
| x86_64 CPU | ✔️ONNX Runtime<br>✔️pplnn<br>✔️ncnn<br>✔️OpenVINO<br>✔️LibTorch | ✔️ONNX Runtime<br>✔️OpenVINO | - | - |
62-
| ARM CPU | ✔️ncnn | - | - | ✔️ncnn |
63-
| RISC-V | ✔️ncnn | - | - | - |
64-
| NVIDIA GPU | ✔️ONNX Runtime<br>✔️TensorRT<br>✔️pplnn<br>✔️LibTorch | ✔️ONNX Runtime<br>✔️TensorRT<br>✔️pplnn | - | - |
65-
| NVIDIA Jetson | ✔️TensorRT | ✔️TensorRT | - | - |
66-
| Huawei ascend310 | ✔️CANN | - | - | - |
67-
| Rockchip | ✔️RKNN | - | - | - |
68-
| Apple M1 | - | - | ✔️CoreML | - |
69-
| Adreno GPU | - | - | - | ✔️ncnn<br>✔️SNPE |
70-
| Hexagon DSP | - | - | - | ✔️SNPE |
59+
| Device / Platform | Linux | Windows | macOS | Android |
60+
| ----------------- | ------------------------------------------------------------------------ | --------------------------------------- | -------- | ---------------- |
61+
| x86_64 CPU | ✔️ONNX Runtime<br>✔️pplnn<br>✔️ncnn<br>✔️OpenVINO<br>✔️LibTorch<br>✔️TVM | ✔️ONNX Runtime<br>✔️OpenVINO | - | - |
62+
| ARM CPU | ✔️ncnn | - | - | ✔️ncnn |
63+
| RISC-V | ✔️ncnn | - | - | - |
64+
| NVIDIA GPU | ✔️ONNX Runtime<br>✔️TensorRT<br>✔️pplnn<br>✔️LibTorch<br>✔️TVM | ✔️ONNX Runtime<br>✔️TensorRT<br>✔️pplnn | - | - |
65+
| NVIDIA Jetson | ✔️TensorRT | ✔️TensorRT | - | - |
66+
| Huawei ascend310 | ✔️CANN | - | - | - |
67+
| Rockchip | ✔️RKNN | - | - | - |
68+
| Apple M1 | - | - | ✔️CoreML | - |
69+
| Adreno GPU | - | - | - | ✔️ncnn<br>✔️SNPE |
70+
| Hexagon DSP | - | - | - | ✔️SNPE |
7171

7272
### SDK 可高度定制化
7373

cmake/modules/FindTVM.cmake

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright (c) OpenMMLab. All rights reserved.
2+
3+
if (NOT DEFINED TVM_DIR)
4+
set(TVM_DIR $ENV{TVM_DIR})
5+
endif ()
6+
if (NOT TVM_DIR)
7+
message(FATAL_ERROR "Please set TVM_DIR with cmake -D option.")
8+
endif()
9+
10+
find_path(
11+
TVM_INCLUDE_DIR tvm/runtime/c_runtime_api.h
12+
HINTS ${TVM_DIR}
13+
PATH_SUFFIXES include)
14+
15+
find_path(
16+
DMLC_CORE_INCLUDE_DIR dmlc/io.h
17+
HINTS ${TVM_DIR}/3rdparty/dmlc-core
18+
PATH_SUFFIXES include)
19+
20+
find_path(
21+
DLPACK_INCLUDE_DIR dlpack/dlpack.h
22+
HINTS ${TVM_DIR}/3rdparty/dlpack
23+
PATH_SUFFIXES include)
24+
25+
find_library(
26+
TVM_LIBRARY_PATH tvm_runtime
27+
HINTS ${TVM_DIR}
28+
PATH_SUFFIXES build lib build/${CMAKE_BUILD_TYPE})
29+
if (NOT (TVM_INCLUDE_DIR AND DMLC_CORE_INCLUDE_DIR AND DLPACK_INCLUDE_DIR AND TVM_LIBRARY_PATH))
30+
message(FATAL_ERROR "Couldn't find tvm in TVM_DIR: "
31+
"${TVM_DIR}, please check if the path is correct.")
32+
endif()
33+
34+
add_library(tvm_runtime SHARED IMPORTED)
35+
set_property(TARGET tvm_runtime APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
36+
if (MSVC)
37+
set_target_properties(tvm_runtime PROPERTIES
38+
IMPORTED_IMPLIB_RELEASE ${TVM_LIBRARY_PATH}
39+
INTERFACE_INCLUDE_DIRECTORIES ${TVM_INCLUDE_DIR} ${DMLC_CORE_INCLUDE_DIR} ${DLPACK_INCLUDE_DIR}
40+
)
41+
42+
else()
43+
set_target_properties(tvm_runtime PROPERTIES
44+
IMPORTED_LOCATION_RELEASE ${TVM_LIBRARY_PATH}
45+
INTERFACE_INCLUDE_DIRECTORIES ${TVM_INCLUDE_DIR} ${DMLC_CORE_INCLUDE_DIR} ${DLPACK_INCLUDE_DIR}
46+
)
47+
endif()

configs/_base_/backends/tvm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
backend_config = dict(type='tvm')
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
_base_ = ['./classification_static.py', '../_base_/backends/tvm.py']
2+
3+
onnx_config = dict(input_shape=[224, 224])
4+
backend_config = dict(model_inputs=[
5+
dict(
6+
shape=dict(input=[1, 3, 224, 224]),
7+
dtype=dict(input='float32'),
8+
tuner=dict(
9+
type='AutoScheduleTuner',
10+
log_file='tvm_tune_log.log',
11+
num_measure_trials=2000))
12+
])
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
_base_ = ['./classification_tvm-autotvm_static-224x224.py']
2+
3+
calib_config = dict(create_calib=True, calib_file='calib_data.h5')
4+
backend_config = dict(model_inputs=[
5+
dict(
6+
shape=dict(input=[1, 3, 224, 224]),
7+
dtype=dict(input='float32'),
8+
tuner=dict(
9+
type='AutoTVMTuner',
10+
log_file='tvm_tune_log.log',
11+
n_trial=1000,
12+
tuner=dict(type='XGBTuner'),
13+
),
14+
qconfig=dict(calibrate_mode='kl_divergence', weight_scale='max'),
15+
)
16+
])
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
_base_ = ['./classification_static.py', '../_base_/backends/tvm.py']
2+
3+
onnx_config = dict(input_shape=[224, 224])
4+
backend_config = dict(model_inputs=[
5+
dict(
6+
shape=dict(input=[1, 3, 224, 224]),
7+
dtype=dict(input='float32'),
8+
tuner=dict(
9+
type='AutoTVMTuner',
10+
log_file='tvm_tune_log.log',
11+
n_trial=1000,
12+
tuner=dict(type='XGBTuner'),
13+
))
14+
])
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
_base_ = ['../_base_/base_static.py', '../../_base_/backends/tvm.py']
2+
3+
onnx_config = dict(input_shape=[1344, 800])
4+
backend_config = dict(model_inputs=[
5+
dict(
6+
use_vm=True,
7+
shape=dict(input=[1, 3, 800, 1344]),
8+
dtype=dict(input='float32'),
9+
tuner=dict(
10+
type='AutoScheduleTuner',
11+
log_file='tvm_tune_log.log',
12+
num_measure_trials=2000))
13+
])
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
_base_ = ['../_base_/base_static.py', '../../_base_/backends/tvm.py']
2+
3+
onnx_config = dict(input_shape=[300, 300])
4+
backend_config = dict(model_inputs=[
5+
dict(
6+
use_vm=True,
7+
shape=dict(input=[1, 3, 300, 300]),
8+
dtype=dict(input='float32'),
9+
tuner=dict(
10+
type='AutoTVMTuner',
11+
log_file='tvm_tune_log.log',
12+
n_trial=1000,
13+
tuner=dict(type='XGBTuner'),
14+
))
15+
])

0 commit comments

Comments
 (0)