Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
urhero
Paddle
提交
c5183caa
P
Paddle
项目概览
urhero
/
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,发现更多精彩内容 >>
提交
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() {
const
MatrixPtr
&
bias
=
hasBias
?
biases_
->
getW
()
:
nullptr
;
const
MatrixPtr
&
out
=
output_
.
value
;
if
(
prev
IsOnlyMKLDNN
())
{
if
(
input
IsOnlyMKLDNN
())
{
const
MatrixPtr
&
in
=
getInputValue
(
0
);
inVal_
=
std
::
dynamic_pointer_cast
<
MKLDNNMatrix
>
(
in
);
CHECK
(
inVal_
)
<<
"Input should be MKLDNNMatrix"
;
...
...
@@ -154,7 +154,7 @@ void MKLDNNFcLayer::resetFwd() {
// change original output value to mkldnn output value
output_
.
value
=
std
::
dynamic_pointer_cast
<
Matrix
>
(
outVal_
);
if
(
!
nex
tIsOnlyMKLDNN
())
{
if
(
!
outpu
tIsOnlyMKLDNN
())
{
convertOutputToOtherDevice
();
}
...
...
@@ -194,19 +194,16 @@ void MKLDNNFcLayer::resetBwd() {
const
MatrixPtr
&
bias
=
hasBias
?
biases_
->
getWGrad
()
:
nullptr
;
// TODO(TJ): merge outgrad
if
(
nextIsOnlyMKLDNN
())
{
// can not directly cast outputgrad to mkldnnmatrix,
// since each layer can not write the inputgrad to mkldnn inputgrad.
// So just create from matrix with outputvalue format.
const
MatrixPtr
&
out
=
getOutput
(
MKLDNN_DEVICE
).
grad
;
outGrad_
=
MKLDNNMatrix
::
create
(
out
,
outVal_
->
getPrimitiveDesc
());
}
else
{
const
MatrixPtr
&
out
=
getOutput
(
CPU_DEVICE
).
grad
;
// fc do not need to convert from cpu device since output always nc
// only need create from cpu device
outGrad_
=
MKLDNNMatrix
::
create
(
out
,
outVal_
->
getPrimitiveDesc
());
}
int
device
=
outputIsOnlyMKLDNN
()
?
MKLDNN_DEVICE
:
CPU_DEVICE
;
// for MKLDNN device:
// can not directly cast outputgrad to mkldnnmatrix,
// since each layer can not write the inputgrad to mkldnn inputgrad.
// So just create from matrix with outputvalue format.
// for CPU device:
// fc do not need to convert from cpu device since output is always nc format
// only need create from cpu device
const
MatrixPtr
&
out
=
getOutput
(
device
).
grad
;
outGrad_
=
MKLDNNMatrix
::
create
(
out
,
outVal_
->
getPrimitiveDesc
());
wgtGrad_
=
MKLDNNMatrix
::
create
(
wgt
,
wgtVal_
->
getPrimitiveDesc
());
biasGrad_
=
hasBias
?
MKLDNNMatrix
::
create
(
bias
,
biasVal_
->
getPrimitiveDesc
())
:
nullptr
;
...
...
@@ -238,7 +235,7 @@ void MKLDNNFcLayer::resetBwd() {
pipelineBwd_
.
push_back
(
*
bwdWgt_
);
/// backward data
int
device
=
prev
IsOnlyMKLDNN
()
?
MKLDNN_DEVICE
:
CPU_DEVICE
;
device
=
input
IsOnlyMKLDNN
()
?
MKLDNN_DEVICE
:
CPU_DEVICE
;
const
MatrixPtr
&
in
=
getInputGrad
(
0
,
device
);
if
(
in
==
nullptr
)
{
return
;
...
...
paddle/gserver/layers/MKLDNNLayer.h
浏览文件 @
c5183caa
...
...
@@ -151,6 +151,8 @@ public:
protected:
/**
* 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
()
{
for
(
size_t
i
=
0
;
i
<
outputOtherDevice_
.
size
();
i
++
)
{
...
...
@@ -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.
*/
bool
prev
IsOnlyMKLDNN
(
int
index
=
0
)
{
bool
input
IsOnlyMKLDNN
(
int
index
=
0
)
{
int
prevDevice
=
getPrev
(
index
)
->
getDeviceId
();
if
(
prevDevice
==
MKLDNN_DEVICE
)
{
return
true
;
...
...
@@ -183,7 +185,7 @@ protected:
* If output only has MKLDNN device.
* Otherwise, other devices should only using CPU device.
*/
bool
nex
tIsOnlyMKLDNN
()
{
bool
outpu
tIsOnlyMKLDNN
()
{
for
(
size_t
i
=
0
;
i
<
outputOtherDevice_
.
size
();
i
++
)
{
CHECK_EQ
(
outputOtherDevice_
[
i
].
deviceId
,
CPU_DEVICE
)
<<
"Only support other device is CPU yet"
;
...
...
@@ -195,7 +197,7 @@ protected:
* Sync input value data
*/
void
syncInputValue
()
{
if
(
prev
IsOnlyMKLDNN
())
{
if
(
input
IsOnlyMKLDNN
())
{
return
;
}
real
*
iData
=
getInputValue
(
0
,
CPU_DEVICE
)
->
getData
();
...
...
@@ -208,7 +210,7 @@ protected:
* Sync output grad data
*/
void
syncOutputGrad
()
{
if
(
nex
tIsOnlyMKLDNN
())
{
if
(
outpu
tIsOnlyMKLDNN
())
{
return
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录