未验证 提交 9eedf05d 编写于 作者: T Tao Luo 提交者: GitHub

solve mklml memory leak on windows (#24015)

* solve mklml memory leak on windows

test=develop

* remove unused msvcr120.dll

test=develop
上级 b71abeee
...@@ -21,14 +21,12 @@ SET(MKLML_INC_DIR ${MKLML_ROOT}/include) ...@@ -21,14 +21,12 @@ SET(MKLML_INC_DIR ${MKLML_ROOT}/include)
SET(MKLML_LIB_DIR ${MKLML_ROOT}/lib) SET(MKLML_LIB_DIR ${MKLML_ROOT}/lib)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}" "${MKLML_ROOT}/lib") SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}" "${MKLML_ROOT}/lib")
SET(TIME_VERSION "2019.0.1.20181227")
IF(WIN32) 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_URL "https://paddlepaddledeps.bj.bcebos.com/${MKLML_VER}.zip" CACHE STRING "" FORCE)
SET(MKLML_LIB ${MKLML_LIB_DIR}/mklml.lib) SET(MKLML_LIB ${MKLML_LIB_DIR}/mklml.lib)
SET(MKLML_IOMP_LIB ${MKLML_LIB_DIR}/libiomp5md.lib) SET(MKLML_IOMP_LIB ${MKLML_LIB_DIR}/libiomp5md.lib)
SET(MKLML_SHARED_LIB ${MKLML_LIB_DIR}/mklml.dll) 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) SET(MKLML_SHARED_IOMP_LIB ${MKLML_LIB_DIR}/libiomp5md.dll)
ELSE() ELSE()
#TODO(intel-huying): #TODO(intel-huying):
......
...@@ -61,9 +61,9 @@ function(copy_part_of_thrid_party TARGET DST) ...@@ -61,9 +61,9 @@ function(copy_part_of_thrid_party TARGET DST)
if(WIN32) if(WIN32)
copy(${TARGET} copy(${TARGET}
SRCS ${MKLML_LIB} ${MKLML_IOMP_LIB} ${MKLML_SHARED_LIB} 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 DSTS ${dst_dir}/lib ${dst_dir}/lib ${dst_dir}/lib
${dst_dir}/lib ${dst_dir}/lib ${dst_dir}) ${dst_dir}/lib ${dst_dir})
else() else()
copy(${TARGET} copy(${TARGET}
SRCS ${MKLML_LIB} ${MKLML_IOMP_LIB} ${MKLML_INC_DIR} SRCS ${MKLML_LIB} ${MKLML_IOMP_LIB} ${MKLML_INC_DIR}
......
...@@ -323,13 +323,11 @@ bool AnalysisPredictor::Run(const std::vector<PaddleTensor> &inputs, ...@@ -323,13 +323,11 @@ bool AnalysisPredictor::Run(const std::vector<PaddleTensor> &inputs,
#ifdef PADDLE_WITH_MKLDNN #ifdef PADDLE_WITH_MKLDNN
if (config_.use_mkldnn_) MkldnnPostReset(); if (config_.use_mkldnn_) MkldnnPostReset();
#endif #endif
#if defined(PADDLE_WITH_MKLML) && defined(_LINUX) #if defined(PADDLE_WITH_MKLML)
// Frees unused memory allocated by the Intel® MKL Memory Allocator to // Frees unused memory allocated by the Intel® MKL Memory Allocator to
// avoid memory leak. See: // avoid memory leak. See:
// https://software.intel.com/en-us/mkl-developer-reference-c-mkl-free-buffers // https://software.intel.com/en-us/mkl-developer-reference-c-mkl-free-buffers
platform::dynload::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 #endif
return true; return true;
} }
...@@ -710,13 +708,11 @@ bool AnalysisPredictor::ZeroCopyRun() { ...@@ -710,13 +708,11 @@ bool AnalysisPredictor::ZeroCopyRun() {
// recover the cpu_math_library_num_threads to 1, in order to avoid thread // recover the cpu_math_library_num_threads to 1, in order to avoid thread
// conflict when integrating it into deployment service. // conflict when integrating it into deployment service.
paddle::platform::SetNumThreads(1); 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 // Frees unused memory allocated by the Intel® MKL Memory Allocator to
// avoid memory leak. See: // avoid memory leak. See:
// https://software.intel.com/en-us/mkl-developer-reference-c-mkl-free-buffers // https://software.intel.com/en-us/mkl-developer-reference-c-mkl-free-buffers
platform::dynload::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 #endif
return true; return true;
} }
......
...@@ -165,7 +165,6 @@ if(WIN32) ...@@ -165,7 +165,6 @@ if(WIN32)
add_custom_command(TARGET ${DEMO_NAME} POST_BUILD 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/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/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 COMMAND ${CMAKE_COMMAND} -E copy ${MKLDNN_PATH}/lib/mkldnn.dll ${CMAKE_BINARY_DIR}/Release
) )
else() else()
......
...@@ -69,7 +69,6 @@ if(WITH_PYTHON) ...@@ -69,7 +69,6 @@ if(WITH_PYTHON)
if(${CBLAS_PROVIDER} STREQUAL MKLML) if(${CBLAS_PROVIDER} STREQUAL MKLML)
add_custom_command(TARGET op_function_generator POST_BUILD 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} ${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} COMMAND ${CMAKE_COMMAND} -E copy ${MKLML_SHARED_IOMP_LIB} ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}
) )
else(${CBLAS_PROVIDER} STREQUAL EXTERN_OPENBLAS) else(${CBLAS_PROVIDER} STREQUAL EXTERN_OPENBLAS)
......
...@@ -251,10 +251,6 @@ if '${WITH_MKL}' == 'ON': ...@@ -251,10 +251,6 @@ if '${WITH_MKL}' == 'ON':
shutil.copy('${MKLML_SHARED_LIB}', libs_path) shutil.copy('${MKLML_SHARED_LIB}', libs_path)
shutil.copy('${MKLML_SHARED_IOMP_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] 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: else:
if os.name == 'nt': if os.name == 'nt':
# copy the openblas.dll # copy the openblas.dll
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册