Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
88c1eedb
MegEngine
项目概览
MegEngine 天元
/
MegEngine
1 年多 前同步成功
通知
403
Star
4705
Fork
582
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
MegEngine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
88c1eedb
编写于
9月 17, 2021
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(mgb/gopt): enable reduce for nchw44
GitOrigin-RevId: fce59d07625095c4096aa6e4feb346984626e9b4
上级
563239d3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
45 addition
and
7 deletion
+45
-7
src/gopt/impl/tensor_reformat.cpp
src/gopt/impl/tensor_reformat.cpp
+19
-1
src/gopt/test/inference.cpp
src/gopt/test/inference.cpp
+26
-6
未找到文件。
src/gopt/impl/tensor_reformat.cpp
浏览文件 @
88c1eedb
...
...
@@ -1753,6 +1753,24 @@ void EnableNchwxxPass::fill_opr_convert_fun(size_t pack_c_size) {
}
};
auto
replace_reduce_opr
=
[
=
](
OperatorNodeBase
*
opr
,
const
VarNodeArray
&
new_inp
)
{
mgb_assert
(
opr
->
input
().
size
()
==
new_inp
.
size
());
auto
&
reduce_opr
=
opr
->
cast_final_safe
<
opr
::
Reduce
>
();
VarNodeArray
temp_inp
=
new_inp
;
if
(
!
opr
->
input
(
0
)
->
shape
().
eq_shape
(
new_inp
[
0
]
->
shape
()))
{
mgb_assert
(
opr
->
input
(
0
)
->
shape
().
ndim
==
4
);
mgb_assert
(
new_inp
[
0
]
->
shape
().
ndim
==
5
);
if
(
reduce_opr
.
param
().
axis
!=
2
&&
reduce_opr
.
param
().
axis
!=
3
)
{
auto
new_var
=
RelayoutPlaceholder
::
make
(
new_inp
[
0
],
src_to_nchw_mode
);
temp_inp
[
0
]
=
new_var
.
node
();
}
}
return
serialization
::
copy_opr_shallow
(
*
opr
,
temp_inp
,
opr
->
config
());
};
//! When input change and all input can convert to nchwxx, this opr will run
//! in nchwxx mode, else it will run in nchw mode, for example concat and
//! elemwise opr
...
...
@@ -1829,13 +1847,13 @@ void EnableNchwxxPass::fill_opr_convert_fun(size_t pack_c_size) {
replace_func
[
opr
::
TypeCvt
::
typeinfo
()]
=
replace_multi_inp_opr
;
replace_func
[
opr
::
ElemwiseMultiType
::
typeinfo
()]
=
replace_multi_inp_opr
;
replace_func
[
opr
::
PowC
::
typeinfo
()]
=
replace_multi_inp_opr
;
replace_func
[
opr
::
Reduce
::
typeinfo
()]
=
replace_reduce_opr
;
//! not support yet
replace_func
[
opr
::
ConvolutionBackwardData
::
typeinfo
()]
=
relayout_inp_to_nchw
;
replace_func
[
opr
::
Subtensor
::
typeinfo
()]
=
relayout_inp_to_nchw
;
replace_func
[
opr
::
GetVarShape
::
typeinfo
()]
=
relayout_inp_to_nchw
;
replace_func
[
opr
::
Dimshuffle
::
typeinfo
()]
=
relayout_inp_to_nchw
;
replace_func
[
opr
::
Reduce
::
typeinfo
()]
=
relayout_inp_to_nchw
;
replace_func
[
opr
::
AssertEqual
::
typeinfo
()]
=
relayout_inp_to_nchw
;
replace_func
[
opr
::
IncrSubtensor
::
typeinfo
()]
=
relayout_inp_to_nchw
;
replace_func
[
opr
::
WarpPerspectiveForward
::
typeinfo
()]
=
...
...
src/gopt/test/inference.cpp
浏览文件 @
88c1eedb
...
...
@@ -3476,14 +3476,24 @@ TEST(TestGoptInference, ConvertFormatNCHW88) {
//! group
auto
w3
=
mkcvar
(
"w3"
,
{
1
,
8
,
8
,
3
,
3
}),
b3
=
mkcvar
(
"b3"
,
{
1
,
8
,
1
,
1
}),
conv3
=
opr
::
ConvBias
::
make
(
conv2
,
w3
,
b3
,
param_conv_bias
);
auto
shape_of
=
opr
::
GetVarShape
::
make
(
conv3
);
//! reduce
opr
::
Reduce
::
Param
param_reduce1
;
param_reduce1
.
axis
=
2
;
param_reduce1
.
mode
=
opr
::
Reduce
::
Mode
::
SUM
;
opr
::
Reduce
::
Param
param_reduce2
;
param_reduce2
.
axis
=
0
;
param_reduce2
.
mode
=
opr
::
Reduce
::
Mode
::
MAX
;
auto
reduce1
=
conv3
+
opr
::
Reduce
::
make
(
conv3
,
param_reduce1
)
+
opr
::
Reduce
::
make
(
conv3
,
param_reduce2
);
auto
shape_of
=
opr
::
GetVarShape
::
make
(
reduce1
);
auto
subtensor
=
opr
::
Subtensor
::
make
(
shape_of
,
{
opr
::
Subtensor
::
AxisIndexer
::
make_interval
(
0
,
x
.
make_scalar
(
2
),
None
,
x
.
make_scalar
(
1
))});
opr
::
Resize
::
Param
param_resize
;
param_resize
.
format
=
opr
::
Resize
::
Param
::
Format
::
NCHW
;
auto
resize
=
opr
::
ResizeForward
::
make
(
conv3
,
subtensor
*
2
,
param_resize
);
auto
resize
=
opr
::
ResizeForward
::
make
(
reduce1
,
subtensor
*
2
,
param_resize
);
auto
mat
=
mkcvar
(
"mat"
,
{
2
,
3
,
3
}),
warp
=
opr
::
WarpPerspectiveForward
::
make
(
resize
,
mat
,
nullptr
,
cg
::
var_from_tensor_shape
(
x
,
{
4
,
4
}));
...
...
@@ -3586,14 +3596,24 @@ TEST(TestGoptInference, ConvertFormatNCHW44) {
//! group
auto
w3
=
mkcvar
(
"w3"
,
{
2
,
4
,
4
,
3
,
3
}),
b3
=
mkcvar
(
"b3"
,
{
1
,
8
,
1
,
1
}),
conv3
=
opr
::
ConvBias
::
make
(
conv2
,
w3
,
b3
,
param_conv_bias
);
auto
shape_of
=
opr
::
GetVarShape
::
make
(
conv3
);
//! reduce
opr
::
Reduce
::
Param
param_reduce1
;
param_reduce1
.
axis
=
1
;
param_reduce1
.
mode
=
opr
::
Reduce
::
Mode
::
MIN
;
opr
::
Reduce
::
Param
param_reduce2
;
param_reduce2
.
axis
=
3
;
param_reduce2
.
mode
=
opr
::
Reduce
::
Mode
::
SUM_SQR
;
auto
reduce1
=
conv3
+
opr
::
Reduce
::
make
(
conv3
,
param_reduce1
)
+
opr
::
Reduce
::
make
(
conv3
,
param_reduce2
);
auto
shape_of
=
opr
::
GetVarShape
::
make
(
reduce1
);
auto
subtensor
=
opr
::
Subtensor
::
make
(
shape_of
,
{
opr
::
Subtensor
::
AxisIndexer
::
make_interval
(
0
,
x
.
make_scalar
(
2
),
None
,
x
.
make_scalar
(
1
))});
opr
::
Resize
::
Param
param_resize
;
param_resize
.
format
=
opr
::
Resize
::
Param
::
Format
::
NCHW
;
auto
resize
=
opr
::
ResizeForward
::
make
(
conv3
,
subtensor
*
2
,
param_resize
);
auto
resize
=
opr
::
ResizeForward
::
make
(
reduce1
,
subtensor
*
2
,
param_resize
);
auto
mat
=
mkcvar
(
"mat"
,
{
2
,
3
,
3
}),
warp
=
opr
::
WarpPerspectiveForward
::
make
(
resize
,
mat
,
nullptr
,
cg
::
var_from_tensor_shape
(
x
,
{
4
,
4
}));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录