Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wzpei9
Paddle
提交
a1331f98
P
Paddle
项目概览
wzpei9
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a1331f98
编写于
3月 06, 2018
作者:
C
chengduoZH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine elementwise_mul_op
上级
351795e8
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
9 addition
and
76 deletion
+9
-76
paddle/fluid/operators/elementwise_mul_op.h
paddle/fluid/operators/elementwise_mul_op.h
+8
-75
paddle/fluid/operators/elementwise_op_function.h
paddle/fluid/operators/elementwise_op_function.h
+1
-1
未找到文件。
paddle/fluid/operators/elementwise_mul_op.h
浏览文件 @
a1331f98
...
@@ -40,80 +40,14 @@ class ElementwiseMulKernel : public framework::OpKernel<T> {
...
@@ -40,80 +40,14 @@ class ElementwiseMulKernel : public framework::OpKernel<T> {
};
};
template
<
typename
T
>
template
<
typename
T
>
struct
ElementwiseMulGradFunctor
{
struct
IdentityGrad_DX
{
template
<
typename
Device
,
typename
X
,
typename
Y
,
typename
Z
,
typename
dX
,
HOSTDEVICE
T
operator
()(
T
x
,
T
y
,
T
out
,
T
dout
)
const
{
return
dout
*
y
;
}
typename
dY
,
typename
dZ
>
void
operator
()(
Device
d
,
X
x
,
Y
y
,
Z
z
,
dX
dx
,
dY
dy
,
dZ
dz
)
{
auto
x_e
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
x
);
auto
y_e
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
y
);
auto
dz_e
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
dz
);
if
(
dx
)
{
auto
dx_e
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
dx
);
dx_e
.
device
(
d
)
=
dz_e
*
y_e
;
}
if
(
dy
)
{
auto
dy_e
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
dy
);
dy_e
.
device
(
d
)
=
x_e
*
dz_e
;
}
}
};
};
template
<
typename
T
>
template
<
typename
T
>
struct
ElementwiseMulBroadCastGradFunctor
{
struct
IdentityGrad_DY
{
template
<
typename
Device
,
typename
X
,
typename
Y
,
typename
Z
,
typename
dX
,
HOSTDEVICE
T
operator
()(
T
x
,
T
y
,
T
out
,
T
dout
)
const
{
return
dout
*
x
;
}
typename
dY
,
typename
dZ
,
typename
Pre
,
typename
N
>
void
operator
()(
Device
d
,
X
x
,
Y
y
,
Z
z
,
dX
dx
,
dY
dy
,
dZ
dz
,
Pre
pre
,
N
n
)
{
auto
x_e
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
x
);
auto
y_e
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
y
);
auto
dz_e
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
dz
);
auto
y_e_bcast
=
y_e
.
reshape
(
Eigen
::
DSizes
<
int
,
2
>
(
1
,
n
))
.
broadcast
(
Eigen
::
DSizes
<
int
,
2
>
(
pre
,
1
))
.
reshape
(
Eigen
::
DSizes
<
int
,
1
>
(
x_e
.
size
()));
if
(
dx
)
{
auto
dx_e
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
dx
);
dx_e
.
device
(
d
)
=
dz_e
*
y_e_bcast
;
}
if
(
dy
)
{
auto
dy_e
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
dy
);
dy_e
.
device
(
d
)
=
(
x_e
*
dz_e
)
.
reshape
(
Eigen
::
DSizes
<
int
,
2
>
(
pre
,
n
))
.
sum
(
Eigen
::
array
<
int
,
1
>
{{
0
}});
}
}
};
};
template
<
typename
T
>
struct
ElementwiseMulBroadCast2GradFunctor
{
template
<
typename
Device
,
typename
X
,
typename
Y
,
typename
Z
,
typename
dX
,
typename
dY
,
typename
dZ
,
typename
Pre
,
typename
N
,
typename
Post
>
void
operator
()(
Device
d
,
X
x
,
Y
y
,
Z
z
,
dX
dx
,
dY
dy
,
dZ
dz
,
Pre
pre
,
N
n
,
Post
post
)
{
auto
x_e
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
x
);
auto
y_e
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
y
);
auto
dz_e
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
dz
);
auto
y_e_bcast
=
y_e
.
reshape
(
Eigen
::
DSizes
<
int
,
3
>
(
1
,
n
,
1
))
.
broadcast
(
Eigen
::
DSizes
<
int
,
3
>
(
pre
,
1
,
post
))
.
reshape
(
Eigen
::
DSizes
<
int
,
1
>
(
x_e
.
size
()));
if
(
dx
)
{
auto
dx_e
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
dx
);
dx_e
.
device
(
d
)
=
dz_e
*
y_e_bcast
;
}
if
(
dy
)
{
auto
dy_e
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
dy
);
dy_e
.
device
(
d
)
=
(
x_e
*
dz_e
)
.
reshape
(
Eigen
::
DSizes
<
int
,
3
>
(
pre
,
n
,
post
))
.
sum
(
Eigen
::
array
<
int
,
2
>
{{
0
,
2
}});
}
}
};
template
<
typename
DeviceContext
,
typename
T
>
template
<
typename
DeviceContext
,
typename
T
>
class
ElementwiseMulGradKernel
:
public
framework
::
OpKernel
<
T
>
{
class
ElementwiseMulGradKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
public:
...
@@ -127,12 +61,11 @@ class ElementwiseMulGradKernel : public framework::OpKernel<T> {
...
@@ -127,12 +61,11 @@ class ElementwiseMulGradKernel : public framework::OpKernel<T> {
auto
*
dx
=
ctx
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"X"
));
auto
*
dx
=
ctx
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"X"
));
auto
*
dy
=
ctx
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"Y"
));
auto
*
dy
=
ctx
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"Y"
));
int
axis
=
ctx
.
Attr
<
int
>
(
"axis"
);
int
axis
=
ctx
.
Attr
<
int
>
(
"axis"
);
Elem
entwiseGradCompute
<
DeviceContext
,
T
,
ElementwiseMulGradFunctor
<
T
>
,
Elem
wiseGradCompute
<
DeviceContext
,
T
,
IdentityGrad_DX
<
T
>
,
ElementwiseMulBroadCastGradFunctor
<
T
>
,
IdentityGrad_DY
<
T
>>
(
ctx
,
*
x
,
*
y
,
*
out
,
*
dout
,
axis
,
dx
,
ElementwiseMulBroadCast2GradFunctor
<
T
>>
(
dy
,
IdentityGrad_DX
<
T
>
(),
ctx
,
x
,
y
,
out
,
dout
,
axis
,
dx
,
dy
);
IdentityGrad_DY
<
T
>
()
);
}
}
};
};
}
// namespace operators
}
// namespace operators
}
// namespace paddle
}
// namespace paddle
paddle/fluid/operators/elementwise_op_function.h
浏览文件 @
a1331f98
...
@@ -301,7 +301,7 @@ struct ElemwiseGradNoBroadcast {
...
@@ -301,7 +301,7 @@ struct ElemwiseGradNoBroadcast {
dx_
[
i
]
=
dx_op_
(
x_
[
i
],
y_
[
i
],
out_
[
i
],
dout_
[
i
]);
dx_
[
i
]
=
dx_op_
(
x_
[
i
],
y_
[
i
],
out_
[
i
],
dout_
[
i
]);
}
}
if
(
dy_
!=
nullptr
)
{
if
(
dy_
!=
nullptr
)
{
dy_
[
i
]
=
d
x
_op_
(
x_
[
i
],
y_
[
i
],
out_
[
i
],
dout_
[
i
]);
dy_
[
i
]
=
d
y
_op_
(
x_
[
i
],
y_
[
i
],
out_
[
i
],
dout_
[
i
]);
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录