Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Oneflow-Inc
oneflow
提交
d28e2ad5
O
oneflow
项目概览
Oneflow-Inc
/
oneflow
上一次同步 接近 3 年
通知
13
Star
2733
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
oneflow
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d28e2ad5
编写于
3月 24, 2019
作者:
S
ShawnXuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
get longest path
Former-commit-id: 7628e866e8246f41960c5b03e1fa92376fb661c7
上级
0f40d420
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
54 addition
and
14 deletion
+54
-14
oneflow/core/graph/logical_graph.cpp
oneflow/core/graph/logical_graph.cpp
+46
-10
oneflow/core/graph/logical_graph.h
oneflow/core/graph/logical_graph.h
+6
-2
oneflow/core/graph/node.h
oneflow/core/graph/node.h
+2
-2
未找到文件。
oneflow/core/graph/logical_graph.cpp
浏览文件 @
d28e2ad5
...
...
@@ -114,7 +114,7 @@ void LogicalGraph::BuildFwStruct() {
NaiveBuildFwStruct
(
&
op_name2nodes
);
FixSharedModelNodes
(
op_name2nodes
);
LinkUnpackFw2PackFw
(
op_name2nodes
);
SetDepth4Nodes
();
SetDepth
AndBranchId
4Nodes
();
total_mbn_num_
=
0
;
ForEachNode
([
&
](
LogicalNode
*
node
)
{
total_mbn_num_
+=
...
...
@@ -173,7 +173,7 @@ void LogicalGraph::NaiveBuildFwStruct(
});
}
void
LogicalGraph
::
SetDepth4Nodes
()
{
void
LogicalGraph
::
SetDepth
AndBranchId
4Nodes
()
{
auto
ForEachInNode
=
[
&
](
LogicalNode
*
node
,
const
std
::
function
<
void
(
LogicalNode
*
)
>&
Handler
)
{
node
->
ForEachNodeOnInEdge
([
&
](
LogicalNode
*
node_on_in_edge
)
{
Handler
(
node_on_in_edge
);
});
};
...
...
@@ -181,21 +181,23 @@ void LogicalGraph::SetDepth4Nodes() {
node
->
ForEachNodeOnOutEdge
([
&
](
LogicalNode
*
node_on_out_edge
)
{
Handler
(
node_on_out_edge
);
});
};
HashMap
<
LogicalNode
*
,
bool
>
has_handled
;
HashMap
<
LogicalNode
*
,
bool
>
has_queued
;
std
::
queue
<
LogicalNode
*>
queue
;
std
::
list
<
LogicalNode
*>
starts
;
ForEachLogicalNode
<
LogicalNode
>
([
&
](
LogicalNode
*
node
)
{
if
(
node
->
in_edges
().
size
()
<
1
)
starts
.
push_back
(
node
);
});
// set depth for nodes
HashMap
<
LogicalNode
*
,
bool
>
has_handled
;
HashMap
<
LogicalNode
*
,
bool
>
has_queued
;
std
::
queue
<
LogicalNode
*>
queue
;
for
(
LogicalNode
*
start
:
starts
)
{
queue
.
push
(
start
);
has_queued
[
start
]
=
true
;
has_handled
[
start
]
=
false
;
}
int
max_depth
=
0
;
while
(
!
queue
.
empty
())
{
LogicalNode
*
cur_node
=
queue
.
front
();
queue
.
pop
();
...
...
@@ -206,6 +208,7 @@ void LogicalGraph::SetDepth4Nodes() {
if
(
!
has_handled
[
in_node
])
need_push
=
true
;
});
cur_node
->
set_depth
(
max_in_nodes_depth
+
1
);
if
(
max_depth
<
max_in_nodes_depth
+
1
)
max_depth
=
max_in_nodes_depth
+
1
;
if
(
need_push
)
queue
.
push
(
cur_node
);
else
...
...
@@ -220,11 +223,44 @@ void LogicalGraph::SetDepth4Nodes() {
});
}
}
// ForEachLogicalNode<LogicalNode>([&](LogicalNode* node) {
// LOG(INFO) << node->op_vec().at(0)->op_name() << " " << node->depth();
// });
ForEachLogicalNode
<
LogicalNode
>
([
&
](
LogicalNode
*
node
)
{
LOG
(
INFO
)
<<
node
->
op_vec
().
at
(
0
)
->
op_name
()
<<
" "
<<
node
->
depth
();
});
// set branch id for nodes
// 1. get longest path
std
::
stack
<
LogicalNode
*>
longest_path_stack
;
for
(
LogicalNode
*
start
:
starts
)
{
ASSERT_TRUE
(
longest_path_stack
.
empty
());
if
(
GetLongestPath
<
LogicalNode
>
(
start
,
max_depth
,
longest_path_stack
,
ForEachOutNode
))
{
break
;
}
}
LOG
(
INFO
)
<<
"longest path size "
<<
max_depth
<<
" "
<<
longest_path_stack
.
size
();
while
(
!
longest_path_stack
.
empty
())
{
LogicalNode
*
node
=
longest_path_stack
.
top
();
longest_path_stack
.
pop
();
LOG
(
INFO
)
<<
node
->
op_vec
().
at
(
0
)
->
op_name
()
<<
" "
<<
node
->
depth
();
}
}
template
<
typename
NodeType
>
bool
LogicalGraph
::
GetLongestPath
(
LogicalNode
*
start
,
int
max_depth
,
std
::
stack
<
NodeType
*>&
longest_path_stack
,
const
std
::
function
<
void
(
NodeType
*
,
const
std
::
function
<
void
(
NodeType
*
)
>&
)
>&
ForEachOutNode
)
{
longest_path_stack
.
push
(
start
);
if
(
start
->
depth
()
==
max_depth
)
return
true
;
bool
get_it
=
false
;
ForEachOutNode
(
start
,
[
&
](
NodeType
*
out_node
)
{
if
(
!
get_it
)
{
if
(
start
->
depth
()
+
1
==
out_node
->
depth
())
get_it
=
GetLongestPath
<
NodeType
>
(
out_node
,
max_depth
,
longest_path_stack
,
ForEachOutNode
);
}
});
if
(
!
get_it
)
longest_path_stack
.
pop
();
return
get_it
;
}
void
LogicalGraph
::
FixSharedModelNodes
(
const
HashMap
<
std
::
string
,
std
::
vector
<
LogicalNode
*>>&
op_name2nodes
)
{
HashSet
<
std
::
string
>
all_shared_model_op_names
;
...
...
oneflow/core/graph/logical_graph.h
浏览文件 @
d28e2ad5
...
...
@@ -40,8 +40,6 @@ class LogicalGraph final : public Graph<LogicalNode, LogicalEdge> {
void
BuildFwStruct
();
void
NaiveBuildFwStruct
(
HashMap
<
std
::
string
,
std
::
vector
<
LogicalNode
*>>*
op_name2nodes
);
void
SetDepth4Nodes
();
void
SetBranchId4Nodes
();
void
FixSharedModelNodes
(
const
HashMap
<
std
::
string
,
std
::
vector
<
LogicalNode
*>>&
op_name2nodes
);
void
LinkUnpackFw2PackFw
(
const
HashMap
<
std
::
string
,
std
::
vector
<
LogicalNode
*>>&
op_name2nodes
);
void
ReConnectToFwClone
(
LogicalNode
*
clone_node
,
const
LogicalBlobId
&
lbi
,
...
...
@@ -74,6 +72,12 @@ class LogicalGraph final : public Graph<LogicalNode, LogicalEdge> {
bool
MustHaveModelDiffAcc
();
void
SetDepthAndBranchId4Nodes
();
template
<
typename
NodeType
>
bool
GetLongestPath
(
LogicalNode
*
start
,
int
max_depth
,
std
::
stack
<
NodeType
*>&
longest_path_stack
,
const
std
::
function
<
void
(
NodeType
*
,
const
std
::
function
<
void
(
NodeType
*
)
>&
)
>&
ForEachOutNode
);
int64_t
total_mbn_num_
;
std
::
vector
<
std
::
vector
<
const
LogicalNode
*>>
fw_node_groups_
;
...
...
oneflow/core/graph/node.h
浏览文件 @
d28e2ad5
...
...
@@ -112,8 +112,8 @@ class Node {
HashSet
<
EdgeType
*>
in_edges_
;
HashSet
<
EdgeType
*>
out_edges_
;
int
depth_
=
0
;
// 4 visualization
int
branch_id_
=
0
;
// 4 visualization
int
depth_
=
0
;
// 4 visualization
int
branch_id_
=
0
;
// 4 visualization
};
}
// namespace oneflow
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录