Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
ae28c0f7
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看板
提交
ae28c0f7
编写于
12月 24, 2019
作者:
Z
zhupengyang
提交者:
GitHub
12月 24, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[XPU] elementwise_add, softmax unit test (#2653)
* [XPU] elementwise_add unit test * [XPU] softmax unit test test=develop
上级
186397fe
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
136 addition
and
1 deletion
+136
-1
lite/tests/kernels/CMakeLists.txt
lite/tests/kernels/CMakeLists.txt
+2
-1
lite/tests/kernels/elementwise_compute_test.cc
lite/tests/kernels/elementwise_compute_test.cc
+12
-0
lite/tests/kernels/softmax_compute_test.cc
lite/tests/kernels/softmax_compute_test.cc
+122
-0
未找到文件。
lite/tests/kernels/CMakeLists.txt
浏览文件 @
ae28c0f7
...
...
@@ -4,7 +4,7 @@ if((NOT LITE_WITH_OPENCL AND NOT LITE_WITH_FPGA) AND (LITE_WITH_X86 OR LITE_WITH
lite_cc_test
(
test_kernel_shuffle_channel_compute SRCS shuffle_channel_compute_test.cc DEPS arena_framework
${
x86_kernels
}
${
arm_kernels
}
${
lite_ops
}
${
host_kernels
}
)
lite_cc_test
(
test_kernel_yolo_box_compute SRCS yolo_box_compute_test.cc DEPS arena_framework
${
x86_kernels
}
${
arm_kernels
}
${
lite_ops
}
${
host_kernels
}
)
lite_cc_test
(
test_fc SRCS fc_compute_test.cc DEPS arena_framework
${
x86_kernels
}
${
arm_kernels
}
${
lite_ops
}
${
host_kernels
}
)
lite_cc_test
(
test_kernel_elementwise_compute SRCS elementwise_compute_test.cc DEPS arena_framework
${
x86_kernels
}
${
arm_kernels
}
${
lite_ops
}
${
host_kernels
}
)
lite_cc_test
(
test_kernel_elementwise_compute SRCS elementwise_compute_test.cc DEPS arena_framework
${
x
pu_kernels
}
${
x
86_kernels
}
${
arm_kernels
}
${
lite_ops
}
${
host_kernels
}
)
lite_cc_test
(
test_kernel_lrn_compute SRCS lrn_compute_test.cc DEPS arena_framework
${
x86_kernels
}
${
arm_kernels
}
${
lite_ops
}
${
host_kernels
}
)
lite_cc_test
(
test_kernel_decode_bboxes_compute SRCS decode_bboxes_compute_test.cc DEPS arena_framework
${
x86_kernels
}
${
arm_kernels
}
${
lite_ops
}
${
host_kernels
}
)
lite_cc_test
(
test_kernel_box_coder_compute SRCS box_coder_compute_test.cc DEPS arena_framework
${
x86_kernels
}
${
arm_kernels
}
${
lite_ops
}
${
host_kernels
}
)
...
...
@@ -28,6 +28,7 @@ if((NOT LITE_WITH_OPENCL AND NOT LITE_WITH_FPGA) AND (LITE_WITH_X86 OR LITE_WITH
lite_cc_test
(
test_kernel_transpose_compute SRCS transpose_compute_test.cc DEPS arena_framework
${
xpu_kernels
}
${
x86_kernels
}
${
arm_kernels
}
${
lite_ops
}
${
host_kernels
}
)
lite_cc_test
(
test_kernel_reshape_compute SRCS reshape_compute_test.cc DEPS arena_framework
${
xpu_kernels
}
${
x86_kernels
}
${
arm_kernels
}
${
lite_ops
}
${
host_kernels
}
)
lite_cc_test
(
test_kernel_layer_norm_compute SRCS layer_norm_compute_test.cc DEPS arena_framework
${
xpu_kernels
}
${
x86_kernels
}
${
arm_kernels
}
${
lite_ops
}
${
host_kernels
}
)
lite_cc_test
(
test_kernel_softmax_compute SRCS softmax_compute_test.cc DEPS arena_framework
${
xpu_kernels
}
${
x86_kernels
}
${
arm_kernels
}
${
lite_ops
}
${
host_kernels
}
)
if
(
LITE_BUILD_EXTRA
)
lite_cc_test
(
test_gru_unit SRCS gru_unit_test.cc DEPS arena_framework
${
x86_kernels
}
${
arm_kernels
}
${
lite_ops
}
${
host_kernels
}
)
...
...
lite/tests/kernels/elementwise_compute_test.cc
浏览文件 @
ae28c0f7
...
...
@@ -653,5 +653,17 @@ TEST(FusionElementwise, precision) {
#endif
}
#ifdef LITE_WITH_XPU
TEST
(
Elementwise_XPU
,
precision
)
{
Place
place
(
TARGET
(
kXPU
));
for
(
int
axis
:
{
-
1
,
1
})
{
std
::
unique_ptr
<
arena
::
TestCase
>
tester
(
new
ElementwiseComputeTester
(
place
,
"def"
,
axis
));
arena
::
Arena
arena
(
std
::
move
(
tester
),
place
,
2e-5
);
arena
.
TestPrecision
();
}
}
#endif
}
// namespace lite
}
// namespace paddle
lite/tests/kernels/softmax_compute_test.cc
0 → 100644
浏览文件 @
ae28c0f7
// Copyright (c) 2019 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.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <gtest/gtest.h>
#include "lite/api/paddle_use_kernels.h"
#include "lite/api/paddle_use_ops.h"
#include "lite/core/arena/framework.h"
#include "lite/tests/utils/fill_data.h"
namespace
paddle
{
namespace
lite
{
class
SoftmaxComputeTest
:
public
arena
::
TestCase
{
protected:
// common attributes for this op.
std
::
string
op_type_
=
"softmax"
;
std
::
string
input_
=
"x"
;
std
::
string
output_
=
"out"
;
DDim
dims_
{{
1
,
2
,
3
,
4
}};
int
axis_
=
1
;
public:
SoftmaxComputeTest
(
const
Place
&
place
,
const
std
::
string
&
alias
,
DDim
dims
,
int
axis
)
:
TestCase
(
place
,
alias
),
dims_
(
dims
),
axis_
(
axis
)
{}
void
RunBaseline
(
Scope
*
scope
)
override
{
auto
x
=
scope
->
FindTensor
(
input_
);
auto
out
=
scope
->
NewTensor
(
output_
);
CHECK
(
out
);
out
->
Resize
(
dims_
);
auto
x_data
=
x
->
data
<
float
>
();
auto
out_data
=
out
->
mutable_data
<
float
>
();
auto
x_rank
=
dims_
.
size
();
if
(
axis_
<
0
)
{
axis_
+=
x_rank
;
}
int
axis_size
=
dims_
[
axis_
];
int
outer_num
=
dims_
.
Slice
(
0
,
axis_
).
production
();
int
inner_num
=
dims_
.
Slice
(
axis_
+
1
,
x_rank
).
production
();
int
compute_size
=
outer_num
*
inner_num
;
for
(
int
i
=
0
;
i
<
compute_size
;
i
++
)
{
int
idx_inner
=
i
%
inner_num
;
int
idx_outer
=
(
i
/
inner_num
)
*
axis_size
;
int
start
=
idx_outer
*
inner_num
+
idx_inner
;
int
offset
;
offset
=
start
;
float
max_data
=
std
::
numeric_limits
<
float
>::
lowest
();
for
(
int
j
=
0
;
j
<
axis_size
;
j
++
)
{
max_data
=
x_data
[
offset
]
>
max_data
?
x_data
[
offset
]
:
max_data
;
offset
+=
inner_num
;
}
offset
=
start
;
float
sum_data
=
0.
f
;
for
(
int
j
=
0
;
j
<
axis_size
;
j
++
)
{
out_data
[
offset
]
=
exp
(
x_data
[
offset
]
-
max_data
);
sum_data
+=
out_data
[
offset
];
offset
+=
inner_num
;
}
offset
=
start
;
for
(
int
j
=
0
;
j
<
axis_size
;
j
++
)
{
out_data
[
offset
]
/=
sum_data
;
offset
+=
inner_num
;
}
}
}
void
PrepareOpDesc
(
cpp
::
OpDesc
*
op_desc
)
{
op_desc
->
SetType
(
op_type_
);
op_desc
->
SetInput
(
"X"
,
{
input_
});
op_desc
->
SetOutput
(
"Out"
,
{
output_
});
op_desc
->
SetAttr
(
"axis"
,
axis_
);
}
void
PrepareData
()
override
{
std
::
vector
<
float
>
din
(
dims_
.
production
());
fill_data_rand
(
din
.
data
(),
-
1.
f
,
1.
f
,
dims_
.
production
());
SetCommonTensor
(
input_
,
dims_
,
din
.
data
());
}
};
TEST
(
Softmax
,
precision
)
{
LOG
(
INFO
)
<<
"test softmax op"
;
float
abs_error
=
2e-5
;
Place
place
;
#if defined(LITE_WITH_XPU)
place
=
TARGET
(
kXPU
);
#else
return
;
#endif
std
::
vector
<
std
::
vector
<
int64_t
>>
dims
{{
1
,
2
,
3
,
4
},
{
2
,
3
,
4
},
{
3
,
4
}};
for
(
auto
dim_in
:
dims
)
{
for
(
auto
axis
:
{
-
1
,
0
,
1
,
2
,
3
})
{
if
(
axis
>=
dim_in
.
size
())
continue
;
std
::
unique_ptr
<
arena
::
TestCase
>
tester
(
new
SoftmaxComputeTest
(
place
,
"def"
,
DDim
(
dim_in
),
axis
));
arena
::
Arena
arena
(
std
::
move
(
tester
),
place
,
abs_error
);
arena
.
TestPrecision
();
}
}
}
}
// namespace lite
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录