Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
TonyTonyFun
Paddle
提交
1199aa68
P
Paddle
项目概览
TonyTonyFun
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
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,发现更多精彩内容 >>
提交
1199aa68
编写于
10月 16, 2017
作者:
T
tensor-tang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bug: clear grad and always share data when output has cpu
and add activation in unit tests
上级
dee7f813
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
31 addition
and
7 deletion
+31
-7
paddle/gserver/layers/MKLDNNConvLayer.cpp
paddle/gserver/layers/MKLDNNConvLayer.cpp
+5
-3
paddle/gserver/layers/MKLDNNLayer.h
paddle/gserver/layers/MKLDNNLayer.h
+18
-1
paddle/gserver/layers/MKLDNNPoolLayer.cpp
paddle/gserver/layers/MKLDNNPoolLayer.cpp
+5
-3
paddle/gserver/tests/test_MKLDNN.cpp
paddle/gserver/tests/test_MKLDNN.cpp
+3
-0
未找到文件。
paddle/gserver/layers/MKLDNNConvLayer.cpp
浏览文件 @
1199aa68
...
@@ -313,6 +313,7 @@ void MKLDNNConvLayer::resetOutValue(
...
@@ -313,6 +313,7 @@ void MKLDNNConvLayer::resetOutValue(
cvtOutVal_
=
MKLDNNMatrix
::
createReorder
(
out
,
cpuOutVal_
);
cvtOutVal_
=
MKLDNNMatrix
::
createReorder
(
out
,
cpuOutVal_
);
CHECK
(
cvtOutVal_
)
<<
"should not be empty"
;
CHECK
(
cvtOutVal_
)
<<
"should not be empty"
;
}
else
{
}
else
{
cpuOut
->
setData
(
output_
.
value
->
getData
());
cpuOutVal_
=
out
;
cpuOutVal_
=
out
;
}
}
// when output is cpu device, change the mkldnn output value and make them
// when output is cpu device, change the mkldnn output value and make them
...
@@ -456,17 +457,18 @@ void MKLDNNConvLayer::resetOutGrad(
...
@@ -456,17 +457,18 @@ void MKLDNNConvLayer::resetOutGrad(
MKLDNNLayer
::
resetOutGrad
(
out
,
outVal_
->
getPrimitiveDesc
());
MKLDNNLayer
::
resetOutGrad
(
out
,
outVal_
->
getPrimitiveDesc
());
}
else
{
}
else
{
const
MatrixPtr
&
cpuOut
=
getOutput
(
CPU_DEVICE
).
grad
;
const
MatrixPtr
&
cpuOut
=
getOutput
(
CPU_DEVICE
).
grad
;
// always share the same grad data of CPU output
// then the activation can get the right grad from output_.grad
output_
.
grad
->
setData
(
cpuOut
->
getData
());
// same PrimitiveDesc with cpuInVal_
// same PrimitiveDesc with cpuInVal_
CHECK
(
cpuOutVal_
);
CHECK
(
cpuOutVal_
);
cpuOutGrad_
=
MKLDNNMatrix
::
create
(
cpuOut
,
cpuOutVal_
->
getPrimitiveDesc
());
cpuOutGrad_
=
MKLDNNMatrix
::
create
(
cpuOut
,
cpuOutVal_
->
getPrimitiveDesc
());
// create reorder if primitive desc does not match
// create reorder if primitive desc does not match
if
(
cpuOutGrad_
->
getPrimitiveDesc
()
!=
outVal_
->
getPrimitiveDesc
())
{
if
(
cpuOutGrad_
->
getPrimitiveDesc
()
!=
outVal_
->
getPrimitiveDesc
())
{
out
=
MKLDNNMatrix
::
create
(
output_
.
grad
,
outVal_
->
getPrimitiveDesc
());
out
=
MKLDNNMatrix
::
create
(
nullptr
,
outVal_
->
getPrimitiveDesc
());
cvtOutGrad_
=
MKLDNNMatrix
::
createReorder
(
cpuOutGrad_
,
out
);
cvtOutGrad_
=
MKLDNNMatrix
::
createReorder
(
cpuOutGrad_
,
out
);
CHECK
(
cvtOutGrad_
);
CHECK
(
cvtOutGrad_
);
}
else
{
}
else
{
// share the same data of CPU output
output_
.
grad
->
setData
(
cpuOut
->
getData
());
out
=
cpuOutGrad_
;
out
=
cpuOutGrad_
;
}
}
}
}
...
...
paddle/gserver/layers/MKLDNNLayer.h
浏览文件 @
1199aa68
...
@@ -46,6 +46,9 @@ protected:
...
@@ -46,6 +46,9 @@ protected:
// backward also need reset after reset forward handle
// backward also need reset after reset forward handle
bool
needResetBwd_
;
bool
needResetBwd_
;
// is output only mkldnn
bool
outputOnlyMKLDNN_
;
// mkldnn engine, stream and primivtives
// mkldnn engine, stream and primivtives
mkldnn
::
engine
engine_
;
mkldnn
::
engine
engine_
;
std
::
shared_ptr
<
MKLDNNStream
>
stream_
;
std
::
shared_ptr
<
MKLDNNStream
>
stream_
;
...
@@ -141,6 +144,9 @@ public:
...
@@ -141,6 +144,9 @@ public:
updateInputData
();
updateInputData
();
}
}
if
(
!
outputOnlyMKLDNN_
)
{
clearGrads
();
}
stream_
->
submit
(
pipelineFwd_
);
stream_
->
submit
(
pipelineFwd_
);
}
}
...
@@ -389,7 +395,8 @@ protected:
...
@@ -389,7 +395,8 @@ protected:
CHECK_EQ
(
outputOtherDevice_
[
i
].
deviceId
,
CPU_DEVICE
)
CHECK_EQ
(
outputOtherDevice_
[
i
].
deviceId
,
CPU_DEVICE
)
<<
"Only support other device is CPU yet"
;
<<
"Only support other device is CPU yet"
;
}
}
return
outputOtherDevice_
.
size
()
==
0
;
outputOnlyMKLDNN_
=
outputOtherDevice_
.
size
()
==
0
;
return
outputOnlyMKLDNN_
;
}
}
/**
/**
...
@@ -398,6 +405,16 @@ protected:
...
@@ -398,6 +405,16 @@ protected:
void
setDevice
(
int
id
)
{
deviceId_
=
id
;
}
void
setDevice
(
int
id
)
{
deviceId_
=
id
;
}
private:
private:
/**
* clear all grad
*/
void
clearGrads
()
{
output_
.
grad
->
zeroMem
();
for
(
size_t
i
=
0
;
i
<
outputOtherDevice_
.
size
();
i
++
)
{
outputOtherDevice_
[
i
].
grad
->
zeroMem
();
}
}
/**
/**
* Set deviceId of the params used in this layer.
* Set deviceId of the params used in this layer.
*/
*/
...
...
paddle/gserver/layers/MKLDNNPoolLayer.cpp
浏览文件 @
1199aa68
...
@@ -146,6 +146,7 @@ void MKLDNNPoolLayer::resetOutValue(MKLDNNMatrixPtr& out) {
...
@@ -146,6 +146,7 @@ void MKLDNNPoolLayer::resetOutValue(MKLDNNMatrixPtr& out) {
cvtOutVal_
=
MKLDNNMatrix
::
createReorder
(
out
,
cpuOutVal_
);
cvtOutVal_
=
MKLDNNMatrix
::
createReorder
(
out
,
cpuOutVal_
);
CHECK
(
cvtOutVal_
)
<<
"should not be emptry"
;
CHECK
(
cvtOutVal_
)
<<
"should not be emptry"
;
}
else
{
}
else
{
cpuOut
->
setData
(
output_
.
value
->
getData
());
cpuOutVal_
=
out
;
cpuOutVal_
=
out
;
}
}
output_
.
value
=
std
::
dynamic_pointer_cast
<
Matrix
>
(
cpuOutVal_
);
output_
.
value
=
std
::
dynamic_pointer_cast
<
Matrix
>
(
cpuOutVal_
);
...
@@ -213,15 +214,16 @@ void MKLDNNPoolLayer::resetOutGrad(MKLDNNMatrixPtr& out) {
...
@@ -213,15 +214,16 @@ void MKLDNNPoolLayer::resetOutGrad(MKLDNNMatrixPtr& out) {
MKLDNNLayer
::
resetOutGrad
(
out
,
outVal_
->
getPrimitiveDesc
());
MKLDNNLayer
::
resetOutGrad
(
out
,
outVal_
->
getPrimitiveDesc
());
}
else
{
}
else
{
const
MatrixPtr
&
cpuOut
=
getOutput
(
CPU_DEVICE
).
grad
;
const
MatrixPtr
&
cpuOut
=
getOutput
(
CPU_DEVICE
).
grad
;
// always share the same grad data of CPU output
// then the activation can get the right grad from output_.grad
output_
.
grad
->
setData
(
cpuOut
->
getData
());
cpuOutGrad_
=
MKLDNNMatrix
::
create
(
cpuOutGrad_
=
MKLDNNMatrix
::
create
(
cpuOut
,
memory
::
dims
{
bs_
,
oc_
,
oh_
,
ow_
},
format
::
nchw
,
engine_
);
cpuOut
,
memory
::
dims
{
bs_
,
oc_
,
oh_
,
ow_
},
format
::
nchw
,
engine_
);
if
(
cpuOutGrad_
->
getPrimitiveDesc
()
!=
outVal_
->
getPrimitiveDesc
())
{
if
(
cpuOutGrad_
->
getPrimitiveDesc
()
!=
outVal_
->
getPrimitiveDesc
())
{
out
=
MKLDNNMatrix
::
create
(
output_
.
grad
,
outVal_
->
getPrimitiveDesc
());
out
=
MKLDNNMatrix
::
create
(
nullptr
,
outVal_
->
getPrimitiveDesc
());
cvtOutGrad_
=
MKLDNNMatrix
::
createReorder
(
cpuOutGrad_
,
out
);
cvtOutGrad_
=
MKLDNNMatrix
::
createReorder
(
cpuOutGrad_
,
out
);
CHECK
(
cvtOutGrad_
)
<<
"should not be emptry"
;
CHECK
(
cvtOutGrad_
)
<<
"should not be emptry"
;
}
else
{
}
else
{
// share the same data of CPU output
output_
.
grad
->
setData
(
cpuOut
->
getData
());
out
=
cpuOutGrad_
;
out
=
cpuOutGrad_
;
}
}
}
}
...
...
paddle/gserver/tests/test_MKLDNN.cpp
浏览文件 @
1199aa68
...
@@ -46,6 +46,7 @@ struct testFcDesc {
...
@@ -46,6 +46,7 @@ struct testFcDesc {
static
void
getMKLDNNFcConfig
(
TestConfig
&
cfg
,
const
testFcDesc
&
pm
)
{
static
void
getMKLDNNFcConfig
(
TestConfig
&
cfg
,
const
testFcDesc
&
pm
)
{
cfg
.
layerConfig
.
set_type
(
"mkldnn_fc"
);
cfg
.
layerConfig
.
set_type
(
"mkldnn_fc"
);
cfg
.
layerConfig
.
set_active_type
(
"sigmoid"
);
cfg
.
layerConfig
.
set_size
(
pm
.
oc
);
cfg
.
layerConfig
.
set_size
(
pm
.
oc
);
cfg
.
inputDefs
.
push_back
(
cfg
.
inputDefs
.
push_back
(
{
INPUT_DATA
,
{
INPUT_DATA
,
...
@@ -86,6 +87,7 @@ struct testConvDesc {
...
@@ -86,6 +87,7 @@ struct testConvDesc {
static
void
getMKLDNNConvConfig
(
TestConfig
&
cfg
,
const
testConvDesc
&
pm
)
{
static
void
getMKLDNNConvConfig
(
TestConfig
&
cfg
,
const
testConvDesc
&
pm
)
{
cfg
.
layerConfig
.
set_type
(
"mkldnn_conv"
);
cfg
.
layerConfig
.
set_type
(
"mkldnn_conv"
);
cfg
.
layerConfig
.
set_active_type
(
"relu"
);
cfg
.
layerConfig
.
set_num_filters
(
pm
.
oc
);
cfg
.
layerConfig
.
set_num_filters
(
pm
.
oc
);
cfg
.
layerConfig
.
set_size
(
pm
.
oc
*
pm
.
oh
*
pm
.
ow
);
cfg
.
layerConfig
.
set_size
(
pm
.
oc
*
pm
.
oh
*
pm
.
ow
);
cfg
.
layerConfig
.
set_shared_biases
(
true
);
cfg
.
layerConfig
.
set_shared_biases
(
true
);
...
@@ -158,6 +160,7 @@ struct testPoolDesc {
...
@@ -158,6 +160,7 @@ struct testPoolDesc {
static
void
getMKLDNNPoolConfig
(
TestConfig
&
cfg
,
const
testPoolDesc
&
pm
)
{
static
void
getMKLDNNPoolConfig
(
TestConfig
&
cfg
,
const
testPoolDesc
&
pm
)
{
cfg
.
layerConfig
.
set_type
(
"mkldnn_pool"
);
cfg
.
layerConfig
.
set_type
(
"mkldnn_pool"
);
cfg
.
layerConfig
.
set_active_type
(
"relu"
);
cfg
.
layerConfig
.
set_size
(
pm
.
ic
*
pm
.
oh
*
pm
.
ow
);
cfg
.
layerConfig
.
set_size
(
pm
.
ic
*
pm
.
oh
*
pm
.
ow
);
cfg
.
inputDefs
.
push_back
(
cfg
.
inputDefs
.
push_back
(
{
INPUT_DATA
,
{
INPUT_DATA
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录