Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
feea5977
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看板
未验证
提交
feea5977
编写于
5月 18, 2020
作者:
W
Wilber
提交者:
GitHub
5月 18, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[host] [Kernel] Add unsqueeze kernel for host. (#3629)
movs unsqueeze frm arm to host.
上级
546d4da8
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
107 addition
and
19 deletion
+107
-19
lite/kernels/arm/CMakeLists.txt
lite/kernels/arm/CMakeLists.txt
+0
-1
lite/kernels/host/CMakeLists.txt
lite/kernels/host/CMakeLists.txt
+1
-0
lite/kernels/host/unsqueeze_compute.cc
lite/kernels/host/unsqueeze_compute.cc
+92
-0
lite/kernels/host/unsqueeze_compute.h
lite/kernels/host/unsqueeze_compute.h
+5
-3
lite/tests/kernels/squeeze_compute_test.cc
lite/tests/kernels/squeeze_compute_test.cc
+4
-4
lite/tests/kernels/unsqueeze_compute_test.cc
lite/tests/kernels/unsqueeze_compute_test.cc
+5
-11
未找到文件。
lite/kernels/arm/CMakeLists.txt
浏览文件 @
feea5977
...
...
@@ -40,7 +40,6 @@ add_kernel(box_coder_compute_arm ARM basic SRCS box_coder_compute.cc DEPS ${lite
add_kernel
(
slice_compute_arm ARM basic SRCS slice_compute.cc DEPS
${
lite_kernel_deps
}
math_arm
)
add_kernel
(
cast_compute_arm ARM basic SRCS cast_compute.cc DEPS
${
lite_kernel_deps
}
math_arm
)
add_kernel
(
squeeze_compute_arm ARM basic SRCS squeeze_compute.cc DEPS
${
lite_kernel_deps
}
math_arm
)
add_kernel
(
unsqueeze_compute_arm ARM basic SRCS unsqueeze_compute.cc DEPS
${
lite_kernel_deps
}
math_arm
)
add_kernel
(
reduce_mean_compute_arm ARM basic SRCS reduce_mean_compute.cc DEPS
${
lite_kernel_deps
}
math_arm
)
add_kernel
(
stack_compute_arm ARM basic SRCS stack_compute.cc DEPS
${
lite_kernel_deps
}
math_arm
)
add_kernel
(
affine_channel_compute_arm ARM basic SRCS affine_channel_compute.cc DEPS
${
lite_kernel_deps
}
math_arm
)
...
...
lite/kernels/host/CMakeLists.txt
浏览文件 @
feea5977
...
...
@@ -3,6 +3,7 @@ message(STATUS "compile with lite host kernels")
add_kernel
(
feed_compute_host Host basic SRCS feed_compute.cc DEPS
${
lite_kernel_deps
}
)
add_kernel
(
fetch_compute_host Host basic SRCS fetch_compute.cc DEPS
${
lite_kernel_deps
}
)
add_kernel
(
reshape_compute_host Host basic SRCS reshape_compute.cc DEPS
${
lite_kernel_deps
}
)
add_kernel
(
unsqueeze_compute_host Host basic SRCS unsqueeze_compute.cc DEPS
${
lite_kernel_deps
}
)
add_kernel
(
multiclass_nms_compute_host Host basic SRCS multiclass_nms_compute.cc DEPS
${
lite_kernel_deps
}
)
add_kernel
(
expand_compute_host Host basic SRCS expand_compute.cc DEPS
${
lite_kernel_deps
}
)
add_kernel
(
shape_compute_host Host extra SRCS shape_compute.cc DEPS
${
lite_kernel_deps
}
)
...
...
lite/kernels/
arm
/unsqueeze_compute.cc
→
lite/kernels/
host
/unsqueeze_compute.cc
浏览文件 @
feea5977
// 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,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "lite/kernels/arm/unsqueeze_compute.h"
#include "lite/kernels/host/unsqueeze_compute.h"
#include <vector>
namespace
paddle
{
...
...
@@ -24,10 +25,9 @@ void UnsqueezeCompute::Run() {
auto
&
param
=
Param
<
operators
::
UnsqueezeParam
>
();
auto
x
=
param
.
X
;
auto
output
=
param
.
Out
;
auto
x_dims
=
x
->
dims
();
auto
*
x_data
=
x
->
data
<
float
>
();
auto
*
out_data
=
output
->
mutable_data
<
float
>
();
memcpy
(
out_data
,
x_data
,
x_dims
.
production
()
*
sizeof
(
float
));
auto
output_dims
=
output
->
dims
();
output
->
CopyDataFrom
(
*
x
);
output
->
Resize
(
output_dims
);
}
void
Unsqueeze2Compute
::
Run
()
{
...
...
@@ -35,12 +35,12 @@ void Unsqueeze2Compute::Run() {
auto
x
=
param
.
X
;
auto
output
=
param
.
Out
;
auto
xshape
=
param
.
XShape
;
auto
x_dims
=
x
->
dims
();
auto
*
x_data
=
x
->
data
<
float
>
();
auto
*
out_data
=
output
->
mutable_data
<
float
>
(
);
auto
*
xshape_data
=
xshape
->
mutable_data
<
float
>
(
);
memcpy
(
out_data
,
x_data
,
x_dims
.
production
()
*
sizeof
(
float
)
);
memcpy
(
xshape_data
,
x_data
,
x_dims
.
production
()
*
sizeof
(
float
)
);
auto
output_dims
=
output
->
dims
();
auto
xshape_dims
=
xshape
->
dims
();
output
->
CopyDataFrom
(
*
x
);
xshape
->
CopyDataFrom
(
*
x
);
output
->
Resize
(
output_dims
);
xshape
->
Resize
(
xshape_dims
);
}
}
// namespace host
...
...
@@ -49,30 +49,44 @@ void Unsqueeze2Compute::Run() {
}
// namespace paddle
REGISTER_LITE_KERNEL
(
unsqueeze
,
k
ARM
,
k
Float
,
k
NCHW
,
k
Host
,
k
Any
,
k
Any
,
paddle
::
lite
::
kernels
::
host
::
UnsqueezeCompute
,
def
)
.
BindInput
(
"X"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kARM
),
PRECISION
(
kAny
))})
.
BindInput
(
"X"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kHost
),
PRECISION
(
kAny
),
DATALAYOUT
(
kAny
),
-
1
)})
.
BindInput
(
"AxesTensor"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kARM
),
PRECISION
(
kInt32
))})
{
LiteType
::
GetTensorTy
(
TARGET
(
kHost
),
PRECISION
(
kInt32
),
DATALAYOUT
(
kAny
),
-
1
)})
.
BindInput
(
"AxesTensorList"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kARM
),
PRECISION
(
kInt32
))})
.
BindOutput
(
"Out"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kARM
),
PRECISION
(
kAny
))})
{
LiteType
::
GetTensorTy
(
TARGET
(
kHost
),
PRECISION
(
kInt32
),
DATALAYOUT
(
kAny
),
-
1
)})
.
BindOutput
(
"Out"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kHost
),
PRECISION
(
kAny
),
DATALAYOUT
(
kAny
),
-
1
)})
.
Finalize
();
REGISTER_LITE_KERNEL
(
unsqueeze2
,
k
ARM
,
k
Float
,
k
NCHW
,
k
Host
,
k
Any
,
k
Any
,
paddle
::
lite
::
kernels
::
host
::
Unsqueeze2Compute
,
def
)
.
BindInput
(
"X"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kARM
),
PRECISION
(
kAny
))})
.
BindInput
(
"X"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kHost
),
PRECISION
(
kAny
),
DATALAYOUT
(
kAny
),
-
1
)})
.
BindInput
(
"AxesTensor"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kARM
),
PRECISION
(
kInt32
))})
{
LiteType
::
GetTensorTy
(
TARGET
(
kHost
),
PRECISION
(
kInt32
),
DATALAYOUT
(
kAny
),
-
1
)})
.
BindInput
(
"AxesTensorList"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kARM
),
PRECISION
(
kInt32
))})
.
BindOutput
(
"Out"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kARM
),
PRECISION
(
kAny
))})
.
BindOutput
(
"XShape"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kARM
))})
{
LiteType
::
GetTensorTy
(
TARGET
(
kHost
),
PRECISION
(
kInt32
),
DATALAYOUT
(
kAny
),
-
1
)})
.
BindOutput
(
"Out"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kHost
),
PRECISION
(
kAny
),
DATALAYOUT
(
kAny
),
-
1
)})
.
BindOutput
(
"XShape"
,
{
LiteType
::
GetTensorTy
(
TARGET
(
kHost
),
PRECISION
(
kAny
),
DATALAYOUT
(
kAny
),
-
1
)})
.
Finalize
();
lite/kernels/
arm
/unsqueeze_compute.h
→
lite/kernels/
host
/unsqueeze_compute.h
浏览文件 @
feea5977
// 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.
...
...
@@ -22,14 +22,16 @@ namespace lite {
namespace
kernels
{
namespace
host
{
class
UnsqueezeCompute
:
public
KernelLite
<
TARGET
(
kARM
),
PRECISION
(
kFloat
)
>
{
class
UnsqueezeCompute
:
public
KernelLite
<
TARGET
(
kHost
),
PRECISION
(
kAny
),
DATALAYOUT
(
kAny
)
>
{
public:
void
Run
()
override
;
virtual
~
UnsqueezeCompute
()
=
default
;
};
class
Unsqueeze2Compute
:
public
KernelLite
<
TARGET
(
kARM
),
PRECISION
(
kFloat
)
>
{
class
Unsqueeze2Compute
:
public
KernelLite
<
TARGET
(
kHost
),
PRECISION
(
kAny
),
DATALAYOUT
(
kAny
)
>
{
public:
void
Run
()
override
;
...
...
lite/tests/kernels/squeeze_compute_test.cc
浏览文件 @
feea5977
...
...
@@ -47,7 +47,7 @@ class SqueezeComputeTester : public arena::TestCase {
bool
should_squeeze
[
9
]
=
{
false
};
if
(
num_squeeze_dims
==
0
)
{
for
(
in
t
idx
=
0
;
idx
<
in_dims
.
size
();
++
idx
)
{
for
(
size_
t
idx
=
0
;
idx
<
in_dims
.
size
();
++
idx
)
{
if
(
in_dims
[
idx
]
==
1
)
{
should_squeeze
[
idx
]
=
true
;
++
cnt_squeezed_dims
;
...
...
@@ -71,7 +71,7 @@ class SqueezeComputeTester : public arena::TestCase {
}
std
::
vector
<
int64_t
>
output_shape
(
in_dims
.
size
()
-
cnt_squeezed_dims
,
0
);
for
(
in
t
in_idx
=
0
,
out_idx
=
0
;
in_idx
<
in_dims
.
size
();
++
in_idx
)
{
for
(
size_
t
in_idx
=
0
,
out_idx
=
0
;
in_idx
<
in_dims
.
size
();
++
in_idx
)
{
if
(
!
should_squeeze
[
in_idx
])
{
output_shape
[
out_idx
++
]
=
in_dims
[
in_idx
];
}
...
...
@@ -135,7 +135,7 @@ class Squeeze2ComputeTester : public arena::TestCase {
bool
should_squeeze
[
9
]
=
{
false
};
if
(
num_squeeze_dims
==
0
)
{
for
(
in
t
idx
=
0
;
idx
<
in_dims
.
size
();
++
idx
)
{
for
(
size_
t
idx
=
0
;
idx
<
in_dims
.
size
();
++
idx
)
{
if
(
in_dims
[
idx
]
==
1
)
{
should_squeeze
[
idx
]
=
true
;
++
cnt_squeezed_dims
;
...
...
@@ -159,7 +159,7 @@ class Squeeze2ComputeTester : public arena::TestCase {
}
std
::
vector
<
int64_t
>
output_shape
(
in_dims
.
size
()
-
cnt_squeezed_dims
,
0
);
for
(
in
t
in_idx
=
0
,
out_idx
=
0
;
in_idx
<
in_dims
.
size
();
++
in_idx
)
{
for
(
size_
t
in_idx
=
0
,
out_idx
=
0
;
in_idx
<
in_dims
.
size
();
++
in_idx
)
{
if
(
!
should_squeeze
[
in_idx
])
{
output_shape
[
out_idx
++
]
=
in_dims
[
in_idx
];
}
...
...
lite/tests/kernels/unsqueeze_compute_test.cc
浏览文件 @
feea5977
...
...
@@ -84,8 +84,7 @@ class UnsqueezeComputeTester : public arena::TestCase {
output_shape
[
out_idx
]
=
in_dims
[
in_idx
++
];
}
}
for
(
size_t
i
=
0
;
i
<
output_shape
.
size
();
++
i
)
out
->
Resize
(
DDim
(
output_shape
));
out
->
Resize
(
DDim
(
output_shape
));
auto
*
input_data
=
input
->
data
<
float
>
();
auto
*
out_data
=
out
->
mutable_data
<
float
>
();
memcpy
(
out_data
,
input_data
,
sizeof
(
float
)
*
dims_
.
production
());
...
...
@@ -258,22 +257,19 @@ void test_unsqueeze2(Place place,
}
}
TEST
(
squeeze
,
precision
)
{
TEST
(
un
squeeze
,
precision
)
{
Place
place
;
float
abs_error
=
2e-5
;
#ifdef LITE_WITH_NPU
place
=
TARGET
(
kNPU
);
abs_error
=
1e-2
;
// Using fp16 in NPU
#elif defined(LITE_WITH_ARM)
place
=
TARGET
(
kARM
);
#else
return
;
place
=
TARGET
(
kHost
)
;
#endif
test_unsqueeze
(
place
,
abs_error
);
}
TEST
(
squeeze2
,
precision
)
{
TEST
(
un
squeeze2
,
precision
)
{
Place
place
;
float
abs_error
=
2e-5
;
std
::
vector
<
std
::
string
>
ignored_outs
=
{};
...
...
@@ -281,10 +277,8 @@ TEST(squeeze2, precision) {
place
=
TARGET
(
kNPU
);
abs_error
=
1e-2
;
// Using fp16 in NPU
ignored_outs
.
push_back
(
"XShape"
);
// not supported out in NPU
#elif defined(LITE_WITH_ARM)
place
=
TARGET
(
kARM
);
#else
return
;
place
=
TARGET
(
kHost
)
;
#endif
test_unsqueeze2
(
place
,
abs_error
,
ignored_outs
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录