Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
dfce4621
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
dfce4621
编写于
10月 11, 2019
作者:
J
juncaipeng
提交者:
GitHub
10月 11, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add rsqrt op, test=develop (#2176)
上级
77811367
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
77 addition
and
2 deletion
+77
-2
lite/api/_paddle_use_ops.h
lite/api/_paddle_use_ops.h
+1
-0
lite/backends/arm/math/activation.cc
lite/backends/arm/math/activation.cc
+12
-0
lite/backends/arm/math/activation.h
lite/backends/arm/math/activation.h
+4
-0
lite/kernels/arm/activation_compute.cc
lite/kernels/arm/activation_compute.cc
+15
-0
lite/kernels/arm/activation_compute.h
lite/kernels/arm/activation_compute.h
+9
-0
lite/operators/activation_ops.cc
lite/operators/activation_ops.cc
+1
-0
lite/tests/kernels/activation_compute_test.cc
lite/tests/kernels/activation_compute_test.cc
+35
-2
未找到文件。
lite/api/_paddle_use_ops.h
浏览文件 @
dfce4621
...
...
@@ -127,3 +127,4 @@ USE_LITE_OP(roi_align)
USE_LITE_OP
(
box_clip
)
USE_LITE_OP
(
assign_value
)
USE_LITE_OP
(
hard_sigmoid
)
USE_LITE_OP
(
rsqrt
)
lite/backends/arm/math/activation.cc
浏览文件 @
dfce4621
...
...
@@ -688,6 +688,18 @@ void act_hard_sigmoid<float>(const float* din,
++
dout
;
}
}
template
<
>
void
act_rsqrt
<
float
>
(
const
float
*
din
,
float
*
dout
,
int
size
,
int
threads
)
{
const
float
*
ptr_in
=
din
;
float
*
ptr_out
=
dout
;
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
ptr_out
[
0
]
=
1.0
/
sqrtf
(
ptr_in
[
0
]);
ptr_in
++
;
ptr_out
++
;
}
}
}
// namespace math
}
// namespace arm
}
// namespace lite
...
...
lite/backends/arm/math/activation.h
浏览文件 @
dfce4621
...
...
@@ -65,6 +65,10 @@ void act_hard_sigmoid(const T* din,
const
float
slope
,
const
float
offset
,
int
threads
);
template
<
typename
T
>
void
act_rsqrt
(
const
T
*
din
,
T
*
dout
,
int
size
,
int
threads
);
}
// namespace math
}
// namespace arm
}
// namespace lite
...
...
lite/kernels/arm/activation_compute.cc
浏览文件 @
dfce4621
...
...
@@ -159,6 +159,16 @@ void HardSigmoidCompute::Run() {
x_data
,
output_data
,
x_dims
.
production
(),
slope
,
offset
,
ctx
.
threads
());
}
void
RsqrtCompute
::
Run
()
{
auto
&
param
=
this
->
Param
<
param_t
>
();
auto
&
ctx
=
this
->
ctx_
->
template
As
<
ARMContext
>();
auto
x_dims
=
param
.
X
->
dims
();
auto
x_data
=
param
.
X
->
data
<
float
>
();
auto
output_data
=
param
.
Out
->
mutable_data
<
float
>
();
lite
::
arm
::
math
::
act_rsqrt
<
float
>
(
x_data
,
output_data
,
x_dims
.
production
(),
ctx
.
threads
());
}
}
// namespace arm
}
// namespace kernels
}
// namespace lite
...
...
@@ -245,3 +255,8 @@ REGISTER_LITE_KERNEL(hard_sigmoid,
.
BindInput
(
"X"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kARM
))})
.
BindOutput
(
"Out"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kARM
))})
.
Finalize
();
REGISTER_LITE_KERNEL
(
rsqrt
,
kARM
,
kFloat
,
kNCHW
,
paddle
::
lite
::
kernels
::
arm
::
RsqrtCompute
,
def
)
.
BindInput
(
"X"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kARM
))})
.
BindOutput
(
"Out"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kARM
))})
.
Finalize
();
lite/kernels/arm/activation_compute.h
浏览文件 @
dfce4621
...
...
@@ -130,6 +130,15 @@ class HardSigmoidCompute : public KernelLite<TARGET(kARM), PRECISION(kFloat)> {
virtual
~
HardSigmoidCompute
()
=
default
;
};
class
RsqrtCompute
:
public
KernelLite
<
TARGET
(
kARM
),
PRECISION
(
kFloat
)
>
{
public:
using
param_t
=
operators
::
ActivationParam
;
void
Run
()
override
;
virtual
~
RsqrtCompute
()
=
default
;
};
}
// namespace arm
}
// namespace kernels
}
// namespace lite
...
...
lite/operators/activation_ops.cc
浏览文件 @
dfce4621
...
...
@@ -117,6 +117,7 @@ REGISTER_LITE_OP(log, paddle::lite::operators::ActivationOp);
REGISTER_LITE_OP
(
exp
,
paddle
::
lite
::
operators
::
ActivationOp
);
REGISTER_LITE_OP
(
floor
,
paddle
::
lite
::
operators
::
ActivationOp
);
REGISTER_LITE_OP
(
hard_sigmoid
,
paddle
::
lite
::
operators
::
ActivationOp
);
REGISTER_LITE_OP
(
rsqrt
,
paddle
::
lite
::
operators
::
ActivationOp
);
#ifdef LITE_WITH_TRAIN
REGISTER_LITE_OP
(
square_grad
,
paddle
::
lite
::
operators
::
ActivationGradOp
);
...
...
lite/tests/kernels/activation_compute_test.cc
浏览文件 @
dfce4621
...
...
@@ -33,7 +33,8 @@ enum activation_type_test {
RELU6
,
LOG
,
EXP
,
FLOOR
FLOOR
,
RSQRT
};
class
ActivationComputeTester
:
public
arena
::
TestCase
{
...
...
@@ -177,6 +178,12 @@ class ActivationComputeTester : public arena::TestCase {
}
break
;
}
case
RSQRT
:
{
for
(
int
i
=
0
;
i
<
dims_
.
production
();
i
++
)
{
output_data
[
i
]
=
1.0
/
std
::
sqrt
(
x_data
[
i
]);
}
break
;
}
default:
LOG
(
INFO
)
<<
"the type of activation is unknow."
;
}
...
...
@@ -205,7 +212,7 @@ class ActivationComputeTester : public arena::TestCase {
std
::
vector
<
float
>
data
(
dims_
.
production
());
for
(
int
i
=
0
;
i
<
dims_
.
production
();
i
++
)
{
float
sign
=
i
%
3
==
0
?
-
1.0
f
:
1.0
f
;
sign
=
type_
==
"log"
?
1
:
sign
;
sign
=
(
type_
==
"log"
||
type_
==
"rsqrt"
)
?
1
:
sign
;
data
[
i
]
=
sign
*
static_cast
<
float
>
(
i
%
128
)
*
0.013
f
+
0.001
;
}
SetCommonTensor
(
input_
,
dims_
,
data
.
data
());
...
...
@@ -553,5 +560,31 @@ TEST(Activation_floor, precision) {
#endif
}
TEST
(
Activation_rsqrt
,
precision
)
{
LOG
(
INFO
)
<<
"test rsqrt op"
;
#ifdef LITE_WITH_ARM
Place
place
(
TARGET
(
kARM
));
for
(
auto
n
:
{
2
})
{
for
(
auto
c
:
{
2
})
{
for
(
auto
h
:
{
2
})
{
for
(
auto
w
:
{
2
})
{
std
::
unique_ptr
<
arena
::
TestCase
>
tester
(
new
ActivationComputeTester
(
place
,
"def"
,
0.01
,
6.
,
"all"
,
0.
,
DDim
(
std
::
vector
<
int64_t
>
({
n
,
c
,
h
,
w
})),
"rsqrt"
,
RSQRT
));
arena
::
Arena
arena
(
std
::
move
(
tester
),
place
,
2e-5
);
arena
.
TestPrecision
();
}
}
}
}
#endif
}
}
// namespace lite
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录