Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
c5183caa
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c5183caa
编写于
8月 30, 2017
作者:
T
tensor-tang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rename
上级
bfbd066f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
20 addition
and
21 deletion
+20
-21
paddle/gserver/layers/MKLDNNFcLayer.cpp
paddle/gserver/layers/MKLDNNFcLayer.cpp
+13
-16
paddle/gserver/layers/MKLDNNLayer.h
paddle/gserver/layers/MKLDNNLayer.h
+7
-5
未找到文件。
paddle/gserver/layers/MKLDNNFcLayer.cpp
浏览文件 @
c5183caa
...
@@ -134,7 +134,7 @@ void MKLDNNFcLayer::resetFwd() {
...
@@ -134,7 +134,7 @@ void MKLDNNFcLayer::resetFwd() {
const
MatrixPtr
&
bias
=
hasBias
?
biases_
->
getW
()
:
nullptr
;
const
MatrixPtr
&
bias
=
hasBias
?
biases_
->
getW
()
:
nullptr
;
const
MatrixPtr
&
out
=
output_
.
value
;
const
MatrixPtr
&
out
=
output_
.
value
;
if
(
prev
IsOnlyMKLDNN
())
{
if
(
input
IsOnlyMKLDNN
())
{
const
MatrixPtr
&
in
=
getInputValue
(
0
);
const
MatrixPtr
&
in
=
getInputValue
(
0
);
inVal_
=
std
::
dynamic_pointer_cast
<
MKLDNNMatrix
>
(
in
);
inVal_
=
std
::
dynamic_pointer_cast
<
MKLDNNMatrix
>
(
in
);
CHECK
(
inVal_
)
<<
"Input should be MKLDNNMatrix"
;
CHECK
(
inVal_
)
<<
"Input should be MKLDNNMatrix"
;
...
@@ -154,7 +154,7 @@ void MKLDNNFcLayer::resetFwd() {
...
@@ -154,7 +154,7 @@ void MKLDNNFcLayer::resetFwd() {
// change original output value to mkldnn output value
// change original output value to mkldnn output value
output_
.
value
=
std
::
dynamic_pointer_cast
<
Matrix
>
(
outVal_
);
output_
.
value
=
std
::
dynamic_pointer_cast
<
Matrix
>
(
outVal_
);
if
(
!
nex
tIsOnlyMKLDNN
())
{
if
(
!
outpu
tIsOnlyMKLDNN
())
{
convertOutputToOtherDevice
();
convertOutputToOtherDevice
();
}
}
...
@@ -194,19 +194,16 @@ void MKLDNNFcLayer::resetBwd() {
...
@@ -194,19 +194,16 @@ void MKLDNNFcLayer::resetBwd() {
const
MatrixPtr
&
bias
=
hasBias
?
biases_
->
getWGrad
()
:
nullptr
;
const
MatrixPtr
&
bias
=
hasBias
?
biases_
->
getWGrad
()
:
nullptr
;
// TODO(TJ): merge outgrad
// TODO(TJ): merge outgrad
if
(
nextIsOnlyMKLDNN
())
{
int
device
=
outputIsOnlyMKLDNN
()
?
MKLDNN_DEVICE
:
CPU_DEVICE
;
// can not directly cast outputgrad to mkldnnmatrix,
// for MKLDNN device:
// since each layer can not write the inputgrad to mkldnn inputgrad.
// can not directly cast outputgrad to mkldnnmatrix,
// So just create from matrix with outputvalue format.
// since each layer can not write the inputgrad to mkldnn inputgrad.
const
MatrixPtr
&
out
=
getOutput
(
MKLDNN_DEVICE
).
grad
;
// So just create from matrix with outputvalue format.
outGrad_
=
MKLDNNMatrix
::
create
(
out
,
outVal_
->
getPrimitiveDesc
());
// for CPU device:
}
else
{
// fc do not need to convert from cpu device since output is always nc format
const
MatrixPtr
&
out
=
getOutput
(
CPU_DEVICE
).
grad
;
// only need create from cpu device
// fc do not need to convert from cpu device since output always nc
const
MatrixPtr
&
out
=
getOutput
(
device
).
grad
;
// only need create from cpu device
outGrad_
=
MKLDNNMatrix
::
create
(
out
,
outVal_
->
getPrimitiveDesc
());
outGrad_
=
MKLDNNMatrix
::
create
(
out
,
outVal_
->
getPrimitiveDesc
());
}
wgtGrad_
=
MKLDNNMatrix
::
create
(
wgt
,
wgtVal_
->
getPrimitiveDesc
());
wgtGrad_
=
MKLDNNMatrix
::
create
(
wgt
,
wgtVal_
->
getPrimitiveDesc
());
biasGrad_
=
hasBias
?
MKLDNNMatrix
::
create
(
bias
,
biasVal_
->
getPrimitiveDesc
())
biasGrad_
=
hasBias
?
MKLDNNMatrix
::
create
(
bias
,
biasVal_
->
getPrimitiveDesc
())
:
nullptr
;
:
nullptr
;
...
@@ -238,7 +235,7 @@ void MKLDNNFcLayer::resetBwd() {
...
@@ -238,7 +235,7 @@ void MKLDNNFcLayer::resetBwd() {
pipelineBwd_
.
push_back
(
*
bwdWgt_
);
pipelineBwd_
.
push_back
(
*
bwdWgt_
);
/// backward data
/// backward data
int
device
=
prev
IsOnlyMKLDNN
()
?
MKLDNN_DEVICE
:
CPU_DEVICE
;
device
=
input
IsOnlyMKLDNN
()
?
MKLDNN_DEVICE
:
CPU_DEVICE
;
const
MatrixPtr
&
in
=
getInputGrad
(
0
,
device
);
const
MatrixPtr
&
in
=
getInputGrad
(
0
,
device
);
if
(
in
==
nullptr
)
{
if
(
in
==
nullptr
)
{
return
;
return
;
...
...
paddle/gserver/layers/MKLDNNLayer.h
浏览文件 @
c5183caa
...
@@ -151,6 +151,8 @@ public:
...
@@ -151,6 +151,8 @@ public:
protected:
protected:
/**
/**
* copy image size and sequence info to other device
* copy image size and sequence info to other device
* @note: can not directly use Layer::copyOutputToOtherDevice since here only
* copy base info and do not copy data value
*/
*/
void
copyOutputInfoToOtherDevice
()
{
void
copyOutputInfoToOtherDevice
()
{
for
(
size_t
i
=
0
;
i
<
outputOtherDevice_
.
size
();
i
++
)
{
for
(
size_t
i
=
0
;
i
<
outputOtherDevice_
.
size
();
i
++
)
{
...
@@ -165,10 +167,10 @@ protected:
...
@@ -165,10 +167,10 @@ protected:
}
}
/**
/**
* I
s previous layer only has MKLDNN typ
e.
* I
f input only has MKLDNN devic
e.
* Otherwise, only support the previous layer using CPU device.
* Otherwise, only support the previous layer using CPU device.
*/
*/
bool
prev
IsOnlyMKLDNN
(
int
index
=
0
)
{
bool
input
IsOnlyMKLDNN
(
int
index
=
0
)
{
int
prevDevice
=
getPrev
(
index
)
->
getDeviceId
();
int
prevDevice
=
getPrev
(
index
)
->
getDeviceId
();
if
(
prevDevice
==
MKLDNN_DEVICE
)
{
if
(
prevDevice
==
MKLDNN_DEVICE
)
{
return
true
;
return
true
;
...
@@ -183,7 +185,7 @@ protected:
...
@@ -183,7 +185,7 @@ protected:
* If output only has MKLDNN device.
* If output only has MKLDNN device.
* Otherwise, other devices should only using CPU device.
* Otherwise, other devices should only using CPU device.
*/
*/
bool
nex
tIsOnlyMKLDNN
()
{
bool
outpu
tIsOnlyMKLDNN
()
{
for
(
size_t
i
=
0
;
i
<
outputOtherDevice_
.
size
();
i
++
)
{
for
(
size_t
i
=
0
;
i
<
outputOtherDevice_
.
size
();
i
++
)
{
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"
;
...
@@ -195,7 +197,7 @@ protected:
...
@@ -195,7 +197,7 @@ protected:
* Sync input value data
* Sync input value data
*/
*/
void
syncInputValue
()
{
void
syncInputValue
()
{
if
(
prev
IsOnlyMKLDNN
())
{
if
(
input
IsOnlyMKLDNN
())
{
return
;
return
;
}
}
real
*
iData
=
getInputValue
(
0
,
CPU_DEVICE
)
->
getData
();
real
*
iData
=
getInputValue
(
0
,
CPU_DEVICE
)
->
getData
();
...
@@ -208,7 +210,7 @@ protected:
...
@@ -208,7 +210,7 @@ protected:
* Sync output grad data
* Sync output grad data
*/
*/
void
syncOutputGrad
()
{
void
syncOutputGrad
()
{
if
(
nex
tIsOnlyMKLDNN
())
{
if
(
outpu
tIsOnlyMKLDNN
())
{
return
;
return
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录