Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
70f398e2
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看板
提交
70f398e2
编写于
9月 21, 2017
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update
上级
859dba59
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
83 addition
and
10 deletion
+83
-10
paddle/framework/attribute.cc
paddle/framework/attribute.cc
+3
-0
paddle/pybind/pybind.cc
paddle/pybind/pybind.cc
+64
-10
python/paddle/v2/framework/tests/test_protobuf_descs.py
python/paddle/v2/framework/tests/test_protobuf_descs.py
+16
-0
未找到文件。
paddle/framework/attribute.cc
浏览文件 @
70f398e2
...
@@ -24,6 +24,9 @@ static ProgramDesc* g_program_desc = nullptr;
...
@@ -24,6 +24,9 @@ static ProgramDesc* g_program_desc = nullptr;
ProgramDesc
&
GetProgramDesc
()
{
ProgramDesc
&
GetProgramDesc
()
{
if
(
g_program_desc
==
nullptr
)
{
if
(
g_program_desc
==
nullptr
)
{
g_program_desc
=
new
ProgramDesc
();
g_program_desc
=
new
ProgramDesc
();
auto
root_block
=
g_program_desc
->
mutable_blocks
()
->
Add
();
root_block
->
set_idx
(
0
);
root_block
->
set_parent_idx
(
-
1
);
}
}
return
*
g_program_desc
;
return
*
g_program_desc
;
}
}
...
...
paddle/pybind/pybind.cc
浏览文件 @
70f398e2
...
@@ -316,21 +316,75 @@ All parameter, weight, gradient are variables in Paddle.
...
@@ -316,21 +316,75 @@ All parameter, weight, gradient are variables in Paddle.
m
.
def
(
"is_compile_gpu"
,
IsCompileGPU
);
m
.
def
(
"is_compile_gpu"
,
IsCompileGPU
);
py
::
class_
<
ProgramDesc
>
(
m
,
"ProgramDesc"
,
""
)
py
::
class_
<
ProgramDesc
>
(
m
,
"ProgramDesc"
,
""
)
.
def_static
(
"instance"
,
[]
{
return
&
GetProgramDesc
();
})
.
def_static
(
"instance"
,
.
def
(
"append_block"
,
[](
ProgramDesc
&
self
)
{
[]
{
return
&
GetProgramDesc
();
},
py
::
return_value_policy
::
reference
)
.
def
(
"append_block"
,
[](
ProgramDesc
&
self
,
BlockDesc
&
parent
)
{
auto
desc
=
self
.
mutable_blocks
()
->
Add
();
auto
desc
=
self
.
mutable_blocks
()
->
Add
();
desc
->
set_idx
(
self
.
mutable_blocks
()
->
size
()
-
1
);
desc
->
set_idx
(
self
.
mutable_blocks
()
->
size
()
-
1
);
desc
->
set_parent_idx
(
parent
.
idx
());
return
desc
;
return
desc
;
});
})
.
def
(
"root_block"
,
[](
ProgramDesc
&
self
)
{
return
self
.
mutable_blocks
()[
0
];
});
py
::
class_
<
BlockDesc
>
(
m
,
"BlockDesc"
,
""
)
py
::
class_
<
BlockDesc
>
(
m
,
"BlockDesc"
,
""
)
.
def
(
"idx"
,
[](
BlockDesc
&
self
)
{
return
self
.
idx
();
})
.
def
(
"idx"
,
[](
BlockDesc
&
self
)
{
return
self
.
idx
();
})
.
def
(
"
set_parent"
,
.
def
(
"
parent"
,
[](
BlockDesc
&
self
)
{
return
self
.
parent_idx
();
})
[](
BlockDesc
&
self
,
int32_t
idx
)
{
self
.
set_parent_idx
(
idx
);
})
.
def
(
"append_op"
,
.
def
(
"parent"
,
[](
BlockDesc
&
self
)
{
return
self
.
parent_idx
();
});
[](
BlockDesc
&
self
)
{
return
self
.
mutable_ops
()
->
Add
();
});
py
::
class_
<
VarDesc
>
(
m
,
"VarDesc"
,
""
);
py
::
class_
<
VarDesc
>
(
m
,
"VarDesc"
,
""
);
py
::
class_
<
OpDesc
>
(
m
,
"OpDesc"
,
""
);
auto
op_desc_set_var
=
[](
OpDesc
::
Var
*
var
,
const
std
::
string
&
parameter
,
const
std
::
vector
<
std
::
string
>
&
arguments
)
{
var
->
set_parameter
(
parameter
);
auto
args
=
var
->
mutable_arguments
();
args
->
Reserve
(
static_cast
<
int
>
(
arguments
.
size
()));
for
(
auto
&
arg
:
arguments
)
{
*
args
->
Add
()
=
arg
;
}
};
auto
op_desc_set_attr
=
[](
OpDesc
&
desc
,
const
std
::
string
&
name
)
{
auto
attr
=
desc
.
mutable_attrs
()
->
Add
();
attr
->
set_name
(
name
);
return
attr
;
};
py
::
class_
<
OpDesc
>
(
m
,
"OpDesc"
,
""
)
.
def
(
"type"
,
[](
OpDesc
&
op
)
{
return
op
.
type
();
})
.
def
(
"set_input"
,
[
op_desc_set_var
](
OpDesc
&
self
,
const
std
::
string
&
parameter
,
const
std
::
vector
<
std
::
string
>
&
arguments
)
{
auto
ipt
=
self
.
mutable_inputs
()
->
Add
();
op_desc_set_var
(
ipt
,
parameter
,
arguments
);
})
.
def
(
"input_names"
,
[](
OpDesc
&
self
)
{
std
::
vector
<
std
::
string
>
ret_val
;
ret_val
.
reserve
(
static_cast
<
size_t
>
(
self
.
inputs
().
size
()));
std
::
transform
(
self
.
inputs
().
begin
(),
self
.
inputs
().
end
(),
std
::
back_inserter
(
ret_val
),
[](
const
OpDesc
::
Var
&
var
)
{
return
var
.
parameter
();
});
return
ret_val
;
})
.
def
(
"__str__"
,
[](
OpDesc
&
self
)
{
return
self
.
DebugString
();
})
.
def
(
"set_output"
,
[
op_desc_set_var
](
OpDesc
&
self
,
const
std
::
string
&
parameter
,
const
std
::
vector
<
std
::
string
>
&
arguments
)
{
auto
opt
=
self
.
mutable_outputs
()
->
Add
();
op_desc_set_var
(
opt
,
parameter
,
arguments
);
})
.
def
(
"set_attr"
,
[
op_desc_set_attr
](
OpDesc
&
self
,
const
std
::
string
&
name
,
int
i
)
{
op_desc_set_attr
(
self
,
name
)
->
set_i
(
i
);
});
return
m
.
ptr
();
return
m
.
ptr
();
}
}
...
...
python/paddle/v2/framework/tests/test_protobuf_descs.py
0 → 100644
浏览文件 @
70f398e2
import
unittest
import
paddle.v2.framework.core
as
core
class
TestProgramDesc
(
unittest
.
TestCase
):
def
test_instance
(
self
):
program_desc
=
core
.
ProgramDesc
.
instance
()
self
.
assertIsNotNone
(
program_desc
)
del
program_desc
program_desc
=
core
.
ProgramDesc
.
instance
()
self
.
assertIsNotNone
(
program_desc
)
del
program_desc
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录