Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wk1234123
Paddle
提交
84835784
P
Paddle
项目概览
wk1234123
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
4
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,发现更多精彩内容 >>
提交
84835784
编写于
11月 10, 2017
作者:
D
Dong Zhihong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix shape bug
上级
58b4c9af
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
23 addition
and
7 deletion
+23
-7
paddle/operators/reduce_op.h
paddle/operators/reduce_op.h
+23
-7
未找到文件。
paddle/operators/reduce_op.h
浏览文件 @
84835784
...
...
@@ -14,6 +14,7 @@
#pragma once
#include "glog/logging.h"
#include "paddle/framework/eigen.h"
#include "paddle/framework/op_registry.h"
...
...
@@ -26,6 +27,10 @@ template <typename T, size_t D, int MajorType = Eigen::RowMajor,
typename
IndexType
=
Eigen
::
DenseIndex
>
using
EigenTensor
=
framework
::
EigenTensor
<
T
,
D
,
MajorType
,
IndexType
>
;
template
<
typename
T
,
int
MajorType
=
Eigen
::
RowMajor
,
typename
IndexType
=
Eigen
::
DenseIndex
>
using
EigenScalar
=
framework
::
EigenScalar
<
T
,
MajorType
,
IndexType
>
;
struct
SumFunctor
{
template
<
typename
Place
,
typename
X
,
typename
Y
,
typename
Dim
>
void
operator
()(
const
Place
&
place
,
X
&
x
,
Y
&
y
,
const
Dim
&
dim
)
{
...
...
@@ -133,10 +138,21 @@ class ReduceKernel : public framework::OpKernel<T> {
dims_vector
.
erase
(
dims_vector
.
begin
()
+
dim
);
dims
=
framework
::
make_ddim
(
dims_vector
);
}
auto
out
=
EigenTensor
<
T
,
D
==
1
?
1
:
(
D
-
1
)
>
::
From
(
*
output
,
dims
);
auto
&
place
=
context
.
GetEigenDevice
<
Place
>
();
Functor
functor
;
functor
(
place
,
x
,
out
,
reduce_dim
);
if
(
D
==
1
)
{
auto
out
=
EigenScalar
<
T
>::
From
(
*
output
);
// auto out = EigenTensor<T, 1>::From(*output, dims);
VLOG
(
0
)
<<
"x dims : "
<<
x
.
rank
()
<<
" out dims : "
<<
out
.
rank
();
functor
(
place
,
x
,
out
,
reduce_dim
);
}
else
{
auto
out
=
EigenTensor
<
T
,
(
D
-
1
)
>::
From
(
*
output
,
dims
);
// VLOG(0) << "x dims : "<< x.dimensions().size() << " out dims : "
// << out.dimensions().size();
functor
(
place
,
x
,
out
,
reduce_dim
);
}
}
};
...
...
@@ -186,13 +202,13 @@ class ReduceGradKernel : public framework::OpKernel<T> {
auto
x_reduce
=
EigenTensor
<
T
,
D
>::
From
(
*
input1
,
dims
);
auto
x_reduce_grad
=
EigenTensor
<
T
,
D
>::
From
(
*
input2
,
dims
);
Eigen
::
array
<
int
,
D
>
br
ao
dcast_dim
;
for
(
size_t
i
=
0
;
i
<
D
;
++
i
)
br
ao
dcast_dim
[
i
]
=
1
;
br
ao
dcast_dim
[
dim
]
=
input0
->
dims
()[
dim
];
Eigen
::
array
<
int
,
D
>
br
oa
dcast_dim
;
for
(
size_t
i
=
0
;
i
<
D
;
++
i
)
br
oa
dcast_dim
[
i
]
=
1
;
br
oa
dcast_dim
[
dim
]
=
input0
->
dims
()[
dim
];
auto
&
place
=
context
.
GetEigenDevice
<
Place
>
();
Functor
functor
;
functor
(
place
,
x
,
x_reduce
,
x_grad
,
x_reduce_grad
,
br
ao
dcast_dim
,
br
ao
dcast_dim
[
dim
]);
functor
(
place
,
x
,
x_reduce
,
x_grad
,
x_reduce_grad
,
br
oa
dcast_dim
,
br
oa
dcast_dim
[
dim
]);
}
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录