Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Oneflow-Inc
oneflow
提交
b3135ba2
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,发现更多精彩内容 >>
提交
b3135ba2
编写于
3月 23, 2019
作者:
S
ShawnXuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SetDepth4Nodes
Former-commit-id: ebceff288f3cc978e122f93b473b4c3d49e32094
上级
fb6a9af8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
51 addition
and
4 deletion
+51
-4
oneflow/core/graph/logical_graph.cpp
oneflow/core/graph/logical_graph.cpp
+47
-2
oneflow/core/graph/node.h
oneflow/core/graph/node.h
+4
-2
未找到文件。
oneflow/core/graph/logical_graph.cpp
浏览文件 @
b3135ba2
...
...
@@ -112,9 +112,9 @@ void LogicalGraph::ForEachLogicalNode(std::function<void(LogicalNodeType*)> func
void
LogicalGraph
::
BuildFwStruct
()
{
HashMap
<
std
::
string
,
std
::
vector
<
LogicalNode
*>>
op_name2nodes
;
NaiveBuildFwStruct
(
&
op_name2nodes
);
SetDepth4Nodes
(
op_name2nodes
);
FixSharedModelNodes
(
op_name2nodes
);
LinkUnpackFw2PackFw
(
op_name2nodes
);
SetDepth4Nodes
(
op_name2nodes
);
total_mbn_num_
=
0
;
ForEachNode
([
&
](
LogicalNode
*
node
)
{
total_mbn_num_
+=
...
...
@@ -174,7 +174,52 @@ void LogicalGraph::NaiveBuildFwStruct(
}
void
LogicalGraph
::
SetDepth4Nodes
(
const
HashMap
<
std
::
string
,
std
::
vector
<
LogicalNode
*>>&
op_name2nodes
)
{}
const
HashMap
<
std
::
string
,
std
::
vector
<
LogicalNode
*>>&
op_name2nodes
)
{
HashMap
<
LogicalNode
*
,
bool
>
has_handled
;
std
::
queue
<
LogicalNode
*>
queue
;
std
::
list
<
LogicalNode
*>
starts
;
ForEachLogicalNode
<
RecordLoadLogicalNode
>
(
[
&
](
RecordLoadLogicalNode
*
node
)
{
starts
.
push_back
(
node
);
});
for
(
LogicalNode
*
start
:
starts
)
{
queue
.
push
(
start
);
has_handled
[
start
]
=
false
;
}
// int depth = 0;
auto
ForEachInNode
=
[
&
](
LogicalNode
*
node
,
const
std
::
function
<
void
(
LogicalNode
*
)
>&
Handler
)
{
node
->
ForEachNodeOnInEdge
([
&
](
LogicalNode
*
node_on_in_edge
)
{
Handler
(
node_on_in_edge
);
});
};
auto
ForEachOutNode
=
[
&
](
LogicalNode
*
node
,
const
std
::
function
<
void
(
LogicalNode
*
)
>&
Handler
)
{
node
->
ForEachNodeOnOutEdge
([
&
](
LogicalNode
*
node_on_out_edge
)
{
Handler
(
node_on_out_edge
);
});
};
while
(
!
queue
.
empty
())
{
LogicalNode
*
cur_node
=
queue
.
front
();
queue
.
pop
();
int
max_in_nodes_depth
=
0
;
bool
need_push
=
false
;
ForEachInNode
(
cur_node
,
[
&
](
LogicalNode
*
in_node
)
{
if
(
in_node
->
depth
()
>
max_in_nodes_depth
)
max_in_nodes_depth
=
in_node
->
depth
();
if
(
!
has_handled
[
in_node
])
need_push
=
true
;
});
cur_node
->
set_depth
(
max_in_nodes_depth
+
1
);
if
(
need_push
)
queue
.
push
(
cur_node
);
else
has_handled
[
cur_node
]
=
true
;
if
(
has_handled
[
cur_node
])
{
ForEachOutNode
(
cur_node
,
[
&
](
LogicalNode
*
out_node
)
{
queue
.
push
(
out_node
);
// has_handled[out_node] = false;
});
}
}
}
void
LogicalGraph
::
FixSharedModelNodes
(
const
HashMap
<
std
::
string
,
std
::
vector
<
LogicalNode
*>>&
op_name2nodes
)
{
...
...
oneflow/core/graph/node.h
浏览文件 @
b3135ba2
...
...
@@ -97,7 +97,9 @@ class Node {
virtual
std
::
string
VisualStr
()
const
{
return
""
;
}
int
depth
()
const
{
return
depth_
;
}
void
set_depth
(
const
int
val
)
{
depth_
=
val
;
}
void
set_depth
(
const
int
val
)
{
if
(
val
>
depth_
)
depth_
=
val
;
}
private:
friend
void
Connect
<
NodeType
,
EdgeType
>
(
NodeType
*
src_node
,
EdgeType
*
edge
,
NodeType
*
dst_node
);
...
...
@@ -107,7 +109,7 @@ class Node {
HashSet
<
EdgeType
*>
in_edges_
;
HashSet
<
EdgeType
*>
out_edges_
;
int
depth_
;
// 4 visualization
int
depth_
=
0
;
// 4 visualization
};
}
// namespace oneflow
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录