Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
8235e8bf
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
332
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看板
提交
8235e8bf
编写于
9月 22, 2020
作者:
Z
zhangwen31
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[arm][kernel]: feat: add arm kernel for op 'pow'
上级
80452148
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
30 addition
and
33 deletion
+30
-33
lite/kernels/arm/CMakeLists.txt
lite/kernels/arm/CMakeLists.txt
+1
-1
lite/kernels/arm/pow_compute.cc
lite/kernels/arm/pow_compute.cc
+10
-8
lite/kernels/arm/pow_compute.h
lite/kernels/arm/pow_compute.h
+3
-3
lite/operators/power_op.h
lite/operators/power_op.h
+3
-0
lite/tests/kernels/CMakeLists.txt
lite/tests/kernels/CMakeLists.txt
+1
-1
lite/tests/kernels/pow_compute_test.cc
lite/tests/kernels/pow_compute_test.cc
+12
-20
未找到文件。
lite/kernels/arm/CMakeLists.txt
浏览文件 @
8235e8bf
...
...
@@ -52,7 +52,7 @@ add_kernel(grid_sampler_compute_arm ARM basic SRCS grid_sampler_compute.cc DEPS
## 2.other basic kernels: basic kernels that not used in basic models
add_kernel
(
negative_compute_arm ARM extra SRCS negative_compute.cc DEPS
${
lite_kernel_deps
}
math_arm
)
add_kernel
(
crop_compute_arm ARM extra SRCS crop_compute.cc DEPS
${
lite_kernel_deps
}
math_arm
)
add_kernel
(
pow
er_compute_arm ARM extra SRCS power
_compute.cc DEPS
${
lite_kernel_deps
}
math_arm
)
add_kernel
(
pow
_compute_arm ARM extra SRCS pow
_compute.cc DEPS
${
lite_kernel_deps
}
math_arm
)
add_kernel
(
norm_compute_arm ARM extra SRCS norm_compute.cc DEPS
${
lite_kernel_deps
}
math_arm
)
add_kernel
(
group_norm_compute ARM extra SRCS group_norm_compute.cc DEPS
${
lite_kernel_deps
}
math_arm
)
## 3. extra kernels
...
...
lite/kernels/arm/pow
er
_compute.cc
→
lite/kernels/arm/pow_compute.cc
浏览文件 @
8235e8bf
// Copyright (c) 20
19
PaddlePaddle Authors. All Rights Reserved.
// Copyright (c) 20
20
PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
...
...
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "lite/kernels/arm/pow
er
_compute.h"
#include "lite/kernels/arm/pow_compute.h"
#include "lite/backends/arm/math/funcs.h"
namespace
paddle
{
...
...
@@ -20,15 +20,17 @@ namespace lite {
namespace
kernels
{
namespace
arm
{
void
Pow
er
Compute
::
Run
()
{
auto
&
param
=
Param
<
operators
::
Pow
er
Param
>
();
void
PowCompute
::
Run
()
{
auto
&
param
=
Param
<
operators
::
PowParam
>
();
const
float
*
x_data
=
param
.
X
->
data
<
float
>
();
float
*
output_data
=
param
.
Out
->
mutable_data
<
float
>
();
DDim
x_dims
=
param
.
X
->
dims
();
float
scale
=
param
.
scale
;
float
shift
=
param
.
shift
;
float
power
=
param
.
powe
r
;
float
scale
=
1.0
;
float
shift
=
0.0
;
float
power
=
param
.
facto
r
;
// fixme: update lite::arm::math::power if necessary, for scale and shift is
// not used
lite
::
arm
::
math
::
power
(
x_data
,
output_data
,
x_dims
.
production
(),
scale
,
shift
,
power
);
}
...
...
@@ -39,7 +41,7 @@ void PowerCompute::Run() {
}
/* namespace paddle */
REGISTER_LITE_KERNEL
(
pow
er
,
kARM
,
kFloat
,
kNCHW
,
paddle
::
lite
::
kernels
::
arm
::
Power
Compute
,
def
)
pow
,
kARM
,
kFloat
,
kNCHW
,
paddle
::
lite
::
kernels
::
arm
::
Pow
Compute
,
def
)
.
BindInput
(
"X"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kARM
))})
.
BindOutput
(
"Out"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kARM
))})
.
Finalize
();
lite/kernels/arm/pow
er
_compute.h
→
lite/kernels/arm/pow_compute.h
浏览文件 @
8235e8bf
// Copyright (c) 20
19
PaddlePaddle Authors. All Rights Reserved.
// Copyright (c) 20
20
PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
...
...
@@ -21,11 +21,11 @@ namespace lite {
namespace
kernels
{
namespace
arm
{
class
Pow
er
Compute
:
public
KernelLite
<
TARGET
(
kARM
),
PRECISION
(
kFloat
)
>
{
class
PowCompute
:
public
KernelLite
<
TARGET
(
kARM
),
PRECISION
(
kFloat
)
>
{
public:
void
Run
()
override
;
virtual
~
Pow
er
Compute
()
=
default
;
virtual
~
PowCompute
()
=
default
;
};
}
/* namespace arm */
...
...
lite/operators/power_op.h
浏览文件 @
8235e8bf
...
...
@@ -23,6 +23,9 @@ namespace paddle {
namespace
lite
{
namespace
operators
{
/**
* @deprecated There is NO power op in paddle fluid
*/
class
PowerOp
:
public
OpLite
{
public:
PowerOp
()
{}
...
...
lite/tests/kernels/CMakeLists.txt
浏览文件 @
8235e8bf
...
...
@@ -2,7 +2,7 @@ if((NOT LITE_WITH_OPENCL AND NOT LITE_WITH_FPGA AND NOT LITE_WITH_BM AND NOT LIT
lite_cc_test
(
test_kernel_conv_compute SRCS conv_compute_test.cc DEPS arena_framework
${
xpu_kernels
}
${
npu_kernels
}
${
huawei_ascend_npu_kernels
}
${
x86_kernels
}
${
cuda_kernels
}
${
arm_kernels
}
${
lite_ops
}
${
host_kernels
}
)
lite_cc_test
(
test_kernel_conv_transpose_compute SRCS conv_transpose_compute_test.cc DEPS arena_framework
${
xpu_kernels
}
${
npu_kernels
}
${
huawei_ascend_npu_kernels
}
${
x86_kernels
}
${
cuda_kernels
}
${
arm_kernels
}
${
lite_ops
}
${
host_kernels
}
)
lite_cc_test
(
test_kernel_scale_compute SRCS scale_compute_test.cc DEPS arena_framework
${
xpu_kernels
}
${
npu_kernels
}
${
huawei_ascend_npu_kernels
}
${
x86_kernels
}
${
cuda_kernels
}
${
arm_kernels
}
${
lite_ops
}
${
host_kernels
}
)
lite_cc_test
(
test_kernel_pow
er_compute SRCS power
_compute_test.cc DEPS arena_framework
${
xpu_kernels
}
${
npu_kernels
}
${
huawei_ascend_npu_kernels
}
${
x86_kernels
}
${
cuda_kernels
}
${
arm_kernels
}
${
lite_ops
}
${
host_kernels
}
)
lite_cc_test
(
test_kernel_pow
_compute SRCS pow
_compute_test.cc DEPS arena_framework
${
xpu_kernels
}
${
npu_kernels
}
${
huawei_ascend_npu_kernels
}
${
x86_kernels
}
${
cuda_kernels
}
${
arm_kernels
}
${
lite_ops
}
${
host_kernels
}
)
lite_cc_test
(
test_kernel_shuffle_channel_compute SRCS shuffle_channel_compute_test.cc DEPS arena_framework
${
xpu_kernels
}
${
npu_kernels
}
${
huawei_ascend_npu_kernels
}
${
x86_kernels
}
${
cuda_kernels
}
${
arm_kernels
}
${
lite_ops
}
${
host_kernels
}
)
lite_cc_test
(
test_kernel_yolo_box_compute SRCS yolo_box_compute_test.cc DEPS arena_framework
${
xpu_kernels
}
${
npu_kernels
}
${
huawei_ascend_npu_kernels
}
${
x86_kernels
}
${
cuda_kernels
}
${
arm_kernels
}
${
lite_ops
}
${
host_kernels
}
)
lite_cc_test
(
test_kernel_fc_compute SRCS fc_compute_test.cc DEPS arena_framework
${
xpu_kernels
}
${
npu_kernels
}
${
huawei_ascend_npu_kernels
}
${
x86_kernels
}
${
cuda_kernels
}
${
arm_kernels
}
${
lite_ops
}
${
host_kernels
}
)
...
...
lite/tests/kernels/pow
er
_compute_test.cc
→
lite/tests/kernels/pow_compute_test.cc
浏览文件 @
8235e8bf
...
...
@@ -20,23 +20,17 @@
namespace
paddle
{
namespace
lite
{
class
Pow
er
ComputeTester
:
public
arena
::
TestCase
{
class
PowComputeTester
:
public
arena
::
TestCase
{
protected:
// common attributes for this op.
std
::
string
input_
=
"X"
;
std
::
string
output_
=
"Out"
;
float
scale_
=
0.
;
float
shift_
=
0.
;
float
power_
=
0.
;
float
factor_
=
0.
;
DDim
dims_
{{
5
,
2
}};
public:
PowerComputeTester
(
const
Place
&
place
,
const
std
::
string
&
alias
,
float
scale
,
float
shift
,
float
power
)
:
TestCase
(
place
,
alias
),
scale_
(
scale
),
shift_
(
shift
),
power_
(
power
)
{}
PowComputeTester
(
const
Place
&
place
,
const
std
::
string
&
alias
,
float
factor
)
:
TestCase
(
place
,
alias
),
factor_
(
factor
)
{}
void
RunBaseline
(
Scope
*
scope
)
override
{
auto
*
out
=
scope
->
NewTensor
(
output_
);
...
...
@@ -48,17 +42,15 @@ class PowerComputeTester : public arena::TestCase {
const
auto
*
x_data
=
x
->
data
<
float
>
();
for
(
int
i
=
0
;
i
<
dims_
.
production
();
i
++
)
{
out_data
[
i
]
=
std
::
pow
(
(
x_data
[
i
]
*
scale_
+
shift_
),
powe
r_
);
out_data
[
i
]
=
std
::
pow
(
x_data
[
i
],
facto
r_
);
}
}
void
PrepareOpDesc
(
cpp
::
OpDesc
*
op_desc
)
{
op_desc
->
SetType
(
"pow
er
"
);
op_desc
->
SetType
(
"pow"
);
op_desc
->
SetInput
(
"X"
,
{
input_
});
op_desc
->
SetOutput
(
"Out"
,
{
output_
});
op_desc
->
SetAttr
(
"scale"
,
scale_
);
op_desc
->
SetAttr
(
"shift"
,
shift_
);
op_desc
->
SetAttr
(
"power"
,
power_
);
op_desc
->
SetAttr
(
"factor"
,
factor_
);
}
void
PrepareData
()
override
{
...
...
@@ -72,12 +64,12 @@ class PowerComputeTester : public arena::TestCase {
}
};
void
test_pow
er
(
Place
place
)
{
void
test_pow
(
Place
place
)
{
for
(
float
scale
:
{
0.923
,
2.
,
1.2
})
{
for
(
float
shift
:
{
1.
,
0.
,
1.2331
})
{
for
(
float
powe
r
:
{
1.
,
1.2
,
1.6
})
{
for
(
float
facto
r
:
{
1.
,
1.2
,
1.6
})
{
std
::
unique_ptr
<
arena
::
TestCase
>
tester
(
new
Pow
erComputeTester
(
place
,
"def"
,
scale
,
shift
,
powe
r
));
new
Pow
ComputeTester
(
place
,
"def"
,
facto
r
));
arena
::
Arena
arena
(
std
::
move
(
tester
),
place
,
2e-4
);
arena
.
TestPrecision
();
}
...
...
@@ -85,13 +77,13 @@ void test_power(Place place) {
}
}
TEST
(
Pow
er
,
precision
)
{
TEST
(
Pow
,
precision
)
{
// #ifdef LITE_WITH_X86
// Place place(TARGET(kX86));
// #endif
#ifdef LITE_WITH_ARM
Place
place
(
TARGET
(
kARM
));
test_pow
er
(
place
);
test_pow
(
place
);
#endif
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录