Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
be41d276
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,发现更多精彩内容 >>
未验证
提交
be41d276
编写于
3月 30, 2020
作者:
Z
zhupengyang
提交者:
GitHub
3月 30, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[NPU] support relu6, conv with relu6, pool with ceil_mode (#3296)
上级
c23f5cb1
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
58 addition
and
20 deletion
+58
-20
lite/kernels/npu/bridges/conv_op.cc
lite/kernels/npu/bridges/conv_op.cc
+2
-0
lite/kernels/npu/bridges/paddle_use_bridges.h
lite/kernels/npu/bridges/paddle_use_bridges.h
+1
-0
lite/kernels/npu/bridges/pool_op.cc
lite/kernels/npu/bridges/pool_op.cc
+8
-8
lite/tests/kernels/activation_compute_test.cc
lite/tests/kernels/activation_compute_test.cc
+14
-9
lite/tests/kernels/pool_compute_test.cc
lite/tests/kernels/pool_compute_test.cc
+33
-3
未找到文件。
lite/kernels/npu/bridges/conv_op.cc
浏览文件 @
be41d276
...
...
@@ -220,6 +220,8 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) {
act_op
->
set_attr_mode
(
CvtActMode
(
act_type
));
if
(
act_type
==
"leaky_relu"
)
{
act_op
->
set_attr_negative_slope
(
leaky_relu_alpha
);
}
else
if
(
act_type
==
"relu6"
)
{
act_op
->
set_attr_coef
(
6.
f
);
}
}
...
...
lite/kernels/npu/bridges/paddle_use_bridges.h
浏览文件 @
be41d276
...
...
@@ -18,6 +18,7 @@ USE_SUBGRAPH_BRIDGE(sigmoid, kNPU);
USE_SUBGRAPH_BRIDGE
(
relu
,
kNPU
);
USE_SUBGRAPH_BRIDGE
(
tanh
,
kNPU
);
USE_SUBGRAPH_BRIDGE
(
relu_clipped
,
kNPU
);
USE_SUBGRAPH_BRIDGE
(
relu6
,
kNPU
);
USE_SUBGRAPH_BRIDGE
(
leaky_relu
,
kNPU
);
USE_SUBGRAPH_BRIDGE
(
softsign
,
kNPU
);
USE_SUBGRAPH_BRIDGE
(
hard_sigmoid
,
kNPU
);
...
...
lite/kernels/npu/bridges/pool_op.cc
浏览文件 @
be41d276
...
...
@@ -99,10 +99,8 @@ int PoolConverter(void* ctx, OpLite* op, KernelBase* kernel) {
ksize
);
// ceil mode
int
ceil_mode
=
0
;
if
(
op_info
->
HasAttr
(
"ceil_mode"
))
{
ceil_mode
=
op_info
->
GetAttr
<
bool
>
(
"ceil_mode"
)
?
1
:
0
;
}
bool
ceil_mode
=
op_info
->
HasAttr
(
"ceil_mode"
)
&&
op_info
->
GetAttr
<
bool
>
(
"ceil_mode"
);
// Pooling node
auto
pool_node
=
graph
->
Add
<
ge
::
op
::
Pooling
>
(
out_name
);
...
...
@@ -112,12 +110,14 @@ int PoolConverter(void* ctx, OpLite* op, KernelBase* kernel) {
pool_op
->
set_attr_pad_mode
(
pad_mode
);
pool_op
->
set_attr_global_pooling
(
global_pooling
);
pool_op
->
set_attr_window
(
ge
::
AttrValue
::
LIST_INT
(
ksize
.
begin
(),
ksize
.
end
()));
pool_op
->
set_attr_pad
(
ge
::
AttrValue
::
LIST_INT
{
paddings
[
0
],
paddings
[
1
],
paddings
[
2
],
paddings
[
3
]}
);
pool_op
->
set_attr_pad
(
ge
::
AttrValue
::
LIST_INT
(
paddings
.
begin
(),
paddings
.
end
())
);
pool_op
->
set_attr_stride
(
ge
::
AttrValue
::
LIST_INT
(
strides
.
begin
(),
strides
.
end
()));
pool_op
->
set_attr_ceil_mode
(
ceil_mode
);
// pool_op->set_attr_data_mode(data_mode);
if
(
ceil_mode
)
{
pool_op
->
set_attr_ceil_mode
(
1
);
pool_op
->
set_attr_data_mode
(
0
);
}
return
REBUILD_WHEN_SHAPE_CHANGED
;
}
...
...
lite/tests/kernels/activation_compute_test.cc
浏览文件 @
be41d276
...
...
@@ -425,19 +425,24 @@ TEST(Activation_swish, precision) {
TEST
(
Activation_relu6
,
precision
)
{
LOG
(
INFO
)
<<
"test relu6 op..."
;
#ifdef LITE_WITH_ARM
Place
place
(
TARGET
(
kARM
));
Place
place
;
float
abs_error
=
2e-5
;
#if defined(LITE_WITH_NPU)
place
=
TARGET
(
kNPU
);
abs_error
=
1e-2
;
// Using fp16 in NPU
#elif defined(LITE_WITH_ARM)
place
=
TARGET
(
kARM
);
#else
return
;
#endif
for
(
auto
dims
:
std
::
vector
<
std
::
vector
<
int64_t
>>
{
{
1
,
3
,
2
,
4
},
{
2
,
3
,
4
},
{
5
,
4
},
{
8
}})
{
for
(
auto
slope
:
{
0.01
,
0.1
})
{
std
::
unique_ptr
<
arena
::
TestCase
>
tester
(
new
ActivationComputeTester
(
place
,
"def"
,
0.01
,
6.
,
"all"
,
0.
,
DDim
(
dims
),
"relu6"
,
RELU6
));
arena
::
Arena
arena
(
std
::
move
(
tester
),
place
,
2e-5
);
arena
.
TestPrecision
();
}
std
::
unique_ptr
<
arena
::
TestCase
>
tester
(
new
ActivationComputeTester
(
place
,
"def"
,
0.01
,
6.
,
"all"
,
0.
,
DDim
(
dims
),
"relu6"
,
RELU6
));
arena
::
Arena
arena
(
std
::
move
(
tester
),
place
,
abs_error
);
arena
.
TestPrecision
();
}
#endif
}
TEST
(
Activation_log
,
precision
)
{
...
...
lite/tests/kernels/pool_compute_test.cc
浏览文件 @
be41d276
...
...
@@ -276,9 +276,24 @@ void TestPoolHelper(Place place,
std
::
string
pooling_type
,
std
::
vector
<
int
>
strides
,
std
::
vector
<
int
>
paddings
,
std
::
vector
<
int
>
ksize
)
{
std
::
unique_ptr
<
arena
::
TestCase
>
tester
(
new
PoolComputeTest
(
place
,
"def"
,
DDim
(
dims
),
pooling_type
,
false
,
strides
,
paddings
,
ksize
));
std
::
vector
<
int
>
ksize
,
bool
exclusive
=
true
,
bool
ceil_mode
=
false
,
bool
adaptive
=
false
,
std
::
string
padding_algorithm
=
""
)
{
std
::
unique_ptr
<
arena
::
TestCase
>
tester
(
new
PoolComputeTest
(
place
,
"def"
,
DDim
(
dims
),
pooling_type
,
false
,
strides
,
paddings
,
ksize
,
exclusive
,
ceil_mode
,
adaptive
,
padding_algorithm
));
arena
::
Arena
arena
(
std
::
move
(
tester
),
place
,
abs_error
);
arena
.
TestPrecision
();
}
...
...
@@ -345,6 +360,20 @@ void TestPoolKsize(Place place, float abs_error = 2e-5) {
}
}
void
TestPoolCeilMode
(
Place
place
,
float
abs_error
=
2e-5
)
{
for
(
auto
pooling_type
:
{
"max"
,
"avg"
})
{
TestPoolHelper
(
place
,
abs_error
,
{
2
,
3
,
6
,
6
},
pooling_type
,
{
2
,
2
},
{
0
,
0
,
0
,
0
},
{
3
,
3
},
true
,
true
);
}
}
TEST
(
Pool
,
precision
)
{
LOG
(
INFO
)
<<
"test pool op"
;
float
abs_error
=
2e-5
;
...
...
@@ -363,6 +392,7 @@ TEST(Pool, precision) {
TestPoolStrides
(
place
,
abs_error
);
TestPoolPaddings
(
place
,
abs_error
);
TestPoolKsize
(
place
,
abs_error
);
TestPoolCeilMode
(
place
,
abs_error
);
}
}
// namespace lite
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录