Support build on jetson (#276)

* support jetson build

* Update allocate.cc

* update setup

* Update CMakeLists.txt

* Update setup.py
This commit is contained in:
Jason
2022-09-23 13:11:11 +08:00
committed by GitHub
parent 2d3e61582d
commit 360bee46b5
5 changed files with 51 additions and 27 deletions

View File

@@ -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.
# 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.
option(BUILD_EXAMPLES "Whether to build fastdeply with vision examples" OFF)
# Whether to build fastdeploy with vision/text/... examples, only for testings.
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
option(GIT_URL "Git URL to clone dependent repos" ${GIT_URL})
@@ -224,18 +233,28 @@ if(ENABLE_TRT_BACKEND)
if(NOT WITH_GPU)
message(FATAL_ERROR "While -DENABLE_TRT_BACKEND=ON, must set -DWITH_GPU=ON, but now it's OFF")
endif()
if(NOT BUILD_ON_JETSON)
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()
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)
include_directories(${TRT_DIRECTORY}/include)
include_directories(${TRT_INC_DIR})
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_PLUGIN_LIB nvinfer_plugin ${TRT_DIRECTORY}/lib)
find_library(TRT_INFER_LIB nvinfer ${TRT_LIB_DIR})
find_library(TRT_ONNX_LIB nvonnxparser ${TRT_LIB_DIR})
find_library(TRT_PLUGIN_LIB nvinfer_plugin ${TRT_LIB_DIR})
list(APPEND DEPEND_LIBS ${TRT_INFER_LIB} ${TRT_ONNX_LIB} ${TRT_PLUGIN_LIB})
if(NOT BUILD_ON_JETSON)
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/third_libs/install/tensorrt")
endif()
@@ -253,7 +272,7 @@ if(ENABLE_TRT_BACKEND)
ERROR_VARIABLE curr_out)
message(STATUS "result:${result} out:${curr_out}")
endif()
endif()
endif()
if(ENABLE_VISION)

View File

@@ -10,6 +10,7 @@ set(ENABLE_TRT_BACKEND @ENABLE_TRT_BACKEND@)
set(ENABLE_PADDLE_FRONTEND @ENABLE_PADDLE_FRONTEND@)
set(ENABLE_VISION @ENABLE_VISION@)
set(ENABLE_TEXT @ENABLE_TEXT@)
set(BUILD_ON_JETON @BUILD_ON_JETSON@)
# set(ENABLE_OPENCV_CUDA @ENABLE_OPENCV_CUDA@)
set(LIBRARY_NAME @LIBRARY_NAME@)
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.")
endif()
endif()
FOREACH(LIB ${FASTDEPLOY_LIBS})
message(get_filename_component(directory ${LIB})
ENDFOREACH(LIB)

View File

@@ -16,7 +16,7 @@
#include <cstring>
#include "NvInferSafeRuntime.h"
#include "NvInferRuntime.h"
#include "fastdeploy/utils/utils.h"
#ifdef ENABLE_PADDLE_FRONTEND
#include "paddle2onnx/converter.h"

View File

@@ -11,7 +11,6 @@
// 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.
#ifdef WITH_GPU
#include <cuda_runtime_api.h>
#endif

View File

@@ -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_TRT_BACKEND"] = os.getenv("ENABLE_TRT_BACKEND", "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["CUDA_DIRECTORY"] = os.getenv("CUDA_DIRECTORY",
"/usr/local/cuda")