Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
c1fd1dc7
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,发现更多精彩内容 >>
提交
c1fd1dc7
编写于
10月 27, 2017
作者:
T
Tao Luo
提交者:
GitHub
10月 27, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5154 from tensor-tang/merge
refine check macro
上级
92c32799
aecfeb72
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
43 addition
and
39 deletion
+43
-39
paddle/gserver/layers/MKLDNNBatchNormLayer.cpp
paddle/gserver/layers/MKLDNNBatchNormLayer.cpp
+8
-17
paddle/gserver/layers/MKLDNNConvLayer.cpp
paddle/gserver/layers/MKLDNNConvLayer.cpp
+26
-16
paddle/gserver/layers/MKLDNNLayer.cpp
paddle/gserver/layers/MKLDNNLayer.cpp
+3
-6
paddle/math/MKLDNNMatrix.h
paddle/math/MKLDNNMatrix.h
+6
-0
未找到文件。
paddle/gserver/layers/MKLDNNBatchNormLayer.cpp
浏览文件 @
c1fd1dc7
...
@@ -216,17 +216,13 @@ void MKLDNNBatchNormLayer::resetFwdPD(
...
@@ -216,17 +216,13 @@ void MKLDNNBatchNormLayer::resetFwdPD(
}
}
auto
fwdDesc
=
bn_fwd
::
desc
(
pk
,
in
->
getMemoryDesc
(),
EPS
,
flags_
);
auto
fwdDesc
=
bn_fwd
::
desc
(
pk
,
in
->
getMemoryDesc
(),
EPS
,
flags_
);
pd
.
reset
(
new
bn_fwd
::
primitive_desc
(
fwdDesc
,
engine_
));
pd
.
reset
(
new
bn_fwd
::
primitive_desc
(
fwdDesc
,
engine_
));
// TODO(TJ): use check macro
CHECK_PRIMITIVE_DESC_EQ
(
out
,
pd
->
dst_primitive_desc
());
CHECK
(
out
);
CHECK
(
out
->
getPrimitiveDesc
()
==
pd
->
dst_primitive_desc
());
if
(
wgt
)
{
if
(
wgt
)
{
CHECK
(
wgt
->
getPrimitiveDesc
()
==
pd
->
weights_primitive_desc
());
CHECK
_PRIMITIVE_DESC_EQ
(
wgt
,
pd
->
weights_primitive_desc
());
}
}
if
(
passType_
!=
PASS_TEST
||
useGlobalStats_
)
{
if
(
passType_
!=
PASS_TEST
||
useGlobalStats_
)
{
CHECK
(
mean_
);
CHECK_PRIMITIVE_DESC_EQ
(
mean_
,
pd
->
mean_primitive_desc
());
CHECK
(
mean_
->
getPrimitiveDesc
()
==
pd
->
mean_primitive_desc
());
CHECK_PRIMITIVE_DESC_EQ
(
var_
,
pd
->
variance_primitive_desc
());
CHECK
(
var_
);
CHECK
(
var_
->
getPrimitiveDesc
()
==
pd
->
variance_primitive_desc
());
}
}
}
}
...
@@ -283,19 +279,14 @@ void MKLDNNBatchNormLayer::resetBwdPD(
...
@@ -283,19 +279,14 @@ void MKLDNNBatchNormLayer::resetBwdPD(
if
(
in
==
nullptr
)
{
if
(
in
==
nullptr
)
{
return
;
return
;
}
}
CHECK
(
out
);
CHECK_PRIMITIVE_DESC_EQ
(
out
,
in
->
getPrimitiveDesc
());
CHECK
(
out
->
getPrimitiveDesc
()
==
in
->
getPrimitiveDesc
());
auto
md
=
in
->
getMemoryDesc
();
auto
md
=
in
->
getMemoryDesc
();
auto
bwdDesc
=
bn_bwd
::
desc
(
prop_kind
::
backward
,
md
,
md
,
EPS
,
flags_
);
auto
bwdDesc
=
bn_bwd
::
desc
(
prop_kind
::
backward
,
md
,
md
,
EPS
,
flags_
);
pd
.
reset
(
new
bn_bwd
::
primitive_desc
(
bwdDesc
,
engine_
,
*
fwdPD_
));
pd
.
reset
(
new
bn_bwd
::
primitive_desc
(
bwdDesc
,
engine_
,
*
fwdPD_
));
// TODO(TJ): use check macro
CHECK
(
wgt
);
CHECK
(
wgt
->
getPrimitiveDesc
()
==
pd
->
diff_weights_primitive_desc
());
CHECK
(
pd
->
weights_primitive_desc
()
==
fwdPD_
->
weights_primitive_desc
());
CHECK
(
pd
->
weights_primitive_desc
()
==
fwdPD_
->
weights_primitive_desc
());
CHECK
(
mean_
);
CHECK_PRIMITIVE_DESC_EQ
(
wgt
,
pd
->
diff_weights_primitive_desc
());
CHECK
(
mean_
->
getPrimitiveDesc
()
==
pd
->
mean_primitive_desc
());
CHECK_PRIMITIVE_DESC_EQ
(
mean_
,
pd
->
mean_primitive_desc
());
CHECK
(
var_
);
CHECK_PRIMITIVE_DESC_EQ
(
var_
,
pd
->
variance_primitive_desc
());
CHECK
(
var_
->
getPrimitiveDesc
()
==
pd
->
variance_primitive_desc
());
}
}
void
MKLDNNBatchNormLayer
::
resetBwdPipeline
(
void
MKLDNNBatchNormLayer
::
resetBwdPipeline
(
...
...
paddle/gserver/layers/MKLDNNConvLayer.cpp
浏览文件 @
c1fd1dc7
...
@@ -262,12 +262,15 @@ void MKLDNNConvLayer::resetBwdWgtPD(
...
@@ -262,12 +262,15 @@ void MKLDNNConvLayer::resetBwdWgtPD(
padR
,
padR
,
padKind
);
padKind
);
pd
.
reset
(
new
conv_bwdWgt
::
primitive_desc
(
bwdWgtDesc
,
engine_
,
*
fwdPD_
));
pd
.
reset
(
new
conv_bwdWgt
::
primitive_desc
(
bwdWgtDesc
,
engine_
,
*
fwdPD_
));
CHECK
(
pd
->
src_primitive_desc
()
==
inVal_
->
getPrimitiveDesc
())
CHECK_PRIMITIVE_DESC_EQ
(
inVal_
,
pd
->
src_primitive_desc
());
<<
"primitive desc of in value should equal"
;
CHECK_PRIMITIVE_DESC_EQ
(
CHECK
(
pd
->
diff_dst_primitive_desc
()
==
outVal_
->
getPrimitiveDesc
())
outVal_
,
<<
"primitive desc of out grad should equal the out value"
;
pd
->
diff_dst_primitive_desc
(),
CHECK
(
pd
->
diff_weights_primitive_desc
()
==
wgtVal_
->
getPrimitiveDesc
())
"primitive desc of out value and grad should be equal"
);
<<
"primitive desc of weight grad should equal the weight value"
;
CHECK_PRIMITIVE_DESC_EQ
(
wgtVal_
,
pd
->
diff_weights_primitive_desc
(),
"primitive desc of weight value and grad should be equal"
);
}
}
void
MKLDNNConvLayer
::
resetBwdDataPD
(
void
MKLDNNConvLayer
::
resetBwdDataPD
(
...
@@ -292,10 +295,14 @@ void MKLDNNConvLayer::resetBwdDataPD(
...
@@ -292,10 +295,14 @@ void MKLDNNConvLayer::resetBwdDataPD(
padR
,
padR
,
padding_kind
::
zero
);
padding_kind
::
zero
);
pd
.
reset
(
new
conv_bwdData
::
primitive_desc
(
bwdDataDesc
,
engine_
,
*
fwdPD_
));
pd
.
reset
(
new
conv_bwdData
::
primitive_desc
(
bwdDataDesc
,
engine_
,
*
fwdPD_
));
CHECK
(
pd
->
diff_src_primitive_desc
()
==
inVal_
->
getPrimitiveDesc
())
CHECK_PRIMITIVE_DESC_EQ
(
<<
"primitive desc of in grad should equal the in value"
;
inVal_
,
CHECK
(
pd
->
diff_dst_primitive_desc
()
==
outVal_
->
getPrimitiveDesc
())
pd
->
diff_src_primitive_desc
(),
<<
"primitive desc of out grad should equal"
;
"primitive desc of in value and grad should be equal"
);
CHECK_PRIMITIVE_DESC_EQ
(
outVal_
,
pd
->
diff_dst_primitive_desc
(),
"primitive desc of out value and grad should be equal"
);
}
}
void
MKLDNNConvLayer
::
resetBwdBuffers
(
void
MKLDNNConvLayer
::
resetBwdBuffers
(
...
@@ -310,17 +317,20 @@ void MKLDNNConvLayer::resetBwdBuffers(
...
@@ -310,17 +317,20 @@ void MKLDNNConvLayer::resetBwdBuffers(
resetWithMatrix
(
resetWithMatrix
(
wgt
,
weight_
->
getWGrad
(),
wgtPD
->
diff_weights_primitive_desc
());
wgt
,
weight_
->
getWGrad
(),
wgtPD
->
diff_weights_primitive_desc
());
CHECK
(
wgtVal_
!=
nullptr
&&
CHECK_PRIMITIVE_DESC_EQ
(
wgt
->
getPrimitiveDesc
()
==
wgtVal_
->
getPrimitiveDesc
())
wgtVal_
,
<<
"primitive desc of weight grad and value should be equal"
;
wgt
->
getPrimitiveDesc
(),
"primitive desc of weight grad and value should be equal"
);
bias
=
nullptr
;
bias
=
nullptr
;
if
(
biases_
&&
biases_
->
getWGrad
())
{
if
(
biases_
&&
biases_
->
getWGrad
())
{
resetWithMatrix
(
resetWithMatrix
(
bias
,
biases_
->
getWGrad
(),
wgtPD
->
diff_bias_primitive_desc
());
bias
,
biases_
->
getWGrad
(),
wgtPD
->
diff_bias_primitive_desc
());
CHECK
(
bias
&&
biasVal_
&&
CHECK
(
bias
);
bias
->
getPrimitiveDesc
()
==
biasVal_
->
getPrimitiveDesc
())
CHECK_PRIMITIVE_DESC_EQ
(
<<
"primitive desc of bias grad should equal the bias value"
;
biasVal_
,
bias
->
getPrimitiveDesc
(),
"primitive desc of bias grad and value should be equal"
);
}
}
if
(
dataPD
==
nullptr
)
{
if
(
dataPD
==
nullptr
)
{
...
...
paddle/gserver/layers/MKLDNNLayer.cpp
浏览文件 @
c1fd1dc7
...
@@ -235,8 +235,7 @@ void MKLDNNLayer::resetInGrad(MKLDNNMatrixPtr& in,
...
@@ -235,8 +235,7 @@ void MKLDNNLayer::resetInGrad(MKLDNNMatrixPtr& in,
in
=
MKLDNNMatrix
::
create
(
intPD
,
inMat
);
in
=
MKLDNNMatrix
::
create
(
intPD
,
inMat
);
Argument
&
arg
=
input
->
getOutput
(
this
->
getName
());
Argument
&
arg
=
input
->
getOutput
(
this
->
getName
());
arg
.
grad
=
std
::
dynamic_pointer_cast
<
Matrix
>
(
in
);
arg
.
grad
=
std
::
dynamic_pointer_cast
<
Matrix
>
(
in
);
CHECK
(
inVal_
);
CHECK_PRIMITIVE_DESC_EQ
(
inVal_
,
intPD
);
CHECK
(
inVal_
->
getPrimitiveDesc
()
==
intPD
)
<<
"the primitive desc must equal"
;
if
(
inputIsOnlyMKLDNN
())
{
if
(
inputIsOnlyMKLDNN
())
{
return
;
return
;
}
}
...
@@ -250,8 +249,7 @@ void MKLDNNLayer::resetInGrad(MKLDNNMatrixPtr& in,
...
@@ -250,8 +249,7 @@ void MKLDNNLayer::resetInGrad(MKLDNNMatrixPtr& in,
CHECK
(
extInVal_
!=
nullptr
&&
isPaddleFormat
(
extInVal_
->
getFormat
()))
CHECK
(
extInVal_
!=
nullptr
&&
isPaddleFormat
(
extInVal_
->
getFormat
()))
<<
"should have external input value and the format must be nchw(nc)"
;
<<
"should have external input value and the format must be nchw(nc)"
;
extInGrad_
=
MKLDNNMatrix
::
create
(
extInVal_
->
getPrimitiveDesc
(),
inMat
);
extInGrad_
=
MKLDNNMatrix
::
create
(
extInVal_
->
getPrimitiveDesc
(),
inMat
);
CHECK
(
inVal_
!=
nullptr
&&
inVal_
->
getPrimitiveDesc
()
==
intPD
)
CHECK_PRIMITIVE_DESC_EQ
(
inVal_
,
intPD
);
<<
"should have internal input value and primitive desc must equal"
;
in
=
MKLDNNMatrix
::
create
(
intPD
);
in
=
MKLDNNMatrix
::
create
(
intPD
);
cvtInGrad_
=
MKLDNNMatrix
::
createReorder
(
in
,
extInGrad_
);
cvtInGrad_
=
MKLDNNMatrix
::
createReorder
(
in
,
extInGrad_
);
CHECK
(
cvtInGrad_
);
CHECK
(
cvtInGrad_
);
...
@@ -277,8 +275,7 @@ void MKLDNNLayer::resetOutGrad(MKLDNNMatrixPtr& out,
...
@@ -277,8 +275,7 @@ void MKLDNNLayer::resetOutGrad(MKLDNNMatrixPtr& out,
CHECK
(
extOutVal_
!=
nullptr
&&
isPaddleFormat
(
extOutVal_
->
getFormat
()))
CHECK
(
extOutVal_
!=
nullptr
&&
isPaddleFormat
(
extOutVal_
->
getFormat
()))
<<
"should have external output value and the format must be nchw(nc)"
;
<<
"should have external output value and the format must be nchw(nc)"
;
extOutGrad_
=
MKLDNNMatrix
::
create
(
extOutVal_
->
getPrimitiveDesc
(),
outMat
);
extOutGrad_
=
MKLDNNMatrix
::
create
(
extOutVal_
->
getPrimitiveDesc
(),
outMat
);
CHECK
(
outVal_
!=
nullptr
&&
outVal_
->
getPrimitiveDesc
()
==
intPD
)
CHECK_PRIMITIVE_DESC_EQ
(
outVal_
,
intPD
);
<<
"should have internal output value and primitive desc must equal"
;
out
=
MKLDNNMatrix
::
create
(
intPD
);
out
=
MKLDNNMatrix
::
create
(
intPD
);
cvtOutGrad_
=
MKLDNNMatrix
::
createReorder
(
extOutGrad_
,
out
);
cvtOutGrad_
=
MKLDNNMatrix
::
createReorder
(
extOutGrad_
,
out
);
CHECK
(
cvtOutGrad_
);
CHECK
(
cvtOutGrad_
);
...
...
paddle/math/MKLDNNMatrix.h
浏览文件 @
c1fd1dc7
...
@@ -24,6 +24,12 @@ namespace paddle {
...
@@ -24,6 +24,12 @@ namespace paddle {
class
MKLDNNMatrix
;
class
MKLDNNMatrix
;
typedef
std
::
shared_ptr
<
MKLDNNMatrix
>
MKLDNNMatrixPtr
;
typedef
std
::
shared_ptr
<
MKLDNNMatrix
>
MKLDNNMatrixPtr
;
#define CHECK_PRIMITIVE_DESC_EQ(MAT, PD, ...) \
CHECK(MAT) << " can not be empty."; \
CHECK(MAT->getPrimitiveDesc() == PD) \
<< #MAT "->getPrimitiveDesc() and " #PD " should be equal.\n " \
<< "" __VA_ARGS__;
/**
/**
* @brief MKLDNN Matrix.
* @brief MKLDNN Matrix.
*
*
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录