Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
891c3c0f
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
1 年多 前同步成功
通知
696
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
891c3c0f
编写于
8月 14, 2018
作者:
X
Xin Pan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test and doc IR Graph
上级
83c85f34
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
127 addition
and
1 deletion
+127
-1
paddle/fluid/framework/ir/graph.h
paddle/fluid/framework/ir/graph.h
+32
-0
paddle/fluid/framework/ir/graph_test.cc
paddle/fluid/framework/ir/graph_test.cc
+95
-1
未找到文件。
paddle/fluid/framework/ir/graph.h
浏览文件 @
891c3c0f
...
@@ -28,6 +28,38 @@ namespace paddle {
...
@@ -28,6 +28,38 @@ namespace paddle {
namespace
framework
{
namespace
framework
{
namespace
ir
{
namespace
ir
{
/*
* The graph is a Directed Acyclic Single Static Assignment Graph.
*
* In more detail, the following properties must hold:
*
* The graph shouldn't contain cycle. Each node is a black-box to the graph
* so the node itself could be a loop operator.
*
* Each Variable-type node has only one input (thus single static assignment).
*
* The output/input of operator is variable and the output/input of variable
* is operator.
*
* The following data harzards in Program are addressed in the Graph:
*
* Write-After-Read
* a = op1(x)
* x = op2(b)
* A control-dependency connection is created bettwen op1 and op2 such that
* op1->op2, so as to ensure correct order.
*
* Write-After-Write
* x = op1(a)
* x = op2(b)
* A control-dependency connection is created between op1 and op2 such that
* op1->op2, so as to ensure correct order.
*
* Other properties currently hold, but is not enforced yet:
*
* Variable-type node (not control dep) with the same variable name share
* the same underlying VarDesc.
*/
class
Graph
{
class
Graph
{
public:
public:
explicit
Graph
(
const
ProgramDesc
&
program
);
explicit
Graph
(
const
ProgramDesc
&
program
);
...
...
paddle/fluid/framework/ir/graph_test.cc
浏览文件 @
891c3c0f
...
@@ -36,7 +36,7 @@ class SumOpMaker : public OpProtoAndCheckerMaker {
...
@@ -36,7 +36,7 @@ class SumOpMaker : public OpProtoAndCheckerMaker {
public:
public:
void
Make
()
{
void
Make
()
{
AddInput
(
"X"
,
""
).
AsDuplicable
();
AddInput
(
"X"
,
""
).
AsDuplicable
();
AddOutput
(
"Out"
,
""
);
AddOutput
(
"Out"
,
""
)
.
AsDuplicable
()
;
AddComment
(
""
);
AddComment
(
""
);
}
}
};
};
...
@@ -59,11 +59,27 @@ class SumOpVarTypeInference : public VarTypeInference {
...
@@ -59,11 +59,27 @@ class SumOpVarTypeInference : public VarTypeInference {
block
->
Var
(
out_var_name
)
->
SetType
(
default_var_type
);
block
->
Var
(
out_var_name
)
->
SetType
(
default_var_type
);
}
}
};
};
class
DummyOpMaker
:
public
OpProtoAndCheckerMaker
{
public:
void
Make
()
{
AddInput
(
"X"
,
""
).
AsDuplicable
();
AddOutput
(
"Out"
,
""
).
AsDuplicable
();
AddComment
(
""
);
}
};
class
DummyOpVarTypeInference
:
public
VarTypeInference
{
public:
void
operator
()(
const
OpDesc
&
op_desc
,
BlockDesc
*
block
)
const
override
{}
};
}
// namespace framework
}
// namespace framework
}
// namespace paddle
}
// namespace paddle
REGISTER_OPERATOR
(
sum
,
paddle
::
framework
::
NOP
,
paddle
::
framework
::
SumOpMaker
,
REGISTER_OPERATOR
(
sum
,
paddle
::
framework
::
NOP
,
paddle
::
framework
::
SumOpMaker
,
paddle
::
framework
::
SumOpVarTypeInference
);
paddle
::
framework
::
SumOpVarTypeInference
);
REGISTER_OPERATOR
(
dummy
,
paddle
::
framework
::
NOP
,
paddle
::
framework
::
SumOpMaker
,
paddle
::
framework
::
SumOpVarTypeInference
);
REGISTER_OPERATOR
(
sum_without_infer_var_type
,
paddle
::
framework
::
NOP
,
REGISTER_OPERATOR
(
sum_without_infer_var_type
,
paddle
::
framework
::
NOP
,
paddle
::
framework
::
SumOpMaker
);
paddle
::
framework
::
SumOpMaker
);
...
@@ -110,5 +126,83 @@ TEST(GraphTest, Basic) {
...
@@ -110,5 +126,83 @@ TEST(GraphTest, Basic) {
}
}
ASSERT_EQ
(
nodes
.
size
(),
5
);
ASSERT_EQ
(
nodes
.
size
(),
5
);
}
}
TEST
(
GraphTest
,
WriteAfterRead
)
{
// void Test() {
ProgramDesc
prog
;
auto
*
op
=
prog
.
MutableBlock
(
0
)
->
AppendOp
();
op
->
SetType
(
"sum"
);
op
->
SetInput
(
"X"
,
{
"a"
});
op
->
SetOutput
(
"Out"
,
{
"b"
});
op
->
SetAttr
(
"op_role"
,
1
);
op
=
prog
.
MutableBlock
(
0
)
->
AppendOp
();
op
->
SetType
(
"dummy"
);
op
->
SetInput
(
"X"
,
{
"c"
});
op
->
SetOutput
(
"Out"
,
{
"a"
});
op
->
SetAttr
(
"op_role"
,
1
);
prog
.
MutableBlock
(
0
)
->
Var
(
"a"
)
->
SetType
(
proto
::
VarType
::
LOD_TENSOR
);
prog
.
MutableBlock
(
0
)
->
Var
(
"b"
)
->
SetType
(
proto
::
VarType
::
LOD_TENSOR
);
prog
.
MutableBlock
(
0
)
->
Var
(
"c"
)
->
SetType
(
proto
::
VarType
::
LOD_TENSOR
);
std
::
unique_ptr
<
ir
::
Graph
>
g
(
new
ir
::
Graph
(
prog
));
ir
::
Node
*
control_dep1
=
nullptr
;
ir
::
Node
*
control_dep2
=
nullptr
;
for
(
ir
::
Node
*
n
:
g
->
Nodes
())
{
if
(
n
->
Name
()
==
"sum"
)
{
ASSERT_EQ
(
n
->
outputs
[
0
]
->
Name
(),
"b"
);
ASSERT_TRUE
(
ir
::
IsControlDepVar
(
*
n
->
outputs
[
1
]));
control_dep1
=
n
->
outputs
[
1
];
ASSERT_EQ
(
n
->
outputs
.
size
(),
2
);
}
if
(
n
->
Name
()
==
"dummy"
)
{
ASSERT_EQ
(
n
->
inputs
[
0
]
->
Name
(),
"c"
);
ASSERT_TRUE
(
ir
::
IsControlDepVar
(
*
n
->
inputs
[
1
]));
control_dep2
=
n
->
inputs
[
1
];
ASSERT_EQ
(
n
->
inputs
.
size
(),
2
);
}
}
ASSERT_EQ
(
control_dep1
,
control_dep2
);
}
TEST
(
GraphTest
,
WriteAfterWrite
)
{
// void Test() {
ProgramDesc
prog
;
auto
*
op
=
prog
.
MutableBlock
(
0
)
->
AppendOp
();
op
->
SetType
(
"sum"
);
op
->
SetInput
(
"X"
,
{
"a"
});
op
->
SetOutput
(
"Out"
,
{
"b"
});
op
->
SetAttr
(
"op_role"
,
1
);
op
=
prog
.
MutableBlock
(
0
)
->
AppendOp
();
op
->
SetType
(
"dummy"
);
op
->
SetInput
(
"X"
,
{
"c"
});
op
->
SetOutput
(
"Out"
,
{
"b"
});
op
->
SetAttr
(
"op_role"
,
1
);
prog
.
MutableBlock
(
0
)
->
Var
(
"a"
)
->
SetType
(
proto
::
VarType
::
LOD_TENSOR
);
prog
.
MutableBlock
(
0
)
->
Var
(
"b"
)
->
SetType
(
proto
::
VarType
::
LOD_TENSOR
);
prog
.
MutableBlock
(
0
)
->
Var
(
"c"
)
->
SetType
(
proto
::
VarType
::
LOD_TENSOR
);
std
::
unique_ptr
<
ir
::
Graph
>
g
(
new
ir
::
Graph
(
prog
));
ir
::
Node
*
control_dep1
=
nullptr
;
ir
::
Node
*
control_dep2
=
nullptr
;
for
(
ir
::
Node
*
n
:
g
->
Nodes
())
{
if
(
n
->
Name
()
==
"sum"
)
{
ASSERT_EQ
(
n
->
outputs
[
0
]
->
Name
(),
"b"
);
ASSERT_TRUE
(
ir
::
IsControlDepVar
(
*
n
->
outputs
[
1
]));
ASSERT_EQ
(
n
->
outputs
.
size
(),
2
);
control_dep1
=
n
->
outputs
[
1
];
}
if
(
n
->
Name
()
==
"dummy"
)
{
ASSERT_EQ
(
n
->
inputs
[
0
]
->
Name
(),
"c"
);
ASSERT_TRUE
(
ir
::
IsControlDepVar
(
*
n
->
inputs
[
1
]));
control_dep2
=
n
->
inputs
[
1
];
ASSERT_EQ
(
n
->
inputs
.
size
(),
2
);
ASSERT_EQ
(
control_dep1
,
control_dep2
);
}
}
}
}
// namespace framework
}
// namespace framework
}
// namespace paddle
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录