Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
32b5caa0
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看板
提交
32b5caa0
编写于
9月 14, 2020
作者:
Z
zhangwen31
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[arm][math]feat: elementwise_add support i32 and i64 now
上级
8018225c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
103 addition
and
0 deletion
+103
-0
lite/backends/arm/math/elementwise.cc
lite/backends/arm/math/elementwise.cc
+83
-0
lite/kernels/arm/elementwise_compute.cc
lite/kernels/arm/elementwise_compute.cc
+20
-0
未找到文件。
lite/backends/arm/math/elementwise.cc
浏览文件 @
32b5caa0
...
...
@@ -21,6 +21,41 @@ namespace lite {
namespace
arm
{
namespace
math
{
// todo: remove this function when all elementwise_add works
template
<
typename
T
>
static
void
naive_elementwise_op
(
const
T
*
dinx
,
const
T
*
diny
,
T
*
dout
,
int
num
,
std
::
function
<
T
(
T
,
T
)
>
op
)
{
for
(
int
i
=
0
;
i
<
num
;
++
i
)
{
*
dout
=
op
(
*
dinx
,
*
diny
);
++
dinx
;
++
diny
;
++
dout
;
}
}
// todo: remove this function when all elementwise_add works
template
<
typename
T
>
static
T
naive_add
(
T
l
,
T
r
)
{
return
l
+
r
;
}
// todo: use arm intrinsics
template
<
>
void
elementwise_add
<
int32_t
>
(
const
int32_t
*
dinx
,
const
int32_t
*
diny
,
int32_t
*
dout
,
int
num
)
{
naive_elementwise_op
<
int32_t
>
(
dinx
,
diny
,
dout
,
num
,
naive_add
<
int32_t
>
);
}
// todo: use arm intrinsics
template
<
>
void
elementwise_add
<
int64_t
>
(
const
int64_t
*
dinx
,
const
int64_t
*
diny
,
int64_t
*
dout
,
int
num
)
{
naive_elementwise_op
<
int64_t
>
(
dinx
,
diny
,
dout
,
num
,
naive_add
<
int64_t
>
);
}
template
<
>
void
elementwise_add
<
float
>
(
const
float
*
dinx
,
const
float
*
diny
,
...
...
@@ -178,6 +213,54 @@ void elementwise_add_tanh<float>(const float* dinx,
}
}
// todo: remove this function when all elementwise_add works
template
<
typename
T
>
static
void
naive_elementwise_op_broadcast
(
const
T
*
x_data
,
const
T
*
y_data
,
T
*
out_data
,
int
batch
,
int
channels
,
int
num
,
std
::
function
<
T
(
T
,
T
)
>
op
)
{
for
(
int
i
=
0
;
i
<
batch
;
++
i
)
{
for
(
int
j
=
0
;
j
<
channels
;
++
j
)
{
int
offset
=
(
i
*
channels
+
j
)
*
num
;
const
T
*
din_ptr
=
x_data
+
offset
;
const
T
diny_data
=
y_data
[
j
];
T
*
dout_ptr
=
out_data
+
offset
;
for
(
int
k
=
0
;
k
<
num
;
++
k
)
{
*
dout_ptr
=
op
(
*
din_ptr
,
diny_data
);
dout_ptr
++
;
din_ptr
++
;
}
}
}
}
// todo: use arm intrinsics
template
<
>
void
elementwise_add_broadcast
<
int32_t
>
(
const
int32_t
*
dinx
,
const
int32_t
*
diny
,
int32_t
*
dout
,
int
batch
,
int
channels
,
int
num
)
{
naive_elementwise_op_broadcast
<
int32_t
>
(
dinx
,
diny
,
dout
,
batch
,
channels
,
num
,
naive_add
<
int32_t
>
);
}
// todo: use arm intrinsics
template
<
>
void
elementwise_add_broadcast
<
int64_t
>
(
const
int64_t
*
dinx
,
const
int64_t
*
diny
,
int64_t
*
dout
,
int
batch
,
int
channels
,
int
num
)
{
naive_elementwise_op_broadcast
<
int64_t
>
(
dinx
,
diny
,
dout
,
batch
,
channels
,
num
,
naive_add
<
int64_t
>
);
}
template
<
>
void
elementwise_add_broadcast
<
float
>
(
const
float
*
dinx
,
const
float
*
diny
,
...
...
lite/kernels/arm/elementwise_compute.cc
浏览文件 @
32b5caa0
...
...
@@ -387,6 +387,26 @@ REGISTER_LITE_KERNEL(
.
BindOutput
(
"Out"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kARM
))})
.
Finalize
();
using
elementwise_add_int32_t
=
paddle
::
lite
::
kernels
::
arm
::
ElementwiseAddCompute
<
int32_t
,
PRECISION
(
kInt32
)
>
;
REGISTER_LITE_KERNEL
(
elementwise_add
,
kARM
,
kInt32
,
kNCHW
,
elementwise_add_int32_t
,
def
)
.
BindInput
(
"X"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kARM
),
PRECISION
(
kInt32
))})
.
BindInput
(
"Y"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kARM
),
PRECISION
(
kInt32
))})
.
BindOutput
(
"Out"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kARM
),
PRECISION
(
kInt32
))})
.
Finalize
();
using
elementwise_add_int64_t
=
paddle
::
lite
::
kernels
::
arm
::
ElementwiseAddCompute
<
int64_t
,
PRECISION
(
kInt64
)
>
;
REGISTER_LITE_KERNEL
(
elementwise_add
,
kARM
,
kInt64
,
kNCHW
,
elementwise_add_int64_t
,
def
)
.
BindInput
(
"X"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kARM
),
PRECISION
(
kInt64
))})
.
BindInput
(
"Y"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kARM
),
PRECISION
(
kInt64
))})
.
BindOutput
(
"Out"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kARM
),
PRECISION
(
kInt64
))})
.
Finalize
();
REGISTER_LITE_KERNEL
(
fusion_elementwise_add_activation
,
kARM
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录