Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
1b67bc02
P
Paddle
项目概览
BaiXuePrincess
/
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看板
未验证
提交
1b67bc02
编写于
3月 27, 2018
作者:
T
Tao Luo
提交者:
GitHub
3月 27, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9329 from tpatejko/tpatejko/mkldnn-lrn
Improvements for MKLDNN LRN
上级
c7bf77d0
14ba67c0
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
33 addition
and
11 deletion
+33
-11
paddle/fluid/operators/lrn_mkldnn_op.cc
paddle/fluid/operators/lrn_mkldnn_op.cc
+13
-10
paddle/fluid/operators/lrn_op.cc
paddle/fluid/operators/lrn_op.cc
+1
-1
python/paddle/fluid/tests/unittests/test_lrn_op.py
python/paddle/fluid/tests/unittests/test_lrn_op.py
+19
-0
未找到文件。
paddle/fluid/operators/lrn_mkldnn_op.cc
浏览文件 @
1b67bc02
...
...
@@ -36,6 +36,14 @@ std::shared_ptr<T> insert_to_context(const std::string& key,
return
p
;
}
template
<
typename
...
Args
>
void
run_primitive
(
Args
&&
...
args
)
{
auto
forward_op
=
mkldnn
::
lrn_forward
{
args
...};
std
::
vector
<
mkldnn
::
primitive
>
pipeline
=
{
forward_op
};
mkldnn
::
stream
(
mkldnn
::
stream
::
kind
::
eager
).
submit
(
pipeline
).
wait
();
}
}
// namespace
template
<
typename
T
>
...
...
@@ -87,8 +95,6 @@ class LRNMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
auto
dst_memory
=
mkldnn
::
memory
{{
dst_md
,
mkldnn_engine
},
static_cast
<
void
*>
(
output_data
)};
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"
;
...
...
@@ -108,9 +114,7 @@ class LRNMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
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
});
run_primitive
(
*
forward_pd
,
*
src_memory
,
*
workspace_memory
,
dst_memory
);
}
else
{
auto
forward_pd
=
mkldnn
::
lrn_forward
::
primitive_desc
{
forward_desc
,
mkldnn_engine
};
...
...
@@ -119,12 +123,8 @@ class LRNMKLDNNOpKernel : public paddle::framework::OpKernel<T> {
auto
workspace_memory
=
mkldnn
::
memory
{
forward_pd
.
workspace_primitive_desc
()};
forward_op
.
reset
(
new
mkldnn
::
lrn_forward
{
forward_pd
,
src_memory
,
workspace_memory
,
dst_memory
});
run_primitive
(
forward_pd
,
src_memory
,
workspace_memory
,
dst_memory
);
}
std
::
vector
<
mkldnn
::
primitive
>
pipeline
=
{
*
forward_op
};
mkldnn
::
stream
(
mkldnn
::
stream
::
kind
::
eager
).
submit
(
pipeline
).
wait
();
}
};
...
...
@@ -136,6 +136,9 @@ class LRNMKLDNNGradOpKernel : public paddle::framework::OpKernel<T> {
"MKLDNN LRN must use float data."
);
PADDLE_ENFORCE
(
paddle
::
platform
::
is_cpu_place
(
ctx
.
GetPlace
()),
"MKLDNN LRN must use CPUPlace."
);
PADDLE_ENFORCE
(
!
ctx
.
Attr
<
bool
>
(
"is_test"
),
"is_test attribute should be set to False in training phase."
);
auto
x
=
ctx
.
Input
<
Tensor
>
(
"X"
);
...
...
paddle/fluid/operators/lrn_op.cc
浏览文件 @
1b67bc02
...
...
@@ -155,8 +155,8 @@ class LRNOp : public framework::OperatorWithKernel {
PADDLE_ENFORCE_EQ
(
x_dim
.
size
(),
4
,
"Input(X)'rank of LRNOp should be 4."
);
ctx
->
SetOutputDim
(
"Out"
,
x_dim
);
ctx
->
SetOutputDim
(
"MidOut"
,
x_dim
);
ctx
->
ShareLoD
(
"X"
,
/*->*/
"Out"
);
ctx
->
SetOutputDim
(
"MidOut"
,
x_dim
);
}
framework
::
OpKernelType
GetExpectedKernelType
(
...
...
python/paddle/fluid/tests/unittests/test_lrn_op.py
浏览文件 @
1b67bc02
...
...
@@ -97,5 +97,24 @@ class TestLRNMKLDNNOp(TestLRNOp):
self
.
check_output
(
atol
=
0.002
)
class
TestLRNMKLDNNOpWithIsTest
(
TestLRNMKLDNNOp
):
def
get_attrs
(
self
):
attrs
=
TestLRNMKLDNNOp
.
get_attrs
(
self
)
attrs
[
'is_test'
]
=
True
return
attrs
def
test_check_grad_normal
(
self
):
def
check_raise_is_test
():
try
:
self
.
check_grad
([
'X'
],
'Out'
,
max_relative_error
=
0.01
)
except
Exception
as
e
:
t
=
\
"is_test attribute should be set to False in training phase."
if
t
in
str
(
e
):
raise
AttributeError
self
.
assertRaises
(
AttributeError
,
check_raise_is_test
)
if
__name__
==
"__main__"
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录