From fe827540a78de6bd8601a52526ec74ba26ae8fa8 Mon Sep 17 00:00:00 2001 From: Wilber Date: Mon, 5 Jul 2021 16:43:40 +0800 Subject: [PATCH] cherry-pick prs. (#33932) --- cmake/inference_lib.cmake | 2 +- cmake/tensorrt.cmake | 20 ++++++++++++++++++- .../inference/api/paddle_analysis_config.h | 2 +- tools/remove_grad_op_and_kernel.py | 7 ++++--- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/cmake/inference_lib.cmake b/cmake/inference_lib.cmake index 9574af761ed..2e7d32046fd 100644 --- a/cmake/inference_lib.cmake +++ b/cmake/inference_lib.cmake @@ -345,7 +345,7 @@ function(version version_file) file(APPEND ${version_file} "CXX compiler version: ${CMAKE_CXX_COMPILER_VERSION}\n") if(TENSORRT_FOUND) file(APPEND ${version_file} - "WITH_TENSORRT: ${TENSORRT_FOUND}\n" "TensorRT version: v${TENSORRT_MAJOR_VERSION}\n") + "WITH_TENSORRT: ${TENSORRT_FOUND}\n" "TensorRT version: v${TENSORRT_MAJOR_VERSION}.${TENSORRT_MINOR_VERSION}.${TENSORRT_PATCH_VERSION}.${TENSORRT_BUILD_VERSION}\n") endif() if(WITH_LITE) file(APPEND ${version_file} "WITH_LITE: ${WITH_LITE}\n" "LITE_GIT_TAG: ${LITE_GIT_TAG}\n") diff --git a/cmake/tensorrt.cmake b/cmake/tensorrt.cmake index 889332fc557..e4b22befff8 100644 --- a/cmake/tensorrt.cmake +++ b/cmake/tensorrt.cmake @@ -47,11 +47,23 @@ if(TENSORRT_FOUND) file(READ ${TENSORRT_INCLUDE_DIR}/NvInfer.h TENSORRT_VERSION_FILE_CONTENTS) string(REGEX MATCH "define NV_TENSORRT_MAJOR +([0-9]+)" TENSORRT_MAJOR_VERSION "${TENSORRT_VERSION_FILE_CONTENTS}") + string(REGEX MATCH "define NV_TENSORRT_MINOR +([0-9]+)" TENSORRT_MINOR_VERSION + "${TENSORRT_VERSION_FILE_CONTENTS}") + string(REGEX MATCH "define NV_TENSORRT_PATCH +([0-9]+)" TENSORRT_PATCH_VERSION + "${TENSORRT_VERSION_FILE_CONTENTS}") + string(REGEX MATCH "define NV_TENSORRT_BUILD +([0-9]+)" TENSORRT_BUILD_VERSION + "${TENSORRT_VERSION_FILE_CONTENTS}") if("${TENSORRT_MAJOR_VERSION}" STREQUAL "") file(READ ${TENSORRT_INCLUDE_DIR}/NvInferVersion.h TENSORRT_VERSION_FILE_CONTENTS) string(REGEX MATCH "define NV_TENSORRT_MAJOR +([0-9]+)" TENSORRT_MAJOR_VERSION "${TENSORRT_VERSION_FILE_CONTENTS}") + string(REGEX MATCH "define NV_TENSORRT_MINOR +([0-9]+)" TENSORRT_MINOR_VERSION + "${TENSORRT_VERSION_FILE_CONTENTS}") + string(REGEX MATCH "define NV_TENSORRT_PATCH +([0-9]+)" TENSORRT_PATCH_VERSION + "${TENSORRT_VERSION_FILE_CONTENTS}") + string(REGEX MATCH "define NV_TENSORRT_BUILD +([0-9]+)" TENSORRT_BUILD_VERSION + "${TENSORRT_VERSION_FILE_CONTENTS}") endif() if("${TENSORRT_MAJOR_VERSION}" STREQUAL "") @@ -60,9 +72,15 @@ if(TENSORRT_FOUND) string(REGEX REPLACE "define NV_TENSORRT_MAJOR +([0-9]+)" "\\1" TENSORRT_MAJOR_VERSION "${TENSORRT_MAJOR_VERSION}") + string(REGEX REPLACE "define NV_TENSORRT_MINOR +([0-9]+)" "\\1" + TENSORRT_MINOR_VERSION "${TENSORRT_MINOR_VERSION}") + string(REGEX REPLACE "define NV_TENSORRT_PATCH +([0-9]+)" "\\1" + TENSORRT_PATCH_VERSION "${TENSORRT_PATCH_VERSION}") + string(REGEX REPLACE "define NV_TENSORRT_BUILD +([0-9]+)" "\\1" + TENSORRT_BUILD_VERSION "${TENSORRT_BUILD_VERSION}") message(STATUS "Current TensorRT header is ${TENSORRT_INCLUDE_DIR}/NvInfer.h. " - "Current TensorRT version is v${TENSORRT_MAJOR_VERSION}. ") + "Current TensorRT version is v${TENSORRT_MAJOR_VERSION}.${TENSORRT_MINOR_VERSION}.${TENSORRT_PATCH_VERSION}.${TENSORRT_BUILD_VERSION} ") include_directories(${TENSORRT_INCLUDE_DIR}) link_directories(${TENSORRT_LIBRARY}) add_definitions(-DPADDLE_WITH_TENSORRT) diff --git a/paddle/fluid/inference/api/paddle_analysis_config.h b/paddle/fluid/inference/api/paddle_analysis_config.h index f9e4869934a..6e986f5f482 100644 --- a/paddle/fluid/inference/api/paddle_analysis_config.h +++ b/paddle/fluid/inference/api/paddle_analysis_config.h @@ -678,7 +678,7 @@ struct PD_INFER_DECL AnalysisConfig { bool xpu_adaptive_seqlen_; // mkldnn related. - int mkldnn_cache_capacity_{0}; + int mkldnn_cache_capacity_{10}; bool use_mkldnn_quantizer_{false}; std::shared_ptr mkldnn_quantizer_config_; bool use_mkldnn_bfloat16_{false}; diff --git a/tools/remove_grad_op_and_kernel.py b/tools/remove_grad_op_and_kernel.py index 85bbf8cdddc..e8ab321e961 100644 --- a/tools/remove_grad_op_and_kernel.py +++ b/tools/remove_grad_op_and_kernel.py @@ -20,6 +20,7 @@ import os import sys import re import glob +import io def find_type_files(cur_dir, file_type, file_list=[]): @@ -124,7 +125,7 @@ if __name__ == '__main__': custom_pattern2 = custom_pattern2[:-1] all_matches = [] - with open(op_file, 'r') as f: + with io.open(op_file, 'r', encoding='utf-8') as f: content = ''.join(f.readlines()) op, op_count = remove_grad_op_and_kernel(content, op_pattern1, @@ -157,8 +158,8 @@ if __name__ == '__main__': for i in all_matches: content = content.replace(i, '') - with open(op_file, 'w') as f: - f.write(content) + with io.open(op_file, 'w', encoding='utf-8') as f: + f.write(u'{}'.format(content)) # 2. update operators/CMakeLists.txt cmake_file = os.path.join(tool_dir, -- GitLab