Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
f465b03e
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
f465b03e
编写于
9月 20, 2018
作者:
M
Michal Gallus
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Enable MKLDNN in Analysis Predictor
Also fix MKL-DNN pooling integration for ceil mode
上级
f66d08c2
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
37 addition
and
7 deletion
+37
-7
paddle/fluid/inference/api/analysis_predictor.cc
paddle/fluid/inference/api/analysis_predictor.cc
+1
-1
paddle/fluid/operators/pool_mkldnn_op.cc
paddle/fluid/operators/pool_mkldnn_op.cc
+36
-6
未找到文件。
paddle/fluid/inference/api/analysis_predictor.cc
浏览文件 @
f465b03e
...
...
@@ -76,10 +76,10 @@ bool AnalysisPredictor::Init(
}
OptimizeInferenceProgram
();
ctx_
=
executor_
->
Prepare
(
*
inference_program_
,
0
);
if
(
config_
.
_use_mkldnn
)
{
executor_
->
EnableMKLDNN
(
*
inference_program_
);
}
ctx_
=
executor_
->
Prepare
(
*
inference_program_
,
0
);
VLOG
(
5
)
<<
"to create variables"
;
PADDLE_ENFORCE
(
scope_
.
get
());
...
...
paddle/fluid/operators/pool_mkldnn_op.cc
浏览文件 @
f465b03e
...
...
@@ -46,6 +46,26 @@ static std::string gethash(const memory::dims& input_dims,
dims2str
(
paddings
)
+
pooling_type
+
suffix
;
}
static
int
ComputeCeiledOutput
(
int
input_size
,
int
kernel_size
,
int
padding
,
int
stride
)
{
return
(
input_size
-
kernel_size
+
2
*
padding
)
/
stride
+
1
;
}
static
void
CorrectOutputSize
(
const
std
::
vector
<
int
>&
src_tz
,
const
std
::
vector
<
int
>&
dst_tz
,
const
std
::
vector
<
int
>&
kernel_size
,
const
std
::
vector
<
int
>&
paddings
,
const
std
::
vector
<
int
>&
strides
,
std
::
vector
<
int
>&
right_bot_padding
)
{
for
(
int
i
=
0
;
i
<
right_bot_padding
.
size
();
i
++
)
{
int
desired_size
=
ComputeCeiledOutput
(
src_tz
[
i
+
2
],
kernel_size
[
i
],
paddings
[
i
],
strides
[
i
]);
if
(
desired_size
!=
dst_tz
[
i
+
2
])
{
right_bot_padding
[
i
]
+=
strides
[
i
];
}
}
}
template
<
typename
T
>
class
PoolMKLDNNOpKernel
:
public
paddle
::
framework
::
OpKernel
<
T
>
{
public:
...
...
@@ -103,6 +123,13 @@ class PoolMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
auto
pool_p
=
std
::
static_pointer_cast
<
pooling_forward
>
(
dev_ctx
.
GetBlob
(
key_pool_p
));
if
(
pool_p
==
nullptr
)
{
const
std
::
vector
<
int
>&
padding_left_top
(
paddings
);
std
::
vector
<
int
>
padding_right_bottom
(
paddings
);
bool
ceil_mode
=
ctx
.
Attr
<
bool
>
(
"ceil_mode"
);
if
(
ceil_mode
)
{
CorrectOutputSize
(
src_tz
,
dst_tz
,
ksize
,
paddings
,
strides
,
padding_right_bottom
);
}
auto
src_md
=
platform
::
MKLDNNMemDesc
(
src_tz
,
platform
::
MKLDNNGetDataType
<
T
>
(),
input_format
);
...
...
@@ -114,8 +141,9 @@ class PoolMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
mkldnn
::
memory
::
format
::
any
);
std
::
shared_ptr
<
mkldnn
::
pooling_forward
::
primitive_desc
>
pool_pd
=
CreatePrimitiveDesc
(
src_md
,
dst_md
,
strides
,
paddings
,
ksize
,
pooling_type
,
mkldnn_engine
);
CreatePrimitiveDesc
(
src_md
,
dst_md
,
strides
,
padding_left_top
,
padding_right_bottom
,
ksize
,
pooling_type
,
mkldnn_engine
,
ceil_mode
);
// save pool_pd into global device context to be referred in backward path
dev_ctx
.
SetBlob
(
key_pool_pd
,
pool_pd
);
...
...
@@ -171,14 +199,16 @@ class PoolMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
private:
std
::
unique_ptr
<
mkldnn
::
pooling_forward
::
primitive_desc
>
CreatePrimitiveDesc
(
const
mkldnn
::
memory
::
desc
&
src
,
const
mkldnn
::
memory
::
desc
&
dst
,
const
std
::
vector
<
int
>&
stride
,
const
std
::
vector
<
int
>&
padding
,
const
std
::
vector
<
int
>&
kernel
,
const
std
::
string
&
pooling_type
,
const
mkldnn
::
engine
&
engine
)
const
{
const
std
::
vector
<
int
>&
stride
,
const
std
::
vector
<
int
>&
padding_left_top
,
const
std
::
vector
<
int
>&
padding_right_bot
,
const
std
::
vector
<
int
>&
kernel
,
const
std
::
string
&
pooling_type
,
const
mkldnn
::
engine
&
engine
,
bool
ceil_mode
)
const
{
auto
pool_desc
=
mkldnn
::
pooling_forward
::
desc
(
mkldnn
::
prop_kind
::
forward
,
pooling_type
==
"max"
?
mkldnn
::
algorithm
::
pooling_max
:
mkldnn
::
algorithm
::
pooling_avg
,
src
,
dst
,
stride
,
kernel
,
padding
,
padding
,
mkldnn
::
padding_kind
::
zero
);
src
,
dst
,
stride
,
kernel
,
padding_left_top
,
padding_right_bot
,
mkldnn
::
padding_kind
::
zero
);
auto
p_pool_pd
=
new
mkldnn
::
pooling_forward
::
primitive_desc
(
pool_desc
,
engine
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录