Skip to content
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
111 changes: 61 additions & 50 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,20 @@
PROJECT(fastdeploy C CXX)
CMAKE_MINIMUM_REQUIRED (VERSION 3.16)

option(CSRCS_DIR_NAME "Name of source code directory")
option(LIBRARY_NAME "Name of build library name")
option(PY_LIBRARY_NAME "Name of build python library name")
if(NOT CSRCS_DIR_NAME)
set(CSRCS_DIR_NAME "./")
endif()
if(NOT LIBRARY_NAME)
set(LIBRARY_NAME "fastdeploy")
endif()
if(NOT PY_LIBRARY_NAME)
set(PY_LIBRARY_NAME "fastdeploy_main")
endif()
include(ExternalProject)
add_subdirectory(fastdeploy)
add_subdirectory(${CSRCS_DIR_NAME}/fastdeploy)
include(external/utils.cmake)

# Set C++11 as standard for the whole project
Expand Down Expand Up @@ -51,7 +63,8 @@ endif()

option(BUILD_FASTDEPLOY_PYTHON "if build python lib for fastdeploy." OFF)

include_directories(${PROJECT_SOURCE_DIR})
set(HEAD_DIR "${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}")
include_directories(${HEAD_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})

if (WITH_VISION_EXAMPLES AND EXISTS ${PROJECT_SOURCE_DIR}/examples)
Expand All @@ -62,12 +75,12 @@ if (WITH_VISION_EXAMPLES AND EXISTS ${PROJECT_SOURCE_DIR}/examples)
endif()

add_definitions(-DFASTDEPLOY_LIB)
file(GLOB_RECURSE ALL_DEPLOY_SRCS ${PROJECT_SOURCE_DIR}/fastdeploy/*.cc)
file(GLOB_RECURSE DEPLOY_ORT_SRCS ${PROJECT_SOURCE_DIR}/fastdeploy/backends/ort/*.cc)
file(GLOB_RECURSE DEPLOY_PADDLE_SRCS ${PROJECT_SOURCE_DIR}/fastdeploy/backends/paddle/*.cc)
file(GLOB_RECURSE DEPLOY_TRT_SRCS ${PROJECT_SOURCE_DIR}/fastdeploy/backends/tensorrt/*.cc ${PROJECT_SOURCE_DIR}/fastdeploy/backends/tensorrt/*.cpp)
file(GLOB_RECURSE DEPLOY_VISION_SRCS ${PROJECT_SOURCE_DIR}/fastdeploy/vision/*.cc)
file(GLOB_RECURSE DEPLOY_PYBIND_SRCS ${PROJECT_SOURCE_DIR}/fastdeploy/pybind/*.cc ${PROJECT_SOURCE_DIR}/fastdeploy/*_pybind.cc)
file(GLOB_RECURSE ALL_DEPLOY_SRCS ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/*.cc)
file(GLOB_RECURSE DEPLOY_ORT_SRCS ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/backends/ort/*.cc)
file(GLOB_RECURSE DEPLOY_PADDLE_SRCS ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/backends/paddle/*.cc)
file(GLOB_RECURSE DEPLOY_TRT_SRCS ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/backends/tensorrt/*.cc ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/backends/tensorrt/*.cpp)
file(GLOB_RECURSE DEPLOY_VISION_SRCS ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/vision/*.cc)
file(GLOB_RECURSE DEPLOY_PYBIND_SRCS ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/pybind/*.cc ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/*_pybind.cc)
list(REMOVE_ITEM ALL_DEPLOY_SRCS ${DEPLOY_ORT_SRCS} ${DEPLOY_PADDLE_SRCS} ${DEPLOY_TRT_SRCS} ${DEPLOY_VISION_SRCS})

set(DEPEND_LIBS "")
Expand Down Expand Up @@ -117,20 +130,24 @@ if(ENABLE_TRT_BACKEND)
endif()
add_definitions(-DENABLE_TRT_BACKEND)
include_directories(${TRT_DIRECTORY}/include)
include_directories(${PROJECT_SOURCE_DIR}/fastdeploy/backends/tensorrt/common)
include_directories(${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/backends/tensorrt/common)
list(APPEND ALL_DEPLOY_SRCS ${DEPLOY_TRT_SRCS})
find_library(TRT_INFER_LIB nvinfer ${TRT_DIRECTORY}/lib)
find_library(TRT_ONNX_LIB nvonnxparser ${TRT_DIRECTORY}/lib)
find_library(TRT_CAFFE_LIB nvcaffe_parser ${TRT_DIRECTORY}/lib)
find_library(TRT_PLUGIN_LIB nvinfer_plugin ${TRT_DIRECTORY}/lib)
list(APPEND DEPEND_LIBS ${TRT_INFER_LIB} ${TRT_ONNX_LIB} ${TRT_CAFFE_LIB} ${TRT_PLUGIN_LIB})

# copy tensorrt libraries to third lib
# if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt")
# file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt/lib")
# endif()
# file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt/lib")
# file(COPY ${TRT_INFER_LIB} ${TRT_ONNX_LIB} ${TRT_CAFFE_LIB} ${TRT_PLUGIN_LIB} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt/lib" FOLLOW_SYMLINK_CHAIN)
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt")
endif()
if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt/lib")
file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt/lib")
endif()
find_package(Python COMPONENTS Interpreter Development REQUIRED)
message(STATUS "Copying ${TRT_DIRECTORY}/lib to ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt/lib ...")
execute_process(COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/copy_directory.py ${TRT_DIRECTORY}/lib ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt/lib)

endif()

if(ENABLE_VISION)
Expand All @@ -157,37 +174,37 @@ else()
endif()
endif()

configure_file(${PROJECT_SOURCE_DIR}/fastdeploy/core/config.h.in ${PROJECT_SOURCE_DIR}/fastdeploy/core/config.h)
configure_file(${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/core/config.h.in ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/core/config.h)
configure_file(${PROJECT_SOURCE_DIR}/FastDeploy.cmake.in ${PROJECT_SOURCE_DIR}/FastDeploy.cmake @ONLY)

list(REMOVE_ITEM ALL_DEPLOY_SRCS ${DEPLOY_PYBIND_SRCS})

add_library(fastdeploy SHARED ${ALL_DEPLOY_SRCS})
redefine_file_macro(fastdeploy)
set_target_properties(fastdeploy PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
add_library(${LIBRARY_NAME} SHARED ${ALL_DEPLOY_SRCS})
redefine_file_macro(${LIBRARY_NAME})
set_target_properties(${LIBRARY_NAME} PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
if(NOT APPLE)
set_target_properties(fastdeploy PROPERTIES LINK_FLAGS "-Wl,--start-group,--exclude-libs,ALL")
set_target_properties(${LIBRARY_NAME} PROPERTIES LINK_FLAGS "-Wl,--start-group,--exclude-libs,ALL")
endif()
set_target_properties(fastdeploy PROPERTIES LINK_FLAGS_RELEASE -s)
set_target_properties(${LIBRARY_NAME} PROPERTIES LINK_FLAGS_RELEASE -s)

file(READ "${PROJECT_SOURCE_DIR}/VERSION_NUMBER" FASTDEPLOY_VERSION)
string(STRIP "${FASTDEPLOY_VERSION}" FASTDEPLOY_VERSION)
if (APPLE)
# set_target_properties(fastdeploy PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
set_target_properties(fastdeploy PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
set_target_properties(${LIBRARY_NAME} PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
elseif(MSVC)
else()
set_target_properties(fastdeploy PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
set_target_properties(fastdeploy PROPERTIES LINK_FLAGS "-Wl,--exclude-libs,ALL")
set_target_properties(fastdeploy PROPERTIES LINK_FLAGS_RELEASE -s)
set_target_properties(${LIBRARY_NAME} PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
set_target_properties(${LIBRARY_NAME} PROPERTIES LINK_FLAGS "-Wl,--exclude-libs,ALL")
set_target_properties(${LIBRARY_NAME} PROPERTIES LINK_FLAGS_RELEASE -s)
endif()

find_package(OpenMP)
if(OpenMP_CXX_FOUND)
list(APPEND DEPEND_LIBS OpenMP::OpenMP_CXX)
endif()
set_target_properties(fastdeploy PROPERTIES VERSION ${FASTDEPLOY_VERSION})
target_link_libraries(fastdeploy ${DEPEND_LIBS})
set_target_properties(${LIBRARY_NAME} PROPERTIES VERSION ${FASTDEPLOY_VERSION})
target_link_libraries(${LIBRARY_NAME} ${DEPEND_LIBS})

# add examples after prepare include paths for third-parties
if (WITH_VISION_EXAMPLES AND EXISTS ${PROJECT_SOURCE_DIR}/examples)
Expand All @@ -200,15 +217,15 @@ include(external/summary.cmake)
fastdeploy_summary()

install(
TARGETS fastdeploy
TARGETS ${LIBRARY_NAME}
LIBRARY DESTINATION lib
)
install(
DIRECTORY ${PROJECT_SOURCE_DIR}/fastdeploy
DIRECTORY ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy
DESTINATION ${CMAKE_INSTALL_PREFIX}/include
FILES_MATCHING
PATTERN "*.h"
PATTERN "${PROJECT_SOURCE_DIR}/fastdeploy/backends/*/*.h"
PATTERN "${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/backends/*/*.h"
)
install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install
Expand Down Expand Up @@ -243,40 +260,34 @@ if(BUILD_FASTDEPLOY_PYTHON)
endif()

if(NOT ENABLE_VISION)
file(GLOB_RECURSE VISION_PYBIND_SRCS ${PROJECT_SOURCE_DIR}/fastdeploy/vision/*_pybind.cc)
file(GLOB_RECURSE VISION_PYBIND_SRCS ${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/vision/*_pybind.cc)
list(REMOVE_ITEM DEPLOY_PYBIND_SRCS ${VISION_PYBIND_SRCS})
endif()
add_library(fastdeploy_main MODULE ${DEPLOY_PYBIND_SRCS})
redefine_file_macro(fastdeploy_main)
set_target_properties(fastdeploy_main PROPERTIES PREFIX "")
set_target_properties(fastdeploy_main
add_library(${PY_LIBRARY_NAME} MODULE ${DEPLOY_PYBIND_SRCS})
redefine_file_macro(${PY_LIBRARY_NAME})
set_target_properties(${PY_LIBRARY_NAME} PROPERTIES PREFIX "")
set_target_properties(${PY_LIBRARY_NAME}
PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
set_target_properties(fastdeploy_main PROPERTIES SUFFIX ${PY_EXT_SUFFIX})
set_target_properties(fastdeploy_main
set_target_properties(${PY_LIBRARY_NAME} PROPERTIES SUFFIX ${PY_EXT_SUFFIX})
set_target_properties(${PY_LIBRARY_NAME}
PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
target_include_directories(fastdeploy_main PRIVATE
target_include_directories(${PY_LIBRARY_NAME} PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>
${PYTHON_INCLUDE_DIR})

target_include_directories(fastdeploy_main PUBLIC ${PROJECT_SOURCE_DIR}/third_party/pybind11/include)
target_include_directories(${PY_LIBRARY_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/third_party/pybind11/include)

if(APPLE)
set_target_properties(fastdeploy_main
set_target_properties(${PY_LIBRARY_NAME}
PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
endif()

if(APPLE)
target_link_libraries(fastdeploy_main PUBLIC fastdeploy)
elseif(WIN32)
target_link_libraries(fastdeploy_main PUBLIC fastdeploy)
else()
target_link_libraries(fastdeploy_main PUBLIC fastdeploy)
endif()
target_link_libraries(${PY_LIBRARY_NAME} PUBLIC ${LIBRARY_NAME})

if(MSVC)
target_link_libraries(fastdeploy_main PRIVATE ${PYTHON_LIBRARIES})
target_compile_options(fastdeploy_main
target_link_libraries(${PY_LIBRARY_NAME} PRIVATE ${PYTHON_LIBRARIES})
target_compile_options(${PY_LIBRARY_NAME}
PRIVATE /MP
/wd4244 # 'argument': conversion from 'google::
# protobuf::uint64' to 'int', possible
Expand All @@ -285,7 +296,7 @@ if(BUILD_FASTDEPLOY_PYTHON)
# possible loss of data
/wd4996 # The second parameter is ignored.
${EXTRA_FLAGS})
target_compile_options(fastdeploy_main PRIVATE $<$<NOT:$<CONFIG:Debug>>:/MT> $<$<CONFIG:Debug>:/MTd>)
target_compile_options(${PY_LIBRARY_NAME} PRIVATE $<$<NOT:$<CONFIG:Debug>>:/MT> $<$<CONFIG:Debug>:/MTd>)
endif()

endif(BUILD_FASTDEPLOY_PYTHON)
Expand Down
21 changes: 13 additions & 8 deletions FastDeploy.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set(ENABLE_TRT_BACKEND @ENABLE_TRT_BACKEND@)
set(ENABLE_PADDLE_FRONTEND @ENABLE_PADDLE_FRONTEND@)
set(ENABLE_VISION @ENABLE_VISION@)
set(ENABLE_OPENCV_CUDA @ENABLE_OPENCV_CUDA@)
set(LIBRARY_NAME @LIBRARY_NAME@)

set(FASTDEPLOY_LIBS "")
set(FASTDEPLOY_INCS "")
Expand All @@ -17,7 +18,7 @@ if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()

find_library(FDLIB fastdeploy ${CMAKE_CURRENT_LIST_DIR}/lib)
find_library(FDLIB ${LIBRARY_NAME} ${CMAKE_CURRENT_LIST_DIR}/lib)
list(APPEND FASTDEPLOY_LIBS ${FDLIB})

if(ENABLE_ORT_BACKEND)
Expand Down Expand Up @@ -51,13 +52,17 @@ if(WITH_GPU)
list(APPEND FASTDEPLOY_LIBS ${CUDA_LIB})

if (ENABLE_TRT_BACKEND)
if (NOT TRT_DIRECTORY)
message(FATAL_ERROR "[FastDeploy] Please define TRT_DIRECTORY, e.g -DTRT_DIRECTORY=/usr/downloads/TensorRT-8.4.1.0")
endif()
find_library(TRT_INFER_LIB nvinfer ${TRT_DIRECTORY}/lib)
find_library(TRT_ONNX_LIB nvonnxparser ${TRT_DIRECTORY}/lib)
find_library(TRT_CAFFE_LIB nvcaffe_parser ${TRT_DIRECTORY}/lib)
find_library(TRT_PLUGIN_LIB nvinfer_plugin ${TRT_DIRECTORY}/lib)
# if (NOT TRT_DIRECTORY)
# message(FATAL_ERROR "[FastDeploy] Please define TRT_DIRECTORY, e.g -DTRT_DIRECTORY=/usr/downloads/TensorRT-8.4.1.0")
# endif()
# find_library(TRT_INFER_LIB nvinfer ${TRT_DIRECTORY}/lib)
# find_library(TRT_ONNX_LIB nvonnxparser ${TRT_DIRECTORY}/lib)
# find_library(TRT_CAFFE_LIB nvcaffe_parser ${TRT_DIRECTORY}/lib)
# find_library(TRT_PLUGIN_LIB nvinfer_plugin ${TRT_DIRECTORY}/lib)
find_library(TRT_INFER_LIB nvinfer ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/tensorrt/lib)
find_library(TRT_ONNX_LIB nvonnxparser ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/tensorrt/lib)
find_library(TRT_CAFFE_LIB nvcaffe_parser ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/tensorrt/lib)
find_library(TRT_PLUGIN_LIB nvinfer_plugin ${CMAKE_CURRENT_LIST_DIR}/third_libs/install/tensorrt/lib)
list(APPEND FASTDEPLOY_LIBS ${TRT_INFER_LIB} ${TRT_ONNX_LIB} ${TRT_CAFFE_LIB} ${TRT_PLUGIN_LIB})
endif()
endif()
Expand Down
32 changes: 32 additions & 0 deletions copy_directory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import shutil
import os
import sys


def copy_directory(src, dst):
if os.path.exists(dst):
raise Exception("Destination {} is already exist.".format(dst))
if not os.path.exists(src):
raise Exception("Source {} is not exist.".format(src))
try:
shutil.copytree(src, dst, symlinks=True)
except:
raise Exception("Copy {} to {} failed.".format(src, dst))


if __name__ == "__main__":
copy_directory(sys.argv[1], sys.argv[2])
8 changes: 4 additions & 4 deletions fastdeploy/backends/ort/ort_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ void OrtBackend::BuildOption(const OrtBackendOption& option) {
}
}
if (!support_cuda) {
FDLogger() << "[WARN] Compiled fastdeploy with onnxruntime doesn't "
"support GPU, the available providers are "
<< providers_msg << "will fallback to CPUExecutionProvider."
<< std::endl;
FDWARNING << "Compiled fastdeploy with onnxruntime doesn't "
"support GPU, the available providers are "
<< providers_msg << "will fallback to CPUExecutionProvider."
<< std::endl;
option_.use_gpu = false;
} else {
FDASSERT(option.gpu_id == 0, "Requires gpu_id == 0, but now gpu_id = " +
Expand Down
Loading