Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
737fedeb
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
337
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看板
未验证
提交
737fedeb
编写于
8月 04, 2020
作者:
Q
Qi Li
提交者:
GitHub
8月 04, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ASCEND] fix conv op, test=develop (#4041)
上级
71d9dbd1
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
19 addition
and
17 deletion
+19
-17
lite/kernels/huawei_ascend_npu/bridges/conv_op.cc
lite/kernels/huawei_ascend_npu/bridges/conv_op.cc
+10
-6
lite/tests/kernels/activation_compute_test.cc
lite/tests/kernels/activation_compute_test.cc
+5
-5
lite/tests/kernels/concat_compute_test.cc
lite/tests/kernels/concat_compute_test.cc
+1
-0
lite/tests/kernels/conv_compute_test.cc
lite/tests/kernels/conv_compute_test.cc
+2
-5
lite/tests/kernels/interp_compute_test.cc
lite/tests/kernels/interp_compute_test.cc
+1
-1
未找到文件。
lite/kernels/huawei_ascend_npu/bridges/conv_op.cc
浏览文件 @
737fedeb
...
@@ -55,9 +55,6 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) {
...
@@ -55,9 +55,6 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) {
auto
strides
=
op_info
->
GetAttr
<
std
::
vector
<
int
>>
(
"strides"
);
auto
strides
=
op_info
->
GetAttr
<
std
::
vector
<
int
>>
(
"strides"
);
auto
paddings
=
op_info
->
GetAttr
<
std
::
vector
<
int
>>
(
"paddings"
);
auto
paddings
=
op_info
->
GetAttr
<
std
::
vector
<
int
>>
(
"paddings"
);
auto
groups
=
op_info
->
GetAttr
<
int
>
(
"groups"
);
auto
groups
=
op_info
->
GetAttr
<
int
>
(
"groups"
);
// Conv2D: groups must set to 1; DepthwiseConv2D: groups not supported.
CHECK_LE
(
groups
,
1
)
<<
"[HUAWEI_ASCEND_NPU] groups > 1 NOT supported, groups: "
<<
groups
;
auto
dilations
=
op_info
->
GetAttr
<
std
::
vector
<
int
>>
(
"dilations"
);
auto
dilations
=
op_info
->
GetAttr
<
std
::
vector
<
int
>>
(
"dilations"
);
bool
with_act
=
bool
with_act
=
op_info
->
HasAttr
(
"with_act"
)
&&
op_info
->
GetAttr
<
bool
>
(
"with_act"
);
op_info
->
HasAttr
(
"with_act"
)
&&
op_info
->
GetAttr
<
bool
>
(
"with_act"
);
...
@@ -114,11 +111,18 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) {
...
@@ -114,11 +111,18 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) {
"filter width after dilation"
;
"filter width after dilation"
;
}
}
// Check Restrictions: outChannel divide groups should equal to 0
CHECK_EQ
(
oc
%
groups
,
0
)
<<
"[HUAWEI_ASCEND_NPU] Huawei Ascend NPU DDK "
"restriction: out channel divice groups should "
"equal to 0"
;
// Check depthwise mode, and decide whether use DepthwiseConv2D Op
// Check depthwise mode, and decide whether use DepthwiseConv2D Op
bool
use_depthwise_conv
=
false
;
bool
use_depthwise_conv
=
false
;
bool
is_depthwise_mode
=
(
ic
==
groups
&&
oc
==
groups
&&
groups
!=
1
);
bool
is_depthwise_mode
=
(
ic
==
groups
&&
oc
==
groups
);
if
(
is_depthwise_mode
&&
dilations
[
0
]
==
1
&&
dilations
[
1
]
==
1
)
{
if
(
is_depthwise_mode
&&
dilations
[
0
]
==
1
&&
dilations
[
1
]
==
1
)
{
use_depthwise_conv
=
true
;
use_depthwise_conv
=
true
;
// Change filter shape {oc, ic/groups = 1, kh, kw} => { K=1, oc, kh, hw}
filter
->
Resize
({
1L
,
oc
,
filter_dims
[
2
],
filter_dims
[
3
]});
LOG
(
WARNING
)
<<
"[HUAWEI_ASCEND_NPU] DepthwiseConv2D op is used."
;
LOG
(
WARNING
)
<<
"[HUAWEI_ASCEND_NPU] DepthwiseConv2D op is used."
;
}
}
...
@@ -197,11 +201,11 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) {
...
@@ -197,11 +201,11 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) {
conv_op
->
set_input_x
(
*
input_node
->
data
());
conv_op
->
set_input_x
(
*
input_node
->
data
());
conv_op
->
set_input_filter
(
*
filter_node
->
data
());
conv_op
->
set_input_filter
(
*
filter_node
->
data
());
conv_op
->
set_attr_strides
(
conv_op
->
set_attr_strides
(
ge
::
Operator
::
OpListInt
({
bs
,
ic
,
strides
[
0
],
strides
[
1
]}));
ge
::
Operator
::
OpListInt
({
1
,
1
,
strides
[
0
],
strides
[
1
]}));
conv_op
->
set_attr_pads
(
ge
::
Operator
::
OpListInt
(
conv_op
->
set_attr_pads
(
ge
::
Operator
::
OpListInt
(
{
paddings
[
0
],
paddings
[
1
],
paddings
[
2
],
paddings
[
3
]}));
{
paddings
[
0
],
paddings
[
1
],
paddings
[
2
],
paddings
[
3
]}));
conv_op
->
set_attr_dilations
(
conv_op
->
set_attr_dilations
(
ge
::
Operator
::
OpListInt
({
bs
,
ic
,
dilations
[
0
],
dilations
[
1
]}));
ge
::
Operator
::
OpListInt
({
1
,
1
,
dilations
[
0
],
dilations
[
1
]}));
conv_op
->
set_attr_groups
(
groups
);
conv_op
->
set_attr_groups
(
groups
);
conv_op
->
set_attr_data_format
(
"NCHW"
);
conv_op
->
set_attr_data_format
(
"NCHW"
);
if
(
bias_node
!=
nullptr
&&
is_channel_bias
)
{
if
(
bias_node
!=
nullptr
&&
is_channel_bias
)
{
...
...
lite/tests/kernels/activation_compute_test.cc
浏览文件 @
737fedeb
...
@@ -321,7 +321,7 @@ TEST(Activation_relu, precision) {
...
@@ -321,7 +321,7 @@ TEST(Activation_relu, precision) {
place
=
TARGET
(
kXPU
);
place
=
TARGET
(
kXPU
);
#elif defined(LITE_WITH_HUAWEI_ASCEND_NPU)
#elif defined(LITE_WITH_HUAWEI_ASCEND_NPU)
place
=
TARGET
(
kHuaweiAscendNPU
);
place
=
TARGET
(
kHuaweiAscendNPU
);
abs_error
=
1e-2
;
//
Using fp16 in NPU
abs_error
=
1e-2
;
//
precision_mode default is force_fp16
#else
#else
return
;
return
;
#endif
#endif
...
@@ -346,7 +346,7 @@ TEST(Activation_leaky_relu, precision) {
...
@@ -346,7 +346,7 @@ TEST(Activation_leaky_relu, precision) {
place
=
TARGET
(
kARM
);
place
=
TARGET
(
kARM
);
#elif defined(LITE_WITH_HUAWEI_ASCEND_NPU)
#elif defined(LITE_WITH_HUAWEI_ASCEND_NPU)
place
=
TARGET
(
kHuaweiAscendNPU
);
place
=
TARGET
(
kHuaweiAscendNPU
);
abs_error
=
1e-2
;
//
Using fp16 in NPU
abs_error
=
1e-2
;
//
precision_mode default is force_fp16
#else
#else
return
;
return
;
#endif
#endif
...
@@ -431,7 +431,7 @@ TEST(Activation_sigmoid, precision) {
...
@@ -431,7 +431,7 @@ TEST(Activation_sigmoid, precision) {
place
=
TARGET
(
kARM
);
place
=
TARGET
(
kARM
);
#elif defined(LITE_WITH_HUAWEI_ASCEND_NPU)
#elif defined(LITE_WITH_HUAWEI_ASCEND_NPU)
place
=
TARGET
(
kHuaweiAscendNPU
);
place
=
TARGET
(
kHuaweiAscendNPU
);
abs_error
=
1e-2
;
//
Using fp16 in NPU
abs_error
=
1e-2
;
//
precision_mode default is force_fp16
#else
#else
return
;
return
;
#endif
#endif
...
@@ -467,7 +467,7 @@ TEST(Activation_tanh, precision) {
...
@@ -467,7 +467,7 @@ TEST(Activation_tanh, precision) {
place
=
TARGET
(
kXPU
);
place
=
TARGET
(
kXPU
);
#elif defined(LITE_WITH_HUAWEI_ASCEND_NPU)
#elif defined(LITE_WITH_HUAWEI_ASCEND_NPU)
place
=
TARGET
(
kHuaweiAscendNPU
);
place
=
TARGET
(
kHuaweiAscendNPU
);
abs_error
=
1e-2
;
//
Using fp16 in NPU
abs_error
=
1e-2
;
//
precision_mode default is force_fp16
#else
#else
return
;
return
;
#endif
#endif
...
@@ -509,7 +509,7 @@ TEST(Activation_relu6, precision) {
...
@@ -509,7 +509,7 @@ TEST(Activation_relu6, precision) {
place
=
TARGET
(
kARM
);
place
=
TARGET
(
kARM
);
#elif defined(LITE_WITH_HUAWEI_ASCEND_NPU)
#elif defined(LITE_WITH_HUAWEI_ASCEND_NPU)
place
=
TARGET
(
kHuaweiAscendNPU
);
place
=
TARGET
(
kHuaweiAscendNPU
);
abs_error
=
1e-2
;
//
Using fp16 in NPU
abs_error
=
1e-2
;
//
precision_mode default is force_fp16
#else
#else
return
;
return
;
#endif
#endif
...
...
lite/tests/kernels/concat_compute_test.cc
浏览文件 @
737fedeb
...
@@ -149,6 +149,7 @@ TEST(Concat, precision) {
...
@@ -149,6 +149,7 @@ TEST(Concat, precision) {
abs_error
=
1e-2
;
// use fp16 in npu
abs_error
=
1e-2
;
// use fp16 in npu
#elif defined(LITE_WITH_HUAWEI_ASCEND_NPU)
#elif defined(LITE_WITH_HUAWEI_ASCEND_NPU)
place
=
TARGET
(
kHuaweiAscendNPU
);
place
=
TARGET
(
kHuaweiAscendNPU
);
abs_error
=
1e-2
;
// precision_mode default is force_fp16
#elif defined(LITE_WITH_ARM)
#elif defined(LITE_WITH_ARM)
place
=
TARGET
(
kARM
);
place
=
TARGET
(
kARM
);
#elif defined(LITE_WITH_X86)
#elif defined(LITE_WITH_X86)
...
...
lite/tests/kernels/conv_compute_test.cc
浏览文件 @
737fedeb
...
@@ -256,7 +256,7 @@ void TestConvGroups(Place place, float abs_error = 2e-5) {
...
@@ -256,7 +256,7 @@ void TestConvGroups(Place place, float abs_error = 2e-5) {
std
::
vector
<
std
::
vector
<
int64_t
>>
{{
1
,
6
,
3
,
4
},
{
5
,
12
,
7
,
8
}})
{
std
::
vector
<
std
::
vector
<
int64_t
>>
{{
1
,
6
,
3
,
4
},
{
5
,
12
,
7
,
8
}})
{
for
(
auto
out_channels
:
{
2
,
3
,
6
})
{
for
(
auto
out_channels
:
{
2
,
3
,
6
})
{
for
(
auto
groups
:
{
2
,
3
,
6
})
{
for
(
auto
groups
:
{
2
,
3
,
6
})
{
#if
def LITE_WITH_NPU
#if
(defined LITE_WITH_NPU) || (defined LITE_WITH_HUAWEI_ASCEND_NPU)
if
(
out_channels
%
groups
!=
0
)
continue
;
if
(
out_channels
%
groups
!=
0
)
continue
;
#endif
#endif
std
::
unique_ptr
<
arena
::
TestCase
>
tester
(
new
ConvComputeTester
(
std
::
unique_ptr
<
arena
::
TestCase
>
tester
(
new
ConvComputeTester
(
...
@@ -420,16 +420,13 @@ TEST(Conv2d, precision) {
...
@@ -420,16 +420,13 @@ TEST(Conv2d, precision) {
abs_error
=
5e-2
;
// Using fp16 in NPU
abs_error
=
5e-2
;
// Using fp16 in NPU
#elif defined(LITE_WITH_HUAWEI_ASCEND_NPU)
#elif defined(LITE_WITH_HUAWEI_ASCEND_NPU)
place
=
TARGET
(
kHuaweiAscendNPU
);
place
=
TARGET
(
kHuaweiAscendNPU
);
abs_error
=
1e-2
;
//
Using fp16 in NPU
abs_error
=
1e-2
;
//
precision_mode default is force_fp16
#else
#else
return
;
return
;
#endif
#endif
TestConvKsize
(
place
,
abs_error
);
TestConvKsize
(
place
,
abs_error
);
// Huawei Ascend NPU DDK not support groups > 1
#if !defined(LITE_WITH_HUAWEI_ASCEND_NPU)
TestConvGroups
(
place
,
abs_error
);
TestConvGroups
(
place
,
abs_error
);
#endif
TestConvDilations
(
place
,
abs_error
);
TestConvDilations
(
place
,
abs_error
);
TestConvStrides
(
place
,
abs_error
);
TestConvStrides
(
place
,
abs_error
);
TestConvPaddings
(
place
,
abs_error
);
TestConvPaddings
(
place
,
abs_error
);
...
...
lite/tests/kernels/interp_compute_test.cc
浏览文件 @
737fedeb
...
@@ -451,7 +451,7 @@ TEST(Interp, precision) {
...
@@ -451,7 +451,7 @@ TEST(Interp, precision) {
abs_error
=
1e-2
;
// use fp16 in npu
abs_error
=
1e-2
;
// use fp16 in npu
#elif defined(LITE_WITH_HUAWEI_ASCEND_NPU)
#elif defined(LITE_WITH_HUAWEI_ASCEND_NPU)
place
=
TARGET
(
kHuaweiAscendNPU
);
place
=
TARGET
(
kHuaweiAscendNPU
);
abs_error
=
1e-2
;
//
use fp16 in npu
abs_error
=
1e-2
;
//
precision_mode default is force_fp16
#elif defined(LITE_WITH_ARM)
#elif defined(LITE_WITH_ARM)
place
=
TARGET
(
kARM
);
place
=
TARGET
(
kARM
);
#else
#else
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录