Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
f5e73f4c
P
Paddle
项目概览
机器未来
/
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看板
提交
f5e73f4c
编写于
10月 03, 2017
作者:
Y
Yang Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pass simple elementwise_add op
上级
e946fc15
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
58 addition
and
41 deletion
+58
-41
paddle/framework/executor.cc
paddle/framework/executor.cc
+15
-21
paddle/framework/executor_test.cc
paddle/framework/executor_test.cc
+43
-20
未找到文件。
paddle/framework/executor.cc
浏览文件 @
f5e73f4c
...
@@ -13,8 +13,10 @@ See the License for the specific language governing permissions and
...
@@ -13,8 +13,10 @@ See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#include "paddle/framework/executor.h"
#include "paddle/framework/executor.h"
#include <iostream>
#include <memory>
#include <memory>
#include <vector>
#include <vector>
#include "paddle/framework/lod_tensor.h"
#include "paddle/framework/op_registry.h"
#include "paddle/framework/op_registry.h"
#include "paddle/framework/scope.h"
#include "paddle/framework/scope.h"
...
@@ -30,41 +32,33 @@ Executor::Executor(const std::vector<platform::Place>& places) {
...
@@ -30,41 +32,33 @@ Executor::Executor(const std::vector<platform::Place>& places) {
void
Executor
::
Run
(
const
ProgramDesc
&
pdesc
,
Scope
*
scope
,
void
Executor
::
Run
(
const
ProgramDesc
&
pdesc
,
Scope
*
scope
,
std
::
vector
<
Tensor
>*
outputs
)
{
std
::
vector
<
Tensor
>*
outputs
)
{
// operators running
// TODO(tonyyang-svail):
// TODO(tonyyang-svail):
// - only runs the first block
// - only runs the first block
// - only runs on the first device
// - only runs on the first device
// - test on gpu
auto
&
block
=
pdesc
.
blocks
(
0
);
auto
&
block
=
pdesc
.
blocks
(
0
);
auto
&
device
=
devices_
[
0
];
auto
&
device
=
devices_
[
0
];
// TODO(tonyyang-svail):
// - runs on a new local scope
// Scope& local_scope = scope->NewScope();
for
(
auto
&
var
:
block
.
vars
())
{
for
(
auto
&
var
:
block
.
vars
())
{
scope
->
NewVar
(
var
.
name
());
scope
->
NewVar
(
var
.
name
());
}
}
// std::vector<op_ptr> ops;
for
(
auto
&
op_desc
:
block
.
ops
())
{
for
(
auto
&
op_desc
:
block
.
ops
())
{
auto
op
=
framework
::
OpRegistry
::
CreateOp
(
op_desc
);
auto
op
=
paddle
::
framework
::
OpRegistry
::
CreateOp
(
op_desc
);
// op->InferShape(*scope);
op
->
Run
(
*
scope
,
*
device
->
cpu_device_context
);
op
->
Run
(
*
scope
,
*
device
->
cpu_device_context
);
}
}
// TODO(tonyyang-svail): need to test gpu device
// print tensor value
// device_->cpu_device_context->Wait();
for
(
auto
&
var
:
block
.
vars
())
{
// #ifndef PADDLE_ONLY_CPU
std
::
cout
<<
var
.
name
()
<<
std
::
endl
;
// if (device_->cuda_device_context) {
auto
v
=
scope
->
FindVar
(
var
.
name
());
// device_->cuda_device_context->Wait();
const
LoDTensor
&
t
=
v
->
Get
<
LoDTensor
>
();
// }
for
(
int
i
=
0
;
i
<
t
.
numel
();
++
i
)
std
::
cout
<<
t
.
data
<
float
>
()[
i
]
<<
" "
;
// #endif
std
::
cout
<<
std
::
endl
;
Scope
&
local_scope
=
scope
->
NewScope
();
local_scope
.
NewVar
();
for
(
auto
device
:
devices_
)
{
device
->
cpu_device_context
->
Wait
();
#ifndef PADDLE_ONLY_CPU
if
(
device
->
cuda_device_context
)
{
device
->
cuda_device_context
->
Wait
();
}
#endif
}
}
}
}
...
...
paddle/framework/executor_test.cc
浏览文件 @
f5e73f4c
...
@@ -16,16 +16,49 @@ limitations under the License. */
...
@@ -16,16 +16,49 @@ limitations under the License. */
#include "gtest/gtest.h"
#include "gtest/gtest.h"
#include "paddle/framework/attribute.h"
#include "paddle/framework/attribute.h"
#include <gtest/gtest.h>
#include "paddle/framework/grad_op_builder.h"
#include "paddle/framework/grad_op_builder.h"
#include "paddle/framework/op_registry.h"
#include "paddle/framework/op_registry.h"
#include "paddle/framework/operator.h"
#include "paddle/framework/operator.h"
#include <vector>
USE_OP
(
elementwise_add
);
USE_OP
(
elementwise_add
);
USE_OP
(
gaussian_random
);
using
namespace
paddle
::
platform
;
using
namespace
paddle
::
platform
;
using
namespace
paddle
::
framework
;
using
namespace
paddle
::
framework
;
typedef
paddle
::
framework
::
BlockDesc
proto_block
;
typedef
paddle
::
framework
::
OpDesc
proto_op
;
using
std
::
string
;
void
add_gaussian_random_op
(
string
var_name
,
proto_block
*
block
)
{
std
::
vector
<
int
>
dim
{
2
,
3
};
// insert variable
auto
a
=
block
->
add_vars
();
a
->
set_name
(
var_name
);
auto
a_lt
=
a
->
mutable_lod_tensor
();
a_lt
->
set_data_type
(
paddle
::
framework
::
DataType
::
FP32
);
for
(
int
i
:
dim
)
{
a_lt
->
add_dims
(
i
);
}
// insert operation
auto
op
=
block
->
add_ops
();
op
->
set_type
(
"gaussian_random"
);
auto
dims
=
op
->
add_attrs
();
dims
->
set_name
(
"dims"
);
dims
->
set_type
(
paddle
::
framework
::
AttrType
::
INTS
);
for
(
int
i
:
dim
)
{
dims
->
add_ints
(
i
);
}
auto
Out
=
op
->
add_outputs
();
Out
->
set_parameter
(
"Out"
);
Out
->
add_arguments
(
var_name
);
}
TEST
(
Executor
,
Init
)
{
TEST
(
Executor
,
Init
)
{
ProgramDesc
pdesc
;
ProgramDesc
pdesc
;
...
@@ -33,35 +66,25 @@ TEST(Executor, Init) {
...
@@ -33,35 +66,25 @@ TEST(Executor, Init) {
root_block
->
set_idx
(
0
);
root_block
->
set_idx
(
0
);
root_block
->
set_parent_idx
(
-
1
);
root_block
->
set_parent_idx
(
-
1
);
auto
a
=
root_block
->
add_vars
();
add_gaussian_random_op
(
"a"
,
root_block
);
a
->
set_name
(
"a"
);
add_gaussian_random_op
(
"b"
,
root_block
);
auto
a_lt
=
a
->
mutable_lod_tensor
();
a_lt
->
set_data_type
(
paddle
::
framework
::
DataType
::
FP32
);
a_lt
->
add_dims
(
640
);
a_lt
->
add_dims
(
640
);
auto
b
=
root_block
->
add_vars
();
b
->
set_name
(
"b"
);
auto
b_lt
=
b
->
mutable_lod_tensor
();
b_lt
->
set_data_type
(
paddle
::
framework
::
DataType
::
FP32
);
b_lt
->
add_dims
(
640
);
b_lt
->
add_dims
(
640
);
auto
c
=
root_block
->
add_vars
();
auto
c
=
root_block
->
add_vars
();
c
->
set_name
(
"c"
);
c
->
set_name
(
"c"
);
auto
c_lt
=
c
->
mutable_lod_tensor
();
auto
c_lt
=
c
->
mutable_lod_tensor
();
c_lt
->
set_data_type
(
paddle
::
framework
::
DataType
::
FP32
);
c_lt
->
set_data_type
(
paddle
::
framework
::
DataType
::
FP32
);
c_lt
->
add_dims
(
640
);
c_lt
->
add_dims
(
640
);
auto
op
1
=
root_block
->
add_ops
();
auto
op
=
root_block
->
add_ops
();
op
1
->
set_type
(
"elementwise_add"
);
op
->
set_type
(
"elementwise_add"
);
auto
X
=
op
1
->
add_inputs
();
auto
X
=
op
->
add_inputs
();
X
->
set_parameter
(
"X"
);
X
->
set_parameter
(
"X"
);
X
->
add_arguments
(
"a"
);
X
->
add_arguments
(
"a"
);
auto
Y
=
op
1
->
add_inputs
();
auto
Y
=
op
->
add_inputs
();
Y
->
set_parameter
(
"Y"
);
Y
->
set_parameter
(
"Y"
);
Y
->
add_arguments
(
"b"
);
Y
->
add_arguments
(
"b"
);
auto
Out
=
op
->
add_outputs
();
Out
->
set_parameter
(
"Out"
);
Out
->
add_arguments
(
"c"
);
CPUPlace
cpu_place1
,
cpu_place2
;
CPUPlace
cpu_place1
,
cpu_place2
;
std
::
vector
<
Place
>
places
;
std
::
vector
<
Place
>
places
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录