Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
36f17dec
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看板
提交
36f17dec
编写于
5月 11, 2020
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(gopt): add layout transform and fuse in load_and_run
GitOrigin-RevId: 9faa7ef06846fcf851e5b65b94cf5daca1de408b
上级
e24fcd00
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
51 addition
and
14 deletion
+51
-14
sdk/load-and-run/src/mgblar.cpp
sdk/load-and-run/src/mgblar.cpp
+22
-3
src/core/impl/graph/cg_impl.cpp
src/core/impl/graph/cg_impl.cpp
+4
-7
src/core/include/megbrain/graph/cg.h
src/core/include/megbrain/graph/cg.h
+12
-3
src/gopt/impl/framework.cpp
src/gopt/impl/framework.cpp
+13
-1
未找到文件。
sdk/load-and-run/src/mgblar.cpp
浏览文件 @
36f17dec
...
...
@@ -972,9 +972,28 @@ Args Args::from_argv(int argc, char **argv) {
continue
;
}
#endif
if
(
!
strcmp
(
argv
[
i
],
"--enable-chwn4"
))
{
mgb_log_warn
(
"enable chwn4 optimization"
);
graph_opt
.
graph_opt
.
enable_chwn4
();
#define cb(_layout) \
if (!strcmp(argv[i], "--enable-" #_layout)) { \
mgb_log_warn("enable " #_layout " optimization"); \
graph_opt.graph_opt.enable_##_layout(); \
continue; \
}
cb
(
chwn4
);
cb
(
nchw44
);
cb
(
nchw88
);
cb
(
nchw32
);
cb
(
nhwcd4
);
#undef cb
if
(
!
strcmp
(
argv
[
i
],
"--enable-fuse-conv-bias-nonlinearity"
))
{
mgb_log_warn
(
"enable fuse-conv-bias-nonlinearity optimization"
);
graph_opt
.
graph_opt
.
enable_fuse_conv_bias_nonlinearity
();
continue
;
}
if
(
!
strcmp
(
argv
[
i
],
"--enable-fuse-conv-bias-with-z"
))
{
mgb_log_warn
(
"enable fuse_conv_bias_with_z optimization"
);
graph_opt
.
graph_opt
.
enable_fuse_conv_bias_with_z
();
continue
;
}
#if MGB_ENABLE_JSON
...
...
src/core/impl/graph/cg_impl.cpp
浏览文件 @
36f17dec
...
...
@@ -462,13 +462,6 @@ ComputingGraphImpl::CompileState ComputingGraphImpl::compile_prepare(
options
().
graph_opt
.
winograd_transform
=
false
;
gopt
::
transform_vars_inplace_with_winograd
(
dest_vars
);
}
if
(
options
().
graph_opt
.
transform_chwn4
())
{
gopt
::
GraphOptimizer
optimizer
;
optimizer
.
apply_optimize_options
(
options
().
graph_opt
);
options
().
graph_opt
.
layout_transform
=
cg
::
GraphCommonOptimizeOptions
::
LayoutTransform
::
DEFAULT
;
optimizer
.
apply_inplace
(
dest_vars
);
}
#if MGB_JIT
if
(
std
::
abs
(
options
().
graph_opt_level
)
==
0
&&
options
().
graph_opt
.
jit
)
{
...
...
@@ -480,6 +473,10 @@ ComputingGraphImpl::CompileState ComputingGraphImpl::compile_prepare(
optimizer
.
apply_inplace
(
dest_vars
);
}
#endif
gopt
::
GraphOptimizer
optimizer
;
optimizer
.
apply_optimize_options
(
options
().
graph_opt
);
options
().
graph_opt
.
reset
();
optimizer
.
apply_inplace
(
dest_vars
);
const
OprNodeArray
*
opr_seq
=
nullptr
;
CompSeqExtraInfo
extra_info
;
...
...
src/core/include/megbrain/graph/cg.h
浏览文件 @
36f17dec
...
...
@@ -92,6 +92,9 @@ struct GraphCommonOptimizeOptions {
bool
f16_io_comp
=
false
;
//! whether to enable conv bias nonlinearity fusion
bool
fuse_conv_bias_nonlinearity
=
false
;
//! fuse pattern like ReLU(conv_bias(x, w, b) + z) or conv_bias(x, w, b)
//! + z -> conv_bias(x, w, b, z)
bool
fuse_conv_bias_with_z
=
false
;
enum
LayoutTransform
:
uint32_t
{
DEFAULT
,
NHWCD4
,
///< compute using NHWCD4 tensor format
...
...
@@ -103,9 +106,14 @@ struct GraphCommonOptimizeOptions {
///< used for cuda
};
LayoutTransform
layout_transform
=
LayoutTransform
::
DEFAULT
;
//! fuse pattern like ReLU(conv_bias(x, w, b) + z) or conv_bias(x, w, b)
//! + z -> conv_bias(x, w, b, z)
bool
fuse_conv_bias_with_z
=
false
;
void
reset
()
{
f16_io_f32_comp
=
false
;
f16_io_comp
=
false
;
fuse_conv_bias_nonlinearity
=
false
;
fuse_conv_bias_with_z
=
false
;
layout_transform
=
LayoutTransform
::
DEFAULT
;
}
#define SET(n) \
GraphCommonOptimizeOptions& enable_##n() { \
...
...
@@ -119,6 +127,7 @@ struct GraphCommonOptimizeOptions {
#undef SET
#define SET(_trans, _trans_capital) \
GraphCommonOptimizeOptions& enable_##_trans() { \
mgb_assert(layout_transform == LayoutTransform::DEFAULT); \
layout_transform = LayoutTransform::_trans_capital; \
return *this; \
} \
...
...
src/gopt/impl/framework.cpp
浏览文件 @
36f17dec
...
...
@@ -706,21 +706,27 @@ VarNode* GraphOptimizer::var_replace_lookup(VarNode *var) {
const
GraphOptimizer
&
GraphOptimizer
::
apply_optimize_options
(
const
cg
::
GraphCommonOptimizeOptions
&
options
)
{
bool
need_param_fuse
=
false
;
if
(
options
.
f16_io_comp
)
{
add_pass
(
ConvertF32ToF16Pass
::
make
(
false
));
need_param_fuse
=
true
;
}
if
(
options
.
f16_io_f32_comp
)
{
add_pass
(
ConvertF32ToF16Pass
::
make
(
true
));
need_param_fuse
=
true
;
}
if
(
options
.
transform_nhwcd4
())
{
add_pass
(
ConvertFormatPass
::
make_nhwcd4_converter
());
add_pass
<
FuseConvBiasNonlinPass
>
();
need_param_fuse
=
true
;
}
if
(
options
.
transform_nchw88
())
{
add_pass
(
EnableNchwxxPass
::
make_nchwxx_converter
(
8
));
need_param_fuse
=
true
;
}
if
(
options
.
transform_nchw44
())
{
add_pass
(
EnableNchwxxPass
::
make_nchwxx_converter
(
4
));
need_param_fuse
=
true
;
}
if
(
options
.
transform_nchw32
())
{
add_pass
<
FuseConvBiasNonlinPass
>
();
...
...
@@ -728,6 +734,7 @@ const GraphOptimizer& GraphOptimizer::apply_optimize_options(
add_pass
(
EnableTensorCorePass
::
make_tensorcore_converter
());
add_pass
<
ShuffleShuffleRemovePass
>
();
add_pass
<
RemoveRedundantTypeCvtPass
>
();
need_param_fuse
=
true
;
}
if
(
options
.
transform_chwn4
())
{
add_pass
<
FuseConvBiasNonlinPass
>
();
...
...
@@ -735,16 +742,21 @@ const GraphOptimizer& GraphOptimizer::apply_optimize_options(
add_pass
(
EnableCHWN4Pass
::
make_chwn4_converter
());
add_pass
<
ShuffleShuffleRemovePass
>
();
add_pass
<
RemoveRedundantTypeCvtPass
>
();
need_param_fuse
=
true
;
}
if
(
options
.
fuse_conv_bias_nonlinearity
)
{
add_pass
<
FuseConvBiasNonlinPass
>
();
need_param_fuse
=
true
;
}
if
(
options
.
fuse_conv_bias_with_z
)
{
add_pass
<
FuseConvBiasNonlinPass
>
();
add_pass
<
FuseConvBiasZPass
>
();
need_param_fuse
=
true
;
}
if
(
need_param_fuse
)
{
add_pass
<
ParamFusePass
>
();
}
add_pass
<
ParamFusePass
>
();
return
*
this
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录