Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
fc385777
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看板
未验证
提交
fc385777
编写于
11月 08, 2019
作者:
W
wangchaochaohu
提交者:
GitHub
11月 08, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix the compile cost long time test=develop (#21064)
上级
2f27b103
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
17 addition
and
22 deletion
+17
-22
paddle/fluid/operators/expand_as_op.h
paddle/fluid/operators/expand_as_op.h
+17
-22
未找到文件。
paddle/fluid/operators/expand_as_op.h
100755 → 100644
浏览文件 @
fc385777
...
...
@@ -31,9 +31,7 @@ limitations under the License. */
break; \
}
#define REP_EXPAND_AS_TEMPLATE(n) BOOST_PP_REPEAT(n, EXPAND_AS_TEMPLATE, ~)
#define COND(n) \
BOOST_PP_GREATER_EQUAL(BOOST_PP_DIV(n, MAX_RANK_SUPPORTED), \
BOOST_PP_MOD(n, MAX_RANK_SUPPORTED))
#define COND(n) BOOST_PP_GREATER_EQUAL(n, BOOST_PP_MOD(n, MAX_RANK_SUPPORTED))
#define EXPAND_AS_GRAD_CASE(n) \
case n: { \
ExpandAsBackward<n>(context, reshape_dims_vec, reduce_dims_vec); \
...
...
@@ -116,23 +114,20 @@ class ExpandAsGradKernel : public framework::OpKernel<T> {
std
::
vector
<
int
>
reshape_dims_vec
;
std
::
vector
<
int
>
reduce_dims_vec
;
for
(
size_t
i
=
0
;
i
<
bcast_dims
.
size
();
++
i
)
{
if
(
bcast_dims
[
i
]
==
1
)
{
reshape_dims_vec
.
push_back
(
x_dims
[
i
]);
}
else
{
if
(
x_dims
[
i
]
==
1
)
{
reduce_dims_vec
.
push_back
(
reshape_dims_vec
.
size
());
reshape_dims_vec
.
push_back
(
bcast_dims
[
i
]);
}
else
{
reduce_dims_vec
.
push_back
(
reshape_dims_vec
.
size
());
reshape_dims_vec
.
push_back
(
bcast_dims
[
i
]);
reshape_dims_vec
.
push_back
(
x_dims
[
i
]);
}
reduce_dims_vec
.
push_back
(
reshape_dims_vec
.
size
());
reshape_dims_vec
.
push_back
(
bcast_dims
[
i
]);
reshape_dims_vec
.
push_back
(
x_dims
[
i
]);
}
int
dims
=
reduce_dims_vec
.
size
();
bool
just_copy
=
true
;
for
(
size_t
i
=
0
;
i
<
bcast_dims
.
size
();
i
++
)
{
if
(
bcast_dims
[
i
]
!=
1
)
{
just_copy
=
false
;
break
;
}
}
int
dims
=
reshape_dims_vec
.
size
()
*
MAX_RANK_SUPPORTED
+
reduce_dims_vec
.
size
()
-
MAX_RANK_SUPPORTED
-
1
;
// no need reduce, just copy
if
(
reduce_dims_vec
.
size
()
==
0
)
{
if
(
just_copy
)
{
auto
*
in0
=
context
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
auto
*
out0
=
context
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"X"
));
out0
->
mutable_data
<
T
>
(
context
.
GetPlace
());
...
...
@@ -140,7 +135,7 @@ class ExpandAsGradKernel : public framework::OpKernel<T> {
out0
);
}
else
{
switch
(
dims
)
{
REP_EXPAND_AS_GRAD_TEMPLATE
(
72
)
REP_EXPAND_AS_GRAD_TEMPLATE
(
MAX_RANK_SUPPORTED
)
default:
PADDLE_THROW
(
"Only support tensor with rank being between 1 and 6."
);
}
...
...
@@ -152,8 +147,8 @@ class ExpandAsGradKernel : public framework::OpKernel<T> {
void
ExpandAsBackward
(
const
framework
::
ExecutionContext
&
context
,
const
std
::
vector
<
int
>&
reshape_dims_vec
,
const
std
::
vector
<
int
>&
reduce_dims_vec
)
const
{
size_t
reshape_size
=
Dims
/
MAX_RANK_SUPPORTED
+
1
;
size_t
reduce_size
=
Dims
%
MAX_RANK_SUPPORTED
+
1
;
size_t
reshape_size
=
reshape_dims_vec
.
size
()
;
size_t
reduce_size
=
reduce_dims_vec
.
size
()
;
PADDLE_ENFORCE_EQ
(
reshape_size
,
reshape_dims_vec
.
size
(),
"Inconsistent size between template Dims and "
"reshape dimensions."
);
...
...
@@ -164,11 +159,11 @@ class ExpandAsGradKernel : public framework::OpKernel<T> {
auto
*
out0
=
context
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"X"
));
out0
->
mutable_data
<
T
>
(
context
.
GetPlace
());
auto
x_grad
=
EigenVector
<
T
>::
Flatten
(
*
out0
);
Eigen
::
DSizes
<
int
,
Dims
/
MAX_RANK_SUPPORTED
+
1
>
reshape_dims
;
Eigen
::
DSizes
<
int
,
Dims
*
2
>
reshape_dims
;
for
(
size_t
i
=
0
;
i
<
reshape_size
;
++
i
)
{
reshape_dims
[
i
]
=
reshape_dims_vec
[
i
];
}
Eigen
::
DSizes
<
int
,
Dims
%
MAX_RANK_SUPPORTED
+
1
>
reduce_dims
;
Eigen
::
DSizes
<
int
,
Dims
>
reduce_dims
;
for
(
size_t
i
=
0
;
i
<
reduce_size
;
++
i
)
{
reduce_dims
[
i
]
=
reduce_dims_vec
[
i
];
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录