Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
马赛克医院
Paddle
提交
72cc64e4
P
Paddle
项目概览
马赛克医院
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
72cc64e4
编写于
3月 21, 2018
作者:
T
Tomasz Patejko
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Device blobs are created only in training. Added testing attribute
上级
2d955275
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
52 addition
and
20 deletion
+52
-20
paddle/fluid/operators/lrn_mkldnn_op.cc
paddle/fluid/operators/lrn_mkldnn_op.cc
+51
-20
paddle/fluid/operators/lrn_op.cc
paddle/fluid/operators/lrn_op.cc
+1
-0
未找到文件。
paddle/fluid/operators/lrn_mkldnn_op.cc
浏览文件 @
72cc64e4
...
...
@@ -22,6 +22,22 @@ namespace operators {
using
paddle
::
framework
::
Tensor
;
using
paddle
::
platform
::
MKLDNNDeviceContext
;
namespace
{
template
<
typename
T
,
typename
...
Args
>
std
::
shared_ptr
<
T
>
insert_to_context
(
const
std
::
string
&
key
,
const
MKLDNNDeviceContext
&
dev_ctx
,
Args
&&
...
args
)
{
auto
p
=
std
::
static_pointer_cast
<
T
,
void
>
(
dev_ctx
.
GetBlob
(
key
));
if
(
!
p
)
{
p
=
std
::
make_shared
<
T
>
(
args
...);
dev_ctx
.
SetBlob
(
key
,
std
::
static_pointer_cast
<
void
,
T
>
(
p
));
}
return
p
;
}
}
// namespace
template
<
typename
T
>
class
LRNMKLDNNOpKernel
:
public
paddle
::
framework
::
OpKernel
<
T
>
{
public:
...
...
@@ -42,15 +58,11 @@ class LRNMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
auto
output_data
=
out
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
mid
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
const
std
::
string
key
=
ctx
.
op
().
Output
(
"Out"
);
const
std
::
string
key_src_memory
=
key
+
"@lrn_src_memory"
;
const
std
::
string
key_pd
=
key
+
"@lrn_pd"
;
const
std
::
string
key_workspace_memory
=
key
+
"@lrn_workspace_memory"
;
const
int
n
=
ctx
.
Attr
<
int
>
(
"n"
);
const
float
alpha
=
ctx
.
Attr
<
float
>
(
"alpha"
);
const
float
beta
=
ctx
.
Attr
<
float
>
(
"beta"
);
const
float
k
=
ctx
.
Attr
<
float
>
(
"k"
);
const
bool
is_test
=
ctx
.
Attr
<
bool
>
(
"is_test"
);
auto
e_mid
=
framework
::
EigenTensor
<
T
,
4
>::
From
(
*
mid
);
e_mid
=
e_mid
.
constant
(
k
);
...
...
@@ -71,28 +83,47 @@ class LRNMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
beta
,
k
};
auto
forward_pd
=
std
::
make_shared
<
mkldnn
::
lrn_forward
::
primitive_desc
>
(
forward_desc
,
mkldnn_engine
);
dev_ctx
.
SetBlob
(
key_pd
,
forward_pd
);
auto
src_memory_pd
=
mkldnn
::
memory
::
primitive_desc
{
src_md
,
mkldnn_engine
};
auto
src_memory
=
std
::
make_shared
<
mkldnn
::
memory
>
(
src_memory_pd
,
static_cast
<
void
*>
(
const_cast
<
float
*>
(
input_data
)));
dev_ctx
.
SetBlob
(
key_src_memory
,
src_memory
);
auto
dst_memory
=
mkldnn
::
memory
{{
dst_md
,
mkldnn_engine
},
static_cast
<
void
*>
(
output_data
)};
auto
workspace_md
=
forward_pd
->
workspace_primitive_desc
();
auto
workspace_memory
=
std
::
make_shared
<
mkldnn
::
memory
>
(
workspace_md
);
std
::
unique_ptr
<
mkldnn
::
lrn_forward
>
forward_op
=
nullptr
;
if
(
!
is_test
)
{
const
std
::
string
key
=
ctx
.
op
().
Output
(
"Out"
);
const
std
::
string
key_src_memory
=
key
+
"@lrn_src_memory"
;
const
std
::
string
key_pd
=
key
+
"@lrn_pd"
;
const
std
::
string
key_workspace_memory
=
key
+
"@lrn_workspace_memory"
;
auto
forward_pd
=
insert_to_context
<
mkldnn
::
lrn_forward
::
primitive_desc
>
(
key_pd
,
dev_ctx
,
forward_desc
,
mkldnn_engine
);
auto
src_memory
=
insert_to_context
<
mkldnn
::
memory
>
(
key_src_memory
,
dev_ctx
,
src_memory_pd
);
src_memory
->
set_data_handle
(
static_cast
<
void
*>
(
const_cast
<
T
*>
(
input_data
)));
auto
workspace_memory
=
insert_to_context
<
mkldnn
::
memory
>
(
key_workspace_memory
,
dev_ctx
,
forward_pd
->
workspace_primitive_desc
());
forward_op
.
reset
(
new
mkldnn
::
lrn_forward
{
*
forward_pd
,
*
src_memory
,
*
workspace_memory
,
dst_memory
});
dev_ctx
.
SetBlob
(
key_workspace_memory
,
workspace_memory
);
}
else
{
auto
forward_pd
=
mkldnn
::
lrn_forward
::
primitive_desc
{
forward_desc
,
mkldnn_engine
};
auto
src_memory
=
mkldnn
::
memory
{
src_memory_pd
,
static_cast
<
void
*>
(
const_cast
<
T
*>
(
input_data
))};
auto
workspace_memory
=
mkldnn
::
memory
{
forward_pd
.
workspace_primitive_desc
()};
auto
forward_op
=
mkldnn
::
lrn_forward
{
*
forward_pd
,
*
src_memory
,
*
workspace_memory
,
dst_memory
};
forward_op
.
reset
(
new
mkldnn
::
lrn_forward
{
forward_pd
,
src_memory
,
workspace_memory
,
dst_memory
});
}
std
::
vector
<
mkldnn
::
primitive
>
pipeline
=
{
forward_op
};
std
::
vector
<
mkldnn
::
primitive
>
pipeline
=
{
*
forward_op
};
mkldnn
::
stream
(
mkldnn
::
stream
::
kind
::
eager
).
submit
(
pipeline
).
wait
();
}
};
...
...
paddle/fluid/operators/lrn_op.cc
浏览文件 @
72cc64e4
...
...
@@ -214,6 +214,7 @@ class LRNOpMaker : public framework::OpProtoAndCheckerMaker {
"Defaults to
\"
NHWC
\"
. Specify the data format of the output data, "
"the input will be transformed automatically. "
)
.
SetDefault
(
"AnyLayout"
);
AddAttr
<
bool
>
(
"is_test"
,
""
).
SetDefault
(
false
);
AddComment
(
R"DOC(
Local Response Normalization Operator.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录