Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
c210374c
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c210374c
编写于
2月 14, 2020
作者:
alinag
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add sumfunctor using tensor computation
test=develop
上级
15d7e8b3
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
46 addition
and
36 deletion
+46
-36
lite/kernels/x86/reduce_compute.h
lite/kernels/x86/reduce_compute.h
+15
-1
lite/kernels/x86/reduce_op_function.h
lite/kernels/x86/reduce_op_function.h
+31
-35
未找到文件。
lite/kernels/x86/reduce_compute.h
浏览文件 @
c210374c
...
@@ -29,6 +29,20 @@ struct SumFunctor {
...
@@ -29,6 +29,20 @@ struct SumFunctor {
void
operator
()(
X
*
x
,
Y
*
y
,
const
Dim
&
dim
)
{
void
operator
()(
X
*
x
,
Y
*
y
,
const
Dim
&
dim
)
{
y
->
device
(
lite
::
fluid
::
EigenDeviceType
<
TARGET
(
kX86
)
>
())
=
x
->
sum
(
dim
);
y
->
device
(
lite
::
fluid
::
EigenDeviceType
<
TARGET
(
kX86
)
>
())
=
x
->
sum
(
dim
);
}
}
template
<
typename
X
,
typename
Y
,
typename
Dim
>
void
operator
()(
X
*
x
,
Y
*
y
,
const
Dim
&
dim
,
size_t
d
,
size_t
r_d
)
{
for
(
int
i
=
0
;
i
<
dim
[
0
];
i
++
)
{
for
(
int
k
=
0
;
k
<
dim
[
2
];
k
++
)
{
auto
output_temp
=
x
[
i
*
dim
[
1
]
*
dim
[
2
]
+
k
];
for
(
int
j
=
1
;
j
<
dim
[
1
];
j
++
)
{
int
input_d
=
i
*
dim
[
1
]
*
dim
[
2
]
+
j
*
dim
[
2
]
+
k
;
output_temp
=
output_temp
+
x
[
input_d
];
}
y
[
i
*
dim
[
2
]
+
k
]
=
output_temp
;
}
}
}
};
};
#define HANDLE_DIM(NDIM, RDIM) \
#define HANDLE_DIM(NDIM, RDIM) \
...
@@ -68,7 +82,7 @@ class ReduceSumCompute : public KernelLite<TARGET(kX86), PRECISION(kFloat)> {
...
@@ -68,7 +82,7 @@ class ReduceSumCompute : public KernelLite<TARGET(kX86), PRECISION(kFloat)> {
HANDLE_DIM
(
4
,
2
);
HANDLE_DIM
(
4
,
2
);
HANDLE_DIM
(
4
,
1
);
HANDLE_DIM
(
4
,
1
);
HANDLE_DIM
(
3
,
2
);
HANDLE_DIM
(
3
,
2
);
HANDLE_DIM
(
3
,
1
);
HANDLE_DIM
T
(
3
,
1
);
HANDLE_DIM
(
2
,
1
);
HANDLE_DIM
(
2
,
1
);
HANDLE_DIM
(
1
,
1
);
HANDLE_DIM
(
1
,
1
);
}
}
...
...
lite/kernels/x86/reduce_op_function.h
浏览文件 @
c210374c
...
@@ -46,24 +46,6 @@ void ReduceFunctor(const lite::Tensor& input,
...
@@ -46,24 +46,6 @@ void ReduceFunctor(const lite::Tensor& input,
lite
::
Tensor
*
output
,
lite
::
Tensor
*
output
,
const
std
::
vector
<
int
>&
dims
,
const
std
::
vector
<
int
>&
dims
,
bool
keep_dim
)
{
bool
keep_dim
)
{
auto
te
=
strstr
(
typeid
(
Functor
).
name
(),
"SumFunctor"
);
if
(
D
==
3
&&
R_D
==
1
&&
te
!=
NULL
)
{
const
lite
::
DDim
&
input_dims
=
input
.
dims
();
const
T
*
input_data
=
input
.
data
<
T
>
();
T
*
output_data
=
output
->
mutable_data
<
T
>
();
for
(
int
i
=
0
;
i
<
input_dims
[
0
];
i
++
)
{
for
(
int
k
=
0
;
k
<
input_dims
[
2
];
k
++
)
{
int
out_d
=
i
*
input_dims
[
2
]
+
k
;
T
output_temp
=
0
;
for
(
int
j
=
0
;
j
<
input_dims
[
1
];
j
++
)
{
int
input_d
=
i
*
input_dims
[
1
]
*
input_dims
[
2
]
+
j
*
input_dims
[
2
]
+
k
;
output_temp
=
output_temp
+
input_data
[
input_d
];
}
output_data
[
out_d
]
=
output_temp
;
}
}
}
else
{
auto
x
=
EigenTensor
<
T
,
D
>::
From
(
input
);
auto
x
=
EigenTensor
<
T
,
D
>::
From
(
input
);
auto
reduce_dim
=
Eigen
::
array
<
int
,
R_D
>
();
auto
reduce_dim
=
Eigen
::
array
<
int
,
R_D
>
();
...
@@ -84,7 +66,21 @@ void ReduceFunctor(const lite::Tensor& input,
...
@@ -84,7 +66,21 @@ void ReduceFunctor(const lite::Tensor& input,
auto
out
=
EigenTensor
<
T
,
(
D
-
R_D
)
>::
From
(
*
output
,
output
->
dims
());
auto
out
=
EigenTensor
<
T
,
(
D
-
R_D
)
>::
From
(
*
output
,
output
->
dims
());
functor
(
&
x
,
&
out
,
reduce_dim
);
functor
(
&
x
,
&
out
,
reduce_dim
);
}
}
}
}
template
<
lite
::
TargetType
Target
,
typename
T
,
size_t
D
,
size_t
R_D
,
typename
Functor
>
void
ReduceFunctorTensor
(
const
lite
::
Tensor
&
input
,
lite
::
Tensor
*
output
,
const
std
::
vector
<
int
>&
dims
,
bool
keep_dim
)
{
Functor
functor
;
const
T
*
input_data
=
input
.
data
<
T
>
();
T
*
output_data
=
output
->
mutable_data
<
T
>
();
functor
(
input_data
,
output_data
,
input
.
dims
(),
D
,
R_D
);
}
}
}
// namespace x86
}
// namespace x86
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录