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 SDK demos #1653

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .circleci/scripts/linux/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cd mmdeploy
MMDEPLOY_DIR=$(pwd)
mkdir -p build && cd build
cmake .. -DMMDEPLOY_BUILD_SDK=ON -DMMDEPLOY_BUILD_TEST=ON -DMMDEPLOY_BUILD_SDK_PYTHON_API=ON \
-DMMDEPLOY_BUILD_EXAMPLES=ON -DMMDEPLOY_BUILD_SDK_CXX_API=ON -DMMDEPLOY_BUILD_SDK_CSHARP_API=ON \
-DMMDEPLOY_BUILD_EXAMPLES=ON -DMMDEPLOY_BUILD_SDK_CSHARP_API=ON \
-DMMDEPLOY_TARGET_DEVICES="$1" -DMMDEPLOY_TARGET_BACKENDS="$2" "${ARGS[@]:2}"

make -j$(nproc) && make install
1 change: 0 additions & 1 deletion .circleci/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ jobs:
-DMMDEPLOY_BUILD_TEST=ON `
-DMMDEPLOY_BUILD_SDK_PYTHON_API=ON `
-DMMDEPLOY_BUILD_EXAMPLES=ON `
-DMMDEPLOY_BUILD_SDK_CXX_API=ON `
-DMMDEPLOY_BUILD_SDK_CSHARP_API=ON `
-DMMDEPLOY_TARGET_BACKENDS="ort" `
-DOpenCV_DIR="$env:OPENCV_PACKAGE_DIR"
Expand Down
24 changes: 13 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ option(MMDEPLOY_BUILD_SDK "build MMDeploy SDK" OFF)
option(MMDEPLOY_BUILD_SDK_MONOLITHIC "build single lib for SDK API" ON)
option(MMDEPLOY_BUILD_TEST "build unittests" OFF)
option(MMDEPLOY_BUILD_SDK_PYTHON_API "build SDK Python API" OFF)
option(MMDEPLOY_BUILD_SDK_CXX_API "build SDK C++ API" OFF)
option(MMDEPLOY_BUILD_SDK_CSHARP_API "build SDK C# API support" OFF)
option(MMDEPLOY_BUILD_SDK_JAVA_API "build SDK JAVA API" OFF)
option(MMDEPLOY_BUILD_EXAMPLES "build examples" OFF)
Expand Down Expand Up @@ -106,7 +105,8 @@ if (MMDEPLOY_BUILD_SDK)

if (MMDEPLOY_BUILD_EXAMPLES)
include(${CMAKE_SOURCE_DIR}/cmake/opencv.cmake)
add_subdirectory(demo/csrc)
add_subdirectory(demo/c)
add_subdirectory(demo/cpp)
endif ()

# export MMDeploy package
Expand All @@ -117,16 +117,18 @@ if (MMDEPLOY_BUILD_SDK)
if (MMDEPLOY_SPDLOG_EXTERNAL)
set(SPDLOG_DEPENDENCY "find_package(spdlog QUIET)")
endif ()
# append backend deps
mmdeploy_add_deps(trt BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS TENSORRT CUDNN)
mmdeploy_add_deps(ort BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS ONNXRUNTIME)
mmdeploy_add_deps(ncnn BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS ncnn)
mmdeploy_add_deps(openvino BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS InferenceEngine)
if (NOT MMDEPLOY_SHARED_LIBS)
mmdeploy_add_deps(pplnn BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS pplnn)
if (NOT MMDEPLOY_BUILD_SDK_MONOLITHIC)
# append backend deps
mmdeploy_add_deps(trt BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS TENSORRT CUDNN)
mmdeploy_add_deps(ort BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS ONNXRUNTIME)
mmdeploy_add_deps(ncnn BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS ncnn)
mmdeploy_add_deps(openvino BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS InferenceEngine)
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)
mmdeploy_add_deps(rknn BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS rknn)
endif ()
mmdeploy_add_deps(snpe BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS snpe)
mmdeploy_add_deps(rknn BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS rknn)

include(CMakePackageConfigHelpers)
# generate the config file that is includes the exports
Expand Down
3 changes: 1 addition & 2 deletions cmake/MMDeployConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ set(MMDEPLOY_TARGET_DEVICES @MMDEPLOY_TARGET_DEVICES@)
set(MMDEPLOY_TARGET_BACKENDS @MMDEPLOY_TARGET_BACKENDS@)
set(MMDEPLOY_BUILD_TYPE @CMAKE_BUILD_TYPE@)
set(MMDEPLOY_BUILD_SHARED @MMDEPLOY_SHARED_LIBS@)
set(MMDEPLOY_BUILD_SDK_CXX_API @MMDEPLOY_BUILD_SDK_CXX_API@)
set(MMDEPLOY_BUILD_SDK_MONOLITHIC @MMDEPLOY_BUILD_SDK_MONOLITHIC@)
set(MMDEPLOY_VERSION_MAJOR @MMDEPLOY_VERSION_MAJOR@)
set(MMDEPLOY_VERSION_MINOR @MMDEPLOY_VERSION_MINOR@)
set(MMDEPLOY_VERSION_PATCH @MMDEPLOY_VERSION_PATCH@)

if (NOT MMDEPLOY_BUILD_SHARED)
if (NOT MMDEPLOY_BUILD_SHARED AND NOT MMDEPLOY_BUILD_SDK_MONOLITHIC)
if ("cuda" IN_LIST MMDEPLOY_TARGET_DEVICES)
find_package(CUDA REQUIRED)
if(MSVC)
Expand Down
4 changes: 4 additions & 0 deletions cmake/modules/FindCUDNN.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Copyright (c) OpenMMLab. All rights reserved.

if (TARGET cudnn)
return()
endif ()

if (NOT DEFINED CUDNN_DIR)
set(CUDNN_DIR $ENV{CUDNN_DIR})
endif ()
Expand Down
4 changes: 3 additions & 1 deletion cmake/modules/FindONNXRUNTIME.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Copyright (c) OpenMMLab. All rights reserved.

if (TARGET onnxruntime)
return ()
endif ()
if (NOT DEFINED ONNXRUNTIME_DIR)
set(ONNXRUNTIME_DIR $ENV{ONNXRUNTIME_DIR})
endif ()
Expand Down
4 changes: 4 additions & 0 deletions cmake/modules/FindTENSORRT.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Copyright (c) OpenMMLab. All rights reserved.

if (TARGET nvinfer)
return ()
endif ()

if (NOT DEFINED TENSORRT_DIR)
set(TENSORRT_DIR $ENV{TENSORRT_DIR})
endif ()
Expand Down
3 changes: 3 additions & 0 deletions cmake/modules/FindTVM.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Copyright (c) OpenMMLab. All rights reserved.
if (TARGET tvm_runtime)
return()
endif ()

if (NOT DEFINED TVM_DIR)
set(TVM_DIR $ENV{TVM_DIR})
Expand Down
5 changes: 0 additions & 5 deletions csrc/mmdeploy/apis/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# Copyright (c) OpenMMLab. All rights reserved.

# Python API depends on C++ API
if (MMDEPLOY_BUILD_SDK_PYTHON_API)
set(MMDEPLOY_BUILD_SDK_CXX_API ON)
endif ()

add_subdirectory(c)
add_subdirectory(cxx)
add_subdirectory(java)
Expand Down
6 changes: 1 addition & 5 deletions csrc/mmdeploy/apis/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ foreach (TASK ${TASK_LIST})
DESTINATION include/mmdeploy)
endforeach ()

install(DIRECTORY ${CMAKE_SOURCE_DIR}/demo/csrc/ DESTINATION example/cpp
FILES_MATCHING
PATTERN "*.cpp"
PATTERN "CMakeLists.txt"
)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/demo/c/ DESTINATION example/c)

if (MMDEPLOY_BUILD_SDK_CSHARP_API OR MMDEPLOY_BUILD_SDK_MONOLITHIC)
add_library(mmdeploy SHARED)
Expand Down
39 changes: 17 additions & 22 deletions csrc/mmdeploy/apis/cxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,22 @@
cmake_minimum_required(VERSION 3.14)
project(mmdeploy_cxx_api)

if (MMDEPLOY_BUILD_SDK_CXX_API)
add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
target_link_libraries(${PROJECT_NAME} INTERFACE mmdeploy::core)
set(_tasks ${MMDEPLOY_TASKS} pipeline)
foreach (task ${_tasks})
target_link_libraries(mmdeploy_${task} INTERFACE ${PROJECT_NAME})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mmdeploy/${task}.hpp
DESTINATION include/mmdeploy)
endforeach ()
if (TARGET mmdeploy)
target_link_libraries(mmdeploy INTERFACE ${PROJECT_NAME})
endif ()
mmdeploy_export(${PROJECT_NAME})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mmdeploy/common.hpp
add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_17)
target_link_libraries(${PROJECT_NAME} INTERFACE mmdeploy::core)
set(_tasks ${MMDEPLOY_TASKS} pipeline)
foreach (task ${_tasks})
target_link_libraries(mmdeploy_${task} INTERFACE ${PROJECT_NAME})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mmdeploy/${task}.hpp
DESTINATION include/mmdeploy)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/demo/csrc/ DESTINATION example/cpp
FILES_MATCHING
PATTERN "*.cxx"
)
endforeach ()
if (TARGET mmdeploy)
target_link_libraries(mmdeploy INTERFACE ${PROJECT_NAME})
endif ()
mmdeploy_export(${PROJECT_NAME})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mmdeploy/common.hpp
DESTINATION include/mmdeploy)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/demo/cpp/ DESTINATION example/cpp)
12 changes: 5 additions & 7 deletions csrc/mmdeploy/archive/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ add_library(${PROJECT_NAME} INTERFACE)
target_link_libraries(${PROJECT_NAME} INTERFACE mmdeploy::core)
add_library(mmdeploy::archive ALIAS mmdeploy_archive)

if (MMDEPLOY_BUILD_SDK_CXX_API)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/csrc/mmdeploy/archive
DESTINATION include/mmdeploy
FILES_MATCHING PATTERN "*.h")
install(FILES ${CMAKE_SOURCE_DIR}/third_party/json/json.hpp
DESTINATION include/mmdeploy/third_party/json)
endif ()
install(DIRECTORY ${CMAKE_SOURCE_DIR}/csrc/mmdeploy/archive
DESTINATION include/mmdeploy
FILES_MATCHING PATTERN "*.h")
install(FILES ${CMAKE_SOURCE_DIR}/third_party/json/json.hpp
DESTINATION include/mmdeploy/third_party/json)
40 changes: 17 additions & 23 deletions csrc/mmdeploy/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ else ()
endif ()
set(SPDLOG_LIB spdlog::spdlog)
mmdeploy_export(spdlog)
if (MMDEPLOY_BUILD_SDK_CXX_API)
install(DIRECTORY ${MMDEPLOY_SPDLOG_DIR}/include/spdlog
DESTINATION include/mmdeploy/third_party)
endif ()
install(DIRECTORY ${MMDEPLOY_SPDLOG_DIR}/include/spdlog
DESTINATION include/mmdeploy/third_party)
endif ()

set(SRCS
Expand Down Expand Up @@ -65,15 +63,13 @@ else ()
target_compile_definitions(${PROJECT_NAME} PUBLIC -DMMDEPLOY_STATUS_USE_SOURCE_LOCATION=1)
endif ()

if (MMDEPLOY_BUILD_SDK_CXX_API)
target_include_directories(${PROJECT_NAME} PUBLIC
$<INSTALL_INTERFACE:include>
$<INSTALL_INTERFACE:include/mmdeploy/third_party/outcome>
$<INSTALL_INTERFACE:include/mmdeploy/third_party/json>)
if (NOT MMDEPLOY_SPDLOG_EXTERNAL)
target_include_directories(spdlog INTERFACE
$<INSTALL_INTERFACE:include/mmdeploy/third_party>)
endif ()
target_include_directories(${PROJECT_NAME} PUBLIC
$<INSTALL_INTERFACE:include>
$<INSTALL_INTERFACE:include/mmdeploy/third_party/outcome>
$<INSTALL_INTERFACE:include/mmdeploy/third_party/json>)
if (NOT MMDEPLOY_SPDLOG_EXTERNAL)
target_include_directories(spdlog INTERFACE
$<INSTALL_INTERFACE:include/mmdeploy/third_party>)
endif ()

target_link_libraries(${PROJECT_NAME} PUBLIC ${SPDLOG_LIB})
Expand All @@ -85,14 +81,12 @@ endif ()

add_library(mmdeploy::core ALIAS ${PROJECT_NAME})

if (MMDEPLOY_BUILD_SDK_CXX_API)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/csrc/mmdeploy/core
DESTINATION include/mmdeploy
FILES_MATCHING PATTERN "*.h")
install(FILES ${CMAKE_SOURCE_DIR}/third_party/outcome/outcome-experimental.hpp
DESTINATION include/mmdeploy/third_party/outcome)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/csrc/mmdeploy/core
DESTINATION include/mmdeploy
FILES_MATCHING PATTERN "*.h")
install(FILES ${CMAKE_SOURCE_DIR}/third_party/outcome/outcome-experimental.hpp
DESTINATION include/mmdeploy/third_party/outcome)

install(DIRECTORY ${CMAKE_SOURCE_DIR}/csrc/mmdeploy/experimental
DESTINATION include/mmdeploy
FILES_MATCHING PATTERN "*.h")
endif ()
install(DIRECTORY ${CMAKE_SOURCE_DIR}/csrc/mmdeploy/experimental
DESTINATION include/mmdeploy
FILES_MATCHING PATTERN "*.h")
18 changes: 18 additions & 0 deletions demo/c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) OpenMMLab. All rights reserved.
cmake_minimum_required(VERSION 3.14)
project(mmdeploy_capi_demo)

if (NOT (${CMAKE_PROJECT_NAME} STREQUAL "MMDeploy"))
find_package(MMDeploy REQUIRED)
endif ()

set(TASK_LIST ${MMDEPLOY_TASKS})

if ("text_detector" IN_LIST TASK_LIST OR "text_recognizer" IN_LIST TASK_LIST)
list(REMOVE_ITEM TASK_LIST "text_detector" "text_recognizer")
add_subdirectory(ocr)
endif()

foreach(TASK ${TASK_LIST})
add_subdirectory(${TASK})
endforeach()
31 changes: 31 additions & 0 deletions demo/c/classifier/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) OpenMMLab. All rights reserved.
cmake_minimum_required(VERSION 3.14)
project(mmdeploy_capi_classifier)

if (NOT (${CMAKE_PROJECT_NAME} STREQUAL "MMDeploy"))
find_package(MMDeploy REQUIRED)
endif ()

find_package(OpenCV REQUIRED)

macro(link_mmdeploy target_name)
if (NOT (MSVC OR APPLE))
# Disable new dtags so that executables can run even without LD_LIBRARY_PATH set
target_link_libraries(${target_name} PRIVATE -Wl,--disable-new-dtags)
endif ()
if (MMDEPLOY_BUILD_SDK_MONOLITHIC)
target_link_libraries(${target_name} PRIVATE mmdeploy ${OpenCV_LIBS})
else ()
# Load MMDeploy modules
mmdeploy_load_static(${target_name} MMDeployStaticModules)
mmdeploy_load_dynamic(${target_name} MMDeployDynamicModules)
# Link to MMDeploy libraries
target_link_libraries(${target_name} PRIVATE MMDeployLibs ${OpenCV_LIBS})
endif ()
endmacro()

add_executable(image_classification main.cpp)
add_executable(batch_image_classification batch.cpp)

link_mmdeploy(image_classification)
link_mmdeploy(batch_image_classification)
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <fstream>
#include <opencv2/imgcodecs/imgcodecs.hpp>
#include <opencv2/imgcodecs.hpp>
#include <string>

#include "mmdeploy/classifier.h"
Expand Down
31 changes: 31 additions & 0 deletions demo/c/detector/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) OpenMMLab. All rights reserved.
cmake_minimum_required(VERSION 3.14)
project(mmdeploy_capi_detector)

if (NOT (${CMAKE_PROJECT_NAME} STREQUAL "MMDeploy"))
find_package(MMDeploy REQUIRED)
endif ()

find_package(OpenCV REQUIRED)

macro(link_mmdeploy target_name)
if (NOT (MSVC OR APPLE))
# Disable new dtags so that executables can run even without LD_LIBRARY_PATH set
target_link_libraries(${target_name} PRIVATE -Wl,--disable-new-dtags)
endif ()
if (MMDEPLOY_BUILD_SDK_MONOLITHIC)
target_link_libraries(${target_name} PRIVATE mmdeploy ${OpenCV_LIBS})
else ()
# Load MMDeploy modules
mmdeploy_load_static(${target_name} MMDeployStaticModules)
mmdeploy_load_dynamic(${target_name} MMDeployDynamicModules)
# Link to MMDeploy libraries
target_link_libraries(${target_name} PRIVATE MMDeployLibs ${OpenCV_LIBS})
endif ()
endmacro()

add_executable(object_detection main.cpp)
add_executable(batch_object_detection batch.cpp)

link_mmdeploy(object_detection)
link_mmdeploy(batch_object_detection)
File renamed without changes.
File renamed without changes.
25 changes: 25 additions & 0 deletions demo/c/ocr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) OpenMMLab. All rights reserved.
cmake_minimum_required(VERSION 3.14)
project(mmdeploy_capi_ocr)

if (NOT (${CMAKE_PROJECT_NAME} STREQUAL "MMDeploy"))
find_package(MMDeploy REQUIRED)
endif ()

find_package(OpenCV REQUIRED)

add_executable(image_ocr main.cpp)

if (NOT (MSVC OR APPLE))
# Disable new dtags so that executables can run even without LD_LIBRARY_PATH set
target_link_libraries(image_ocr PRIVATE -Wl,--disable-new-dtags)
endif ()
if (MMDEPLOY_BUILD_SDK_MONOLITHIC)
target_link_libraries(image_ocr PRIVATE mmdeploy ${OpenCV_LIBS})
else ()
# Load MMDeploy modules
mmdeploy_load_static(image_ocr MMDeployStaticModules)
mmdeploy_load_dynamic(image_ocr MMDeployDynamicModules)
# Link to MMDeploy libraries
target_link_libraries(image_ocr PRIVATE MMDeployLibs ${OpenCV_LIBS})
endif ()
File renamed without changes.
Loading