From b4c83b9e9eb34397ea30e7b0f71e135d62a97dbf Mon Sep 17 00:00:00 2001 From: MRXLT Date: Wed, 12 Aug 2020 17:30:16 +0800 Subject: [PATCH] for compile --- cmake/paddlepaddle.cmake | 57 ++++++++++++------- core/general-server/CMakeLists.txt | 6 +- core/predictor/framework/infer.h | 10 ++++ .../inferencer-fluid-gpu/CMakeLists.txt | 1 + .../include/fluid_gpu_engine.h | 16 +++++- 5 files changed, 68 insertions(+), 22 deletions(-) diff --git a/cmake/paddlepaddle.cmake b/cmake/paddlepaddle.cmake index eee5369f..c1a7ce0a 100644 --- a/cmake/paddlepaddle.cmake +++ b/cmake/paddlepaddle.cmake @@ -31,13 +31,14 @@ message( "WITH_GPU = ${WITH_GPU}") # Paddle Version should be one of: # latest: latest develop build # version number like 1.5.2 -SET(PADDLE_VERSION "1.8.1") +SET(PADDLE_VERSION "1.8.3") if (WITH_GPU) if (WITH_TRT) SET(PADDLE_LIB_VERSION "${PADDLE_VERSION}-gpu-cuda10.1-cudnn7.6-avx-mkl-trt6") else() SET(PADDLE_LIB_VERSION "${PADDLE_VERSION}-gpu-cuda10-cudnn7-avx-mkl") + endif() else() if (WITH_AVX) if (WITH_MKLML) @@ -53,21 +54,38 @@ endif() SET(PADDLE_LIB_PATH "http://paddle-inference-lib.bj.bcebos.com/${PADDLE_LIB_VERSION}/fluid_inference.tgz") MESSAGE(STATUS "PADDLE_LIB_PATH=${PADDLE_LIB_PATH}") if (WITH_GPU OR WITH_MKLML) -ExternalProject_Add( - "extern_paddle" - ${EXTERNAL_PROJECT_LOG_ARGS} - URL "${PADDLE_LIB_PATH}" - PREFIX "${PADDLE_SOURCES_DIR}" - DOWNLOAD_DIR "${PADDLE_DOWNLOAD_DIR}" - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - UPDATE_COMMAND "" - INSTALL_COMMAND - ${CMAKE_COMMAND} -E copy_directory ${PADDLE_DOWNLOAD_DIR}/paddle/include ${PADDLE_INSTALL_DIR}/include && - ${CMAKE_COMMAND} -E copy_directory ${PADDLE_DOWNLOAD_DIR}/paddle/lib ${PADDLE_INSTALL_DIR}/lib && - ${CMAKE_COMMAND} -E copy_directory ${PADDLE_DOWNLOAD_DIR}/third_party ${PADDLE_INSTALL_DIR}/third_party && - ${CMAKE_COMMAND} -E copy ${PADDLE_INSTALL_DIR}/third_party/install/mkldnn/lib/libmkldnn.so.0 ${PADDLE_INSTALL_DIR}/third_party/install/mkldnn/lib/libmkldnn.so -) + if (WITH_TRT) + ExternalProject_Add( + "extern_paddle" + ${EXTERNAL_PROJECT_LOG_ARGS} + URL "${PADDLE_LIB_PATH}" + PREFIX "${PADDLE_SOURCES_DIR}" + DOWNLOAD_DIR "${PADDLE_DOWNLOAD_DIR}" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + UPDATE_COMMAND "" + INSTALL_COMMAND + ${CMAKE_COMMAND} -E copy_directory ${PADDLE_DOWNLOAD_DIR}/paddle/include ${PADDLE_INSTALL_DIR}/include && + ${CMAKE_COMMAND} -E copy_directory ${PADDLE_DOWNLOAD_DIR}/paddle/lib ${PADDLE_INSTALL_DIR}/lib && + ${CMAKE_COMMAND} -E copy_directory ${PADDLE_DOWNLOAD_DIR}/third_party ${PADDLE_INSTALL_DIR}/third_party + ) + else() + ExternalProject_Add( + "extern_paddle" + ${EXTERNAL_PROJECT_LOG_ARGS} + URL "${PADDLE_LIB_PATH}" + PREFIX "${PADDLE_SOURCES_DIR}" + DOWNLOAD_DIR "${PADDLE_DOWNLOAD_DIR}" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + UPDATE_COMMAND "" + INSTALL_COMMAND + ${CMAKE_COMMAND} -E copy_directory ${PADDLE_DOWNLOAD_DIR}/paddle/include ${PADDLE_INSTALL_DIR}/include && + ${CMAKE_COMMAND} -E copy_directory ${PADDLE_DOWNLOAD_DIR}/paddle/lib ${PADDLE_INSTALL_DIR}/lib && + ${CMAKE_COMMAND} -E copy_directory ${PADDLE_DOWNLOAD_DIR}/third_party ${PADDLE_INSTALL_DIR}/third_party && + ${CMAKE_COMMAND} -E copy ${PADDLE_INSTALL_DIR}/third_party/install/mkldnn/lib/libmkldnn.so.0 ${PADDLE_INSTALL_DIR}/third_party/install/mkldnn/lib/libmkldnn.so + ) + endif() else() ExternalProject_Add( "extern_paddle" @@ -98,12 +116,13 @@ SET_PROPERTY(TARGET openblas PROPERTY IMPORTED_LOCATION ${PADDLE_INSTALL_DIR}/th ADD_LIBRARY(paddle_fluid SHARED IMPORTED GLOBAL) SET_PROPERTY(TARGET paddle_fluid PROPERTY IMPORTED_LOCATION ${PADDLE_INSTALL_DIR}/lib/libpaddle_fluid.so) +if (WITH_TRT) ADD_LIBRARY(nvinfer SHARED IMPORTED GLOBAL) -SET_PROPERTY(TARGET nvinfer PROPERTY IMPORTED_LOCATION /paddle/third_party/TensorRT-6.0.1.5/lib/libnvinfer.so) +SET_PROPERTY(TARGET nvinfer PROPERTY IMPORTED_LOCATION ${TENSORRT_ROOT}/lib/libnvinfer.so) ADD_LIBRARY(nvinfer_plugin SHARED IMPORTED GLOBAL) -SET_PROPERTY(TARGET nvinfer_plugin PROPERTY IMPORTED_LOCATION /paddle/third_party/TensorRT-6.0.1.5/lib/libnvinfer_plugin.so) - +SET_PROPERTY(TARGET nvinfer_plugin PROPERTY IMPORTED_LOCATION ${TENSORRT_ROOT}/lib/libnvinfer_plugin.so) +endif() ADD_LIBRARY(xxhash STATIC IMPORTED GLOBAL) SET_PROPERTY(TARGET xxhash PROPERTY IMPORTED_LOCATION ${PADDLE_INSTALL_DIR}/third_party/install/xxhash/lib/libxxhash.a) diff --git a/core/general-server/CMakeLists.txt b/core/general-server/CMakeLists.txt index 9056e229..aa1b7bad 100644 --- a/core/general-server/CMakeLists.txt +++ b/core/general-server/CMakeLists.txt @@ -9,7 +9,7 @@ endif() target_include_directories(serving PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/../../core/predictor ) - + include_directories(${CUDNN_ROOT}/include/) if(WITH_GPU) target_link_libraries(serving -Wl,--whole-archive fluid_gpu_engine -Wl,--no-whole-archive) @@ -29,7 +29,11 @@ if(WITH_GPU) endif() if(WITH_MKL OR WITH_GPU) + if (WITH_TRT) + target_link_libraries(serving -liomp5 -lmklml_intel -lpthread -lcrypto -lm -lrt -lssl -ldl -lz -lbz2) + else() target_link_libraries(serving -liomp5 -lmklml_intel -lmkldnn -lpthread -lcrypto -lm -lrt -lssl -ldl -lz -lbz2) +endif() else() target_link_libraries(serving openblas -lpthread -lcrypto -lm -lrt -lssl -ldl -lz -lbz2) endif() diff --git a/core/predictor/framework/infer.h b/core/predictor/framework/infer.h index aedf951d..1ab49f36 100644 --- a/core/predictor/framework/infer.h +++ b/core/predictor/framework/infer.h @@ -38,6 +38,7 @@ class InferEngineCreationParams { _enable_ir_optimization = false; _static_optimization = false; _force_update_static_cache = false; + _use_trt = false; } void set_path(const std::string& path) { _path = path; } @@ -50,12 +51,16 @@ class InferEngineCreationParams { _enable_ir_optimization = enable_ir_optimization; } + void set_use_trt(bool use_trt) { _use_trt = use_trt; } + bool enable_memory_optimization() const { return _enable_memory_optimization; } bool enable_ir_optimization() const { return _enable_ir_optimization; } + bool use_trt() const { return _use_trt; } + void set_static_optimization(bool static_optimization = false) { _static_optimization = static_optimization; } @@ -86,6 +91,7 @@ class InferEngineCreationParams { bool _enable_ir_optimization; bool _static_optimization; bool _force_update_static_cache; + bool _use_trt; }; class InferEngine { @@ -172,6 +178,10 @@ class ReloadableInferEngine : public InferEngine { force_update_static_cache); } + if (conf.has_use_trt()) { + _infer_engine_params.set_use_trt(conf.use_trt()); + } + if (!check_need_reload() || load(_infer_engine_params) != 0) { LOG(ERROR) << "Failed load model_data_path" << _model_data_path; return -1; diff --git a/paddle_inference/inferencer-fluid-gpu/CMakeLists.txt b/paddle_inference/inferencer-fluid-gpu/CMakeLists.txt index 725da85b..6ba3ddd6 100644 --- a/paddle_inference/inferencer-fluid-gpu/CMakeLists.txt +++ b/paddle_inference/inferencer-fluid-gpu/CMakeLists.txt @@ -2,6 +2,7 @@ FILE(GLOB fluid_gpu_engine_srcs ${CMAKE_CURRENT_LIST_DIR}/src/*.cpp) add_library(fluid_gpu_engine ${fluid_gpu_engine_srcs}) target_include_directories(fluid_gpu_engine PUBLIC ${CMAKE_BINARY_DIR}/Paddle/fluid_install_dir/) + add_dependencies(fluid_gpu_engine pdserving extern_paddle configure) target_link_libraries(fluid_gpu_engine pdserving paddle_fluid iomp5 mklml_intel -lpthread -lcrypto -lm -lrt -lssl -ldl -lz) diff --git a/paddle_inference/inferencer-fluid-gpu/include/fluid_gpu_engine.h b/paddle_inference/inferencer-fluid-gpu/include/fluid_gpu_engine.h index e9af5ece..60d5bcdb 100644 --- a/paddle_inference/inferencer-fluid-gpu/include/fluid_gpu_engine.h +++ b/paddle_inference/inferencer-fluid-gpu/include/fluid_gpu_engine.h @@ -178,7 +178,7 @@ class FluidGpuNativeCore : public FluidFamilyCore { } }; -class FluidTRTAnalysisDirCore : public FluidFamilyCore { +class FluidGpuAnalysisDirCore : public FluidFamilyCore { public: int create(const predictor::InferEngineCreationParams& params) { std::string data_path = params.get_path(); @@ -238,14 +238,26 @@ class FluidTRTAnalysisDirCore : public FluidFamilyCore { analysis_config.SetTRTDynamicShapeInfo( min_input_shape, max_input_shape, opt_input_shape); #endif + int batch = 8; + int min_subgraph_size = 3; if (params.use_trt()) { analysis_config.EnableTensorRtEngine( 1 << 30, batch, - 5, + min_subgraph_size, paddle::AnalysisConfig::Precision::kFloat32, true, true); + } else { + if (params.enable_memory_optimization()) { + analysis_config.EnableMemoryOptim(); + } + + if (params.enable_ir_optimization()) { + analysis_config.SwitchIrOptim(true); + } else { + analysis_config.SwitchIrOptim(false); + } } AutoLock lock(GlobalPaddleCreateMutex::instance()); _core = -- GitLab