Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
067ed70f
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
提交
067ed70f
编写于
12月 10, 2018
作者:
T
Tao Luo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add HasProtoAttr function in op_desc.h, clean node.h
test=develop
上级
e99597d3
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
28 addition
and
59 deletion
+28
-59
paddle/fluid/framework/ir/is_test_pass.cc
paddle/fluid/framework/ir/is_test_pass.cc
+1
-1
paddle/fluid/framework/ir/is_test_pass_tester.cc
paddle/fluid/framework/ir/is_test_pass_tester.cc
+2
-2
paddle/fluid/framework/ir/mkldnn_placement_pass.cc
paddle/fluid/framework/ir/mkldnn_placement_pass.cc
+9
-6
paddle/fluid/framework/ir/node.cc
paddle/fluid/framework/ir/node.cc
+0
-22
paddle/fluid/framework/ir/node.h
paddle/fluid/framework/ir/node.h
+0
-12
paddle/fluid/framework/op_desc.cc
paddle/fluid/framework/op_desc.cc
+10
-14
paddle/fluid/framework/op_desc.h
paddle/fluid/framework/op_desc.h
+5
-1
paddle/fluid/pybind/tensor_py.h
paddle/fluid/pybind/tensor_py.h
+1
-1
未找到文件。
paddle/fluid/framework/ir/is_test_pass.cc
浏览文件 @
067ed70f
...
...
@@ -38,7 +38,7 @@ std::unique_ptr<ir::Graph> IsTestPass::ApplyImpl(
for
(
const
Node
*
n
:
graph
->
Nodes
())
{
if
(
n
->
IsOp
())
{
auto
*
op
=
n
->
Op
();
if
(
n
->
RuntimeHas
Attr
(
"is_test"
))
{
if
(
op
->
HasAttr
(
"is_test"
)
||
op
->
HasProto
Attr
(
"is_test"
))
{
op
->
SetAttr
(
"is_test"
,
true
);
}
else
if
(
std
::
find
(
begin
(
op_list
),
end
(
op_list
),
op
->
Type
())
!=
end
(
op_list
))
{
...
...
paddle/fluid/framework/ir/is_test_pass_tester.cc
浏览文件 @
067ed70f
...
...
@@ -104,9 +104,9 @@ TEST(IsTestPass, basic) {
auto
*
op
=
node
->
Op
();
auto
op_name
=
boost
::
get
<
std
::
string
>
(
op
->
GetAttr
(
"name"
));
if
(
op_name
==
"conv3"
)
{
ASSERT_FALSE
(
node
->
Runtime
HasAttr
(
"is_test"
));
ASSERT_FALSE
(
op
->
HasAttr
(
"is_test"
));
}
else
{
ASSERT_TRUE
(
node
->
Runtime
HasAttr
(
"is_test"
));
ASSERT_TRUE
(
op
->
HasAttr
(
"is_test"
));
EXPECT_TRUE
(
boost
::
get
<
bool
>
(
op
->
GetAttr
(
"is_test"
)));
}
}
...
...
paddle/fluid/framework/ir/mkldnn_placement_pass.cc
浏览文件 @
067ed70f
...
...
@@ -25,12 +25,15 @@ std::unique_ptr<ir::Graph> MKLDNNPlacementPass::ApplyImpl(
const
auto
&
op_types_list
=
Get
<
std
::
unordered_set
<
std
::
string
>>
(
"mkldnn_enabled_op_types"
);
for
(
const
Node
*
n
:
graph
->
Nodes
())
{
if
(
n
->
IsOp
()
&&
n
->
RuntimeHasAttr
(
"use_mkldnn"
))
{
if
(
op_types_list
.
empty
())
{
n
->
Op
()
->
SetAttr
(
"use_mkldnn"
,
true
);
}
else
if
(
std
::
find
(
op_types_list
.
begin
(),
op_types_list
.
end
(),
n
->
Name
())
!=
op_types_list
.
end
())
{
n
->
Op
()
->
SetAttr
(
"use_mkldnn"
,
true
);
if
(
n
->
IsOp
())
{
auto
*
op
=
n
->
Op
();
if
(
op
->
HasAttr
(
"use_mkldnn"
)
||
op
->
HasProtoAttr
(
"use_mkldnn"
))
{
if
(
op_types_list
.
empty
())
{
op
->
SetAttr
(
"use_mkldnn"
,
true
);
}
else
if
(
std
::
find
(
op_types_list
.
begin
(),
op_types_list
.
end
(),
n
->
Name
())
!=
op_types_list
.
end
())
{
op
->
SetAttr
(
"use_mkldnn"
,
true
);
}
}
}
}
...
...
paddle/fluid/framework/ir/node.cc
浏览文件 @
067ed70f
...
...
@@ -30,28 +30,6 @@ std::unique_ptr<Node> CreateNodeForTest(const std::string &name,
return
std
::
unique_ptr
<
Node
>
(
new
Node
(
name
,
type
));
}
bool
Node
::
RuntimeHasAttr
(
const
std
::
string
&
name
)
const
{
if
(
Op
()
->
HasAttr
(
name
))
{
return
true
;
}
else
{
auto
&
op_info
=
OpInfoMap
::
Instance
();
auto
op_type
=
Op
()
->
Type
();
if
(
op_info
.
Has
(
op_type
))
{
auto
op_info_ptr
=
op_info
.
Get
(
op_type
);
if
(
op_info_ptr
.
HasOpProtoAndChecker
())
{
const
proto
::
OpProto
&
proto
=
op_info_ptr
.
Proto
();
for
(
int
i
=
0
;
i
!=
proto
.
attrs_size
();
++
i
)
{
const
proto
::
OpProto
::
Attr
&
attr
=
proto
.
attrs
(
i
);
if
(
attr
.
name
()
==
name
)
{
return
true
;
}
}
}
}
}
return
false
;
}
}
// namespace ir
}
// namespace framework
}
// namespace paddle
paddle/fluid/framework/ir/node.h
浏览文件 @
067ed70f
...
...
@@ -108,18 +108,6 @@ class Node {
Name
().
find
(
ir
::
Node
::
kControlDepVarName
)
!=
std
::
string
::
npos
;
}
// RuntimeHasAttr is different with HasAttr now.
// 1. For Op()->HasAttr(), it judges whether a stored program_desc_ has attr,
// thus, if stored program_desc_ are old which don't have an attr, a new
// library which adds the attr already will fail on this function.
// Details:
// https://github.com/PaddlePaddle/Paddle/pull/14608#issuecomment-442309087
// 2. For Op()->RuntimeHasAttr, it judges the attr in runtime to avoid above
// problem.
// TODO(luotao): Maybe we should enhance HasAttr later, instead of adding
// RuntimeHasAttr.
bool
RuntimeHasAttr
(
const
std
::
string
&
name
)
const
;
std
::
vector
<
Node
*>
inputs
;
std
::
vector
<
Node
*>
outputs
;
...
...
paddle/fluid/framework/op_desc.cc
浏览文件 @
067ed70f
...
...
@@ -237,20 +237,16 @@ void OpDesc::SetOutput(const std::string ¶m_name,
this
->
outputs_
[
param_name
]
=
args
;
}
bool
OpDesc
::
HasAttr
(
const
std
::
string
&
name
)
const
{
if
(
attrs_
.
find
(
name
)
!=
attrs_
.
end
())
{
return
true
;
}
else
{
auto
&
op_info
=
OpInfoMap
::
Instance
();
if
(
op_info
.
Has
(
desc_
.
type
()))
{
auto
op_info_ptr
=
op_info
.
Get
(
desc_
.
type
());
if
(
op_info_ptr
.
HasOpProtoAndChecker
())
{
const
proto
::
OpProto
&
proto
=
op_info_ptr
.
Proto
();
for
(
int
i
=
0
;
i
!=
proto
.
attrs_size
();
++
i
)
{
const
proto
::
OpProto
::
Attr
&
attr
=
proto
.
attrs
(
i
);
if
(
attr
.
name
()
==
name
)
{
return
true
;
}
bool
OpDesc
::
HasProtoAttr
(
const
std
::
string
&
name
)
const
{
auto
&
op_info
=
OpInfoMap
::
Instance
();
if
(
op_info
.
Has
(
desc_
.
type
()))
{
auto
op_info_ptr
=
op_info
.
Get
(
desc_
.
type
());
if
(
op_info_ptr
.
HasOpProtoAndChecker
())
{
const
proto
::
OpProto
&
proto
=
op_info_ptr
.
Proto
();
for
(
int
i
=
0
;
i
!=
proto
.
attrs_size
();
++
i
)
{
const
proto
::
OpProto
::
Attr
&
attr
=
proto
.
attrs
(
i
);
if
(
attr
.
name
()
==
name
)
{
return
true
;
}
}
}
...
...
paddle/fluid/framework/op_desc.h
浏览文件 @
067ed70f
...
...
@@ -61,7 +61,11 @@ class OpDesc {
void
SetOutput
(
const
std
::
string
&
param_name
,
const
std
::
vector
<
std
::
string
>
&
args
);
bool
HasAttr
(
const
std
::
string
&
name
)
const
;
bool
HasAttr
(
const
std
::
string
&
name
)
const
{
return
attrs_
.
find
(
name
)
!=
attrs_
.
end
();
}
bool
HasProtoAttr
(
const
std
::
string
&
name
)
const
;
proto
::
AttrType
GetAttrType
(
const
std
::
string
&
name
)
const
;
...
...
paddle/fluid/pybind/tensor_py.h
浏览文件 @
067ed70f
...
...
@@ -182,7 +182,7 @@ inline void PyCPUTensorSetFromArray(
paddle
::
platform
::
CPUPlace
place
)
{
std
::
vector
<
int64_t
>
dims
;
dims
.
reserve
(
array
.
ndim
());
for
(
size_
t
i
=
0
;
i
<
array
.
ndim
();
++
i
)
{
for
(
in
t
i
=
0
;
i
<
array
.
ndim
();
++
i
)
{
dims
.
push_back
(
static_cast
<
int
>
(
array
.
shape
()[
i
]));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录