Skip to content
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

feat(tools/deploy.py): support snpe #789

Merged
merged 10 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions .github/workflows/backend-ncnn.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: backend
name: backend-ncnn

on:
push:
Expand All @@ -23,7 +23,6 @@ jobs:
matrix:
python-version: [3.7]
torch: [1.9.0]
mmcv: [1.4.2]
include:
- torch: 1.9.0
torch_version: torch1.9
Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/backend-snpe.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: backend-snpe

on:
push:
paths-ignore:
- "demo/**"
- "tools/**"

pull_request:
paths-ignore:
- "demo/**"
- "tools/**"
- "docs/**"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build_sdk_demo:
runs-on: ubuntu-18.04
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: update
run: sudo apt update
- name: Install dependencies
run: |
sudo apt install wget libprotobuf-dev protobuf-compiler
sudo apt update
sudo apt install -y ffmpeg libsm6 libxext6 git ninja-build libglib2.0-0 libxrender-dev libc++1-9 libc++abi1-9
sudo add-apt-repository ppa:ignaciovizzo/opencv3-nonfree
sudo apt install libopencv-dev
pkg-config --libs opencv
- name: Install snpe
run: |
wget https://media.githubusercontent.com/media/tpoisonooo/mmdeploy_snpe_testdata/main/snpe-1.59.tar.gz
tar xf snpe-1.59.tar.gz
pushd snpe-1.59.0.3230
pwd
popd
- name: Build SDK Demo with SNPE backend
run: |
mkdir -p build && pushd build
export SNPE_ROOT=/home/runner/work/mmdeploy/mmdeploy/snpe-1.59.0.3230
export LD_LIBRARY_PATH=${SNPE_ROOT}/lib/x86_64-linux-clang:${LD_LIBRARY_PATH}
export MMDEPLOY_SNPE_X86_CI=1
cmake .. -DCMAKE_CXX_COMPILER=g++-7 -DMMDEPLOY_SHARED_LIBS=ON -DMMDEPLOY_BUILD_SDK=ON -DMMDEPLOY_BUILD_SDK_PYTHON_API=OFF -DMMDEPLOY_TARGET_DEVICES=cpu -DMMDEPLOY_TARGET_BACKENDS=snpe -DMMDEPLOY_CODEBASES=all
make -j2
make install
pushd install/example
mkdir build && pushd build
cmake .. -DMMDeploy_DIR=${PWD}/../../lib/cmake/MMDeploy
make -j2
ls ./*
popd
popd
popd
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,7 @@ bin/
mmdeploy/backend/ncnn/onnx2ncnn

/mmdeploy-*

# snpe
grpc-cpp-plugin
service/snpe/grpc_cpp_plugin
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ repos:
rev: 4.0.1
hooks:
- id: flake8
args: ["--exclude=*/client/inference_pb2.py,*/client/inference_pb2_grpc.py"]
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ if (MMDEPLOY_BUILD_SDK)
if (NOT MMDEPLOY_SHARED_LIBS)
mmdeploy_add_deps(pplnn BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS pplnn)
endif ()
mmdeploy_add_deps(snpe BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS snpe)

include(CMakePackageConfigHelpers)
# generate the config file that is includes the exports
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ The currently supported codebases and models are as follows, and more will be in

Models can be exported and run in the following backends, and more will be compatible

| ONNX Runtime | TensorRT | ppl.nn | ncnn | OpenVINO | LibTorch | more |
| ------------ | -------- | ------ | ---- | -------- | -------- | ---------------------------------------------- |
| ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | [benchmark](docs/en/03-benchmark/benchmark.md) |
| ONNX Runtime | TensorRT | ppl.nn | ncnn | OpenVINO | LibTorch | snpe | more |
| ------------ | -------- | ------ | ---- | -------- | -------- | ---- | ---------------------------------------------- |
| ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | [benchmark](docs/en/03-benchmark/benchmark.md) |

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

Expand All @@ -73,6 +73,7 @@ Please read [getting_started.md](docs/en/get_started.md) for the basic usage of
- [Build for Win10](docs/en/01-how-to-build/windows.md)
- [Build for Android](docs/en/01-how-to-build/android.md)
- [Build for Jetson](docs/en/01-how-to-build/jetsons.md)
- [Build for SNPE](docs/en/01-how-to-build/snpe.md)
- User Guide
- [How to convert model](docs/en/02-how-to-run/convert_model.md)
- [How to write config](docs/en/02-how-to-run/write_config.md)
Expand Down
7 changes: 4 additions & 3 deletions README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ MMDeploy 是 [OpenMMLab](https://openmmlab.com/) 模型部署工具箱,**为

### 支持多种推理后端

| ONNX Runtime | TensorRT | ppl.nn | ncnn | OpenVINO | more |
| ------------ | -------- | ------ | ---- | -------- | ------------------------------------------------- |
| ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | [benchmark](docs/zh_cn/03-benchmark/benchmark.md) |
| ONNX Runtime | TensorRT | ppl.nn | ncnn | OpenVINO | LibTorch | snpe | more |
| ------------ | -------- | ------ | ---- | -------- | -------- | ---- | ------------------------------------------------- |
| ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | [benchmark](docs/zh_cn/03-benchmark/benchmark.md) |

### SDK 可高度定制化

Expand All @@ -71,6 +71,7 @@ MMDeploy 是 [OpenMMLab](https://openmmlab.com/) 模型部署工具箱,**为
- [Build for Win10](docs/zh_cn/01-how-to-build/windows.md)
- [Build for Android](docs/zh_cn/01-how-to-build/android.md)
- [Build for Jetson](docs/en/01-how-to-build/jetsons.md)
- [Build for SNPE](docs/zh_cn/01-how-to-build/snpe.md)
- 使用
- [把模型转换到推理 Backend](docs/zh_cn/02-how-to-run/convert_model.md)
- [配置转换参数](docs/zh_cn/02-how-to-run/write_config.md)
Expand Down
1 change: 1 addition & 0 deletions configs/_base_/backends/snpe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
backend_config = dict(type='snpe')
3 changes: 3 additions & 0 deletions configs/mmcls/classification_snpe_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_base_ = ['./classification_static.py', '../_base_/backends/snpe.py']

onnx_config = dict(input_shape=None)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_base_ = ['./super-resolution_static.py', '../../_base_/backends/snpe.py']
onnx_config = dict(input_shape=[256, 256])
3 changes: 3 additions & 0 deletions configs/mmocr/text-detection/text-detection_snpe_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_base_ = ['./text-detection_static.py', '../../_base_/backends/snpe.py']

onnx_config = dict(input_shape=None)
3 changes: 3 additions & 0 deletions configs/mmpose/pose-detection_snpe_static-256x256.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_base_ = ['./pose-detection_static.py', '../_base_/backends/snpe.py']

onnx_config = dict(input_shape=[256, 256])
3 changes: 3 additions & 0 deletions configs/mmseg/segmentation_snpe_static-512x1024.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_base_ = ['./segmentation_static.py', '../_base_/backends/snpe.py']

onnx_config = dict(input_shape=[1024, 512])
4 changes: 4 additions & 0 deletions csrc/mmdeploy/net/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ if ("openvino" IN_LIST MMDEPLOY_TARGET_BACKENDS)
add_subdirectory(openvino)
endif ()

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

mmdeploy_add_module(${PROJECT_NAME} net_module.cpp)
add_library(mmdeploy::net_module ALIAS ${PROJECT_NAME})
25 changes: 25 additions & 0 deletions csrc/mmdeploy/net/snpe/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) OpenMMLab. All rights reserved.

project(mmdeploy_snpe_net)

add_library(snpe SHARED IMPORTED)

if(NOT DEFINED ENV{MMDEPLOY_SNPE_X86_CI})
set(sub_dir "aarch64-android-clang6.0")
else()
set(sub_dir "x86_64-linux-clang")
endif()

if (NOT EXISTS $ENV{SNPE_ROOT}/lib/${sub_dir}/)
message(ERROR "SNPE_ROOT directory not exist: $ENV{SNPE_ROOT}/lib/${sub_dir}/")
endif()
message(STATUS "SNPE lib directory $ENV{SNPE_ROOT}/lib/${sub_dir}/")

set_target_properties(snpe PROPERTIES
IMPORTED_LOCATION "$ENV{SNPE_ROOT}/lib/${sub_dir}/libSNPE.so"
INTERFACE_INCLUDE_DIRECTORIES "$ENV{SNPE_ROOT}/include/zdl"
)

mmdeploy_add_module(${PROJECT_NAME} snpe_net.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE snpe)
add_library(mmdeploy::snpe_net ALIAS ${PROJECT_NAME})
Loading