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

[Refactor] Rename mmdeploy_python to mmdeploy_runtime #1911

Merged
merged 10 commits into from
Mar 29, 2023
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
234 changes: 234 additions & 0 deletions .github/workflows/prebuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
name: prebuild

on:
push:
branches:
- main
- dev-1.x
RunningLeon marked this conversation as resolved.
Show resolved Hide resolved
- master
paths:
- "mmdeploy/version.py"

permissions: write-all

jobs:
linux_build:
runs-on: [self-hosted, linux-3090]
container:
image: openmmlab/mmdeploy:manylinux2014_x86_64-cuda11.3
options: "--gpus=all --ipc=host"
volumes:
- /data2/actions-runner/prebuild:/__w/mmdeploy/prebuild
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive
- name: Get mmdeploy version
run: |
export MMDEPLOY_VERSION=$(python3 -c "import sys; sys.path.append('mmdeploy');from version import __version__;print(__version__)")
echo $MMDEPLOY_VERSION
echo "MMDEPLOY_VERSION=$MMDEPLOY_VERSION" >> $GITHUB_ENV
- name: Build MMDeploy
run: |
source activate mmdeploy-3.6
pip install pyyaml packaging setuptools wheel
lvhan028 marked this conversation as resolved.
Show resolved Hide resolved
mkdir pack; cd pack
python ../tools/package_tools/generate_build_config.py --backend 'trt;ort' \
--system linux --output config.yml --build-mmdeploy
python ../tools/package_tools/mmdeploy_builder.py --config config.yml
- name: Build sdk cpu backend
run: |
source activate mmdeploy-3.6
cd pack
python ../tools/package_tools/generate_build_config.py --backend 'ort' \
--system linux --output config.yml --device cpu --build-sdk --build-sdk-monolithic \
--build-sdk-python --sdk-dynamic-net
python ../tools/package_tools/mmdeploy_builder.py --config config.yml
- name: Build sdk cuda backend
run: |
source activate mmdeploy-3.6
cd pack
python ../tools/package_tools/generate_build_config.py --backend 'ort;trt' \
--system linux --output config.yml --device cuda --build-sdk --build-sdk-monolithic \
--build-sdk-python --sdk-dynamic-net
python ../tools/package_tools/mmdeploy_builder.py --config config.yml
- name: Move artifact
run: |
mkdir -p /__w/mmdeploy/prebuild/$MMDEPLOY_VERSION
rm -rf /__w/mmdeploy/prebuild/$MMDEPLOY_VERSION/*
mv pack/* /__w/mmdeploy/prebuild/$MMDEPLOY_VERSION

linux_test:
runs-on: [self-hosted, linux-3090]
needs: linux_build
container:
image: openmmlab/mmdeploy:ubuntu20.04-cuda11.3
options: "--gpus=all --ipc=host"
volumes:
- /data2/actions-runner/prebuild:/__w/mmdeploy/prebuild
- /data2/actions-runner/testmodel:/__w/mmdeploy/testmodel
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get mmdeploy version
run: |
export MMDEPLOY_VERSION=$(python3 -c "import sys; sys.path.append('mmdeploy');from version import __version__;print(__version__)")
echo $MMDEPLOY_VERSION
echo "MMDEPLOY_VERSION=$MMDEPLOY_VERSION" >> $GITHUB_ENV
- name: Test python
run: |
cd /__w/mmdeploy/prebuild/$MMDEPLOY_VERSION
bash $GITHUB_WORKSPACE/tools/package_tools/test/test_sdk_python.sh
- name: Test c/cpp
run: |
cd /__w/mmdeploy/prebuild/$MMDEPLOY_VERSION
bash $GITHUB_WORKSPACE/tools/package_tools/test/test_sdk.sh

linux_upload:
runs-on: [self-hosted, linux-3090]
if: startsWith(github.ref, 'refs/tags/')
environment: 'prod'
needs: linux_test
env:
PREBUILD_DIR: /data2/actions-runner/prebuild
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get mmdeploy version
run: |
export MMDEPLOY_VERSION=$(python3 -c "import sys; sys.path.append('mmdeploy');from version import __version__;print(__version__)")
echo $MMDEPLOY_VERSION
echo "MMDEPLOY_VERSION=$MMDEPLOY_VERSION" >> $GITHUB_ENV
- name: Upload mmdeploy
run: |
cd $PREBUILD_DIR/$MMDEPLOY_VERSION/mmdeploy
pip install twine
# twine upload * --repository testpypi -u __token__ -p ${{ secrets.test_pypi_password }}
twine upload * -u __token__ -p ${{ secrets.pypi_password }}
- name: Upload mmdeploy_runtime
run: |
cd $PREBUILD_DIR/$MMDEPLOY_VERSION/mmdeploy_runtime
# twine upload * --repository testpypi -u __token__ -p ${{ secrets.test_pypi_password }}
twine upload * -u __token__ -p ${{ secrets.pypi_password }}
- name: Zip mmdeploy sdk
run: |
cd $PREBUILD_DIR/$MMDEPLOY_VERSION/sdk
for folder in *
do
tar czf $folder.tar.gz $folder
done
- name: Upload mmdeploy sdk
uses: softprops/action-gh-release@v1
with:
files: |
$PREBUILD_DIR/$MMDEPLOY_VERSION/sdk/*.tar.gz


windows_build:
runs-on: [self-hosted, win10-3080]
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive
- name: Get mmdeploy version
run: |
conda activate mmdeploy-3.8
$env:MMDEPLOY_VERSION=(python -c "import sys; sys.path.append('mmdeploy');from version import __version__;print(__version__)")
echo $env:MMDEPLOY_VERSION
echo "MMDEPLOY_VERSION=$env:MMDEPLOY_VERSION" >> $env:GITHUB_ENV
- name: Build MMDeploy
run: |
. D:\DEPS\cienv\prebuild_gpu_env.ps1
conda activate mmdeploy-3.6
mkdir pack; cd pack
python ../tools/package_tools/generate_build_config.py --backend 'trt;ort' `
--system windows --output config.yml --build-mmdeploy
python ../tools/package_tools/mmdeploy_builder.py --config config.yml
- name: Build sdk cpu backend
run: |
. D:\DEPS\cienv\prebuild_cpu_env.ps1
conda activate mmdeploy-3.6
cd pack
python ../tools/package_tools/generate_build_config.py --backend 'ort' `
--system windows --output config.yml --device cpu --build-sdk --build-sdk-monolithic `
--build-sdk-python --sdk-dynamic-net
python ../tools/package_tools/mmdeploy_builder.py --config config.yml
- name: Build sdk cuda backend
run: |
. D:\DEPS\cienv\prebuild_gpu_env.ps1
conda activate mmdeploy-3.6
cd pack
python ../tools/package_tools/generate_build_config.py --backend 'ort;trt' `
--system windows --output config.yml --device cuda --build-sdk --build-sdk-monolithic `
--build-sdk-python --sdk-dynamic-net
python ../tools/package_tools/mmdeploy_builder.py --config config.yml
- name: Move artifact
run: |
New-Item "D:/DEPS/ciartifact/$env:MMDEPLOY_VERSION" -ItemType Directory -Force
Remove-Item "D:/DEPS/ciartifact/$env:MMDEPLOY_VERSION/*" -Force -Recurse
Move-Item pack/* "D:/DEPS/ciartifact/$env:MMDEPLOY_VERSION"

windows_test:
runs-on: [self-hosted, win10-3080]
needs: windows_build
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get mmdeploy version
run: |
conda activate mmdeploy-3.8
$env:MMDEPLOY_VERSION=(python -c "import sys; sys.path.append('mmdeploy');from version import __version__;print(__version__)")
echo $env:MMDEPLOY_VERSION
echo "MMDEPLOY_VERSION=$env:MMDEPLOY_VERSION" >> $env:GITHUB_ENV
- name: Test python
run: |
cd "D:/DEPS/ciartifact/$env:MMDEPLOY_VERSION"
. D:\DEPS\cienv\prebuild_cpu_env.ps1
conda activate ci-test
& "$env:GITHUB_WORKSPACE/tools/package_tools/test/test_sdk_python.ps1"
- name: Test c/cpp
run: |
cd "D:/DEPS/ciartifact/$env:MMDEPLOY_VERSION"
. D:\DEPS\cienv\prebuild_cpu_env.ps1
& "$env:GITHUB_WORKSPACE/tools/package_tools/test/test_sdk.ps1"

windows_upload:
runs-on: [self-hosted, win10-3080]
if: startsWith(github.ref, 'refs/tags/')
environment: 'prod'
needs: windows_test
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get mmdeploy version
run: |
conda activate mmdeploy-3.8
$env:MMDEPLOY_VERSION=(python -c "import sys; sys.path.append('mmdeploy');from version import __version__;print(__version__)")
echo $env:MMDEPLOY_VERSION
echo "MMDEPLOY_VERSION=$env:MMDEPLOY_VERSION" >> $env:GITHUB_ENV
- name: Upload mmdeploy
run: |
cd "D:/DEPS/ciartifact/$env:MMDEPLOY_VERSION/mmdeploy"
conda activate mmdeploy-3.8
# twine upload * --repository testpypi -u __token__ -p ${{ secrets.test_pypi_password }}
twine upload * -u __token__ -p ${{ secrets.pypi_password }}
- name: Upload mmdeploy_runtime
run: |
cd "D:/DEPS/ciartifact/$env:MMDEPLOY_VERSION/mmdeploy_runtime"
conda activate mmdeploy-3.8
# twine upload * --repository testpypi -u __token__ -p ${{ secrets.test_pypi_password }}
twine upload * -u __token__ -p ${{ secrets.pypi_password }}
- name: Zip mmdeploy sdk
run: |
cd "D:/DEPS/ciartifact/$env:MMDEPLOY_VERSION/sdk"
$folders = $(ls).Name
foreach ($folder in $folders) {
Compress-Archive -Path $folder -DestinationPath "$folder.zip"
}
- name: Upload mmdeploy sdk
uses: softprops/action-gh-release@v1
with:
files: |
D:/DEPS/ciartifact/$env:MMDEPLOY_VERSION/sdk/*.zip
4 changes: 3 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ repos:
rev: 4.0.1
hooks:
- id: flake8
args: ["--exclude=*/client/inference_pb2.py,*/client/inference_pb2_grpc.py"]
args: ["--exclude=*/client/inference_pb2.py, \
*/client/inference_pb2_grpc.py, \
tools/package_tools/packaging/setup.py"]
- repo: https://github.com/PyCQA/isort
rev: 5.11.5
hooks:
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include mmdeploy/backend/ncnn/*.so
include mmdeploy/backend/ncnn/*.dll
include mmdeploy/backend/ncnn/*.pyd
include mmdeploy/lib/*.so
include mmdeploy/lib/*.so*
include mmdeploy/lib/*.dll
include mmdeploy/lib/*.pyd
include mmdeploy/backend/torchscript/*.so
Expand Down
21 changes: 20 additions & 1 deletion cmake/loader.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,27 @@
namespace mmdeploy {
namespace {

#ifdef _WIN32
inline static const std::wstring GetDllPath() {
HMODULE hm = NULL;
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
(LPWSTR)&GetDllPath, &hm);
std::wstring ret;
ret.resize(MAX_PATH);
GetModuleFileNameW(hm, &ret[0], ret.size());
ret = ret.substr(0, ret.find_last_of(L"/\\"));
return ret;
}
#endif

void* mmdeploy_load_library(const char* name) {
fprintf(stderr, "loading %s ...\n", name);

#ifdef _WIN32
auto handle = LoadLibraryExA(name, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
auto handle = LoadLibraryExA(name, NULL, LOAD_LIBRARY_SEARCH_USER_DIRS);
if (handle == NULL) {
handle = LoadLibraryExA(name, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
}
#else
auto handle = dlopen(name, RTLD_NOW | RTLD_GLOBAL);
#endif
Expand All @@ -44,6 +60,9 @@ void* mmdeploy_load_library(const char* name) {
class Loader {
public:
Loader() {
#ifdef _WIN32
AddDllDirectory(GetDllPath().c_str());
#endif
const char* modules[] = {
@_MMDEPLOY_DYNAMIC_MODULES@
};
Expand Down
17 changes: 13 additions & 4 deletions csrc/mmdeploy/apis/python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Copyright (c) OpenMMLab. All rights reserved.

cmake_minimum_required(VERSION 3.14)
project(mmdeploy_python)
project(mmdeploy_runtime)

set(MMDEPLOY_PYTHON_SRCS
set(MMDEPLOY_RUNTIME_SRCS
common.cpp
internal.cpp
pipeline.cpp)
Expand All @@ -20,12 +20,21 @@ elseif (NOT TARGET pybind11)
endif ()

foreach (task_name ${MMDEPLOY_TASKS})
list(APPEND MMDEPLOY_PYTHON_SRCS ${task_name}.cpp)
list(APPEND MMDEPLOY_RUNTIME_SRCS ${task_name}.cpp)
endforeach ()

pybind11_add_module(${PROJECT_NAME} ${MMDEPLOY_PYTHON_SRCS})
pybind11_add_module(${PROJECT_NAME} ${MMDEPLOY_RUNTIME_SRCS})
# disable MMDEPLOY_CXX_USE_OPENCV in apis/cxx/mmdeploy/common.hpp
target_compile_definitions(${PROJECT_NAME} PRIVATE -DMMDEPLOY_CXX_USE_OPENCV=0)
if (APPLE)
set_target_properties(${PROJECT_NAME} PROPERTIES
BUILD_RPATH "@loader_path"
INSTALL_RPATH "@loader_path")
else ()
set_target_properties(${PROJECT_NAME} PROPERTIES
BUILD_RPATH "\$ORIGIN"
INSTALL_RPATH "\$ORIGIN")
endif ()

# https://github.com/pybind/pybind11/issues/1604
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
Expand Down
2 changes: 1 addition & 1 deletion csrc/mmdeploy/apis/python/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static PythonBindingRegisterer register_scheduler{[](py::module& m) {

} // namespace mmdeploy::python

PYBIND11_MODULE(mmdeploy_python, m) {
PYBIND11_MODULE(mmdeploy_runtime, m) {
for (const auto& f : mmdeploy::python::gPythonBindings()) {
f(m);
}
Expand Down
9 changes: 9 additions & 0 deletions csrc/mmdeploy/backend_ops/onnxruntime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ target_link_libraries(${PROJECT_NAME}_obj PUBLIC onnxruntime)

mmdeploy_add_library(${PROJECT_NAME} SHARED EXCLUDE "")
target_link_libraries(${PROJECT_NAME} PUBLIC ${PROJECT_NAME}_obj)
if (APPLE)
set_target_properties(${PROJECT_NAME} PROPERTIES
BUILD_RPATH "@loader_path"
INSTALL_RPATH "@loader_path")
else ()
set_target_properties(${PROJECT_NAME} PROPERTIES
BUILD_RPATH "\$ORIGIN"
INSTALL_RPATH "\$ORIGIN")
endif ()
add_library(mmdeploy::onnxruntime::ops ALIAS ${PROJECT_NAME})

set(_ORT_OPS_DIR ${CMAKE_SOURCE_DIR}/mmdeploy/lib)
Expand Down
2 changes: 1 addition & 1 deletion csrc/mmdeploy/device/cpu/cpu_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CpuHostMemory : public NonCopyable {
#elif defined(ANDROID)
posix_memalign(&data_, alignment, space);
#else
data_ = std::aligned_alloc(alignment, space);
data_ = aligned_alloc(alignment, space);
#endif
if (!data_) {
return Status(eOutOfMemory);
Expand Down
2 changes: 1 addition & 1 deletion csrc/mmdeploy/net/trt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ target_include_directories(${PROJECT_NAME} PRIVATE
target_include_directories(${PROJECT_NAME} PRIVATE ${CUDNN_DIR}/include)
target_include_directories(${PROJECT_NAME} PRIVATE ${CUDA_TOOLKIT_ROOT_DIR}/include)
target_link_libraries(${PROJECT_NAME} PRIVATE mmdeploy_tensorrt_ops_obj)
target_link_libraries(${PROJECT_NAME} PUBLIC ${TENSORRT_LIBS} cudnn)
target_link_libraries(${PROJECT_NAME} PUBLIC ${TENSORRT_LIBS} cudnn cuda)

add_library(mmdeploy::trt_net ALIAS ${PROJECT_NAME})
2 changes: 1 addition & 1 deletion demo/csrc/cpp/text_det_recog.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ int main(int argc, char* argv[]) {

auto output = pipeline.Apply(mat);

MMDEPLOY_INFO("output:\n{}", output);
// MMDEPLOY_INFO("output:\n{}", output);

return 0;
}
2 changes: 1 addition & 1 deletion demo/python/det_pose.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import cv2
import numpy as np
from mmdeploy_python import Detector, PoseDetector
from mmdeploy_runtime import Detector, PoseDetector
RunningLeon marked this conversation as resolved.
Show resolved Hide resolved


def parse_args():
Expand Down
2 changes: 1 addition & 1 deletion demo/python/image_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import argparse

import cv2
from mmdeploy_python import Classifier
from mmdeploy_runtime import Classifier


def parse_args():
Expand Down
Loading