Skip to content

Commit 914f434

Browse files
grimoirePeterH0323
authored andcommitted
[Refactor][tools] Add prebuild tools. (open-mmlab#347)
* move to lib * optional import pytorch rewriter * reduce torch dependancy of tensorrt export * remove more mmcv support * fix pytest * remove mmcv logge * Add `mmdeploy.utils.logging` * Improve the common of the `get_logger` * Fix lint * onnxruntim add try catch to import wrapper if pytorch is available * Using `mmcv.utils.logging` in all files under `mmdeploy/codebase` * add __init__ * add prebuild tools * support windows * for comment * exit if failed * add exist * decouple * add tags * remove .mmdeploy_python * read python version from system * update windows config * update linux config * remote many * better build name * rename python tag * fix pyhon-tag * update window config * add env search * update tag * fix build without CUDA_TOOLKIT_ROOT_DIR Co-authored-by: HinGwenWoong <[email protected]>
1 parent a84e90e commit 914f434

File tree

37 files changed

+723
-153
lines changed

37 files changed

+723
-153
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ __pycache__/
55

66
# C extensions
77
*.so
8+
onnx2ncnn
89

910
# Distribution / packaging
1011
.Python

MANIFEST.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
include requirements/*.txt
2+
include mmdeploy/backend/ncnn/*.so
3+
include mmdeploy/backend/ncnn/*.dll
4+
include mmdeploy/backend/ncnn/*.pyd
5+
include mmdeploy/lib/*.so
6+
include mmdeploy/lib/*.dll
7+
include mmdeploy/lib/*.pyd

csrc/backend_ops/ncnn/onnx2ncnn/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ if (PROTOBUF_FOUND)
1212
${CMAKE_CURRENT_BINARY_DIR})
1313
target_link_libraries(onnx2ncnn PRIVATE ${PROTOBUF_LIBRARIES})
1414

15+
set(_NCNN_CONVERTER_DIR ${CMAKE_SOURCE_DIR}/mmdeploy/backend/ncnn)
16+
install(TARGETS onnx2ncnn DESTINATION ${_NCNN_CONVERTER_DIR})
1517
else ()
1618
message(
1719
FATAL_ERROR "Protobuf not found, onnx model convert tool won't be built")

csrc/backend_ops/ncnn/ops/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ target_include_directories(${PROJECT_NAME}
2323
PUBLIC ${_COMMON_INCLUDE_DIRS})
2424

2525
add_library(mmdeploy::ncnn_ops ALIAS ${PROJECT_NAME})
26+
27+
set(_NCNN_OPS_DIR ${CMAKE_SOURCE_DIR}/mmdeploy/lib)
28+
install(TARGETS ${PROJECT_NAME} DESTINATION ${_NCNN_OPS_DIR})

csrc/backend_ops/onnxruntime/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ target_link_libraries(${PROJECT_NAME}_obj PUBLIC onnxruntime)
2222
mmdeploy_add_library(${PROJECT_NAME} SHARED EXCLUDE "")
2323
target_link_libraries(${PROJECT_NAME} PUBLIC ${PROJECT_NAME}_obj)
2424
add_library(mmdeploy::onnxruntime::ops ALIAS ${PROJECT_NAME})
25+
26+
set(_ORT_OPS_DIR ${CMAKE_SOURCE_DIR}/mmdeploy/lib)
27+
install(TARGETS ${PROJECT_NAME} DESTINATION ${_ORT_OPS_DIR})

csrc/backend_ops/tensorrt/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ mmdeploy_export(${PROJECT_NAME}_obj)
3535
mmdeploy_add_module(${PROJECT_NAME} MODULE EXCLUDE "")
3636
target_link_libraries(${PROJECT_NAME} PRIVATE ${PROJECT_NAME}_obj)
3737
add_library(mmdeploy::tensorrt_ops ALIAS ${PROJECT_NAME})
38+
39+
set(_TRT_OPS_DIR ${CMAKE_SOURCE_DIR}/mmdeploy/lib)
40+
install(TARGETS ${PROJECT_NAME} DESTINATION ${_TRT_OPS_DIR})

mmdeploy/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
from mmdeploy.utils import get_root_logger
55
from .version import __version__ # noqa F401
66

7-
importlib.import_module('mmdeploy.pytorch')
7+
if importlib.util.find_spec('torch'):
8+
importlib.import_module('mmdeploy.pytorch')
9+
else:
10+
logger = get_root_logger()
11+
logger.debug('torch is not installed.')
812

913
if importlib.util.find_spec('mmcv'):
1014
importlib.import_module('mmdeploy.mmcv')

mmdeploy/backend/__init__.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1 @@
11
# Copyright (c) OpenMMLab. All rights reserved.
2-
from mmdeploy.backend.ncnn import is_available as ncnn_available
3-
from mmdeploy.backend.onnxruntime import is_available as ort_available
4-
from mmdeploy.backend.openvino import is_available as openvino_available
5-
from mmdeploy.backend.pplnn import is_available as pplnn_available
6-
from mmdeploy.backend.sdk import is_available as sdk_available
7-
from mmdeploy.backend.tensorrt import is_available as trt_available
8-
9-
__all__ = []
10-
if ncnn_available():
11-
from .ncnn import NCNNWrapper # noqa: F401,F403
12-
__all__.append('NCNNWrapper')
13-
if ort_available():
14-
from .onnxruntime import ORTWrapper # noqa: F401,F403
15-
__all__.append('ORTWrapper')
16-
if trt_available():
17-
from .tensorrt import TRTWrapper # noqa: F401,F403
18-
__all__.append('TRTWrapper')
19-
if pplnn_available():
20-
from .pplnn import PPLNNWrapper # noqa: F401,F403
21-
__all__.append('PPLNNWrapper')
22-
if openvino_available():
23-
from .openvino import OpenVINOWrapper # noqa: F401,F403
24-
__all__.append('OpenVINOWrapper')
25-
if sdk_available():
26-
from .sdk import SDKWrapper # noqa: F401,F403
27-
__all__.append('SDKWrapper')

mmdeploy/backend/ncnn/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ def is_plugin_available():
3232

3333

3434
if is_available():
35-
from .wrapper import NCNNWrapper
35+
try:
36+
from .wrapper import NCNNWrapper
3637

37-
__all__ = ['NCNNWrapper']
38+
__all__ = ['NCNNWrapper']
39+
except Exception:
40+
pass

mmdeploy/backend/ncnn/init_plugins.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ def get_ops_path() -> str:
1111
str: The library path of ncnn custom ops.
1212
"""
1313
candidates = [
14-
'../../../build/lib/libmmdeploy_ncnn_ops.so',
15-
'../../../build/bin/*/mmdeploy_ncnn_ops.dll'
14+
'../../lib/libmmdeploy_ncnn_ops.so', '../../lib/mmdeploy_ncnn_ops.dll'
1615
]
1716
return get_file_path(os.path.dirname(__file__), candidates)
1817

@@ -23,7 +22,5 @@ def get_onnx2ncnn_path() -> str:
2322
Returns:
2423
str: A path of onnx2ncnn tool.
2524
"""
26-
candidates = [
27-
'../../../build/bin/onnx2ncnn', '../../../build/bin/*/onnx2ncnn.exe'
28-
]
25+
candidates = ['./onnx2ncnn', './onnx2ncnn.exe']
2926
return get_file_path(os.path.dirname(__file__), candidates)

0 commit comments

Comments
 (0)