Skip to content
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
5a070b7
finish framework
Oct 9, 2022
2b51167
add autotvm and auto-scheduler tuner
Oct 10, 2022
2707a61
add python deploy api
Oct 10, 2022
67aafe6
add SDK net(WIP
Oct 11, 2022
8bc613a
add sdk support
Oct 13, 2022
cf37141
support det, support vm
Oct 14, 2022
cfecea4
fix vm sdk
Oct 17, 2022
25c9cf3
support two stage detector
Oct 17, 2022
0f2ec5b
add instance seg support
Oct 18, 2022
5d54cff
add docstring
Oct 18, 2022
7f0229b
update docs and ut
Oct 19, 2022
cf8ebbb
add quantize
Oct 21, 2022
f70bc07
update doc
Oct 27, 2022
6972a52
update docs
Oct 28, 2022
07dbafb
merge master
Oct 31, 2022
81ee509
synchronize stream
Nov 2, 2022
36e0e34
support dlpack
Oct 31, 2022
611adf9
remove submodule
Oct 31, 2022
305d196
fix stride
Oct 31, 2022
b3ec0cb
add alignment
Nov 1, 2022
f0306bd
support dlpack
Nov 2, 2022
677bcec
remove submodule
Nov 7, 2022
e441a7a
replace exclusive_scan
Nov 8, 2022
e28e471
add backend check
Nov 8, 2022
dd9bcec
add build script
Nov 16, 2022
8542584
fix comment
Nov 17, 2022
b9c967d
add ci
Nov 17, 2022
57182d3
fix ci
Nov 18, 2022
3a27a60
ci fix2
Nov 18, 2022
5c0d753
update build script
grimoire Nov 20, 2022
ab76486
update ci
grimoire Nov 20, 2022
afc723e
add pytest
grimoire Nov 20, 2022
42d3525
update sed command
Nov 21, 2022
8a76030
update sed again
Nov 21, 2022
97cebdd
add xgboost
Nov 21, 2022
f6aff47
remove tvm ut
Nov 21, 2022
e330be9
update ansor runner
Nov 24, 2022
8ec96a3
add stream sync
Nov 25, 2022
0360ffd
fix topk
Nov 25, 2022
56f02d5
sync default stream
Nov 25, 2022
d359573
update readme
Dec 5, 2022
0315868
solve conflict
Dec 7, 2022
270a9f6
fix tvm net
Dec 7, 2022
ffe2331
fix window
Dec 9, 2022
411abcb
merge master
grimoire Dec 10, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .codespell_ignore.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
cann
CANN
nd
41 changes: 41 additions & 0 deletions .github/workflows/backend-tvm.yml
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()'
12 changes: 6 additions & 6 deletions .gitmodules
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
26 changes: 14 additions & 12 deletions README.md

Large diffs are not rendered by default.

26 changes: 14 additions & 12 deletions README_zh-CN.md

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions cmake/modules/FindTVM.cmake
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()
1 change: 1 addition & 0 deletions configs/_base_/backends/tvm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
backend_config = dict(type='tvm')
12 changes: 12 additions & 0 deletions configs/mmcls/classification_tvm-ansor_static-224x224.py
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 configs/mmcls/classification_tvm-autotvm-int8_static-224x224.py
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 configs/mmcls/classification_tvm-autotvm_static-224x224.py
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 configs/mmdet/detection/detection_tvm-ansor_static-800x1344.py
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 configs/mmdet/detection/detection_tvm-autotvm_static-300x300.py
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 configs/mmdet/detection/detection_tvm-autotvm_static-800x1344.py
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'),
))
])
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))
])
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'),
))
])
12 changes: 12 additions & 0 deletions configs/mmseg/segmentation_tvm-ansor_static-512x1024.py
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))
])
13 changes: 13 additions & 0 deletions configs/mmseg/segmentation_tvm-autotvm_static-512x1024.py
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')))
])
1 change: 1 addition & 0 deletions csrc/mmdeploy/core/tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace mmdeploy {
namespace framework {

using TensorShape = std::vector<int64_t>;

struct TensorDesc {
Device device;
DataType data_type{DataType::kFLOAT};
Expand Down
18 changes: 13 additions & 5 deletions csrc/mmdeploy/device/cpu/cpu_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ class CpuHostMemory : public NonCopyable {
public:
CpuHostMemory() : size_(), data_(), owned_data_{false} {}
Result<void> Init(size_t size, size_t alignment) {
if (alignment != 1) {
return Status(eNotSupported);
}
data_ = std::malloc(size);
size_t space = (size + alignment - 1) / alignment * alignment;
#ifdef _MSC_VER
data_ = _aligned_malloc(space, alignment);
#else
data_ = std::aligned_alloc(alignment, space);
#endif
if (!data_) {
return Status(eOutOfMemory);
}
aligned_data_ = data_;
size_ = size;
owned_data_ = true;
return success();
Expand All @@ -38,7 +41,11 @@ class CpuHostMemory : public NonCopyable {
~CpuHostMemory() {
if (data_) {
if (owned_data_) {
#ifdef _MSC_VER
_aligned_free(data_);
#else
std::free(data_);
#endif
owned_data_ = false;
}
data_ = nullptr;
Expand All @@ -47,11 +54,12 @@ class CpuHostMemory : public NonCopyable {
size_ = 0;
}
size_t size() const { return size_; }
void* data() const { return data_; }
void* data() const { return owned_data_ ? aligned_data_ : data_; }

private:
size_t size_;
void* data_;
void* aligned_data_{nullptr};
bool owned_data_;
std::shared_ptr<void> external_;
};
Expand Down
2 changes: 1 addition & 1 deletion csrc/mmdeploy/device/cuda/cuda_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class CudaDeviceMemory : public NonCopyable {
public:
explicit CudaDeviceMemory(int device_id) : device_id_(device_id), size_(), owned_block_() {}
Result<void> Init(size_t size, Allocator allocator, size_t alignment, uint64_t flags) {
if (alignment != 1) {
if (alignment > 256 || 256 % alignment != 0) {
return Status(eNotSupported);
}
allocator_ = std::move(allocator);
Expand Down
4 changes: 4 additions & 0 deletions csrc/mmdeploy/net/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ if ("coreml" IN_LIST MMDEPLOY_TARGET_BACKENDS)
add_subdirectory(coreml)
endif ()

if ("tvm" IN_LIST MMDEPLOY_TARGET_BACKENDS)
add_subdirectory(tvm)
endif ()

if ("rknn" IN_LIST MMDEPLOY_TARGET_BACKENDS)
add_subdirectory(rknn)
endif ()
Expand Down
11 changes: 11 additions & 0 deletions csrc/mmdeploy/net/tvm/CMakeLists.txt
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})
Loading