Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
5fe7cd14
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看板
提交
5fe7cd14
编写于
3月 28, 2020
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mge/jit): fix typo InternalGraphGenerator
GitOrigin-RevId: 1ab14acbd23181963322a724a7e2ea1cdda09629
上级
80d3a06f
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
28 addition
and
28 deletion
+28
-28
src/jit/impl/fusion_pass.cpp
src/jit/impl/fusion_pass.cpp
+11
-11
src/jit/impl/internal_graph.cpp
src/jit/impl/internal_graph.cpp
+8
-8
src/jit/include/megbrain/jit/internal_graph.h
src/jit/include/megbrain/jit/internal_graph.h
+3
-3
src/jit/test/codegen.cpp
src/jit/test/codegen.cpp
+2
-2
src/jit/test/fusion.cpp
src/jit/test/fusion.cpp
+3
-3
src/jit/test/helper.cpp
src/jit/test/helper.cpp
+1
-1
未找到文件。
src/jit/impl/fusion_pass.cpp
浏览文件 @
5fe7cd14
...
...
@@ -33,16 +33,16 @@ class JITFusionPass::Impl final {
CompNode
::
UnorderedMap
<
size_t
>
m_cn2max_nr_input
;
SubGraph
::
Rewriter
m_rewriter
;
SmallVector
<
std
::
unique_ptr
<
InternalGraphGenrator
>>
m_igraph_gen_storage
;
ThinHashMap
<
VarNode
*
,
InternalGraphGenrator
*>
m_var2igraph_gen
;
SmallVector
<
std
::
unique_ptr
<
InternalGraphGen
e
rator
>>
m_igraph_gen_storage
;
ThinHashMap
<
VarNode
*
,
InternalGraphGen
e
rator
*>
m_var2igraph_gen
;
//! map from var to its reader oprs and the corresponding dependency types
ThinHashMap
<
VarNode
*
,
SmallVector
<
std
::
pair
<
OperatorNodeBase
*
,
DepType
>>>
m_var_readers
;
ThinHashSet
<
VarNode
*>
m_endpoint_set
;
//! create a new InternalGraphGenrator rooted at given opr
InternalGraphGenrator
*
create_new_igraph_gen
(
OperatorNodeBase
*
opr
);
//! create a new InternalGraphGen
e
rator rooted at given opr
InternalGraphGen
e
rator
*
create_new_igraph_gen
(
OperatorNodeBase
*
opr
);
//! process a single operator, maintaining m_var2igraph_gen
void
process_opr
(
OperatorNodeBase
*
opr
);
...
...
@@ -51,11 +51,11 @@ class JITFusionPass::Impl final {
//! check whether all oprs which depend on the var are in i_graph
bool
test_all_readers_in_the_graph
(
VarNode
*
var
,
InternalGraphGenrator
*
i_graph
);
InternalGraphGen
e
rator
*
i_graph
);
//! check shape to determine whether the opr should be added to the internal
//! graph
bool
check_shape
(
cg
::
OperatorNodeBase
*
opr
,
InternalGraphGenrator
*
i_graph
);
bool
check_shape
(
cg
::
OperatorNodeBase
*
opr
,
InternalGraphGen
e
rator
*
i_graph
);
//! use m_rewriter to update graph
void
update_graph
();
...
...
@@ -155,7 +155,7 @@ void JITFusionPass::Impl::update_graph() {
}
bool
JITFusionPass
::
Impl
::
test_all_readers_in_the_graph
(
VarNode
*
var
,
InternalGraphGenrator
*
ig_gen
)
{
VarNode
*
var
,
InternalGraphGen
e
rator
*
ig_gen
)
{
for
(
auto
&&
reader
:
m_var_readers
.
at
(
var
))
{
if
(
reader
.
second
&
DepType
::
DEV_VALUE
)
{
if
(
ig_gen
->
opr_set
().
count
(
reader
.
first
)
==
0
)
{
...
...
@@ -167,7 +167,7 @@ bool JITFusionPass::Impl::test_all_readers_in_the_graph(
}
bool
JITFusionPass
::
Impl
::
check_shape
(
cg
::
OperatorNodeBase
*
opr
,
InternalGraphGenrator
*
ig_gen
)
{
InternalGraphGen
e
rator
*
ig_gen
)
{
if
(
!
cg
::
is_static_var_shape
(
opr
->
output
(
0
)))
{
// currently we do not handle dynamic shape in JIT
return
false
;
...
...
@@ -249,9 +249,9 @@ bool JITFusionPass::Impl::check_shape(cg::OperatorNodeBase* opr,
}
}
InternalGraphGenrator
*
JITFusionPass
::
Impl
::
create_new_igraph_gen
(
InternalGraphGen
e
rator
*
JITFusionPass
::
Impl
::
create_new_igraph_gen
(
OperatorNodeBase
*
opr
)
{
auto
uptr
=
std
::
make_unique
<
InternalGraphGenrator
>
(
opr
);
auto
uptr
=
std
::
make_unique
<
InternalGraphGen
e
rator
>
(
opr
);
auto
ptr
=
uptr
.
get
();
m_igraph_gen_storage
.
emplace_back
(
std
::
move
(
uptr
));
m_var2igraph_gen
[
opr
->
output
(
0
)]
=
ptr
;
...
...
@@ -267,7 +267,7 @@ void JITFusionPass::Impl::process_opr(OperatorNodeBase* opr) {
}
// dimshuffle should not be an endpoint, because megbrain has lazy
// dimshuffle machanism
InternalGraphGenrator
*
ig_gen
=
nullptr
;
InternalGraphGen
e
rator
*
ig_gen
=
nullptr
;
if
(
m_var2igraph_gen
.
count
(
opr
->
output
(
0
))
==
0
)
{
// because of the reverse traversal, when an operator is being
// processed but not in m_var2igraph_gen, means it is a endpoint of a
...
...
src/jit/impl/internal_graph.cpp
浏览文件 @
5fe7cd14
...
...
@@ -81,12 +81,12 @@ InternalGraphPtr expand_executor_opr(const InternalGraphPtr& prev_igraph) {
}
// namespace
InternalGraphGen
rator
::
InternalGraphGen
rator
(
cg
::
OperatorNodeBase
*
opr
)
InternalGraphGen
erator
::
InternalGraphGene
rator
(
cg
::
OperatorNodeBase
*
opr
)
:
m_output
{
opr
->
output
(
0
)}
{
add_opr
(
opr
);
}
VarNode
*
InternalGraphGenrator
::
replace_graph_by_placeholder
()
{
VarNode
*
InternalGraphGen
e
rator
::
replace_graph_by_placeholder
()
{
ThinHashMap
<
VarNode
*
,
VarNode
*>
old2new
;
auto
cpu_default
=
CompNode
::
default_cpu
();
auto
igraph_copy_opr_shallow
=
[
cpu_default
](
OperatorNodeBase
*
opr
,
...
...
@@ -163,7 +163,7 @@ VarNode* InternalGraphGenrator::replace_graph_by_placeholder() {
return
old2new
.
at
(
m_output
);
}
InternalGraphPtr
InternalGraphGenrator
::
generate
()
{
InternalGraphPtr
InternalGraphGen
e
rator
::
generate
()
{
m_input_idx
=
0
;
auto
new_nd
=
replace_graph_by_placeholder
();
...
...
@@ -172,7 +172,7 @@ InternalGraphPtr InternalGraphGenrator::generate() {
return
expand_executor_opr
(
igraph
);
}
size_t
InternalGraphGenrator
::
get_cnt_input_if_add
(
size_t
InternalGraphGen
e
rator
::
get_cnt_input_if_add
(
cg
::
OperatorNodeBase
*
opr
)
const
{
// minus 1 first because this opr should be removed from subgraph's input
size_t
new_cnt_input
=
m_graph_input_set
.
size
()
-
1
;
...
...
@@ -183,7 +183,7 @@ size_t InternalGraphGenrator::get_cnt_input_if_add(
return
new_cnt_input
;
}
void
InternalGraphGenrator
::
add_opr
(
cg
::
OperatorNodeBase
*
opr
)
{
void
InternalGraphGen
e
rator
::
add_opr
(
cg
::
OperatorNodeBase
*
opr
)
{
if
(
m_opr_set
.
count
(
opr
))
{
// ignore duplicated oprs (which occur in tests)
return
;
...
...
@@ -253,7 +253,7 @@ void InternalGraphGenrator::add_opr(cg::OperatorNodeBase* opr) {
}
}
void
InternalGraphGenrator
::
find_reduce_opr_deps
(
cg
::
OperatorNodeBase
*
opr
)
{
void
InternalGraphGen
e
rator
::
find_reduce_opr_deps
(
cg
::
OperatorNodeBase
*
opr
)
{
mgb_assert
(
opr
->
same_type
<
opr
::
Reduce
>
()
||
(
opr
->
same_type
<
jit
::
JITExecutor
>
()
&&
try_cast_as_op
<
jit
::
JITExecutor
>
(
opr
)
->
has_reduce
()));
...
...
@@ -264,7 +264,7 @@ void InternalGraphGenrator::find_reduce_opr_deps(cg::OperatorNodeBase* opr) {
cg
::
DepOprIter
{
cb
}.
add
(
opr
);
}
void
InternalGraphGenrator
::
find_oprs_depended_by_dimshuffle
(
void
InternalGraphGen
e
rator
::
find_oprs_depended_by_dimshuffle
(
cg
::
OperatorNodeBase
*
dimshuffle
)
{
mgb_assert
(
dimshuffle
->
same_type
<
opr
::
Dimshuffle
>
()
||
...
...
@@ -287,7 +287,7 @@ void InternalGraphGenrator::find_oprs_depended_by_dimshuffle(
cg
::
DepOprIter
{
cb
}.
add
(
dimshuffle
);
}
PlaceholderArray
InternalGraphGenrator
::
to_placeholder_opr_arr
(
PlaceholderArray
InternalGraphGen
e
rator
::
to_placeholder_opr_arr
(
const
VarNodeArray
&
vars
)
{
PlaceholderArray
ret
(
vars
.
size
());
for
(
size_t
i
=
0
;
i
<
vars
.
size
();
++
i
)
{
...
...
src/jit/include/megbrain/jit/internal_graph.h
浏览文件 @
5fe7cd14
...
...
@@ -76,12 +76,12 @@ private:
* This object stores intermediate state during visiting the computing graph in
* JITFusionPass.
*
* The graph is iterated in reverse topological order. InternalGraphGenrator
* The graph is iterated in reverse topological order. InternalGraphGen
e
rator
* starts with a single operator (i.e. the output node of the fused opr), and
* new oprs are gradually added into it. Thus the process is expanding a tree
* rooted at the output node.
*/
class
InternalGraphGenrator
{
class
InternalGraphGen
e
rator
{
//! replace oprs in the graph of m_output and populate m_orig_inps,
//! m_placeholders
VarNode
*
replace_graph_by_placeholder
();
...
...
@@ -95,7 +95,7 @@ class InternalGraphGenrator {
void
find_oprs_depended_by_dimshuffle
(
cg
::
OperatorNodeBase
*
opr
);
public:
explicit
InternalGraphGenrator
(
cg
::
OperatorNodeBase
*
opr
);
explicit
InternalGraphGen
e
rator
(
cg
::
OperatorNodeBase
*
opr
);
//! generate the graph; this method can be called multiple times
InternalGraphPtr
generate
();
...
...
src/jit/test/codegen.cpp
浏览文件 @
5fe7cd14
...
...
@@ -54,7 +54,7 @@ void run<simple>(Backend backend, CompNode cn) {
VarNodeArray
inputs
{
a
.
node
(),
b
.
node
(),
c
.
node
()},
outputs
{
y
.
node
()};
auto
ig_gen
=
std
::
make_unique
<
InternalGraphGenrator
>
(
y
.
node
()
->
owner_opr
());
std
::
make_unique
<
InternalGraphGen
e
rator
>
(
y
.
node
()
->
owner_opr
());
for
(
auto
i
:
get_rev_topo_order
(
y
))
{
if
(
!
i
->
same_type
<
opr
::
Host2DeviceCopy
>
())
{
...
...
@@ -91,7 +91,7 @@ void run<grad>(Backend backend, CompNode cn) {
VarNodeArray
inputs
{
a
.
node
(),
b
.
node
(),
c
.
node
()},
outputs
{
y
.
node
()};
auto
ig_gen
=
std
::
make_unique
<
InternalGraphGenrator
>
(
y
.
node
()
->
owner_opr
());
std
::
make_unique
<
InternalGraphGen
e
rator
>
(
y
.
node
()
->
owner_opr
());
for
(
auto
i
:
get_rev_topo_order
(
y
))
{
if
(
!
i
->
same_type
<
opr
::
Host2DeviceCopy
>
())
{
...
...
src/jit/test/fusion.cpp
浏览文件 @
5fe7cd14
...
...
@@ -540,7 +540,7 @@ void run<expand_jit_executor>(Backend backend, CompNode cn) {
auto
make_jit
=
[](
SymbolVar
target
,
const
SymbolVarArray
&
inputs
)
{
auto
y
=
target
.
node
();
auto
ig_gen
=
std
::
make_unique
<
InternalGraphGenrator
>
(
y
->
owner_opr
());
auto
ig_gen
=
std
::
make_unique
<
InternalGraphGen
e
rator
>
(
y
->
owner_opr
());
auto
inputs_vptr
=
cg
::
to_var_node_array
(
inputs
);
for
(
auto
i
:
get_rev_topo_order
(
target
,
{
inputs_vptr
.
begin
(),
inputs_vptr
.
end
()}))
{
...
...
@@ -830,9 +830,9 @@ TEST(TestJITFusionHalide, JITExecutor) {
y
=
opr
::
reduce_sum
(
a
+
b
,
shape_of_b
),
z
=
opr
::
reduce_sum
(
a
*
b
,
shape_of_a
);
auto
ig_gen_1
=
std
::
make_unique
<
InternalGraphGenrator
>
(
y
.
node
()
->
owner_opr
());
std
::
make_unique
<
InternalGraphGen
e
rator
>
(
y
.
node
()
->
owner_opr
());
auto
ig_gen_2
=
std
::
make_unique
<
InternalGraphGenrator
>
(
z
.
node
()
->
owner_opr
());
std
::
make_unique
<
InternalGraphGen
e
rator
>
(
z
.
node
()
->
owner_opr
());
{
ThinHashSet
<
VarNode
*>
nd_set
;
nd_set
.
insert
(
a
.
node
());
...
...
src/jit/test/helper.cpp
浏览文件 @
5fe7cd14
...
...
@@ -85,7 +85,7 @@ void FusionChecker::ensure_init_graph() {
SymbolVar
jit_y
;
if
(
m_direct_build
)
{
auto
ig_gen
=
std
::
make_unique
<
InternalGraphGenrator
>
(
auto
ig_gen
=
std
::
make_unique
<
InternalGraphGen
e
rator
>
(
m_truth_y
.
node
()
->
owner_opr
());
ThinHashSet
<
VarNode
*>
endpoints_set
;
for
(
size_t
i
=
0
;
i
<
m_nr_input
;
++
i
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录