-
Notifications
You must be signed in to change notification settings - Fork 675
[Enhancement] Support tvm #1216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 44 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
5a070b7
finish framework
2b51167
add autotvm and auto-scheduler tuner
2707a61
add python deploy api
67aafe6
add SDK net(WIP
8bc613a
add sdk support
cf37141
support det, support vm
cfecea4
fix vm sdk
25c9cf3
support two stage detector
0f2ec5b
add instance seg support
5d54cff
add docstring
7f0229b
update docs and ut
cf8ebbb
add quantize
f70bc07
update doc
6972a52
update docs
07dbafb
merge master
81ee509
synchronize stream
36e0e34
support dlpack
611adf9
remove submodule
305d196
fix stride
b3ec0cb
add alignment
f0306bd
support dlpack
677bcec
remove submodule
e441a7a
replace exclusive_scan
e28e471
add backend check
dd9bcec
add build script
8542584
fix comment
b9c967d
add ci
57182d3
fix ci
3a27a60
ci fix2
5c0d753
update build script
grimoire ab76486
update ci
grimoire afc723e
add pytest
grimoire 42d3525
update sed command
8a76030
update sed again
97cebdd
add xgboost
f6aff47
remove tvm ut
e330be9
update ansor runner
8ec96a3
add stream sync
0360ffd
fix topk
56f02d5
sync default stream
d359573
update readme
0315868
solve conflict
270a9f6
fix tvm net
ffe2331
fix window
411abcb
merge master
grimoire File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,2 +1,3 @@ | ||
cann | ||
CANN | ||
nd |
This file contains hidden or 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,41 @@ | ||
name: backend-tvm | ||
|
||
on: | ||
push: | ||
paths-ignore: | ||
- "demo/**" | ||
- "tools/**" | ||
|
||
pull_request: | ||
paths-ignore: | ||
- "demo/**" | ||
- "tools/**" | ||
- "docs/**" | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
script_install: | ||
runs-on: ubuntu-20.04 | ||
strategy: | ||
matrix: | ||
python-version: [3.7] | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
with: | ||
submodules: 'recursive' | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install mmdeploy | ||
run: | | ||
python3 tools/scripts/build_ubuntu_x64_tvm.py | ||
source ~/mmdeploy.env | ||
python3 -m pip install torch==1.8.2 torchvision==0.9.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cpu | ||
python3 -m pip install mmcv-full==1.5.1 -f https://download.openmmlab.com/mmcv/dist/cpu/torch1.8.0/index.html | ||
python3 -m pip install decorator psutil scipy attrs tornado pytest | ||
python3 -c 'import mmdeploy.apis.tvm as tvm_api; assert tvm_api.is_available()' |
This file contains hidden or 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,9 +1,9 @@ | ||
[submodule "third_party/cub"] | ||
path = third_party/cub | ||
url = https://github.com/NVIDIA/cub.git | ||
path = third_party/cub | ||
url = https://github.com/NVIDIA/cub.git | ||
[submodule "third_party/pybind11"] | ||
path = third_party/pybind11 | ||
url = https://github.com/pybind/pybind11.git | ||
path = third_party/pybind11 | ||
url = https://github.com/pybind/pybind11.git | ||
[submodule "third_party/spdlog"] | ||
path = third_party/spdlog | ||
url = https://github.com/gabime/spdlog.git | ||
path = third_party/spdlog | ||
url = https://github.com/gabime/spdlog.git |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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,47 @@ | ||
# Copyright (c) OpenMMLab. All rights reserved. | ||
|
||
if (NOT DEFINED TVM_DIR) | ||
set(TVM_DIR $ENV{TVM_DIR}) | ||
endif () | ||
if (NOT TVM_DIR) | ||
message(FATAL_ERROR "Please set TVM_DIR with cmake -D option.") | ||
endif() | ||
|
||
find_path( | ||
TVM_INCLUDE_DIR tvm/runtime/c_runtime_api.h | ||
HINTS ${TVM_DIR} | ||
PATH_SUFFIXES include) | ||
|
||
find_path( | ||
DMLC_CORE_INCLUDE_DIR dmlc/io.h | ||
HINTS ${TVM_DIR}/3rdparty/dmlc-core | ||
PATH_SUFFIXES include) | ||
|
||
find_path( | ||
DLPACK_INCLUDE_DIR dlpack/dlpack.h | ||
HINTS ${TVM_DIR}/3rdparty/dlpack | ||
PATH_SUFFIXES include) | ||
|
||
find_library( | ||
TVM_LIBRARY_PATH tvm_runtime | ||
HINTS ${TVM_DIR} | ||
PATH_SUFFIXES build lib build/Release build/Debug) | ||
if (NOT (TVM_INCLUDE_DIR AND DMLC_CORE_INCLUDE_DIR AND DLPACK_INCLUDE_DIR AND TVM_LIBRARY_PATH)) | ||
message(FATAL_ERROR "Couldn't find tvm in TVM_DIR: " | ||
"${TVM_DIR}, please check if the path is correct.") | ||
endif() | ||
|
||
add_library(tvm_runtime SHARED IMPORTED) | ||
set_property(TARGET tvm_runtime APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) | ||
if (MSVC) | ||
set_target_properties(tvm_runtime PROPERTIES | ||
IMPORTED_IMPLIB_RELEASE ${TVM_LIBRARY_PATH} | ||
INTERFACE_INCLUDE_DIRECTORIES ${TVM_INCLUDE_DIR} ${DMLC_CORE_INCLUDE_DIR} ${DLPACK_INCLUDE_DIR} | ||
) | ||
|
||
else() | ||
set_target_properties(tvm_runtime PROPERTIES | ||
IMPORTED_LOCATION_RELEASE ${TVM_LIBRARY_PATH} | ||
INTERFACE_INCLUDE_DIRECTORIES ${TVM_INCLUDE_DIR} ${DMLC_CORE_INCLUDE_DIR} ${DLPACK_INCLUDE_DIR} | ||
) | ||
endif() |
This file contains hidden or 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 @@ | ||
backend_config = dict(type='tvm') |
This file contains hidden or 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,12 @@ | ||
_base_ = ['./classification_static.py', '../_base_/backends/tvm.py'] | ||
|
||
onnx_config = dict(input_shape=[224, 224]) | ||
backend_config = dict(model_inputs=[ | ||
dict( | ||
shape=dict(input=[1, 3, 224, 224]), | ||
dtype=dict(input='float32'), | ||
tuner=dict( | ||
type='AutoScheduleTuner', | ||
log_file='tvm_tune_log.log', | ||
num_measure_trials=2000)) | ||
]) |
16 changes: 16 additions & 0 deletions
16
configs/mmcls/classification_tvm-autotvm-int8_static-224x224.py
This file contains hidden or 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,16 @@ | ||
_base_ = ['./classification_tvm-autotvm_static-224x224.py'] | ||
|
||
calib_config = dict(create_calib=True, calib_file='calib_data.h5') | ||
backend_config = dict(model_inputs=[ | ||
dict( | ||
shape=dict(input=[1, 3, 224, 224]), | ||
dtype=dict(input='float32'), | ||
tuner=dict( | ||
type='AutoTVMTuner', | ||
log_file='tvm_tune_log.log', | ||
n_trial=1000, | ||
tuner=dict(type='XGBTuner'), | ||
), | ||
qconfig=dict(calibrate_mode='kl_divergence', weight_scale='max'), | ||
) | ||
]) |
13 changes: 13 additions & 0 deletions
13
configs/mmcls/classification_tvm-autotvm_static-224x224.py
This file contains hidden or 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 @@ | ||
_base_ = ['./classification_static.py', '../_base_/backends/tvm.py'] | ||
|
||
onnx_config = dict(input_shape=[224, 224]) | ||
backend_config = dict(model_inputs=[ | ||
dict( | ||
shape=dict(input=[1, 3, 224, 224]), | ||
dtype=dict(input='float32'), | ||
tuner=dict( | ||
type='AutoTVMTuner', | ||
log_file='tvm_tune_log.log', | ||
n_trial=1000, | ||
tuner=dict(type='XGBTuner'))) | ||
]) |
13 changes: 13 additions & 0 deletions
13
configs/mmdet/detection/detection_tvm-ansor_static-800x1344.py
This file contains hidden or 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 @@ | ||
_base_ = ['../_base_/base_static.py', '../../_base_/backends/tvm.py'] | ||
|
||
onnx_config = dict(input_shape=[1344, 800]) | ||
backend_config = dict(model_inputs=[ | ||
dict( | ||
use_vm=True, | ||
shape=dict(input=[1, 3, 800, 1344]), | ||
dtype=dict(input='float32'), | ||
tuner=dict( | ||
type='AutoScheduleTuner', | ||
log_file='tvm_tune_log.log', | ||
num_measure_trials=2000)) | ||
]) |
15 changes: 15 additions & 0 deletions
15
configs/mmdet/detection/detection_tvm-autotvm_static-300x300.py
This file contains hidden or 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,15 @@ | ||
_base_ = ['../_base_/base_static.py', '../../_base_/backends/tvm.py'] | ||
|
||
onnx_config = dict(input_shape=[300, 300]) | ||
backend_config = dict(model_inputs=[ | ||
dict( | ||
use_vm=True, | ||
shape=dict(input=[1, 3, 300, 300]), | ||
dtype=dict(input='float32'), | ||
tuner=dict( | ||
type='AutoTVMTuner', | ||
log_file='tvm_tune_log.log', | ||
n_trial=1000, | ||
tuner=dict(type='XGBTuner'), | ||
)) | ||
]) |
15 changes: 15 additions & 0 deletions
15
configs/mmdet/detection/detection_tvm-autotvm_static-800x1344.py
This file contains hidden or 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,15 @@ | ||
_base_ = ['../_base_/base_static.py', '../../_base_/backends/tvm.py'] | ||
|
||
onnx_config = dict(input_shape=[1344, 800]) | ||
backend_config = dict(model_inputs=[ | ||
dict( | ||
use_vm=True, | ||
shape=dict(input=[1, 3, 800, 1344]), | ||
dtype=dict(input='float32'), | ||
tuner=dict( | ||
type='AutoTVMTuner', | ||
log_file='tvm_tune_log.log', | ||
n_trial=1000, | ||
tuner=dict(type='XGBTuner'), | ||
)) | ||
]) |
15 changes: 15 additions & 0 deletions
15
configs/mmdet/instance-seg/instance-seg_tvm-ansor_static-800x1344.py
This file contains hidden or 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,15 @@ | ||
_base_ = [ | ||
'../_base_/base_instance-seg_static.py', '../../_base_/backends/tvm.py' | ||
] | ||
|
||
onnx_config = dict(input_shape=[1344, 800]) | ||
backend_config = dict(model_inputs=[ | ||
dict( | ||
use_vm=True, | ||
shape=dict(input=[1, 3, 800, 1344]), | ||
dtype=dict(input='float32'), | ||
tuner=dict( | ||
type='AutoScheduleTuner', | ||
log_file='tvm_tune_log.log', | ||
num_measure_trials=20000)) | ||
]) |
17 changes: 17 additions & 0 deletions
17
configs/mmdet/instance-seg/instance-seg_tvm-autotvm_static-800x1344.py
This file contains hidden or 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,17 @@ | ||
_base_ = [ | ||
'../_base_/base_instance-seg_static.py', '../../_base_/backends/tvm.py' | ||
] | ||
|
||
onnx_config = dict(input_shape=[1344, 800]) | ||
backend_config = dict(model_inputs=[ | ||
dict( | ||
use_vm=True, | ||
shape=dict(input=[1, 3, 800, 1344]), | ||
dtype=dict(input='float32'), | ||
tuner=dict( | ||
type='AutoTVMTuner', | ||
log_file='tvm_tune_log.log', | ||
n_trial=10000, | ||
tuner=dict(type='XGBTuner'), | ||
)) | ||
]) |
This file contains hidden or 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,12 @@ | ||
_base_ = ['./segmentation_static.py', '../_base_/backends/tvm.py'] | ||
|
||
onnx_config = dict(input_shape=[1024, 512]) | ||
backend_config = dict(model_inputs=[ | ||
dict( | ||
shape=dict(input=[1, 3, 512, 1024]), | ||
dtype=dict(input='float32'), | ||
tuner=dict( | ||
type='AutoScheduleTuner', | ||
log_file='tvm_tune_log.log', | ||
num_measure_trials=2000)) | ||
]) |
This file contains hidden or 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 @@ | ||
_base_ = ['./segmentation_static.py', '../_base_/backends/tvm.py'] | ||
|
||
onnx_config = dict(input_shape=[1024, 512]) | ||
backend_config = dict(model_inputs=[ | ||
dict( | ||
shape=dict(input=[1, 3, 512, 1024]), | ||
dtype=dict(input='float32'), | ||
tuner=dict( | ||
type='AutoTVMTuner', | ||
log_file='tvm_tune_log.log', | ||
n_trial=1000, | ||
tuner=dict(type='XGBTuner'))) | ||
]) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,11 @@ | ||
# Copyright (c) OpenMMLab. All rights reserved. | ||
|
||
project(mmdeploy_tvm_net) | ||
|
||
include(${CMAKE_SOURCE_DIR}/cmake/modules/FindTVM.cmake) | ||
|
||
mmdeploy_add_module(${PROJECT_NAME} tvm_net.cpp) | ||
target_include_directories(${PROJECT_NAME} PRIVATE ${TVM_INCLUDE_DIR} ${DLPACK_INCLUDE_DIR} ${DMLC_CORE_INCLUDE_DIR}) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE tvm_runtime mmdeploy_dlpack_utils) | ||
|
||
add_library(mmdeploy::tvm_net ALIAS ${PROJECT_NAME}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.