Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
df7fabee
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
df7fabee
编写于
9月 24, 2020
作者:
W
Wilber
提交者:
GitHub
9月 24, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix memory leak for mkldnn. (#27493)
上级
b7319ef5
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
41 addition
and
4 deletion
+41
-4
paddle/fluid/inference/api/analysis_predictor.cc
paddle/fluid/inference/api/analysis_predictor.cc
+30
-4
paddle/fluid/inference/api/analysis_predictor.h
paddle/fluid/inference/api/analysis_predictor.h
+11
-0
未找到文件。
paddle/fluid/inference/api/analysis_predictor.cc
浏览文件 @
df7fabee
...
...
@@ -245,7 +245,18 @@ bool AnalysisPredictor::PrepareExecutor() {
void
AnalysisPredictor
::
MkldnnPreSet
(
const
std
::
vector
<
PaddleTensor
>
&
inputs
)
{
#ifdef PADDLE_WITH_MKLDNN
VLOG
(
2
)
<<
"AnalysisPredictor::Run get_cur_mkldnn_session_id="
std
::
vector
<
std
::
vector
<
int
>>
inputs_shape
;
for
(
size_t
i
=
0
;
i
<
inputs
.
size
();
++
i
)
{
inputs_shape
.
emplace_back
(
inputs
[
i
].
shape
);
}
MkldnnPreSet
(
inputs_shape
);
#endif
}
void
AnalysisPredictor
::
MkldnnPreSet
(
const
std
::
vector
<
std
::
vector
<
int
>>
&
inputs_shape
)
{
#ifdef PADDLE_WITH_MKLDNN
VLOG
(
2
)
<<
"AnalysisPredictor::ZeroCopyRun get_cur_mkldnn_session_id="
<<
platform
::
MKLDNNDeviceContext
::
tls
().
get_cur_mkldnn_session_id
();
// In cache clearing mode.
if
(
config_
.
mkldnn_cache_capacity_
>
0
)
{
...
...
@@ -257,9 +268,9 @@ void AnalysisPredictor::MkldnnPreSet(const std::vector<PaddleTensor> &inputs) {
config_
.
mkldnn_cache_capacity_
);
// Set current_input_shape for caching dynamic shape.
std
::
stringstream
ss
;
for
(
size_t
i
=
0
;
i
<
inputs
.
size
();
++
i
)
{
for
(
size_t
j
=
0
;
j
<
inputs
[
i
].
shape
.
size
();
++
j
)
{
ss
<<
inputs
[
i
].
shape
[
j
]
<<
"-"
;
for
(
size_t
i
=
0
;
i
<
inputs
_shape
.
size
();
++
i
)
{
for
(
size_t
j
=
0
;
j
<
inputs
_shape
[
i
]
.
size
();
++
j
)
{
ss
<<
inputs
_shape
[
i
]
[
j
]
<<
"-"
;
}
}
VLOG
(
2
)
<<
"Set input shape="
<<
ss
.
str
();
...
...
@@ -742,6 +753,18 @@ std::unique_ptr<ZeroCopyTensor> AnalysisPredictor::GetOutputTensor(
bool
AnalysisPredictor
::
ZeroCopyRun
()
{
paddle
::
platform
::
SetNumThreads
(
config_
.
cpu_math_library_num_threads
());
#ifdef PADDLE_WITH_MKLDNN
if
(
config_
.
use_mkldnn_
)
{
std
::
vector
<
std
::
vector
<
int
>>
shape_vector
;
auto
names
=
GetInputNames
();
for
(
size_t
i
=
0
;
i
<
names
.
size
();
++
i
)
{
auto
in_tensor
=
GetInputTensor
(
names
[
i
]);
shape_vector
.
emplace_back
(
in_tensor
->
shape
());
}
MkldnnPreSet
(
shape_vector
);
}
#endif
executor_
->
Run
();
// Fix TensorArray reuse not cleaned bug.
tensor_array_batch_cleaner_
.
CollectTensorArrays
(
sub_scope_
);
...
...
@@ -750,6 +773,9 @@ 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
);
#ifdef PADDLE_WITH_MKLDNN
if
(
config_
.
use_mkldnn_
)
MkldnnPostReset
();
#endif
#if defined(PADDLE_WITH_MKLML)
// Frees unused memory allocated by the Intel® MKL Memory Allocator to
// avoid memory leak. See:
...
...
paddle/fluid/inference/api/analysis_predictor.h
浏览文件 @
df7fabee
...
...
@@ -317,6 +317,17 @@ class AnalysisPredictor : public PaddlePredictor {
/// \param[in] inputs tensors
///
void
MkldnnPreSet
(
const
std
::
vector
<
PaddleTensor
>
&
inputs
);
///
/// \brief PreSet for Mkldnn multi-thread and dynamic shape input.
///
/// Used in AnalysisPredictor::Run(), do not support
/// AnalysisPredictor::ZeroCopyRun() now.
///
/// \param[in] inputs tensor shape
///
void
MkldnnPreSet
(
const
std
::
vector
<
std
::
vector
<
int
>>
&
inputs_shape
);
///
/// \brief PostReset for Mkldnn multi-thread and dynamic shape input.
///
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录