Skip to content

Commit 7cb4b9b

Browse files
author
q.yao
authored
[Enhancement] Support tvm (#1216)
* finish framework * add autotvm and auto-scheduler tuner * add python deploy api * add SDK net(WIP * add sdk support * support det, support vm * fix vm sdk * support two stage detector * add instance seg support * add docstring * update docs and ut * add quantize * update doc * update docs * synchronize stream * support dlpack * remove submodule * fix stride * add alignment * support dlpack * remove submodule * replace exclusive_scan * add backend check * add build script * fix comment * add ci * fix ci * ci fix2 * update build script * update ci * add pytest * update sed command * update sed again * add xgboost * remove tvm ut * update ansor runner * add stream sync * fix topk * sync default stream * fix tvm net * fix window
1 parent ac47cad commit 7cb4b9b

File tree

60 files changed

+2392
-55
lines changed

Some content is hidden

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

60 files changed

+2392
-55
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

.github/workflows/backend-tvm.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: backend-tvm
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- "demo/**"
7+
- "tools/**"
8+
9+
pull_request:
10+
paths-ignore:
11+
- "demo/**"
12+
- "tools/**"
13+
- "docs/**"
14+
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: true
18+
19+
jobs:
20+
script_install:
21+
runs-on: ubuntu-20.04
22+
strategy:
23+
matrix:
24+
python-version: [3.7]
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v3
28+
with:
29+
submodules: 'recursive'
30+
- name: Set up Python ${{ matrix.python-version }}
31+
uses: actions/setup-python@v2
32+
with:
33+
python-version: ${{ matrix.python-version }}
34+
- name: Install mmdeploy
35+
run: |
36+
python3 tools/scripts/build_ubuntu_x64_tvm.py
37+
source ~/mmdeploy.env
38+
python3 -m pip install torch==1.8.2 torchvision==0.9.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cpu
39+
python3 -m pip install mmcv-full==1.5.1 -f https://download.openmmlab.com/mmcv/dist/cpu/torch1.8.0/index.html
40+
python3 -m pip install decorator psutil scipy attrs tornado pytest
41+
python3 -c 'import mmdeploy.apis.tvm as tvm_api; assert tvm_api.is_available()'

.gitmodules

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[submodule "third_party/cub"]
2-
path = third_party/cub
3-
url = https://github.com/NVIDIA/cub.git
2+
path = third_party/cub
3+
url = https://github.com/NVIDIA/cub.git
44
[submodule "third_party/pybind11"]
5-
path = third_party/pybind11
6-
url = https://github.com/pybind/pybind11.git
5+
path = third_party/pybind11
6+
url = https://github.com/pybind/pybind11.git
77
[submodule "third_party/spdlog"]
8-
path = third_party/spdlog
9-
url = https://github.com/gabime/spdlog.git
8+
path = third_party/spdlog
9+
url = https://github.com/gabime/spdlog.git

README.md

Lines changed: 14 additions & 12 deletions
Large diffs are not rendered by default.

README_zh-CN.md

Lines changed: 14 additions & 12 deletions
Large diffs are not rendered by default.

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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
])

0 commit comments

Comments
 (0)