Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
5dd5ed67
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看板
未验证
提交
5dd5ed67
编写于
9月 22, 2020
作者:
Z
zhupengyang
提交者:
GitHub
9月 22, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[xpu] fix gather and cast unittests (#4396)
上级
db44e8b4
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
32 addition
and
15 deletion
+32
-15
lite/tests/kernels/cast_compute_test.cc
lite/tests/kernels/cast_compute_test.cc
+1
-2
lite/tests/kernels/gather_compute_test.cc
lite/tests/kernels/gather_compute_test.cc
+31
-13
未找到文件。
lite/tests/kernels/cast_compute_test.cc
浏览文件 @
5dd5ed67
...
...
@@ -130,7 +130,6 @@ void TestCast(Place place, float abs_error, int in_dtype, int out_dtype) {
}
TEST
(
Cast
,
precision
)
{
LOG
(
INFO
)
<<
"test cast op"
;
Place
place
;
float
abs_error
=
2e-5
;
#if defined(LITE_WITH_ARM)
...
...
@@ -150,7 +149,7 @@ TEST(Cast, precision) {
TestCast
(
place
,
abs_error
,
20
,
5
);
#endif
TestCast
(
place
,
abs_error
,
2
,
5
);
#if defined(LITE_WITH_
XPU) || defined(LITE_WITH_
HUAWEI_ASCEND_NPU)
#if defined(LITE_WITH_HUAWEI_ASCEND_NPU)
TestCast
(
place
,
abs_error
,
3
,
5
);
TestCast
(
place
,
abs_error
,
5
,
3
);
#endif
...
...
lite/tests/kernels/gather_compute_test.cc
浏览文件 @
5dd5ed67
...
...
@@ -21,6 +21,7 @@
namespace
paddle
{
namespace
lite
{
template
<
class
T
=
float
,
class
R
=
int64_t
>
class
GatherComputeTest
:
public
arena
::
TestCase
{
protected:
// common attributes for this op.
...
...
@@ -53,9 +54,9 @@ class GatherComputeTest : public arena::TestCase {
out_dims
[
0
]
=
batch_size
;
out
->
Resize
(
out_dims
);
auto
x_data
=
x
->
data
<
int64_t
>
();
auto
index_data
=
index
->
data
<
int64_t
>
();
auto
out_data
=
out
->
mutable_data
<
int64_t
>
();
auto
x_data
=
x
->
template
data
<
T
>();
auto
index_data
=
index
->
template
data
<
R
>();
auto
out_data
=
out
->
template
mutable_data
<
T
>();
auto
slice_num
=
x_dims
[
0
];
auto
slice_size
=
x_dims
.
Slice
(
1
,
x_dims
.
size
()).
production
();
...
...
@@ -66,7 +67,7 @@ class GatherComputeTest : public arena::TestCase {
CHECK_GE
(
index
,
0
)
<<
"gather ids[i] expected >= 0 but got "
<<
index
;
memcpy
(
out_data
+
i
*
slice_size
,
x_data
+
index
*
slice_size
,
slice_size
*
sizeof
(
int64_t
));
slice_size
*
sizeof
(
T
));
}
}
...
...
@@ -78,11 +79,12 @@ class GatherComputeTest : public arena::TestCase {
}
void
PrepareData
()
override
{
std
::
vector
<
int64_t
>
x
(
x_dims_
.
production
());
fill_data_rand
(
x
.
data
(),
int64_t
(
-
1
),
int64_t
(
1
),
x_dims_
.
production
());
std
::
vector
<
T
>
x
(
x_dims_
.
production
());
fill_data_rand
(
x
.
data
(),
static_cast
<
T
>
(
-
1
),
static_cast
<
T
>
(
1
),
x_dims_
.
production
());
std
::
vector
<
int64_t
>
index
(
index_dims_
.
production
());
fill_data_rand
<
int64_t
>
(
std
::
vector
<
R
>
index
(
index_dims_
.
production
());
fill_data_rand
<
R
>
(
index
.
data
(),
0
,
x_dims_
[
0
]
-
1
,
index_dims_
.
production
());
SetCommonTensor
(
x_
,
x_dims_
,
x
.
data
());
...
...
@@ -90,8 +92,20 @@ class GatherComputeTest : public arena::TestCase {
}
};
template
<
class
T
=
float
,
class
R
=
int64_t
>
void
TestGather
(
const
std
::
vector
<
int64_t
>&
x_dims
,
const
std
::
vector
<
int64_t
>&
index_dims
,
Place
place
,
float
abs_error
=
1e-5
,
const
std
::
string
&
alias
=
"def"
)
{
std
::
unique_ptr
<
arena
::
TestCase
>
tester
(
new
GatherComputeTest
<
T
,
R
>
(
place
,
alias
,
DDim
(
x_dims
),
DDim
(
index_dims
)));
arena
::
Arena
arena
(
std
::
move
(
tester
),
place
,
abs_error
);
arena
.
TestPrecision
();
}
TEST
(
Gather
,
precision
)
{
float
abs_error
=
2
e-5
;
float
abs_error
=
1
e-5
;
Place
place
;
#if defined(LITE_WITH_NPU)
place
=
TARGET
(
kNPU
);
...
...
@@ -110,10 +124,14 @@ TEST(Gather, precision) {
for
(
auto
x_dims
:
std
::
vector
<
std
::
vector
<
int64_t
>>
{{
5
,
2
,
3
,
4
},
{
8
,
3
,
5
},
{
12
,
3
}})
{
for
(
auto
index_dims
:
std
::
vector
<
std
::
vector
<
int64_t
>>
{{
3
},
{
7
},
{
10
}})
{
std
::
unique_ptr
<
arena
::
TestCase
>
tester
(
new
GatherComputeTest
(
place
,
"int64"
,
DDim
(
x_dims
),
DDim
(
index_dims
)));
arena
::
Arena
arena
(
std
::
move
(
tester
),
place
,
abs_error
);
arena
.
TestPrecision
();
#if defined(LITE_WITH_XPU) || defined(LITE_WITH_NPU)
TestGather
<
float
,
int
>
(
x_dims
,
index_dims
,
place
,
abs_error
,
"def"
);
#else
TestGather
<
float
,
int64_t
>
(
x_dims
,
index_dims
,
place
,
abs_error
,
"int64"
);
TestGather
<
int64_t
,
int64_t
>
(
x_dims
,
index_dims
,
place
,
abs_error
,
"int64"
);
TestGather
<
float
,
int
>
(
x_dims
,
index_dims
,
place
,
abs_error
,
"int32"
);
#endif
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录