Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
63da1451
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看板
提交
63da1451
编写于
4月 09, 2020
作者:
D
dingminghui
提交者:
jackzhang235
4月 10, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(layout): fix compute error in nhwc2nchw layout trans
上级
067111d4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
22 addition
and
25 deletion
+22
-25
lite/kernels/mlu/layout_compute.h
lite/kernels/mlu/layout_compute.h
+22
-25
未找到文件。
lite/kernels/mlu/layout_compute.h
浏览文件 @
63da1451
...
...
@@ -34,17 +34,17 @@ struct FPTypeTraits {};
template
<
>
struct
FPTypeTraits
<
paddle
::
lite_api
::
PrecisionType
::
kFloat
>
{
typedef
float
T
;
using
type
=
float
;
};
template
<
>
struct
FPTypeTraits
<
paddle
::
lite_api
::
PrecisionType
::
kFP16
>
{
typedef
paddle
::
lite
::
fluid
::
float16
T
;
using
type
=
paddle
::
lite
::
fluid
::
float16
;
};
template
<
>
struct
FPTypeTraits
<
paddle
::
lite_api
::
PrecisionType
::
kInt8
>
{
typedef
int8_t
T
;
using
type
=
int8_t
;
};
template
<
lite
::
TargetType
Target
,
typename
T
>
...
...
@@ -81,36 +81,36 @@ class LayoutNchwToNhwcCompute
auto
&
param
=
this
->
template
Param
<
param_t
>();
auto
*
x
=
param
.
x
;
auto
*
out
=
param
.
y
;
out
->
template
mutable_data
<
typename
FPTypeTraits
<
Precision
>
::
T
>
();
auto
x_dims
=
param
.
x
->
dims
().
size
();
out
->
template
mutable_data
<
typename
FPTypeTraits
<
Precision
>
::
type
>
();
auto
x_
n
dims
=
param
.
x
->
dims
().
size
();
auto
&
context
=
this
->
ctx_
->
template
As
<
X86Context
>();
const
auto
origin_dims
=
out
->
dims
().
Vectorize
();
std
::
vector
<
int
>
axis
;
switch
(
x_dims
)
{
switch
(
x_
n
dims
)
{
case
2
:
axis
=
{
0
,
1
};
break
;
case
3
:
axis
=
{
0
,
2
,
1
};
out
->
Resize
(
std
::
vector
<
int64_t
>
{
o
ut
->
dims
()[
0
],
out
->
dims
()[
2
],
out
->
dims
()
[
1
]});
o
rigin_dims
[
0
],
origin_dims
[
2
],
origin_dims
[
1
]});
break
;
case
4
:
axis
=
{
0
,
2
,
3
,
1
};
out
->
Resize
(
std
::
vector
<
int64_t
>
{
o
ut
->
dims
()[
0
],
out
->
dims
()[
2
],
out
->
dims
()[
3
],
out
->
dims
()
[
1
]});
o
rigin_dims
[
0
],
origin_dims
[
2
],
origin_dims
[
3
],
origin_dims
[
1
]});
break
;
default:
CHECK
(
0
)
<<
"Unsupport dim in mlu layout nchw to nhwc"
;
}
LayoutTransCompute
<
lite
::
TargetType
::
kX86
,
typename
FPTypeTraits
<
Precision
>::
T
>
(
x_dims
,
context
,
*
x
,
out
,
axis
);
typename
FPTypeTraits
<
Precision
>::
type
>
(
x_
n
dims
,
context
,
*
x
,
out
,
axis
);
if
(
x_dims
>
2
)
{
if
(
x_
n
dims
>
2
)
{
out
->
Resize
(
origin_dims
);
}
}
...
...
@@ -130,25 +130,26 @@ class LayoutNhwcToNchwCompute
auto
&
param
=
this
->
template
Param
<
param_t
>();
auto
*
x
=
param
.
x
;
auto
*
out
=
param
.
y
;
out
->
template
mutable_data
<
typename
FPTypeTraits
<
Precision
>
::
T
>
();
auto
x_dims
=
param
.
x
->
dims
().
size
();
out
->
template
mutable_data
<
typename
FPTypeTraits
<
Precision
>
::
type
>
();
auto
&
context
=
this
->
ctx_
->
template
As
<
X86Context
>();
const
auto
origin_dims
=
out
->
dims
().
Vectorize
();
TensorLite
tmp_t
;
tmp_t
.
ShareDataWith
(
*
x
);
const
auto
x_dims
=
x
->
dims
().
Vectorize
();
auto
x_ndims
=
param
.
x
->
dims
().
size
();
std
::
vector
<
int
>
axis
;
switch
(
x_dims
)
{
switch
(
x_
n
dims
)
{
case
2
:
axis
=
{
0
,
1
};
break
;
case
3
:
out
->
Resize
(
std
::
vector
<
int64_t
>
{
out
->
dims
()[
0
],
out
->
dims
()[
2
],
out
->
dims
()[
1
]});
tmp_t
.
Resize
(
std
::
vector
<
int64_t
>
{
x_dims
[
0
],
x_dims
[
2
],
x_dims
[
1
]});
axis
=
{
0
,
2
,
1
};
break
;
case
4
:
out
->
Resize
(
std
::
vector
<
int64_t
>
{
out
->
dims
()[
0
],
out
->
dims
()[
3
],
out
->
dims
()[
1
],
out
->
dims
()[
2
]});
tmp_t
.
Resize
(
std
::
vector
<
int64_t
>
{
x_dims
[
0
],
x_dims
[
2
],
x_dims
[
3
],
x_dims
[
1
]});
axis
=
{
0
,
3
,
1
,
2
};
break
;
default:
...
...
@@ -156,12 +157,8 @@ class LayoutNhwcToNchwCompute
}
LayoutTransCompute
<
lite
::
TargetType
::
kX86
,
typename
FPTypeTraits
<
Precision
>::
T
>
(
x_dims
,
context
,
*
x
,
out
,
axis
);
if
(
x_dims
>
2
)
{
out
->
Resize
(
origin_dims
);
}
typename
FPTypeTraits
<
Precision
>::
type
>
(
x_ndims
,
context
,
tmp_t
,
out
,
axis
);
}
std
::
string
doc
()
const
override
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录