Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OPTHREE
Paddle
提交
005f15b4
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,发现更多精彩内容 >>
提交
005f15b4
编写于
10月 07, 2017
作者:
Y
Yang Yang
提交者:
gangliao
10月 08, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FeedOp and FetchOp unit test
上级
b68a95f7
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
22 addition
and
40 deletion
+22
-40
paddle/framework/executor.cc
paddle/framework/executor.cc
+2
-4
paddle/framework/executor_test.cc
paddle/framework/executor_test.cc
+20
-36
未找到文件。
paddle/framework/executor.cc
浏览文件 @
005f15b4
...
...
@@ -69,12 +69,10 @@ void Executor::Run(const ProgramDesc& pdesc, Scope* scope) {
}
std
::
vector
<
bool
>
should_run
=
Preprocess
(
pdesc
);
PADDLE_ENFORCE
(
should_run
.
size
()
==
block
.
ops_size
(),
"should_run.size() != block.ops_size()"
);
for
(
int
i
=
0
;
i
<
should_run
.
size
();
++
i
)
{
PADDLE_ENFORCE
(
should_run
.
size
()
==
block
.
ops_size
());
for
(
size_t
i
=
0
;
i
<
should_run
.
size
();
++
i
)
{
if
(
should_run
[
i
])
{
auto
op
=
paddle
::
framework
::
OpRegistry
::
CreateOp
(
block
.
ops
(
i
));
std
::
cout
<<
op
->
DebugString
()
<<
std
::
endl
;
op
->
Run
(
*
scope
,
*
device
);
}
}
...
...
paddle/framework/executor_test.cc
浏览文件 @
005f15b4
...
...
@@ -127,10 +127,11 @@ void add_fetch_op(string var_name, std::vector<int>& dim, int index,
std
::
once_flag
set_variable_flag
;
// Tensors in feed value variable will only be in CPUPlace
// So we can memcpy the data from vector<T> to feed_value
template
<
typename
T
>
void
set_feed_variable
(
const
std
::
vector
<
std
::
vector
<
T
>>&
inputs
)
{
typedef
std
::
vector
<
paddle
::
framework
::
Tensor
>
FeedInputs
;
// Tensors in feed value variable will only be in CPUPlace
Variable
*
g_feed_value
=
GetGlobalScope
()
->
FindVar
(
"feed_value"
);
FeedInputs
&
feed_inputs
=
*
(
g_feed_value
->
GetMutable
<
FeedInputs
>
());
auto
size
=
inputs
.
size
();
...
...
@@ -142,10 +143,11 @@ void set_feed_variable(const std::vector<std::vector<T>>& inputs) {
}
}
// Tensors in fetch value variable will only be in CPUPlace
// So we can memcpy the data from fetch_value to vector<T>
template
<
typename
T
>
std
::
vector
<
std
::
vector
<
T
>>
get_fetch_variable
()
{
typedef
std
::
vector
<
paddle
::
framework
::
Tensor
>
FetchOutputs
;
// Tensors in fetch value variable will only be in CPUPlace
Variable
*
g_fetch_value
=
GetGlobalScope
()
->
FindVar
(
"fetch_value"
);
FetchOutputs
&
fetch_outputs
=
*
(
g_fetch_value
->
GetMutable
<
FetchOutputs
>
());
...
...
@@ -159,6 +161,7 @@ std::vector<std::vector<T>> get_fetch_variable() {
fetch_outputs
[
i
].
numel
()
*
sizeof
(
T
));
result
.
push_back
(
tmp
);
}
return
result
;
}
...
...
@@ -197,7 +200,7 @@ class ExecutorTesterRandom : public ::testing::Test {
ProgramDesc
pdesc_
;
};
class
ExecutorTesterFeed
:
public
::
testing
::
Test
{
class
ExecutorTesterFeed
AndFetch
:
public
::
testing
::
Test
{
public:
virtual
void
SetUp
()
override
{
auto
root_block
=
pdesc_
.
add_blocks
();
...
...
@@ -208,26 +211,8 @@ class ExecutorTesterFeed : public ::testing::Test {
add_feed_op
(
"a"
,
dim
,
0
,
root_block
);
add_feed_op
(
"b"
,
dim
,
1
,
root_block
);
auto
c
=
root_block
->
add_vars
();
c
->
set_name
(
"c"
);
auto
c_lt
=
c
->
mutable_lod_tensor
();
c_lt
->
set_data_type
(
paddle
::
framework
::
DataType
::
FP32
);
auto
op
=
root_block
->
add_ops
();
op
->
set_type
(
"elementwise_add"
);
auto
X
=
op
->
add_inputs
();
X
->
set_parameter
(
"X"
);
X
->
add_arguments
(
"a"
);
auto
Y
=
op
->
add_inputs
();
Y
->
set_parameter
(
"Y"
);
Y
->
add_arguments
(
"b"
);
auto
Out
=
op
->
add_outputs
();
Out
->
set_parameter
(
"Out"
);
Out
->
add_arguments
(
"c"
);
add_fetch_op
(
"a"
,
dim
,
0
,
root_block
);
add_fetch_op
(
"
c"
,
dim
,
0
,
root_block
);
add_fetch_op
(
"
b"
,
dim
,
1
,
root_block
);
std
::
vector
<
float
>
vec1
=
{
1.0
,
2.0
,
3.0
,
4.0
,
5.0
,
6.0
};
std
::
vector
<
float
>
vec2
=
{
4.0
,
5.0
,
6.0
,
7.0
,
8.0
,
9.0
};
...
...
@@ -255,6 +240,7 @@ TEST_F(ExecutorTesterRandom, CPU) {
Executor
*
executor
=
new
Executor
(
places
);
executor
->
Run
(
pdesc_
,
GetGlobalScope
());
std
::
vector
<
std
::
vector
<
float
>>
result
=
get_fetch_variable
<
float
>
();
for
(
auto
&
vec
:
result
)
{
for
(
auto
&
num
:
vec
)
{
std
::
cout
<<
num
<<
" "
;
...
...
@@ -264,7 +250,7 @@ TEST_F(ExecutorTesterRandom, CPU) {
delete
executor
;
}
TEST_F
(
ExecutorTesterFeed
,
CPU
)
{
TEST_F
(
ExecutorTesterFeed
AndFetch
,
CPU
)
{
std
::
vector
<
Place
>
places
;
CPUPlace
cpu_place
;
places
.
push_back
(
cpu_place
);
...
...
@@ -279,16 +265,15 @@ TEST_F(ExecutorTesterFeed, CPU) {
// 3 mini-batch
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
// need to set feed variable before Executor::Run
std
::
cout
<<
"start mini-batch "
<<
i
<<
std
::
endl
;
set_feed_variable
<
float
>
(
inputs_
);
executor
->
Run
(
pdesc_
,
GetGlobalScope
());
std
::
vector
<
std
::
vector
<
float
>>
result
=
get_fetch_variable
<
float
>
();
for
(
auto
&
vec
:
result
)
{
for
(
auto
&
num
:
vec
)
{
std
::
cout
<<
num
<<
" "
;
PADDLE_ENFORCE_EQ
(
result
.
size
(),
inputs_
.
size
());
for
(
size_t
i
=
0
;
i
<
result
.
size
();
++
i
)
{
PADDLE_ENFORCE_EQ
(
result
[
i
].
size
(),
inputs_
[
i
].
size
());
for
(
size_t
j
=
0
;
j
<
result
[
i
].
size
();
++
j
)
{
PADDLE_ENFORCE_EQ
(
result
[
i
][
j
],
inputs_
[
i
][
j
]);
}
std
::
cout
<<
std
::
endl
;
}
}
...
...
@@ -314,7 +299,7 @@ TEST_F(ExecutorTesterRandom, GPU) {
delete
executor
;
}
TEST_F
(
ExecutorTesterFeed
,
GPU
)
{
TEST_F
(
ExecutorTesterFeed
AndFetch
,
GPU
)
{
std
::
vector
<
Place
>
places
;
GPUPlace
gpu_place
(
0
);
places
.
push_back
(
gpu_place
);
...
...
@@ -331,16 +316,15 @@ TEST_F(ExecutorTesterFeed, GPU) {
// 3 mini-batch
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
// need to set feed variable before Executor::Run
std
::
cout
<<
"start mini-batch "
<<
i
<<
std
::
endl
;
set_feed_variable
<
float
>
(
inputs_
);
executor
->
Run
(
pdesc_
,
GetGlobalScope
());
std
::
vector
<
std
::
vector
<
float
>>
result
=
get_fetch_variable
<
float
>
();
for
(
auto
&
vec
:
result
)
{
for
(
auto
&
num
:
vec
)
{
std
::
cout
<<
num
<<
" "
;
PADDLE_ENFORCE_EQ
(
result
.
size
(),
inputs_
.
size
());
for
(
size_t
i
=
0
;
i
<
result
.
size
();
++
i
)
{
PADDLE_ENFORCE_EQ
(
result
[
i
].
size
(),
inputs_
[
i
].
size
());
for
(
size_t
j
=
0
;
j
<
result
[
i
].
size
();
++
j
)
{
PADDLE_ENFORCE_EQ
(
result
[
i
][
j
],
inputs_
[
i
][
j
]);
}
std
::
cout
<<
std
::
endl
;
}
}
delete
executor
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录