mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-06 09:07:10 +08:00
Support build on jetson (#276)
* support jetson build * Update allocate.cc * update setup * Update CMakeLists.txt * Update setup.py
This commit is contained in:
@@ -65,8 +65,17 @@ option(WITH_LITE_STATIC "Use Paddle-Lite static lib for Android." OFF)
|
|||||||
# Please don't open this flag now, some bugs exists.
|
# Please don't open this flag now, some bugs exists.
|
||||||
# option(ENABLE_OPENCV_CUDA "Whether to enable opencv with cuda, this will allow process image with GPU." OFF)
|
# option(ENABLE_OPENCV_CUDA "Whether to enable opencv with cuda, this will allow process image with GPU." OFF)
|
||||||
|
|
||||||
# Whether to build fastdeply with vision/text/... examples, only for testings.
|
# Whether to build fastdeploy with vision/text/... examples, only for testings.
|
||||||
option(BUILD_EXAMPLES "Whether to build fastdeply with vision examples" OFF)
|
option(BUILD_EXAMPLES "Whether to build fastdeploy with vision examples" OFF)
|
||||||
|
|
||||||
|
# Whether to build fastdeploy on device Nvidia Jetson
|
||||||
|
# Only support CPU Inference & GPU(TensorRT) Inference Now
|
||||||
|
option(BUILD_ON_JETSON "Whether to build fastdeploy on Nvidia Jetson" OFF)
|
||||||
|
if(BUILD_ON_JETSON)
|
||||||
|
set(WITH_GPU ON)
|
||||||
|
set(ENABLE_TRT_BACKEND ON)
|
||||||
|
set(ENABLE_ORT_BACKEND ON)
|
||||||
|
endif()
|
||||||
|
|
||||||
# config GIT_URL with github mirrors to speed up dependent repos clone
|
# config GIT_URL with github mirrors to speed up dependent repos clone
|
||||||
option(GIT_URL "Git URL to clone dependent repos" ${GIT_URL})
|
option(GIT_URL "Git URL to clone dependent repos" ${GIT_URL})
|
||||||
@@ -224,36 +233,46 @@ if(ENABLE_TRT_BACKEND)
|
|||||||
if(NOT WITH_GPU)
|
if(NOT WITH_GPU)
|
||||||
message(FATAL_ERROR "While -DENABLE_TRT_BACKEND=ON, must set -DWITH_GPU=ON, but now it's OFF")
|
message(FATAL_ERROR "While -DENABLE_TRT_BACKEND=ON, must set -DWITH_GPU=ON, but now it's OFF")
|
||||||
endif()
|
endif()
|
||||||
if(NOT TRT_DIRECTORY)
|
if(NOT BUILD_ON_JETSON)
|
||||||
message(FATAL_ERROR "While -DENABLE_TRT_BACKEND=ON, must define -DTRT_DIRECTORY, e.g -DTRT_DIRECTORY=/Downloads/TensorRT-8.4")
|
if(NOT TRT_DIRECTORY)
|
||||||
|
message(FATAL_ERROR "While -DENABLE_TRT_BACKEND=ON, must define -DTRT_DIRECTORY, e.g -DTRT_DIRECTORY=/Downloads/TensorRT-8.4")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
set(TRT_INC_DIR /usr/include/aarch64-linux-gnu/)
|
||||||
|
set(TRT_LIB_DIR /usr/lib/aarch64-linux-gnu/)
|
||||||
|
if(NOT BUILD_ON_JETSON)
|
||||||
|
set(TRT_INC_DIR ${TRT_DIRECTORY}/include)
|
||||||
|
set(TRT_LIB_DIR ${TRT_DIRECTORY}/lib)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_definitions(-DENABLE_TRT_BACKEND)
|
add_definitions(-DENABLE_TRT_BACKEND)
|
||||||
include_directories(${TRT_DIRECTORY}/include)
|
include_directories(${TRT_INC_DIR})
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/backends/tensorrt/common)
|
include_directories(${PROJECT_SOURCE_DIR}/${CSRCS_DIR_NAME}/fastdeploy/backends/tensorrt/common)
|
||||||
list(APPEND ALL_DEPLOY_SRCS ${DEPLOY_TRT_SRCS})
|
list(APPEND ALL_DEPLOY_SRCS ${DEPLOY_TRT_SRCS})
|
||||||
find_library(TRT_INFER_LIB nvinfer ${TRT_DIRECTORY}/lib)
|
find_library(TRT_INFER_LIB nvinfer ${TRT_LIB_DIR})
|
||||||
find_library(TRT_ONNX_LIB nvonnxparser ${TRT_DIRECTORY}/lib)
|
find_library(TRT_ONNX_LIB nvonnxparser ${TRT_LIB_DIR})
|
||||||
find_library(TRT_PLUGIN_LIB nvinfer_plugin ${TRT_DIRECTORY}/lib)
|
find_library(TRT_PLUGIN_LIB nvinfer_plugin ${TRT_LIB_DIR})
|
||||||
list(APPEND DEPEND_LIBS ${TRT_INFER_LIB} ${TRT_ONNX_LIB} ${TRT_PLUGIN_LIB})
|
list(APPEND DEPEND_LIBS ${TRT_INFER_LIB} ${TRT_ONNX_LIB} ${TRT_PLUGIN_LIB})
|
||||||
|
|
||||||
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt")
|
if(NOT BUILD_ON_JETSON)
|
||||||
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt")
|
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}/scripts/copy_directory.py ${TRT_DIRECTORY}/lib ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt/lib)
|
||||||
|
if(UNIX)
|
||||||
|
execute_process(COMMAND sh -c "ls *.so*" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt/lib
|
||||||
|
COMMAND sh -c "xargs patchelf --set-rpath '$ORIGIN'" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt/lib
|
||||||
|
RESULT_VARIABLE result
|
||||||
|
OUTPUT_VARIABLE curr_out
|
||||||
|
ERROR_VARIABLE curr_out)
|
||||||
|
message(STATUS "result:${result} out:${curr_out}")
|
||||||
|
endif()
|
||||||
endif()
|
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}/scripts/copy_directory.py ${TRT_DIRECTORY}/lib ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt/lib)
|
|
||||||
if(UNIX)
|
|
||||||
execute_process(COMMAND sh -c "ls *.so*" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt/lib
|
|
||||||
COMMAND sh -c "xargs patchelf --set-rpath '$ORIGIN'" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt/lib
|
|
||||||
RESULT_VARIABLE result
|
|
||||||
OUTPUT_VARIABLE curr_out
|
|
||||||
ERROR_VARIABLE curr_out)
|
|
||||||
message(STATUS "result:${result} out:${curr_out}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(ENABLE_VISION)
|
if(ENABLE_VISION)
|
||||||
|
@@ -10,6 +10,7 @@ set(ENABLE_TRT_BACKEND @ENABLE_TRT_BACKEND@)
|
|||||||
set(ENABLE_PADDLE_FRONTEND @ENABLE_PADDLE_FRONTEND@)
|
set(ENABLE_PADDLE_FRONTEND @ENABLE_PADDLE_FRONTEND@)
|
||||||
set(ENABLE_VISION @ENABLE_VISION@)
|
set(ENABLE_VISION @ENABLE_VISION@)
|
||||||
set(ENABLE_TEXT @ENABLE_TEXT@)
|
set(ENABLE_TEXT @ENABLE_TEXT@)
|
||||||
|
set(BUILD_ON_JETON @BUILD_ON_JETSON@)
|
||||||
# set(ENABLE_OPENCV_CUDA @ENABLE_OPENCV_CUDA@)
|
# set(ENABLE_OPENCV_CUDA @ENABLE_OPENCV_CUDA@)
|
||||||
set(LIBRARY_NAME @LIBRARY_NAME@)
|
set(LIBRARY_NAME @LIBRARY_NAME@)
|
||||||
set(OPENCV_DIRECTORY @OPENCV_DIRECTORY@)
|
set(OPENCV_DIRECTORY @OPENCV_DIRECTORY@)
|
||||||
@@ -138,3 +139,7 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|||||||
message(FATAL_ERROR "[ERROR] FastDeploy require g++ version >= 5.4.0, but now your g++ version is ${CMAKE_CXX_COMPILER_VERSION}, this may cause failure! Use -DCMAKE_CXX_COMPILER to define path of your compiler.")
|
message(FATAL_ERROR "[ERROR] FastDeploy require g++ version >= 5.4.0, but now your g++ version is ${CMAKE_CXX_COMPILER_VERSION}, this may cause failure! Use -DCMAKE_CXX_COMPILER to define path of your compiler.")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
FOREACH(LIB ${FASTDEPLOY_LIBS})
|
||||||
|
message(get_filename_component(directory ${LIB})
|
||||||
|
ENDFOREACH(LIB)
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#include "NvInferSafeRuntime.h"
|
#include "NvInferRuntime.h"
|
||||||
#include "fastdeploy/utils/utils.h"
|
#include "fastdeploy/utils/utils.h"
|
||||||
#ifdef ENABLE_PADDLE_FRONTEND
|
#ifdef ENABLE_PADDLE_FRONTEND
|
||||||
#include "paddle2onnx/converter.h"
|
#include "paddle2onnx/converter.h"
|
||||||
|
@@ -11,7 +11,6 @@
|
|||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#ifdef WITH_GPU
|
#ifdef WITH_GPU
|
||||||
#include <cuda_runtime_api.h>
|
#include <cuda_runtime_api.h>
|
||||||
#endif
|
#endif
|
||||||
|
@@ -57,6 +57,7 @@ setup_configs["ENABLE_VISION"] = os.getenv("ENABLE_VISION", "OFF")
|
|||||||
setup_configs["ENABLE_TEXT"] = os.getenv("ENABLE_TEXT", "OFF")
|
setup_configs["ENABLE_TEXT"] = os.getenv("ENABLE_TEXT", "OFF")
|
||||||
setup_configs["ENABLE_TRT_BACKEND"] = os.getenv("ENABLE_TRT_BACKEND", "OFF")
|
setup_configs["ENABLE_TRT_BACKEND"] = os.getenv("ENABLE_TRT_BACKEND", "OFF")
|
||||||
setup_configs["WITH_GPU"] = os.getenv("WITH_GPU", "OFF")
|
setup_configs["WITH_GPU"] = os.getenv("WITH_GPU", "OFF")
|
||||||
|
setup_configs["BUILD_ON_JETSON"] = os.getenv("BUILD_ON_JETSON", "OFF")
|
||||||
setup_configs["TRT_DIRECTORY"] = os.getenv("TRT_DIRECTORY", "UNDEFINED")
|
setup_configs["TRT_DIRECTORY"] = os.getenv("TRT_DIRECTORY", "UNDEFINED")
|
||||||
setup_configs["CUDA_DIRECTORY"] = os.getenv("CUDA_DIRECTORY",
|
setup_configs["CUDA_DIRECTORY"] = os.getenv("CUDA_DIRECTORY",
|
||||||
"/usr/local/cuda")
|
"/usr/local/cuda")
|
||||||
|
Reference in New Issue
Block a user