Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OPTHREE
Paddle
提交
e05e27a7
P
Paddle
项目概览
OPTHREE
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e05e27a7
编写于
9月 22, 2017
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix bug
上级
dc643a33
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
48 addition
and
16 deletion
+48
-16
paddle/pybind/protobuf.cc
paddle/pybind/protobuf.cc
+48
-16
未找到文件。
paddle/pybind/protobuf.cc
浏览文件 @
e05e27a7
...
...
@@ -42,15 +42,23 @@ inline void VectorToRepeated(const std::vector<T> &vec,
class
ProgramDescBind
;
class
OpDescBind
;
class
BlockDescBind
;
class
VarDescBind
;
class
Op
DescBind
{
class
Var
DescBind
{
public:
explicit
OpDescBind
(
BlockDescBind
*
block
)
:
block_
(
block
)
{}
explicit
VarDescBind
(
const
std
::
string
&
name
)
{
var_desc_
.
set_name
(
name
);
}
VarDesc
*
Proto
()
{
return
&
var_desc_
;
}
private:
VarDesc
var_desc_
;
};
operator
OpDesc
*
()
{
return
&
op_desc_
;
}
class
OpDescBind
{
public:
OpDesc
*
Proto
()
{
return
&
op_desc_
;
}
private:
BlockDescBind
*
block_
;
OpDesc
op_desc_
;
};
...
...
@@ -59,14 +67,28 @@ public:
BlockDescBind
(
ProgramDescBind
*
prog
,
BlockDesc
*
desc
)
:
prog_
(
prog
),
desc_
(
desc
),
need_update_
(
false
)
{}
BlockDescBind
(
const
BlockDescBind
&
o
)
=
delete
;
BlockDescBind
&
operator
=
(
const
BlockDescBind
&
o
)
=
delete
;
int32_t
id
()
const
{
return
desc_
->
idx
();
}
int32_t
Parent
()
const
{
return
desc_
->
parent_idx
();
}
VarDescBind
*
NewVar
(
const
std
::
string
&
name
)
{
need_update_
=
true
;
auto
it
=
vars_
.
find
(
name
);
PADDLE_ENFORCE
(
it
==
vars_
.
end
(),
"Duplicated variable %s"
,
name
);
auto
var
=
new
VarDescBind
(
name
);
vars_
[
name
].
reset
(
var
);
return
var
;
}
BlockDescBind
*
ParentBlock
()
const
;
OpDescBind
*
AppendOp
()
{
need_update_
=
true
;
ops_
.
emplace_back
(
this
);
return
&
ops_
.
back
();
ops_
.
emplace_back
(
new
OpDescBind
()
);
return
ops_
.
back
().
get
();
}
void
Sync
()
{
...
...
@@ -75,8 +97,9 @@ public:
op_field
.
Clear
();
op_field
.
Reserve
(
static_cast
<
int
>
(
ops_
.
size
()));
for
(
auto
&
op_desc
:
ops_
)
{
op_field
.
AddAllocated
(
op_desc
);
op_field
.
AddAllocated
(
op_desc
->
Proto
()
);
}
need_update_
=
false
;
}
}
...
...
@@ -85,7 +108,8 @@ private:
BlockDesc
*
desc_
;
// not_own
bool
need_update_
;
std
::
deque
<
OpDescBind
>
ops_
;
std
::
deque
<
std
::
unique_ptr
<
OpDescBind
>>
ops_
;
std
::
unordered_map
<
std
::
string
,
std
::
unique_ptr
<
VarDescBind
>>
vars_
;
};
using
ProgDescMap
=
...
...
@@ -106,18 +130,20 @@ public:
}
return
*
ptr
;
}
ProgramDescBind
(
const
ProgramDescBind
&
o
)
=
delete
;
ProgramDescBind
&
operator
=
(
const
ProgramDescBind
&
o
)
=
delete
;
BlockDescBind
*
AppendBlock
(
const
BlockDescBind
&
parent
)
{
auto
*
b
=
prog_
->
add_blocks
();
b
->
set_parent_idx
(
parent
.
id
());
b
->
set_idx
(
prog_
->
blocks_size
()
-
1
);
blocks_
.
emplace_back
(
this
,
b
);
return
&
blocks_
.
back
();
blocks_
.
emplace_back
(
new
BlockDescBind
(
this
,
b
)
);
return
blocks_
.
back
().
get
();
}
BlockDescBind
*
Root
()
{
return
&
blocks_
.
fron
t
();
}
BlockDescBind
*
Root
()
{
return
blocks_
.
front
().
ge
t
();
}
BlockDescBind
*
Block
(
size_t
idx
)
{
return
&
blocks_
[
idx
]
;
}
BlockDescBind
*
Block
(
size_t
idx
)
{
return
blocks_
[
idx
].
get
()
;
}
std
::
string
DebugString
()
{
return
Proto
()
->
DebugString
();
}
...
...
@@ -125,25 +151,31 @@ public:
ProgramDesc
*
Proto
()
{
for
(
auto
&
block
:
blocks_
)
{
block
.
Sync
();
block
->
Sync
();
}
return
prog_
;
}
private:
explicit
ProgramDescBind
(
ProgramDesc
*
prog
)
:
prog_
(
prog
)
{
blocks_
.
reserve
(
100
);
for
(
auto
&
block
:
*
prog
->
mutable_blocks
())
{
blocks_
.
emplace_back
(
this
,
&
block
);
blocks_
.
emplace_back
(
new
BlockDescBind
(
this
,
&
block
)
);
}
}
// Not owned
ProgramDesc
*
prog_
;
std
::
vector
<
BlockDescBind
>
blocks_
;
std
::
vector
<
std
::
unique_ptr
<
BlockDescBind
>
>
blocks_
;
};
BlockDescBind
*
BlockDescBind
::
ParentBlock
()
const
{
if
(
this
->
desc_
->
parent_idx
()
==
-
1
)
{
return
nullptr
;
}
return
prog_
->
Block
(
static_cast
<
size_t
>
(
this
->
desc_
->
parent_idx
()));
}
void
BindProgramDesc
(
py
::
module
&
m
)
{
py
::
class_
<
ProgramDescBind
>
(
m
,
"ProgramDesc"
,
""
)
.
def_static
(
"instance"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录