Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
b33ec46e
MegEngine
项目概览
MegEngine 天元
/
MegEngine
大约 1 年 前同步成功
通知
399
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看板
提交
b33ec46e
编写于
9月 30, 2021
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mgb/gopt): fix layout gtrans when graph partition has opr with different format
GitOrigin-RevId: 326fdebb0cdf5ec0d950d3c8e9c451bf8f262d7e
上级
fe15239a
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
40 addition
and
21 deletion
+40
-21
src/gopt/impl/global_layout_transform/dynamic_programming_solver.cpp
...pl/global_layout_transform/dynamic_programming_solver.cpp
+2
-0
src/gopt/impl/global_layout_transform/profiling_based_solver.cpp
...t/impl/global_layout_transform/profiling_based_solver.cpp
+31
-10
src/gopt/include/megbrain/gopt/solver.h
src/gopt/include/megbrain/gopt/solver.h
+7
-11
未找到文件。
src/gopt/impl/global_layout_transform/dynamic_programming_solver.cpp
浏览文件 @
b33ec46e
...
...
@@ -221,6 +221,8 @@ void DynamicProgrammingSolver::Impl::analyze_edges(
edges
[
cur
].
push_back
(
ov
);
edge2idx
[
cur
].
emplace
(
ov
,
idx
++
);
}
if
(
cur
==
0
)
return
;
cur
--
;
for
(
const
auto
&
opr
:
reverse_adaptor
(
topo
))
{
for
(
const
auto
&
i
:
opr
->
input
())
{
...
...
src/gopt/impl/global_layout_transform/profiling_based_solver.cpp
浏览文件 @
b33ec46e
...
...
@@ -19,19 +19,41 @@ using namespace mgb;
using
namespace
gopt
;
using
namespace
opr
;
namespace
{
using
OprFormat
=
SolverBase
::
OprFormat
;
template
<
typename
Opr
>
bool
check_format_aware_opr_valid
(
const
OperatorNodeBase
*
opr_
,
OprFormat
opr_format
)
{
auto
&&
opr
=
opr_
->
cast_final_safe
<
Opr
>
();
return
opr
.
param
().
format
==
opr_format
;
}
}
// namespace
/* =================== ProfilingBasedSolverSolver ======================*/
ProfilingBasedSolver
::
ProfilingBasedSolver
(
std
::
unique_ptr
<
ProfilerBase
>
profiler
)
:
m_profiler
{
std
::
move
(
profiler
)}
{
static
const
ThinHashSet
<
Typeinfo
*>
format_aware_oprs
=
{
#define cb(_Opr) _Opr::typeinfo()
cb
(
Convolution
),
cb
(
ConvBiasForward
),
cb
(
ConvolutionBackwardData
),
cb
(
PoolingForward
),
cb
(
WarpPerspective
),
cb
(
Resize
),
static
const
ThinHashMap
<
Typeinfo
*
,
thin_function
<
bool
(
const
OperatorNodeBase
*
,
OprFormat
opr_format
)
>>
format_aware_opr_validators
=
{
#define cb(t) \
{opr::t::typeinfo(), std::bind( \
check_format_aware_opr_valid<opr::t>, \
std::placeholders::_1, std::placeholders::_2)}
cb
(
Convolution
),
cb
(
ConvBiasForward
),
cb
(
ConvolutionBackwardData
),
cb
(
PoolingForward
),
cb
(
WarpPerspective
),
cb
(
Resize
),
};
m_graph_partition_filter
=
[](
const
GraphPartition
&
partition
)
{
m_problem_filter
=
[](
const
Problem
&
problem
)
{
auto
&&
base_opr_format
=
problem
.
attribute
().
base_opr_format
;
bool
has_format_aware_opr
=
false
;
for
(
auto
&&
opr
:
partition
.
all_oprs
())
{
if
(
!
has_format_aware_opr
&&
format_aware_oprs
.
count
(
opr
->
dyn_typeinfo
()))
{
for
(
auto
&&
opr
:
problem
.
graph_partition
().
all_oprs
())
{
auto
iter
=
format_aware_opr_validators
.
find
(
opr
->
dyn_typeinfo
());
if
(
iter
!=
format_aware_opr_validators
.
end
()
&&
iter
->
second
(
opr
,
base_opr_format
))
{
has_format_aware_opr
=
true
;
break
;
}
...
...
@@ -42,8 +64,7 @@ ProfilingBasedSolver::ProfilingBasedSolver(std::unique_ptr<ProfilerBase> profile
ProfilingBasedSolver
::
Solution
ProfilingBasedSolver
::
solve
(
const
Problem
&
problem
)
const
{
const
auto
&
partition
=
problem
.
graph_partition
();
if
(
!
m_graph_partition_filter
(
partition
))
if
(
!
m_problem_filter
(
problem
))
return
Solution
{};
return
do_solve
(
problem
);
}
...
...
src/gopt/include/megbrain/gopt/solver.h
浏览文件 @
b33ec46e
...
...
@@ -49,18 +49,16 @@ public:
*/
class
ProfilingBasedSolver
:
public
SolverBase
{
public:
using
GraphPartitionFilter
=
thin_function
<
bool
(
const
GraphPartition
&
graph_partition
)
>
;
using
ProblemFilter
=
thin_function
<
bool
(
const
Problem
&
)
>
;
ProfilingBasedSolver
(
std
::
unique_ptr
<
ProfilerBase
>
profiler
);
/*!
* \note some graph partition (for example, graph partition without format
* aware operators like conv, deconv, warp, resize etc.) will be filtered by
* the
GraphPartition
Filter, which can reduce the profiling time. */
* the
Problem
Filter, which can reduce the profiling time. */
ProfilingBasedSolver
(
std
::
unique_ptr
<
ProfilerBase
>
profiler
,
GraphPartitionFilter
graph_partition_filter
)
std
::
unique_ptr
<
ProfilerBase
>
profiler
,
ProblemFilter
problem_filter
)
:
m_profiler
{
std
::
move
(
profiler
)},
m_
graph_partition_filter
{
std
::
move
(
graph_partition
_filter
)}
{}
m_
problem_filter
{
std
::
move
(
problem
_filter
)}
{}
virtual
~
ProfilingBasedSolver
()
=
default
;
Solution
solve
(
const
Problem
&
problem
)
const
override
;
virtual
Solution
do_solve
(
const
Problem
&
problem
)
const
=
0
;
...
...
@@ -69,7 +67,7 @@ protected:
std
::
unique_ptr
<
ProfilerBase
>
m_profiler
;
private:
GraphPartitionFilter
m_graph_partition
_filter
;
ProblemFilter
m_problem
_filter
;
};
/*!
...
...
@@ -81,10 +79,8 @@ public:
DynamicProgrammingSolver
(
std
::
unique_ptr
<
ProfilerBase
>
profiler
)
:
ProfilingBasedSolver
(
std
::
move
(
profiler
)){};
DynamicProgrammingSolver
(
std
::
unique_ptr
<
ProfilerBase
>
profiler
,
GraphPartitionFilter
graph_partition_filter
)
:
ProfilingBasedSolver
(
std
::
move
(
profiler
),
std
::
move
(
graph_partition_filter
)){};
std
::
unique_ptr
<
ProfilerBase
>
profiler
,
ProblemFilter
problem_filter
)
:
ProfilingBasedSolver
(
std
::
move
(
profiler
),
std
::
move
(
problem_filter
)){};
~
DynamicProgrammingSolver
()
noexcept
=
default
;
Solution
do_solve
(
const
Problem
&
problem
)
const
override
;
bool
can_solve
(
const
Problem
&
problem
)
const
override
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录