From 9eedf05d2f30671da5332f2f8b50e2061d5a0758 Mon Sep 17 00:00:00 2001 From: Tao Luo Date: Fri, 1 May 2020 22:28:19 +0800 Subject: [PATCH] solve mklml memory leak on windows (#24015) * solve mklml memory leak on windows test=develop * remove unused msvcr120.dll test=develop --- cmake/external/mklml.cmake | 4 +--- cmake/inference_lib.cmake | 4 ++-- paddle/fluid/inference/api/analysis_predictor.cc | 8 ++------ paddle/fluid/inference/api/demo_ci/CMakeLists.txt | 1 - paddle/fluid/pybind/CMakeLists.txt | 1 - python/setup.py.in | 4 ---- 6 files changed, 5 insertions(+), 17 deletions(-) diff --git a/cmake/external/mklml.cmake b/cmake/external/mklml.cmake index d0af809f4bb..4cf9b626d15 100644 --- a/cmake/external/mklml.cmake +++ b/cmake/external/mklml.cmake @@ -21,14 +21,12 @@ SET(MKLML_INC_DIR ${MKLML_ROOT}/include) SET(MKLML_LIB_DIR ${MKLML_ROOT}/lib) SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}" "${MKLML_ROOT}/lib") -SET(TIME_VERSION "2019.0.1.20181227") IF(WIN32) - SET(MKLML_VER "mklml_win_${TIME_VERSION}" CACHE STRING "" FORCE) + SET(MKLML_VER "mklml_win_2019.0.5.20190502" CACHE STRING "" FORCE) SET(MKLML_URL "https://paddlepaddledeps.bj.bcebos.com/${MKLML_VER}.zip" CACHE STRING "" FORCE) SET(MKLML_LIB ${MKLML_LIB_DIR}/mklml.lib) SET(MKLML_IOMP_LIB ${MKLML_LIB_DIR}/libiomp5md.lib) SET(MKLML_SHARED_LIB ${MKLML_LIB_DIR}/mklml.dll) - SET(MKLML_SHARED_LIB_DEPS ${MKLML_LIB_DIR}/msvcr120.dll) SET(MKLML_SHARED_IOMP_LIB ${MKLML_LIB_DIR}/libiomp5md.dll) ELSE() #TODO(intel-huying): diff --git a/cmake/inference_lib.cmake b/cmake/inference_lib.cmake index a52d91741af..7ab74e3cf2c 100644 --- a/cmake/inference_lib.cmake +++ b/cmake/inference_lib.cmake @@ -61,9 +61,9 @@ function(copy_part_of_thrid_party TARGET DST) if(WIN32) copy(${TARGET} SRCS ${MKLML_LIB} ${MKLML_IOMP_LIB} ${MKLML_SHARED_LIB} - ${MKLML_SHARED_LIB_DEPS} ${MKLML_SHARED_IOMP_LIB} ${MKLML_INC_DIR} + ${MKLML_SHARED_IOMP_LIB} ${MKLML_INC_DIR} DSTS ${dst_dir}/lib ${dst_dir}/lib ${dst_dir}/lib - ${dst_dir}/lib ${dst_dir}/lib ${dst_dir}) + ${dst_dir}/lib ${dst_dir}) else() copy(${TARGET} SRCS ${MKLML_LIB} ${MKLML_IOMP_LIB} ${MKLML_INC_DIR} diff --git a/paddle/fluid/inference/api/analysis_predictor.cc b/paddle/fluid/inference/api/analysis_predictor.cc index 1bcbe6acf02..5220388a277 100644 --- a/paddle/fluid/inference/api/analysis_predictor.cc +++ b/paddle/fluid/inference/api/analysis_predictor.cc @@ -323,13 +323,11 @@ bool AnalysisPredictor::Run(const std::vector &inputs, #ifdef PADDLE_WITH_MKLDNN if (config_.use_mkldnn_) MkldnnPostReset(); #endif -#if defined(PADDLE_WITH_MKLML) && defined(_LINUX) +#if defined(PADDLE_WITH_MKLML) // Frees unused memory allocated by the IntelĀ® MKL Memory Allocator to // avoid memory leak. See: // https://software.intel.com/en-us/mkl-developer-reference-c-mkl-free-buffers platform::dynload::MKL_Free_Buffers(); -// We don't support windows since MKL_Free_Buffers is not in -// mklml_win_2019.0.1.20181227.zip. We will upgrade mklml_win version later. #endif return true; } @@ -710,13 +708,11 @@ bool AnalysisPredictor::ZeroCopyRun() { // recover the cpu_math_library_num_threads to 1, in order to avoid thread // conflict when integrating it into deployment service. paddle::platform::SetNumThreads(1); -#if defined(PADDLE_WITH_MKLML) && defined(_LINUX) +#if defined(PADDLE_WITH_MKLML) // Frees unused memory allocated by the IntelĀ® MKL Memory Allocator to // avoid memory leak. See: // https://software.intel.com/en-us/mkl-developer-reference-c-mkl-free-buffers platform::dynload::MKL_Free_Buffers(); -// We don't support windows since MKL_Free_Buffers is not in -// mklml_win_2019.0.1.20181227.zip. We will upgrade mklml_win version later. #endif return true; } diff --git a/paddle/fluid/inference/api/demo_ci/CMakeLists.txt b/paddle/fluid/inference/api/demo_ci/CMakeLists.txt index 67519e3f4c5..0eccba2f00d 100644 --- a/paddle/fluid/inference/api/demo_ci/CMakeLists.txt +++ b/paddle/fluid/inference/api/demo_ci/CMakeLists.txt @@ -165,7 +165,6 @@ if(WIN32) add_custom_command(TARGET ${DEMO_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${MATH_LIB_PATH}/lib/mklml.dll ${CMAKE_BINARY_DIR}/Release COMMAND ${CMAKE_COMMAND} -E copy ${MATH_LIB_PATH}/lib/libiomp5md.dll ${CMAKE_BINARY_DIR}/Release - COMMAND ${CMAKE_COMMAND} -E copy ${MATH_LIB_PATH}/lib/msvcr120.dll ${CMAKE_BINARY_DIR}/Release COMMAND ${CMAKE_COMMAND} -E copy ${MKLDNN_PATH}/lib/mkldnn.dll ${CMAKE_BINARY_DIR}/Release ) else() diff --git a/paddle/fluid/pybind/CMakeLists.txt b/paddle/fluid/pybind/CMakeLists.txt index 0fad32d160f..70cd1b5d1af 100644 --- a/paddle/fluid/pybind/CMakeLists.txt +++ b/paddle/fluid/pybind/CMakeLists.txt @@ -69,7 +69,6 @@ if(WITH_PYTHON) if(${CBLAS_PROVIDER} STREQUAL MKLML) add_custom_command(TARGET op_function_generator POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${MKLML_SHARED_LIB} ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} - COMMAND ${CMAKE_COMMAND} -E copy ${MKLML_SHARED_LIB_DEPS} ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} COMMAND ${CMAKE_COMMAND} -E copy ${MKLML_SHARED_IOMP_LIB} ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE} ) else(${CBLAS_PROVIDER} STREQUAL EXTERN_OPENBLAS) diff --git a/python/setup.py.in b/python/setup.py.in index 8432361403b..4fc2c352a53 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -251,10 +251,6 @@ if '${WITH_MKL}' == 'ON': shutil.copy('${MKLML_SHARED_LIB}', libs_path) shutil.copy('${MKLML_SHARED_IOMP_LIB}', libs_path) package_data['paddle.libs']+=[('libmklml_intel' if os.name != 'nt' else 'mklml') + ext_name, ('libiomp5' if os.name != 'nt' else 'libiomp5md') + ext_name] - # mklml has dependency to vs runtime library - if os.name == 'nt': - shutil.copy('${MKLML_SHARED_LIB_DEPS}', libs_path) - package_data['paddle.libs'] += ['msvcr120.dll'] else: if os.name == 'nt': # copy the openblas.dll -- GitLab