Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
5ec2fb0c
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5ec2fb0c
编写于
8月 31, 2018
作者:
N
nhzlx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add flexibledfs for find path between two nodes
上级
af15f6f0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
111 addition
and
0 deletion
+111
-0
paddle/fluid/inference/analysis/data_flow_graph.cc
paddle/fluid/inference/analysis/data_flow_graph.cc
+37
-0
paddle/fluid/inference/analysis/data_flow_graph.h
paddle/fluid/inference/analysis/data_flow_graph.h
+3
-0
paddle/fluid/inference/analysis/data_flow_graph_tester.cc
paddle/fluid/inference/analysis/data_flow_graph_tester.cc
+71
-0
未找到文件。
paddle/fluid/inference/analysis/data_flow_graph.cc
浏览文件 @
5ec2fb0c
...
...
@@ -480,6 +480,8 @@ void FilterRedundantOutputOfSubGraph(DataFlowGraph *graph) {
for
(
auto
*
out
:
op_nodes
[
i
]
->
outlinks
)
{
if
(
follow_up_input_names
.
count
(
out
->
name
()))
{
filtered_subgraph_outlinks
.
push_back
(
out
);
}
else
{
out
->
SetDeleted
();
}
}
PADDLE_ENFORCE_GE
(
filtered_subgraph_outlinks
.
size
(),
1UL
);
...
...
@@ -487,6 +489,41 @@ void FilterRedundantOutputOfSubGraph(DataFlowGraph *graph) {
}
}
void
FlexibleDFS
(
const
std
::
vector
<
Node
*>
&
source
,
bool
reverse
,
const
std
::
function
<
bool
(
const
Node
*
)
>
&
enter
,
const
std
::
function
<
bool
(
const
Node
*
)
>
&
leave
)
{
typedef
struct
{
const
Node
*
node
;
bool
leave
;
}
FNode
;
std
::
vector
<
FNode
>
stack
;
for
(
auto
&
node
:
source
)
{
stack
.
push_back
(
FNode
{
node
,
false
});
}
std
::
unordered_set
<
const
Node
*>
visited
;
while
(
!
stack
.
empty
())
{
auto
fnode
=
stack
.
back
();
stack
.
pop_back
();
if
(
fnode
.
leave
)
{
if
(
leave
&&
!
leave
(
fnode
.
node
))
return
;
}
if
(
visited
.
count
(
fnode
.
node
))
continue
;
visited
.
insert
(
fnode
.
node
);
if
(
enter
&&
!
enter
(
fnode
.
node
))
return
;
if
(
leave
)
stack
.
push_back
(
FNode
{
fnode
.
node
,
true
});
const
std
::
vector
<
Node
*>
iter_nodes
=
reverse
==
true
?
fnode
.
node
->
inlinks
:
fnode
.
node
->
outlinks
;
for
(
const
Node
*
node
:
iter_nodes
)
{
if
(
!
visited
.
count
(
node
))
{
stack
.
push_back
(
FNode
{
node
,
false
});
}
}
}
}
}
// namespace analysis
}
// namespace inference
}
// namespace paddle
paddle/fluid/inference/analysis/data_flow_graph.h
浏览文件 @
5ec2fb0c
...
...
@@ -204,6 +204,9 @@ std::pair<std::vector<Node *>, std::vector<Node *>>
ExtractInputAndOutputOfSubGraph
(
std
::
vector
<
Node
*>
&
graph
);
// NOLINT
void
FilterRedundantOutputOfSubGraph
(
DataFlowGraph
*
graph
);
void
FlexibleDFS
(
const
std
::
vector
<
Node
*>
&
source
,
bool
reverse
,
const
std
::
function
<
bool
(
const
Node
*
)
>
&
enter
,
const
std
::
function
<
bool
(
const
Node
*
)
>
&
leave
);
}
// namespace analysis
}
// namespace inference
}
// namespace paddle
paddle/fluid/inference/analysis/data_flow_graph_tester.cc
浏览文件 @
5ec2fb0c
...
...
@@ -160,6 +160,77 @@ TEST(DataFlowGraph, Build_IR_Graph) {
ASSERT_EQ
(
graph
.
nodes
.
size
(),
ir_graph
.
Nodes
().
size
());
}
// FlexibleDFS
/*
* Graph topology
* inputs: 0
* 0 -> 1
* 1 -> 2
* 1 -> 3
* 3 -> 4
* 4 -> 5
* 5 -> 2
*/
TEST
(
DataFlowGraph
,
flexibledfs
)
{
DataFlowGraph
graph
;
for
(
int
i
=
0
;
i
<
6
;
i
++
)
{
auto
*
node
=
graph
.
nodes
.
Create
(
Node
::
Type
::
kValue
);
node
->
SetName
(
"node-"
+
std
::
to_string
(
i
));
}
auto
add_link
=
[
&
](
int
i
,
int
j
)
{
Node
*
source
=
graph
.
nodes
.
GetMutable
(
i
);
Node
*
target
=
graph
.
nodes
.
GetMutable
(
j
);
target
->
inlinks
.
push_back
(
source
);
source
->
outlinks
.
push_back
(
target
);
};
add_link
(
0
,
1
);
add_link
(
1
,
2
);
add_link
(
1
,
3
);
add_link
(
3
,
4
);
add_link
(
4
,
5
);
add_link
(
5
,
2
);
graph
.
Build
();
std
::
vector
<
const
Node
*>
order
;
FlexibleDFS
(
graph
.
inputs
(),
false
,
nullptr
,
[
&
order
](
const
Node
*
n
)
{
order
.
push_back
(
n
);
return
true
;
});
ASSERT_EQ
(
order
.
size
(),
6UL
);
order
.
clear
();
// reverse dfs
FlexibleDFS
(
graph
.
outputs
(),
true
,
nullptr
,
[
&
order
](
const
Node
*
n
)
{
order
.
push_back
(
n
);
return
true
;
});
ASSERT_EQ
(
order
.
size
(),
6UL
);
// If we delete
Node
*
last_node
=
graph
.
nodes
.
GetMutable
(
2
);
Node
*
direct_node
=
graph
.
nodes
.
GetMutable
(
1
);
std
::
vector
<
Node
*>
source_nodes
;
for
(
Node
*
node
:
last_node
->
inlinks
)
{
if
(
node
!=
direct_node
)
source_nodes
.
push_back
(
node
);
}
bool
has_cycle
=
false
;
FlexibleDFS
(
source_nodes
,
true
,
nullptr
,
[
&
has_cycle
,
direct_node
](
const
Node
*
n
)
{
if
(
n
==
direct_node
)
{
has_cycle
=
true
;
return
false
;
}
return
true
;
});
ASSERT_TRUE
(
has_cycle
);
}
}
// namespace analysis
}
// namespace inference
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录