Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
fa164241
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
提交
fa164241
编写于
11月 05, 2018
作者:
Z
Zhang, Guoming
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
merge PR-14185
上级
03df18c9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
74 addition
and
8 deletion
+74
-8
paddle/fluid/operators/conv_mkldnn_op.cc
paddle/fluid/operators/conv_mkldnn_op.cc
+54
-8
paddle/fluid/platform/mkldnn_helper.h
paddle/fluid/platform/mkldnn_helper.h
+20
-0
未找到文件。
paddle/fluid/operators/conv_mkldnn_op.cc
浏览文件 @
fa164241
...
...
@@ -59,6 +59,11 @@ class ConvMKLDNNHandler : public platform::MKLDNNHandler {
size_t
GetDstMemorySize
()
const
{
return
conv_pd_
->
dst_primitive_desc
().
get_size
();
}
mkldnn
::
memory
::
format
GetDstFormat
()
const
{
return
static_cast
<
mkldnn
::
memory
::
format
>
(
conv_pd_
->
dst_primitive_desc
().
desc
().
data
.
format
);
}
size_t
GetDiffWeightsMemorySize
()
const
{
return
conv_bwd_weights_pd_
->
diff_weights_primitive_desc
().
get_size
();
...
...
@@ -111,6 +116,21 @@ class ConvMKLDNNHandler : public platform::MKLDNNHandler {
"@data-weights_mem_p"
,
pipeline
);
}
std
::
shared_ptr
<
mkldnn
::
memory
>
AcquireResidualDataMemory
(
const
mkldnn
::
memory
::
desc
&
md
,
void
*
ptr
)
{
return
this
->
AcquireMemory
(
md
,
ptr
,
"@user_residual_data_mem_p"
);
}
std
::
shared_ptr
<
mkldnn
::
memory
>
AcquireDstMemoryFromResidualDataMemory
(
const
std
::
shared_ptr
<
mkldnn
::
memory
>&
user_residual_memory_p
,
void
*
dst_ptr
,
std
::
vector
<
mkldnn
::
primitive
>&
pipeline
)
{
// NOLINT
return
this
->
AcquireMemory
(
user_residual_memory_p
,
this
->
AcquireDstMemoryFromPrimitive
(
dst_ptr
),
"@residual_data_mem_p"
,
pipeline
);
}
std
::
shared_ptr
<
mkldnn
::
memory
>
AcquireDiffSrcMemoryFromDataPrimitive
(
void
*
ptr
)
{
return
this
->
AcquireMemoryFromPrimitive
(
...
...
@@ -505,6 +525,7 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
// create reorder primitive if the input format is not the preferred one
auto
src_memory_p
=
handler
.
AcquireSrcMemoryFromPrimitive
(
user_src_memory_p
,
pipeline
);
std
::
shared_ptr
<
mkldnn
::
memory
>
weights_memory_p
;
if
(
is_INT8
){
int
mask_reorder
=
is_multi_channel
?
((
g
!=
1
)
?
(
1
<<
1
)
+
(
1
<<
0
)
:
1
<<
0
)
:
0
;
...
...
@@ -549,7 +570,13 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
}
}
}
else
{
T
*
output_data
=
nullptr
;
// create reorder primitive if the input format is not the preferred one
// auto src_memory_p =
// handler.AcquireSrcMemoryFromPrimitive(user_src_memory_p, pipeline);
// auto weights_memory_p = handler.AcquireWeightsMemoryFromPrimitive(
// user_weights_memory_p, pipeline, is_test);
// std::shared_ptr<mkldnn::memory> dst_memory_p;
if
(
fuse_residual_conn
)
{
auto
residual_param
=
ctx
.
Input
<
Tensor
>
(
"ResidualData"
);
auto
residual_param_data
=
residual_param
->
data
<
T
>
();
...
...
@@ -561,14 +588,34 @@ class ConvMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
"Output and elementwise parameter need to have the "
"same dimension sizes"
);
output
->
ShareDataWith
(
*
residual_param
);
output_data
=
output
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
if
(
residual_param
->
format
()
!=
handler
.
GetDstFormat
())
{
auto
output_data
=
output
->
mutable_data
<
T
>
(
ctx
.
GetPlace
(),
handler
.
GetDstMemorySize
());
auto
residual_data_tz
=
paddle
::
framework
::
vectorize2int
(
residual_param
->
dims
());
auto
residual_data_type
=
paddle
::
framework
::
ToMKLDNNDataType
(
residual_param
->
type
());
auto
user_residual_md
=
platform
::
MKLDNNMemDesc
(
residual_data_tz
,
residual_data_type
,
residual_param
->
format
());
auto
user_residual_memory_p
=
handler
.
AcquireResidualDataMemory
(
user_residual_md
,
to_void_cast
<
T
>
(
residual_param_data
));
dst_memory_p
=
handler
.
AcquireDstMemoryFromResidualDataMemory
(
user_residual_memory_p
,
to_void_cast
<
T
>
(
output_data
),
pipeline
);
}
else
{
output
->
ShareDataWith
(
*
residual_param
);
auto
output_data
=
output
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
dst_memory_p
=
handler
.
AcquireDstMemoryFromPrimitive
(
to_void_cast
<
T
>
(
output_data
));
}
}
else
{
output_data
=
output
->
mutable_data
<
T
>
(
ctx
.
GetPlace
(),
handler
.
GetDstMemorySize
());
auto
output_data
=
output
->
mutable_data
<
T
>
(
ctx
.
GetPlace
(),
handler
.
GetDstMemorySize
());
dst_memory_p
=
handler
.
AcquireDstMemoryFromPrimitive
(
to_void_cast
<
T
>
(
output_data
));
}
dst_memory_p
=
handler
.
AcquireDstMemoryFromPrimitive
(
to_void_cast
<
T
>
(
output_data
));
//
dst_memory_p =
//
handler.AcquireDstMemoryFromPrimitive(to_void_cast<T>(output_data));
}
// create convolution op primitive
...
...
@@ -912,7 +959,6 @@ class ConvMKLDNNGradOpKernel : public paddle::framework::OpKernel<T> {
user_weights_md
,
to_void_cast
<
T
>
(
filter_data
));
auto
user_diff_dst_memory_p
=
handler
.
AcquireDiffDstMemory
(
user_diff_dst_md
,
to_void_cast
<
T
>
(
output_grad_data
));
// create backward conv primitive for weights
if
(
filter_grad
)
{
auto
src_memory_p
=
handler
.
AcquireSrcMemoryFromWeightsPrimitive
(
...
...
paddle/fluid/platform/mkldnn_helper.h
浏览文件 @
fa164241
...
...
@@ -188,6 +188,26 @@ class MKLDNNHandler {
return
mem_p
;
}
std
::
shared_ptr
<
mkldnn
::
memory
>
AcquireMemory
(
const
std
::
shared_ptr
<
mkldnn
::
memory
>&
user_memory_p
,
const
std
::
shared_ptr
<
mkldnn
::
memory
>&
target_memory_p
,
const
std
::
string
&
suffix
,
std
::
vector
<
mkldnn
::
primitive
>&
pipeline
)
{
// NOLINT
auto
local_key
=
key_
+
suffix
;
auto
key_reorder_p
=
key_
+
suffix
+
"reorder_p"
;
auto
stored_reorder_p
=
std
::
static_pointer_cast
<
mkldnn
::
reorder
>
(
dev_ctx_
.
GetBlob
(
key_reorder_p
));
if
(
stored_reorder_p
)
{
pipeline
.
push_back
(
*
stored_reorder_p
);
}
else
{
auto
reorder_p
=
std
::
make_shared
<
mkldnn
::
reorder
>
(
*
user_memory_p
,
*
target_memory_p
);
dev_ctx_
.
SetBlob
(
key_reorder_p
,
reorder_p
);
pipeline
.
push_back
(
*
reorder_p
);
}
return
target_memory_p
;
}
std
::
shared_ptr
<
mkldnn
::
memory
>
AcquireMemory
(
mkldnn
::
memory
::
primitive_desc
&
mpd
,
// NOLINT
mkldnn
::
memory
::
primitive_desc
&
user_mpd
,
// NOLINT
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录