Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
d550380e
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
提交
d550380e
编写于
10月 02, 2017
作者:
Q
qiaolongfei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add CompileTimeInferShapeContext
上级
31bdb3f3
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
41 addition
and
52 deletion
+41
-52
paddle/framework/CMakeLists.txt
paddle/framework/CMakeLists.txt
+1
-1
paddle/framework/block_desc.cc
paddle/framework/block_desc.cc
+5
-0
paddle/framework/block_desc.h
paddle/framework/block_desc.h
+2
-0
paddle/framework/operator.h
paddle/framework/operator.h
+33
-51
未找到文件。
paddle/framework/CMakeLists.txt
浏览文件 @
d550380e
...
...
@@ -23,7 +23,7 @@ cc_library(proto_desc SRCS var_desc.cc op_desc.cc block_desc.cc program_desc.cc
cc_library
(
op_proto_maker SRCS op_proto_maker.cc DEPS framework_proto attribute
)
cc_test
(
op_proto_maker_test SRCS op_proto_maker_test.cc DEPS op_proto_maker
)
cc_library
(
op_info SRCS op_info.cc DEPS attribute framework_proto proto_desc
)
cc_library
(
operator SRCS operator.cc DEPS op_info device_context tensor scope
)
cc_library
(
operator SRCS operator.cc DEPS op_info device_context tensor scope
proto_desc
)
cc_test
(
operator_test SRCS operator_test.cc DEPS operator op_registry
)
cc_library
(
grad_op_builder SRCS grad_op_builder.cc DEPS operator proto_desc
)
...
...
paddle/framework/block_desc.cc
浏览文件 @
d550380e
...
...
@@ -34,6 +34,11 @@ VarDescBind *BlockDescBind::Var(const std::string &name) const {
return
it
->
second
.
get
();
}
bool
BlockDescBind
::
HasVar
(
const
std
::
string
&
name
)
const
{
auto
it
=
vars_
.
find
(
name
);
return
it
!=
vars_
.
end
();
}
std
::
vector
<
VarDescBind
*>
BlockDescBind
::
AllVars
()
const
{
std
::
vector
<
VarDescBind
*>
res
;
for
(
const
auto
&
p
:
vars_
)
{
...
...
paddle/framework/block_desc.h
浏览文件 @
d550380e
...
...
@@ -45,6 +45,8 @@ class BlockDescBind {
VarDescBind
*
Var
(
const
std
::
string
&
name_bytes
)
const
;
bool
HasVar
(
const
std
::
string
&
var_name
)
const
;
std
::
vector
<
VarDescBind
*>
AllVars
()
const
;
BlockDescBind
*
ParentBlock
()
const
;
...
...
paddle/framework/operator.h
浏览文件 @
d550380e
...
...
@@ -319,100 +319,82 @@ class ExecutionContext : public InferShapeContext {
class
CompileTimeInferShapeContext
:
public
InferShapeContextBase
{
public:
CompileTimeInferShapeContext
(
const
Op
eratorBase
&
op
,
const
Scope
&
scope
)
:
op_
(
op
),
scope_
(
scope
)
{}
CompileTimeInferShapeContext
(
const
Op
DescBind
&
op
,
const
BlockDescBind
&
block
)
:
op_
(
op
),
block_
(
block
)
{}
bool
HasInput
(
const
std
::
string
&
name
)
const
{
auto
ipt
=
op_
.
Input
(
name
);
auto
*
var
=
ipt
==
kEmptyVarName
?
nullptr
:
scope_
.
FindVar
(
ipt
);
return
var
!=
nullptr
;
const
std
::
vector
<
std
::
string
>&
input_names
=
op_
.
Input
(
name
);
PADDLE_ENFORCE_EQ
(
input_names
.
size
(),
1UL
,
"Inputs(%s) length is not 1"
,
name
);
return
block_
.
HasVar
(
input_names
[
0
]);
}
bool
HasOutput
(
const
std
::
string
&
name
)
const
{
auto
ipt
=
op_
.
Output
(
name
);
auto
*
var
=
ipt
==
kEmptyVarName
?
nullptr
:
scope_
.
FindVar
(
ipt
);
return
var
!=
nullptr
;
const
std
::
vector
<
std
::
string
>&
output_names
=
op_
.
Output
(
name
);
PADDLE_ENFORCE_EQ
(
output_names
.
size
(),
1UL
,
"Outputs(%s) length is not 1"
,
name
);
return
block_
.
HasVar
(
output_names
[
0
]);
}
bool
HasInputs
(
const
std
::
string
&
name
)
const
{
auto
inputs
=
op_
.
Inputs
(
name
);
if
(
inputs
.
size
()
==
0UL
)
{
return
false
;
}
for
(
auto
&
input
:
inputs
)
{
if
(
scope_
.
FindVar
(
input
)
==
nullptr
)
{
return
false
;
}
const
std
::
vector
<
std
::
string
>&
input_names
=
op_
.
Input
(
name
);
PADDLE_ENFORCE_GT
(
input_names
.
size
(),
0UL
,
"Inputs(%s) length is 0"
,
name
);
for
(
auto
&
input
:
input_names
)
{
if
(
!
block_
.
HasVar
(
input
))
return
false
;
}
return
true
;
}
bool
HasOutputs
(
const
std
::
string
&
name
)
const
{
auto
outputs
=
op_
.
Outputs
(
name
);
if
(
outputs
.
size
()
==
0UL
)
{
return
false
;
}
for
(
auto
&
output
:
outputs
)
{
if
(
scope_
.
FindVar
(
output
)
==
nullptr
)
{
return
false
;
}
const
std
::
vector
<
std
::
string
>&
output_names
=
op_
.
Output
(
name
);
PADDLE_ENFORCE_GT
(
output_names
.
size
(),
0UL
,
"Inputs(%s) length is 0"
,
name
);
for
(
auto
&
output
:
output_names
)
{
if
(
!
block_
.
HasVar
(
name
))
return
false
;
}
return
true
;
}
DDim
GetInputDim
(
const
std
::
string
&
name
)
const
{
return
GetDim
(
op_
.
Input
(
name
));
std
::
vector
<
DDim
>
ddims
=
GetInputsDim
(
name
);
PADDLE_ENFORCE_EQ
(
ddims
.
size
(),
1UL
,
"Inputs(%s) length is not 1"
,
name
);
return
ddims
[
0
];
}
void
SetInputDim
(
const
std
::
string
&
name
,
const
DDim
&
dim
)
{
Set
Dim
(
op_
.
Input
(
name
),
dim
);
Set
InputsDim
(
name
,
{
dim
}
);
}
DDim
GetOutputDim
(
const
std
::
string
&
name
)
const
{
return
GetDim
(
op_
.
Output
(
name
));
std
::
vector
<
DDim
>
ddims
=
GetOutputsDim
(
name
);
PADDLE_ENFORCE_EQ
(
ddims
.
size
(),
1UL
,
"Outputs(%s) length is not 1"
,
name
);
return
ddims
[
0
];
}
void
SetOutputDim
(
const
std
::
string
&
name
,
const
DDim
&
dim
)
{
Set
Dim
(
op_
.
Output
(
name
),
dim
);
Set
OutputsDim
(
name
,
{
dim
}
);
}
AttrReader
Attrs
()
const
{
return
AttrReader
(
op_
.
Attrs
());
}
AttrReader
Attrs
()
const
{
return
AttrReader
(
op_
.
GetAttrMap
());
}
const
std
::
vector
<
std
::
string
>&
Inputs
(
const
std
::
string
&
name
)
const
{
return
op_
.
Input
s
(
name
);
return
op_
.
Input
(
name
);
}
const
std
::
vector
<
std
::
string
>&
Outputs
(
const
std
::
string
&
name
)
const
{
return
op_
.
Output
s
(
name
);
return
op_
.
Output
(
name
);
}
private:
template
<
bool
Allocate
>
Tensor
*
GetTensor
(
const
std
::
string
&
name
)
const
{
Tensor
*
t
=
nullptr
;
auto
*
var
=
scope_
.
FindVar
(
name
);
if
(
!
var
->
IsType
<
LoDTensor
>
()
&&
!
var
->
IsType
<
Tensor
>
())
{
if
(
Allocate
)
{
t
=
var
->
GetMutable
<
LoDTensor
>
();
}
else
{
PADDLE_THROW
(
"Variable(%s) should be tensor"
,
name
);
}
}
else
{
t
=
GetTensorFromVar
(
scope_
.
FindVar
(
name
));
}
return
t
;
}
DDim
GetDim
(
const
std
::
string
&
name
)
const
{
return
GetTensor
<
false
>
(
name
)
->
dims
(
);
return
framework
::
make_ddim
(
block_
.
Var
(
name
)
->
Shape
()
);
}
void
SetDim
(
const
std
::
string
&
name
,
const
DDim
&
dim
)
{
GetTensor
<
true
>
(
name
)
->
Resize
(
dim
);
block_
.
Var
(
name
)
->
SetShape
(
framework
::
vectorize
(
dim
)
);
}
const
Op
eratorBase
&
op_
;
const
Scope
&
scope
_
;
const
Op
DescBind
&
op_
;
const
BlockDescBind
&
block
_
;
};
class
RuntimeInferShapeContext
:
public
InferShapeContextBase
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录