Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
9941d746
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看板
未验证
提交
9941d746
编写于
9月 23, 2019
作者:
J
juncaipeng
提交者:
GitHub
9月 23, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add cast from uint8 to float, test=develop (#2080)
* add cast from uint8 to float, test=develop
上级
977838b1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
31 addition
and
14 deletion
+31
-14
lite/kernels/arm/cast_compute.cc
lite/kernels/arm/cast_compute.cc
+6
-0
lite/tests/kernels/cast_compute_test.cc
lite/tests/kernels/cast_compute_test.cc
+25
-14
未找到文件。
lite/kernels/arm/cast_compute.cc
浏览文件 @
9941d746
...
...
@@ -53,6 +53,12 @@ void CastCompute::Run() {
// float>);
// todo: the input type actually is float.
memcpy
(
out_data
,
x_data_begin
,
sizeof
(
float
)
*
param
.
X
->
numel
());
}
else
if
(
param
.
in_dtype
==
20
&&
param
.
out_dtype
==
5
)
{
// uint8->float32
const
unsigned
char
*
x_data_begin
=
param
.
X
->
data
<
unsigned
char
>
();
const
unsigned
char
*
x_data_end
=
x_data_begin
+
param
.
X
->
numel
();
float
*
out_data
=
param
.
Out
->
mutable_data
<
float
>
();
std
::
transform
(
x_data_begin
,
x_data_end
,
out_data
,
TransOp
<
unsigned
char
,
float
>
);
}
else
{
LOG
(
FATAL
)
<<
"other has not been implemented"
;
}
...
...
lite/tests/kernels/cast_compute_test.cc
浏览文件 @
9941d746
...
...
@@ -27,7 +27,7 @@ class CastComputeTester : public arena::TestCase {
std
::
string
output_
=
"out"
;
int
in_dtype_
;
int
out_dtype_
;
DDim
x_dims_
{{
2
,
2
,
2
,
2
}};
DDim
x_dims_
{{
2
,
2
}};
public:
CastComputeTester
(
const
Place
&
place
,
...
...
@@ -41,27 +41,32 @@ class CastComputeTester : public arena::TestCase {
CHECK
(
out
);
out
->
Resize
(
x_dims_
);
if
(
out_dtype_
==
5
&&
in_dtype_
==
21
)
{
if
(
out_dtype_
==
5
&&
in_dtype_
==
20
)
{
auto
*
x
=
scope
->
FindTensor
(
input_
);
auto
*
x_data
=
x
->
data
<
unsigned
char
>
();
auto
*
output_data
=
out
->
mutable_data
<
float
>
();
for
(
int
i
=
0
;
i
<
x_dims_
.
production
();
i
++
)
{
*
output_data
=
static_cast
<
float
>
(
*
x_data
);
output_data
++
;
x_data
++
;
}
}
else
if
(
out_dtype_
==
5
&&
in_dtype_
==
21
)
{
auto
*
output_data
=
out
->
mutable_data
<
float
>
();
auto
*
x
=
scope
->
FindTensor
(
input_
);
auto
*
x_data
=
x
->
data
<
char
>
();
auto
*
output_data_tmp
=
output_data
;
auto
*
x_data_tmp
=
x_data
;
for
(
int
i
=
0
;
i
<
x_dims_
.
production
();
i
++
)
{
*
output_data
_tmp
=
static_cast
<
float
>
(
*
x_data_tmp
);
output_data
_tmp
++
;
x_data
_tmp
++
;
*
output_data
=
static_cast
<
float
>
(
*
x_data
);
output_data
++
;
x_data
++
;
}
}
else
if
(
out_dtype_
==
5
&&
in_dtype_
==
2
)
{
auto
*
output_data
=
out
->
mutable_data
<
float
>
();
auto
*
x
=
scope
->
FindTensor
(
input_
);
auto
*
x_data
=
x
->
data
<
int32_t
>
();
auto
*
output_data_tmp
=
output_data
;
auto
*
x_data_tmp
=
x_data
;
for
(
int
i
=
0
;
i
<
x_dims_
.
production
();
i
++
)
{
*
output_data
_tmp
=
static_cast
<
float
>
(
*
x_data_tmp
);
output_data
_tmp
++
;
x_data
_tmp
++
;
*
output_data
=
static_cast
<
float
>
(
*
x_data
);
output_data
++
;
x_data
++
;
}
}
}
...
...
@@ -75,7 +80,13 @@ class CastComputeTester : public arena::TestCase {
}
void
PrepareData
()
override
{
if
(
in_dtype_
==
21
)
{
if
(
in_dtype_
==
20
)
{
std
::
vector
<
unsigned
char
>
x_data
(
x_dims_
.
production
());
for
(
int
i
=
0
;
i
<
x_dims_
.
production
();
i
++
)
{
x_data
[
i
]
=
static_cast
<
unsigned
char
>
(
i
%
128
);
}
SetCommonTensor
(
input_
,
x_dims_
,
x_data
.
data
());
}
else
if
(
in_dtype_
==
21
)
{
std
::
vector
<
char
>
x_data
(
x_dims_
.
production
());
for
(
int
i
=
0
;
i
<
x_dims_
.
production
();
i
++
)
{
float
sign
=
i
%
3
==
0
?
-
1.0
f
:
1.0
f
;
...
...
@@ -101,7 +112,7 @@ TEST(Cast, precision) {
Place
place
(
TARGET
(
kARM
));
std
::
unique_ptr
<
arena
::
TestCase
>
tester
(
new
CastComputeTester
(
place
,
"def"
,
2
1
,
5
));
new
CastComputeTester
(
place
,
"def"
,
2
0
,
5
));
arena
::
Arena
arena
(
std
::
move
(
tester
),
place
,
2e-5
);
arena
.
TestPrecision
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录