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

solve mklml memory leak (#23557)

上级 84cd45f6
...@@ -37,6 +37,9 @@ ...@@ -37,6 +37,9 @@
#include "paddle/fluid/inference/utils/singleton.h" #include "paddle/fluid/inference/utils/singleton.h"
#include "paddle/fluid/memory/memcpy.h" #include "paddle/fluid/memory/memcpy.h"
#include "paddle/fluid/platform/cpu_helper.h" #include "paddle/fluid/platform/cpu_helper.h"
#ifdef PADDLE_WITH_MKLML
#include "paddle/fluid/platform/dynload/mklml.h"
#endif
#include "paddle/fluid/platform/gpu_info.h" #include "paddle/fluid/platform/gpu_info.h"
#include "paddle/fluid/platform/place.h" #include "paddle/fluid/platform/place.h"
#include "paddle/fluid/platform/profiler.h" #include "paddle/fluid/platform/profiler.h"
...@@ -308,6 +311,14 @@ bool AnalysisPredictor::Run(const std::vector<PaddleTensor> &inputs, ...@@ -308,6 +311,14 @@ bool AnalysisPredictor::Run(const std::vector<PaddleTensor> &inputs,
paddle::platform::SetNumThreads(1); paddle::platform::SetNumThreads(1);
#ifdef PADDLE_WITH_MKLDNN #ifdef PADDLE_WITH_MKLDNN
if (config_.use_mkldnn_) MkldnnPostReset(); if (config_.use_mkldnn_) MkldnnPostReset();
#endif
#if defined(PADDLE_WITH_MKLML) && defined(_LINUX)
// 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 #endif
return true; return true;
} }
...@@ -648,6 +659,14 @@ bool AnalysisPredictor::ZeroCopyRun() { ...@@ -648,6 +659,14 @@ 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)
// 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; return true;
} }
......
...@@ -89,6 +89,7 @@ extern void* mklml_dso_handle; ...@@ -89,6 +89,7 @@ extern void* mklml_dso_handle;
__macro(vdInv); \ __macro(vdInv); \
__macro(vmsErf); \ __macro(vmsErf); \
__macro(vmdErf); \ __macro(vmdErf); \
__macro(MKL_Free_Buffers); \
__macro(MKL_Set_Num_Threads) __macro(MKL_Set_Num_Threads)
MKLML_ROUTINE_EACH(DECLARE_DYNAMIC_LOAD_MKLML_WRAP); MKLML_ROUTINE_EACH(DECLARE_DYNAMIC_LOAD_MKLML_WRAP);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册