Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
a086f2e2
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
a086f2e2
编写于
7月 29, 2020
作者:
myq406450149
提交者:
GitHub
7月 29, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix transpose error. test=develop (#4012)
上级
1a12ea87
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
56 addition
and
27 deletion
+56
-27
lite/kernels/arm/transpose_compute.cc
lite/kernels/arm/transpose_compute.cc
+56
-27
未找到文件。
lite/kernels/arm/transpose_compute.cc
浏览文件 @
a086f2e2
...
...
@@ -25,26 +25,6 @@ namespace lite {
namespace
kernels
{
namespace
arm
{
template
<
typename
Dtype
>
void
trans_basic
(
const
int
count
,
const
Dtype
*
din
,
const
int
*
permute_order
,
const
int
*
old_steps
,
const
int
*
new_steps
,
const
int
num_axes
,
Dtype
*
dout
)
{
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
int
old_idx
=
0
;
int
idx
=
i
;
for
(
int
j
=
0
;
j
<
num_axes
;
++
j
)
{
int
order
=
permute_order
[
j
];
old_idx
+=
(
idx
/
new_steps
[
j
])
*
old_steps
[
order
];
idx
%=
new_steps
[
j
];
}
dout
[
i
]
=
din
[
old_idx
];
}
}
template
<
typename
Dtype
>
void
transpose_mat
(
const
Dtype
*
din
,
Dtype
*
dout
,
...
...
@@ -201,6 +181,61 @@ void TransposeCompute::PrepareForRun() {
_old_steps
=
get_stride
(
input
->
dims
());
}
}
template
<
typename
Dtype
>
void
TransposeCompute_
(
const
std
::
vector
<
int
>&
axis
,
const
lite
::
Tensor
*
input
,
lite
::
Tensor
*
output
)
{
// const Dtype *input_ptr = input->data<Dtype>();
const
Dtype
*
input_ptr
=
input
->
data
<
float
>
();
Dtype
*
output_ptr
=
output
->
mutable_data
<
Dtype
>
();
// input and output's shape dimension must >= 2 && <= 6.
const
DDim
&
in_dim
=
input
->
dims
();
const
DDim
&
out_dim
=
output
->
dims
();
// precompute inverted output dim and strides
size_t
rout_dim
[
6
],
strides
[
6
];
int
permute
=
axis
.
size
();
// permute must >=2 && <= 6.
for
(
int
i
=
0
;
i
<
permute
;
++
i
)
{
int
k
=
permute
-
1
-
i
;
strides
[
k
]
=
1
;
for
(
int
j
=
axis
[
i
]
+
1
;
j
<
permute
;
++
j
)
{
strides
[
k
]
*=
in_dim
[
j
];
}
rout_dim
[
k
]
=
out_dim
[
i
];
}
// unroll the first 2 dimensions
int
reamin_dim
=
1
;
for
(
int
i
=
2
;
i
<
out_dim
.
size
();
++
i
)
{
reamin_dim
*=
out_dim
[
i
];
}
#pragma omp parallel for collapse(2)
for
(
int
batch
=
0
;
batch
<
out_dim
[
0
];
++
batch
)
{
for
(
int
j
=
0
;
j
<
out_dim
[
1
];
++
j
)
{
size_t
offset
=
batch
*
strides
[
permute
-
1
]
+
j
*
strides
[
permute
-
2
];
Dtype
*
out_ptr
=
output_ptr
+
(
batch
*
out_dim
[
1
]
+
j
)
*
reamin_dim
;
int
indics
[
4
]
=
{
0
,
0
,
0
,
0
};
for
(
int
k
=
0
;
k
<
reamin_dim
;
++
k
)
{
out_ptr
[
k
]
=
input_ptr
[
offset
];
indics
[
0
]
+=
1
;
offset
+=
strides
[
0
];
for
(
int
p
=
0
;
p
<
permute
-
3
;
++
p
)
{
if
(
indics
[
p
]
==
rout_dim
[
p
])
{
indics
[
p
+
1
]
+=
1
;
indics
[
p
]
=
0
;
offset
+=
strides
[
p
+
1
];
offset
-=
rout_dim
[
p
]
*
strides
[
p
];
}
else
{
break
;
}
}
}
}
}
}
// Transpose
void
TransposeCompute
::
Run
()
{
auto
&
param
=
Param
<
operators
::
TransposeParam
>
();
...
...
@@ -220,13 +255,7 @@ void TransposeCompute::Run() {
if
(
trans_mat
)
{
transpose_mat
(
din
,
dout
,
_trans_num
,
_trans_w
,
_trans_h
);
}
else
{
trans_basic
(
output
->
numel
(),
din
,
param
.
axis
.
data
(),
_old_steps
.
data
(),
_new_steps
.
data
(),
input
->
dims
().
size
(),
dout
);
TransposeCompute_
<
float
>
(
axis
,
input
,
output
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录