Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
cdc44a54
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
cdc44a54
编写于
10月 12, 2022
作者:
S
sunli
提交者:
GitHub
10月 12, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix wz review (#46937)
* fix wz review * update code
上级
acdaa4fb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
46 addition
and
56 deletion
+46
-56
paddle/fluid/framework/paddle2cinn/cinn_subgraph_detector.cc
paddle/fluid/framework/paddle2cinn/cinn_subgraph_detector.cc
+15
-45
paddle/fluid/framework/paddle2cinn/cinn_subgraph_detector.h
paddle/fluid/framework/paddle2cinn/cinn_subgraph_detector.h
+31
-11
未找到文件。
paddle/fluid/framework/paddle2cinn/cinn_subgraph_detector.cc
浏览文件 @
cdc44a54
...
...
@@ -50,46 +50,16 @@ std::unordered_set<Node*> GetConsumerOps(Node* node) {
return
consumers
;
}
struct
Hasher
{
size_t
operator
()(
const
CinnSubGraphPtr
&
subgraph
)
const
noexcept
{
return
std
::
hash
<
uint64_t
>
()(
reinterpret_cast
<
uint64_t
>
(
subgraph
.
get
()));
}
};
struct
Comparator
{
bool
operator
()(
const
CinnSubGraphPtr
&
first
,
const
CinnSubGraphPtr
&
second
)
const
noexcept
{
return
first
.
get
()
==
second
.
get
();
}
};
struct
CinnSubGraph
{
using
CinnSubGraphPtr
=
std
::
shared_ptr
<
CinnSubGraph
>
;
// construct function
CinnSubGraph
()
{}
// construct function
CinnSubGraph
(
Node
*
op
,
bool
subst
)
:
substitute
(
subst
)
{
Insert
(
op
);
}
void
CinnSubGraph
::
Insert
(
Node
*
op
)
{
nodes
.
push_back
(
op
);
node_set
.
insert
(
op
);
void
Insert
(
Node
*
op
)
{
nodes
.
push_back
(
op
);
node_set
.
insert
(
op
);
auto
producers
=
GetProducerOps
(
op
);
for
(
auto
producer
:
producers
)
{
input_nodes
.
insert
(
producer
);
}
input_nodes
.
erase
(
op
);
auto
producers
=
GetProducerOps
(
op
);
for
(
auto
producer
:
producers
)
{
input_nodes
.
insert
(
producer
);
}
int
depth
{
0
};
int
max_depth
{
0
},
min_depth
{
INT_MAX
};
bool
substitute
{
true
};
std
::
vector
<
Node
*>
nodes
;
std
::
unordered_set
<
Node
*>
node_set
;
std
::
unordered_set
<
Node
*>
input_nodes
;
std
::
unordered_set
<
CinnSubGraphPtr
,
Hasher
,
Comparator
>
producers
;
std
::
unordered_set
<
CinnSubGraphPtr
,
Hasher
,
Comparator
>
consumers
;
};
input_nodes
.
erase
(
op
);
}
void
CinnSubgraphDetector
::
DoOpFusion
()
{
// sort node from input to output
...
...
@@ -183,7 +153,7 @@ void CinnSubgraphDetector::DoSubGraphFusion() {
continue
;
}
// do fusion
update
|=
FuseSubGraph
(
&
subgraph
);
update
|=
FuseSubGraph
(
subgraph
);
}
if
(
!
update
)
{
break
;
...
...
@@ -191,8 +161,8 @@ void CinnSubgraphDetector::DoSubGraphFusion() {
}
}
bool
CinnSubgraphDetector
::
FuseSubGraph
(
CinnSubGraphPtr
*
subgraph_ptr
)
{
auto
producer
=
*
subgraph_ptr
;
bool
CinnSubgraphDetector
::
FuseSubGraph
(
CinnSubGraphPtr
subgraph_ptr
)
{
auto
producer
=
subgraph_ptr
;
auto
&
consumers
=
producer
->
consumers
;
std
::
vector
<
CinnSubGraphPtr
>
candidates
;
for
(
auto
&
consumer
:
consumers
)
{
...
...
@@ -276,11 +246,11 @@ bool CinnSubgraphDetector::FuseSubGraph(CinnSubGraphPtr* subgraph_ptr) {
bool
CinnSubgraphDetector
::
IsDependency
(
const
CinnSubGraphPtr
&
producer_g
,
const
CinnSubGraphPtr
&
consumer
,
const
std
::
unordered_set
<
CinnSubGraphPtr
,
Hasher
,
Comparator
>&
consumers
)
{
const
std
::
unordered_set
<
CinnSubGraphPtr
>&
consumers
)
{
std
::
queue
<
CinnSubGraphPtr
>
candidates
;
candidates
.
push
(
consumer
);
std
::
unordered_set
<
CinnSubGraphPtr
,
Hasher
,
Comparator
>
visited_set
;
std
::
unordered_set
<
CinnSubGraphPtr
>
visited_set
;
while
(
!
candidates
.
empty
())
{
auto
&
candidate
=
candidates
.
front
();
candidates
.
pop
();
...
...
@@ -303,12 +273,12 @@ bool CinnSubgraphDetector::IsDependency(
bool
CinnSubgraphDetector
::
IsDependencySimplify
(
const
CinnSubGraphPtr
&
producer_g
,
const
CinnSubGraphPtr
&
consumer
,
const
std
::
unordered_set
<
CinnSubGraphPtr
,
Hasher
,
Comparator
>&
consumers
)
{
const
std
::
unordered_set
<
CinnSubGraphPtr
>&
consumers
)
{
std
::
queue
<
CinnSubGraphPtr
>
candidates
;
candidates
.
push
(
consumer
);
// check upper bound.
int
check_upper_depth
=
producer_g
->
max_depth
;
std
::
unordered_set
<
CinnSubGraphPtr
,
Hasher
,
Comparator
>
visited_set
;
std
::
unordered_set
<
CinnSubGraphPtr
>
visited_set
;
while
(
!
candidates
.
empty
())
{
auto
&
candidate
=
candidates
.
front
();
candidates
.
pop
();
...
...
paddle/fluid/framework/paddle2cinn/cinn_subgraph_detector.h
浏览文件 @
cdc44a54
...
...
@@ -31,10 +31,32 @@ namespace paddle2cinn {
using
Node
=
ir
::
Node
;
using
Graph
=
ir
::
Graph
;
struct
Hasher
;
struct
Comparator
;
/*
*
*
*/
struct
CinnSubGraph
;
using
CinnSubGraphPtr
=
std
::
shared_ptr
<
CinnSubGraph
>
;
struct
CinnSubGraph
{
// construct function
CinnSubGraph
()
{}
// construct function
CinnSubGraph
(
Node
*
op
,
bool
subst
)
:
substitute
(
subst
)
{
Insert
(
op
);
}
void
Insert
(
Node
*
op
);
int
depth
{
0
};
int
max_depth
{
0
};
int
min_depth
{
INT_MAX
};
bool
substitute
{
true
};
std
::
vector
<
Node
*>
nodes
;
std
::
unordered_set
<
Node
*>
node_set
;
std
::
unordered_set
<
Node
*>
input_nodes
;
std
::
unordered_set
<
CinnSubGraphPtr
>
producers
;
std
::
unordered_set
<
CinnSubGraphPtr
>
consumers
;
};
/*
* Detect the nodes in a subgraph that meet some conditions. This class doesn't
* modify the graph.
...
...
@@ -55,16 +77,14 @@ class CinnSubgraphDetector {
void
BuildSubGraph
();
// SubGraph Fusion
void
DoSubGraphFusion
();
bool
FuseSubGraph
(
CinnSubGraphPtr
*
);
bool
FuseSubGraph
(
CinnSubGraphPtr
);
// check exist depency.
bool
IsDependency
(
const
CinnSubGraphPtr
&
,
const
CinnSubGraphPtr
&
,
const
std
::
unordered_set
<
CinnSubGraphPtr
,
Hasher
,
Comparator
>
&
);
bool
IsDependencySimplify
(
const
CinnSubGraphPtr
&
,
const
CinnSubGraphPtr
&
,
const
std
::
unordered_set
<
CinnSubGraphPtr
,
Hasher
,
Comparator
>
&
);
bool
IsDependency
(
const
CinnSubGraphPtr
&
,
const
CinnSubGraphPtr
&
,
const
std
::
unordered_set
<
CinnSubGraphPtr
>
&
);
bool
IsDependencySimplify
(
const
CinnSubGraphPtr
&
,
const
CinnSubGraphPtr
&
,
const
std
::
unordered_set
<
CinnSubGraphPtr
>
&
);
private:
Graph
*
graph_
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录