Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
e080dd3c
MegEngine
项目概览
MegEngine 天元
/
MegEngine
1 年多 前同步成功
通知
404
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看板
提交
e080dd3c
编写于
5月 10, 2020
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(gopt): rename nchw2xxx to xxx
GitOrigin-RevId: fcb08c09e0e48afbad99230cb67ceb7fa1c9119f
上级
a3560fa1
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
45 addition
and
45 deletion
+45
-45
python_module/megengine/_internal/__init__.py
python_module/megengine/_internal/__init__.py
+5
-5
python_module/src/swig/misc.i
python_module/src/swig/misc.i
+5
-5
src/gopt/impl/framework.cpp
src/gopt/impl/framework.cpp
+5
-5
src/gopt/include/megbrain/gopt/framework.h
src/gopt/include/megbrain/gopt/framework.h
+12
-12
src/gopt/test/inference.cpp
src/gopt/test/inference.cpp
+17
-17
src/opr/test/io.cpp
src/opr/test/io.cpp
+1
-1
未找到文件。
python_module/megengine/_internal/__init__.py
浏览文件 @
e080dd3c
...
...
@@ -588,11 +588,11 @@ def optimize_for_inference(
layout_tranform
=
None
for
k
,
v
in
{
"use_nhwcd4"
:
"n
chw2n
hwcd4"
,
"use_nchw32"
:
"nchw
2nchw
32"
,
"use_nchw88"
:
"nchw
2nchw
88"
,
"use_nchw44"
:
"nchw
2nchw
44"
,
"use_chwn4"
:
"nchw42
chwn4"
,
"use_nhwcd4"
:
"nhwcd4"
,
"use_nchw32"
:
"nchw32"
,
"use_nchw88"
:
"nchw88"
,
"use_nchw44"
:
"nchw44"
,
"use_chwn4"
:
"
chwn4"
,
}.
items
():
if
settings
[
k
]:
assert
(
...
...
python_module/src/swig/misc.i
浏览文件 @
e080dd3c
...
...
@@ -80,11 +80,11 @@ struct _OptimizeForInferenceOptions {
#
define
SET
(
_trans
,
_trans_capital
)
\
void
enable_
##
_trans
()
;
\
SET
(
n
chw2nhwcd4
,
NCHW2
NHWCD4
)
;
SET
(
nchw
2nchw88
,
NCHW2
NCHW88
)
;
SET
(
nchw
2nchw44
,
NCHW2
NCHW44
)
;
SET
(
nchw
2nchw32
,
NCHW2
NCHW32
)
;
SET
(
nchw42chwn4
,
NCHW42
CHWN4
)
;
SET
(
n
hwcd4
,
NHWCD4
)
;
SET
(
nchw
88
,
NCHW88
)
;
SET
(
nchw
44
,
NCHW44
)
;
SET
(
nchw
32
,
NCHW32
)
;
SET
(
chwn4
,
CHWN4
)
;
#
undef
SET
}
;
...
...
src/gopt/impl/framework.cpp
浏览文件 @
e080dd3c
...
...
@@ -708,23 +708,23 @@ void GraphOptimizer::apply_optimize_options(
if
(
options
->
f16_io_f32_comp
)
{
add_pass
(
ConvertF32ToF16Pass
::
make
(
true
));
}
if
(
options
->
transform_n
chw2n
hwcd4
())
{
if
(
options
->
transform_nhwcd4
())
{
add_pass
(
ConvertFormatPass
::
make_nhwcd4_converter
());
add_pass
<
FuseConvBiasNonlinPass
>
();
}
if
(
options
->
transform_nchw
2nchw
88
())
{
if
(
options
->
transform_nchw88
())
{
add_pass
(
EnableNchwxxPass
::
make_nchwxx_converter
(
8
));
}
if
(
options
->
transform_nchw
2nchw
44
())
{
if
(
options
->
transform_nchw44
())
{
add_pass
(
EnableNchwxxPass
::
make_nchwxx_converter
(
4
));
}
if
(
options
->
transform_nchw
2nchw
32
())
{
if
(
options
->
transform_nchw32
())
{
add_pass
<
FuseConvBiasNonlinPass
>
();
add_pass
(
EnableTensorCorePass
::
make_tensorcore_converter
());
add_pass
<
ShuffleShuffleRemovePass
>
();
add_pass
<
RemoveRedundantTypeCvtPass
>
();
}
if
(
options
->
transform_
nchw42
chwn4
())
{
if
(
options
->
transform_chwn4
())
{
add_pass
<
FuseConvBiasNonlinPass
>
();
add_pass
<
FuseConvBiasZPass
>
();
add_pass
(
EnableCHWN4Pass
::
make_chwn4_converter
());
...
...
src/gopt/include/megbrain/gopt/framework.h
浏览文件 @
e080dd3c
...
...
@@ -390,13 +390,13 @@ namespace gopt {
bool
fuse_conv_bias_nonlinearity
=
false
;
enum
LayoutTransform
:
uint32_t
{
DEFAULT
,
N
CHW2N
HWCD4
,
///< compute using NHWCD4 tensor format
NCHW
2NCHW
88
,
///< compute using NCHW88 tensor format
NCHW
2NCHW
44
,
///< compute using NCHW44 tensor format
NCHW
2NCHW
32
,
///< compute using NCHW32 tensor format, used for
NHWCD4
,
///< compute using NHWCD4 tensor format
NCHW88
,
///< compute using NCHW88 tensor format
NCHW44
,
///< compute using NCHW44 tensor format
NCHW32
,
///< compute using NCHW32 tensor format, used for
///< tensorcore
NCHW42CHWN4
,
///< compute using CHWN4 tensor format, transformed
///< from NCHW4, mainly
used for cuda
CHWN4
,
///< compute using CHWN4 tensor format, transformed mainly
///<
used for cuda
};
LayoutTransform
layout_transform
=
LayoutTransform
::
DEFAULT
;
//! fuse pattern like ReLU(conv_bias(x, w, b) + z) or conv_bias(x, w, b)
...
...
@@ -422,11 +422,11 @@ namespace gopt {
return layout_transform == LayoutTransform::_trans_capital; \
}
SET
(
n
chw2nhwcd4
,
NCHW2
NHWCD4
);
SET
(
nchw
2nchw88
,
NCHW2
NCHW88
);
SET
(
nchw
2nchw44
,
NCHW2
NCHW44
);
SET
(
nchw
2nchw32
,
NCHW2
NCHW32
);
SET
(
nchw42chwn4
,
NCHW42
CHWN4
);
SET
(
n
hwcd4
,
NHWCD4
);
SET
(
nchw
88
,
NCHW88
);
SET
(
nchw
44
,
NCHW44
);
SET
(
nchw
32
,
NCHW32
);
SET
(
chwn4
,
CHWN4
);
#undef SET
};
...
...
src/gopt/test/inference.cpp
浏览文件 @
e080dd3c
...
...
@@ -992,7 +992,7 @@ TEST(TestGoptInference, ConvertFormatNHWCD4) {
SymbolVar
y_opt
;
auto
options
=
gopt
::
OptimizeForInferenceOptions
{};
options
.
enable_n
chw2n
hwcd4
();
options
.
enable_nhwcd4
();
unpack_vector
(
gopt
::
optimize_for_inference
({
y
},
options
),
y_opt
);
ASSERT_EQ
(
opr
::
Convolution
::
Param
::
Format
::
NHWCD4
,
...
...
@@ -1051,7 +1051,7 @@ TEST(TestGoptInference, ConvertFormatNHWCD4LOCAL) {
SymbolVar
y_opt
;
auto
options
=
gopt
::
OptimizeForInferenceOptions
{};
options
.
enable_n
chw2n
hwcd4
();
options
.
enable_nhwcd4
();
unpack_vector
(
gopt
::
optimize_for_inference
({
y
},
options
),
y_opt
);
ASSERT_EQ
(
opr
::
Convolution
::
Param
::
Format
::
NHWCD4
,
...
...
@@ -1102,7 +1102,7 @@ TEST(TestGoptInference, ConvertFormatNHWCD4Deconv) {
SymbolVar
y_opt
;
auto
options
=
gopt
::
OptimizeForInferenceOptions
{};
options
.
enable_n
chw2n
hwcd4
();
options
.
enable_nhwcd4
();
unpack_vector
(
gopt
::
optimize_for_inference
({
y
},
options
),
y_opt
);
ASSERT_EQ
(
opr
::
Convolution
::
Param
::
Format
::
NCHW
,
...
...
@@ -1147,7 +1147,7 @@ TEST(TestGoptInference, ConvertFormatNHWCD4Qint8) {
SymbolVar
y_opt
;
auto
options
=
gopt
::
OptimizeForInferenceOptions
{};
options
.
enable_n
chw2n
hwcd4
();
options
.
enable_nhwcd4
();
unpack_vector
(
gopt
::
optimize_for_inference
({
y
},
options
),
y_opt
);
ASSERT_EQ
(
opr
::
ConvBias
::
Param
::
Format
::
NHWCD4
,
...
...
@@ -1199,7 +1199,7 @@ TEST(TestGoptInference, ConvertFormatPadIC) {
auto
y
=
opr
::
Convolution
::
make
(
concat
,
w1
,
param
);
SymbolVar
y_opt
;
auto
options
=
gopt
::
OptimizeForInferenceOptions
{};
options
.
enable_n
chw2n
hwcd4
();
options
.
enable_nhwcd4
();
unpack_vector
(
gopt
::
optimize_for_inference
({
y
},
options
),
y_opt
);
HostTensorND
host_y_opt
,
host_y
;
...
...
@@ -1285,7 +1285,7 @@ TEST(TestGoptInference, ConvBiasNonlinearityFusePass) {
y_y
=
opr
::
Convolution
::
make
(
y_expand
,
w3
,
param
),
y
=
y_y
+
y_tmp
;
SymbolVar
y_opt
;
auto
options
=
gopt
::
OptimizeForInferenceOptions
{};
options
.
enable_n
chw2n
hwcd4
().
enable_fuse_conv_bias_nonlinearity
();
options
.
enable_nhwcd4
().
enable_fuse_conv_bias_nonlinearity
();
unpack_vector
(
gopt
::
optimize_for_inference
({
y
},
options
),
y_opt
);
ASSERT_EQ
(
3u
,
find_opr
<
opr
::
ConvBias
>
(
y_opt
).
input
().
size
());
graph
->
compile
({{
y_opt
,
{}}})
...
...
@@ -1516,7 +1516,7 @@ TEST(TestEnableTensorCore, SmallInputShape) {
SymbolVar
y_no_tc
;
{
auto
options
=
gopt
::
OptimizeForInferenceOptions
{};
options
.
enable_nchw
2nchw
32
().
enable_fuse_conv_bias_nonlinearity
();
options
.
enable_nchw32
().
enable_fuse_conv_bias_nonlinearity
();
unpack_vector
(
gopt
::
optimize_for_inference
({
y
},
options
),
y_opt
);
}
{
...
...
@@ -1581,7 +1581,7 @@ TEST(TestEnableTensorCore, ConvBiasWithZ) {
SymbolVar
y_no_tc
;
{
auto
options
=
gopt
::
OptimizeForInferenceOptions
{};
options
.
enable_fuse_conv_bias_nonlinearity
().
enable_nchw
2nchw
32
();
options
.
enable_fuse_conv_bias_nonlinearity
().
enable_nchw32
();
unpack_vector
(
gopt
::
optimize_for_inference
({
y
},
options
),
y_opt
);
}
{
...
...
@@ -1649,12 +1649,12 @@ TEST(TestGoptInference, EnableTensorCore) {
SymbolVar
y_no_tc
;
{
auto
options
=
gopt
::
OptimizeForInferenceOptions
{};
options
.
enable_fuse_conv_bias_nonlinearity
().
enable_nchw
2nchw
32
();
options
.
enable_fuse_conv_bias_nonlinearity
().
enable_nchw32
();
unpack_vector
(
gopt
::
optimize_for_inference
({
y4
},
options
),
y_opt
);
}
{
auto
options
=
gopt
::
OptimizeForInferenceOptions
{};
options
.
enable_fuse_conv_bias_nonlinearity
().
enable_nchw
2nchw
32
();
options
.
enable_fuse_conv_bias_nonlinearity
().
enable_nchw32
();
unpack_vector
(
gopt
::
optimize_for_inference
({
y4
},
options
),
y_no_tc
);
}
auto
nr_dimshuffle
=
find_opr_num
<
mgb
::
opr
::
Dimshuffle
>
(
y_opt
);
...
...
@@ -1855,7 +1855,7 @@ TEST(TestEnableTensorCore, ShuffleMerge) {
SymbolVar
y_no_tc
;
{
auto
options
=
gopt
::
OptimizeForInferenceOptions
{};
options
.
enable_fuse_conv_bias_nonlinearity
().
enable_nchw
2nchw
32
();
options
.
enable_fuse_conv_bias_nonlinearity
().
enable_nchw32
();
unpack_vector
(
gopt
::
optimize_for_inference
({
y
},
options
),
y_opt
);
}
{
...
...
@@ -1923,7 +1923,7 @@ TEST(FuseConvBiasZPass, Basic) {
auto
options
=
gopt
::
OptimizeForInferenceOptions
{};
options
.
enable_fuse_conv_bias_nonlinearity
()
.
enable_fuse_conv_bias_with_z
()
.
enable_nchw
2nchw
32
();
.
enable_nchw32
();
unpack_vector
(
gopt
::
optimize_for_inference
({
y1
},
options
),
y_opt
);
}
auto
nr_elemwisemultitype
=
find_opr_num
<
opr
::
ElemwiseMultiType
>
(
y_opt
);
...
...
@@ -1940,7 +1940,7 @@ TEST(FuseConvBiasZPass, Basic) {
auto
options
=
gopt
::
OptimizeForInferenceOptions
{};
options
.
enable_fuse_conv_bias_nonlinearity
()
.
enable_fuse_conv_bias_with_z
()
.
enable_nchw
2nchw
32
();
.
enable_nchw32
();
unpack_vector
(
gopt
::
optimize_for_inference
({
y2
},
options
),
y_opt
);
}
...
...
@@ -2013,7 +2013,7 @@ TEST(TestGoptInference, EnableCHWN4) {
SymbolVar
y_cudnn
;
{
auto
options
=
gopt
::
OptimizeForInferenceOptions
{};
options
.
enable_
nchw42
chwn4
();
options
.
enable_chwn4
();
unpack_vector
(
gopt
::
optimize_for_inference
({
y4
},
options
),
y_opt
);
}
unpack_vector
(
gopt
::
GraphOptimizer
{}
...
...
@@ -2099,7 +2099,7 @@ TEST(TestGoptInference, EnableCHWN4WarpPespective) {
SymbolVar
y_cudnn
;
{
auto
options
=
gopt
::
OptimizeForInferenceOptions
{};
options
.
enable_
nchw42
chwn4
();
options
.
enable_chwn4
();
unpack_vector
(
gopt
::
optimize_for_inference
({
y2
},
options
),
y_opt
);
}
unpack_vector
(
gopt
::
GraphOptimizer
{}
...
...
@@ -2386,7 +2386,7 @@ TEST(TestGoptInference, ConvertFormatNCHW88) {
SymbolVar
y_opt
;
{
auto
options
=
gopt
::
OptimizeForInferenceOptions
{};
options
.
enable_nchw
2nchw
88
();
options
.
enable_nchw88
();
unpack_vector
(
gopt
::
optimize_for_inference
({
y
},
options
),
y_opt
);
}
...
...
@@ -2467,7 +2467,7 @@ TEST(TestGoptInference, ConvertFormatNCHW44) {
SymbolVar
y_opt
;
auto
options
=
gopt
::
OptimizeForInferenceOptions
{};
options
.
enable_nchw
2nchw
44
();
options
.
enable_nchw44
();
unpack_vector
(
gopt
::
optimize_for_inference
({
y
},
options
),
y_opt
);
ASSERT_EQ
(
opr
::
ConvBias
::
Param
::
Format
::
NCHW44
,
...
...
src/opr/test/io.cpp
浏览文件 @
e080dd3c
...
...
@@ -501,7 +501,7 @@ TEST(TestOprIO, MultipleDeviceTensorWithFormatHolderCpu) {
auto
y
=
opr
::
Elemwise
::
make
({
conv2
},
opr
::
Elemwise
::
Param
::
Mode
::
RELU
);
auto
options
=
gopt
::
OptimizeForInferenceOptions
{};
options
.
enable_n
chw2n
hwcd4
();
options
.
enable_nhwcd4
();
SymbolVar
y_opt
=
gopt
::
optimize_for_inference
({
y
},
options
)[
0
].
rename
(
"out"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录