Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
cdc44a54
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
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) {
...
@@ -50,46 +50,16 @@ std::unordered_set<Node*> GetConsumerOps(Node* node) {
return
consumers
;
return
consumers
;
}
}
struct
Hasher
{
void
CinnSubGraph
::
Insert
(
Node
*
op
)
{
size_t
operator
()(
const
CinnSubGraphPtr
&
subgraph
)
const
noexcept
{
nodes
.
push_back
(
op
);
return
std
::
hash
<
uint64_t
>
()(
reinterpret_cast
<
uint64_t
>
(
subgraph
.
get
()));
node_set
.
insert
(
op
);
}
};
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
Insert
(
Node
*
op
)
{
auto
producers
=
GetProducerOps
(
op
);
nodes
.
push_back
(
op
);
for
(
auto
producer
:
producers
)
{
node_set
.
insert
(
op
);
input_nodes
.
insert
(
producer
);
auto
producers
=
GetProducerOps
(
op
);
for
(
auto
producer
:
producers
)
{
input_nodes
.
insert
(
producer
);
}
input_nodes
.
erase
(
op
);
}
}
input_nodes
.
erase
(
op
);
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
;
};
void
CinnSubgraphDetector
::
DoOpFusion
()
{
void
CinnSubgraphDetector
::
DoOpFusion
()
{
// sort node from input to output
// sort node from input to output
...
@@ -183,7 +153,7 @@ void CinnSubgraphDetector::DoSubGraphFusion() {
...
@@ -183,7 +153,7 @@ void CinnSubgraphDetector::DoSubGraphFusion() {
continue
;
continue
;
}
}
// do fusion
// do fusion
update
|=
FuseSubGraph
(
&
subgraph
);
update
|=
FuseSubGraph
(
subgraph
);
}
}
if
(
!
update
)
{
if
(
!
update
)
{
break
;
break
;
...
@@ -191,8 +161,8 @@ void CinnSubgraphDetector::DoSubGraphFusion() {
...
@@ -191,8 +161,8 @@ void CinnSubgraphDetector::DoSubGraphFusion() {
}
}
}
}
bool
CinnSubgraphDetector
::
FuseSubGraph
(
CinnSubGraphPtr
*
subgraph_ptr
)
{
bool
CinnSubgraphDetector
::
FuseSubGraph
(
CinnSubGraphPtr
subgraph_ptr
)
{
auto
producer
=
*
subgraph_ptr
;
auto
producer
=
subgraph_ptr
;
auto
&
consumers
=
producer
->
consumers
;
auto
&
consumers
=
producer
->
consumers
;
std
::
vector
<
CinnSubGraphPtr
>
candidates
;
std
::
vector
<
CinnSubGraphPtr
>
candidates
;
for
(
auto
&
consumer
:
consumers
)
{
for
(
auto
&
consumer
:
consumers
)
{
...
@@ -276,11 +246,11 @@ bool CinnSubgraphDetector::FuseSubGraph(CinnSubGraphPtr* subgraph_ptr) {
...
@@ -276,11 +246,11 @@ bool CinnSubgraphDetector::FuseSubGraph(CinnSubGraphPtr* subgraph_ptr) {
bool
CinnSubgraphDetector
::
IsDependency
(
bool
CinnSubgraphDetector
::
IsDependency
(
const
CinnSubGraphPtr
&
producer_g
,
const
CinnSubGraphPtr
&
producer_g
,
const
CinnSubGraphPtr
&
consumer
,
const
CinnSubGraphPtr
&
consumer
,
const
std
::
unordered_set
<
CinnSubGraphPtr
,
Hasher
,
Comparator
>&
consumers
)
{
const
std
::
unordered_set
<
CinnSubGraphPtr
>&
consumers
)
{
std
::
queue
<
CinnSubGraphPtr
>
candidates
;
std
::
queue
<
CinnSubGraphPtr
>
candidates
;
candidates
.
push
(
consumer
);
candidates
.
push
(
consumer
);
std
::
unordered_set
<
CinnSubGraphPtr
,
Hasher
,
Comparator
>
visited_set
;
std
::
unordered_set
<
CinnSubGraphPtr
>
visited_set
;
while
(
!
candidates
.
empty
())
{
while
(
!
candidates
.
empty
())
{
auto
&
candidate
=
candidates
.
front
();
auto
&
candidate
=
candidates
.
front
();
candidates
.
pop
();
candidates
.
pop
();
...
@@ -303,12 +273,12 @@ bool CinnSubgraphDetector::IsDependency(
...
@@ -303,12 +273,12 @@ bool CinnSubgraphDetector::IsDependency(
bool
CinnSubgraphDetector
::
IsDependencySimplify
(
bool
CinnSubgraphDetector
::
IsDependencySimplify
(
const
CinnSubGraphPtr
&
producer_g
,
const
CinnSubGraphPtr
&
producer_g
,
const
CinnSubGraphPtr
&
consumer
,
const
CinnSubGraphPtr
&
consumer
,
const
std
::
unordered_set
<
CinnSubGraphPtr
,
Hasher
,
Comparator
>&
consumers
)
{
const
std
::
unordered_set
<
CinnSubGraphPtr
>&
consumers
)
{
std
::
queue
<
CinnSubGraphPtr
>
candidates
;
std
::
queue
<
CinnSubGraphPtr
>
candidates
;
candidates
.
push
(
consumer
);
candidates
.
push
(
consumer
);
// check upper bound.
// check upper bound.
int
check_upper_depth
=
producer_g
->
max_depth
;
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
())
{
while
(
!
candidates
.
empty
())
{
auto
&
candidate
=
candidates
.
front
();
auto
&
candidate
=
candidates
.
front
();
candidates
.
pop
();
candidates
.
pop
();
...
...
paddle/fluid/framework/paddle2cinn/cinn_subgraph_detector.h
浏览文件 @
cdc44a54
...
@@ -31,10 +31,32 @@ namespace paddle2cinn {
...
@@ -31,10 +31,32 @@ namespace paddle2cinn {
using
Node
=
ir
::
Node
;
using
Node
=
ir
::
Node
;
using
Graph
=
ir
::
Graph
;
using
Graph
=
ir
::
Graph
;
struct
Hasher
;
/*
struct
Comparator
;
*
*
*/
struct
CinnSubGraph
;
struct
CinnSubGraph
;
using
CinnSubGraphPtr
=
std
::
shared_ptr
<
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
* Detect the nodes in a subgraph that meet some conditions. This class doesn't
* modify the graph.
* modify the graph.
...
@@ -55,16 +77,14 @@ class CinnSubgraphDetector {
...
@@ -55,16 +77,14 @@ class CinnSubgraphDetector {
void
BuildSubGraph
();
void
BuildSubGraph
();
// SubGraph Fusion
// SubGraph Fusion
void
DoSubGraphFusion
();
void
DoSubGraphFusion
();
bool
FuseSubGraph
(
CinnSubGraphPtr
*
);
bool
FuseSubGraph
(
CinnSubGraphPtr
);
// check exist depency.
// check exist depency.
bool
IsDependency
(
bool
IsDependency
(
const
CinnSubGraphPtr
&
,
const
CinnSubGraphPtr
&
,
const
CinnSubGraphPtr
&
,
const
CinnSubGraphPtr
&
,
const
std
::
unordered_set
<
CinnSubGraphPtr
>
&
);
const
std
::
unordered_set
<
CinnSubGraphPtr
,
Hasher
,
Comparator
>
&
);
bool
IsDependencySimplify
(
const
CinnSubGraphPtr
&
,
bool
IsDependencySimplify
(
const
CinnSubGraphPtr
&
,
const
CinnSubGraphPtr
&
,
const
std
::
unordered_set
<
CinnSubGraphPtr
>
&
);
const
CinnSubGraphPtr
&
,
const
std
::
unordered_set
<
CinnSubGraphPtr
,
Hasher
,
Comparator
>
&
);
private:
private:
Graph
*
graph_
;
Graph
*
graph_
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录