Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
项目经理老王
Mace
提交
c741936c
Mace
项目概览
项目经理老王
/
Mace
与 Fork 源项目一致
Fork自
Xiaomi / Mace
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Mace
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c741936c
编写于
10月 22, 2018
作者:
李
李滨
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'mnmt' into 'master'
Improve transpose performance See merge request !840
上级
dd091b4b
aadb5e54
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
35 addition
and
9 deletion
+35
-9
mace/kernels/transpose.h
mace/kernels/transpose.h
+34
-9
mace/ops/transpose_benchmark.cc
mace/ops/transpose_benchmark.cc
+1
-0
未找到文件。
mace/kernels/transpose.h
浏览文件 @
c741936c
...
...
@@ -122,16 +122,16 @@ struct TransposeFunctor : OpKernel {
if
(
input
->
dim_size
()
==
2
)
{
MACE_CHECK
(
dims_
[
0
]
==
1
&&
dims_
[
1
]
==
0
,
"no need transform"
);
index_t
stride_i
=
input_shape
[
0
];
index_t
stride_j
=
input_shape
[
1
];
index_t
tile_size
=
input_shape
[
0
]
>
512
||
input_shape
[
1
]
>
512
?
64
:
32
;
index_t
height
=
input_shape
[
0
];
index_t
width
=
input_shape
[
1
];
index_t
stride_i
=
height
;
index_t
stride_j
=
width
;
index_t
tile_size
=
height
>
512
||
width
>
512
?
64
:
32
;
#pragma omp parallel for collapse(2)
for
(
index_t
i
=
0
;
i
<
input_shape
[
0
]
;
i
+=
tile_size
)
{
for
(
index_t
j
=
0
;
j
<
input_shape
[
1
]
;
j
+=
tile_size
)
{
index_t
end_i
=
std
::
min
(
i
+
tile_size
,
input_shape
[
0
]
);
index_t
end_j
=
std
::
min
(
j
+
tile_size
,
input_shape
[
1
]
);
for
(
index_t
i
=
0
;
i
<
height
;
i
+=
tile_size
)
{
for
(
index_t
j
=
0
;
j
<
width
;
j
+=
tile_size
)
{
index_t
end_i
=
std
::
min
(
i
+
tile_size
,
height
);
index_t
end_j
=
std
::
min
(
j
+
tile_size
,
width
);
for
(
index_t
tile_i
=
i
;
tile_i
<
end_i
;
++
tile_i
)
{
for
(
index_t
tile_j
=
j
;
tile_j
<
end_j
;
++
tile_j
)
{
output_data
[
tile_j
*
stride_i
+
tile_i
]
=
...
...
@@ -144,6 +144,7 @@ struct TransposeFunctor : OpKernel {
std
::
vector
<
int
>
transpose_order_from_NHWC_to_NCHW
{
0
,
3
,
1
,
2
};
std
::
vector
<
int
>
transpose_order_from_NCHW_to_NHWC
{
0
,
2
,
3
,
1
};
index_t
batch_size
=
input
->
dim
(
1
)
*
input
->
dim
(
2
)
*
input
->
dim
(
3
);
if
(
dims_
==
transpose_order_from_NHWC_to_NCHW
&&
input
->
dim
(
3
)
==
3
)
{
for
(
index_t
b
=
0
;
b
<
input
->
dim
(
0
);
++
b
)
{
TransposeNHWCToNCHWC3
(
input_data
+
b
*
batch_size
,
...
...
@@ -159,6 +160,30 @@ struct TransposeFunctor : OpKernel {
input
->
dim
(
2
),
input
->
dim
(
3
));
}
}
else
if
(
dims_
==
std
::
vector
<
int
>
{
0
,
2
,
1
,
3
})
{
index_t
height
=
input_shape
[
1
];
index_t
width
=
input_shape
[
2
];
index_t
channel
=
input_shape
[
3
];
index_t
channel_raw_size
=
channel
*
sizeof
(
T
);
index_t
stride_i
=
height
;
index_t
stride_j
=
width
;
index_t
tile_size
=
std
::
max
(
static_cast
<
index_t
>
(
1
),
static_cast
<
index_t
>
(
std
::
sqrt
(
8
*
1024
/
channel
)));
#pragma omp parallel for collapse(2)
for
(
index_t
i
=
0
;
i
<
height
;
i
+=
tile_size
)
{
for
(
index_t
j
=
0
;
j
<
width
;
j
+=
tile_size
)
{
index_t
end_i
=
std
::
min
(
i
+
tile_size
,
height
);
index_t
end_j
=
std
::
min
(
j
+
tile_size
,
width
);
for
(
index_t
tile_i
=
i
;
tile_i
<
end_i
;
++
tile_i
)
{
for
(
index_t
tile_j
=
j
;
tile_j
<
end_j
;
++
tile_j
)
{
memcpy
(
output_data
+
(
tile_j
*
stride_i
+
tile_i
)
*
channel
,
input_data
+
(
tile_i
*
stride_j
+
tile_j
)
*
channel
,
channel_raw_size
);
}
}
}
}
}
else
{
std
::
vector
<
index_t
>
in_stride
{
input_shape
[
1
]
*
input_shape
[
2
]
*
input_shape
[
3
],
...
...
mace/ops/transpose_benchmark.cc
浏览文件 @
c741936c
...
...
@@ -88,6 +88,7 @@ MACE_BM_TRANSPOSE4D(1, 512, 512, 3, 0, 3, 1, 2);
MACE_BM_TRANSPOSE4D
(
1
,
2
,
512
,
512
,
0
,
2
,
3
,
1
);
MACE_BM_TRANSPOSE4D
(
1
,
64
,
64
,
512
,
0
,
3
,
1
,
2
);
MACE_BM_TRANSPOSE4D
(
1
,
512
,
64
,
64
,
0
,
2
,
3
,
1
);
MACE_BM_TRANSPOSE4D
(
1
,
4
,
20
,
64
,
0
,
2
,
1
,
3
);
MACE_BM_TRANSPOSE2D
(
128
,
128
);
MACE_BM_TRANSPOSE2D
(
512
,
512
);
MACE_BM_TRANSPOSE2D
(
1024
,
1024
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录