Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
f410622f
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f410622f
编写于
10月 10, 2017
作者:
Y
Yang Yang
浏览文件
操作
浏览文件
下载
差异文件
merge follow comment
上级
a528a971
436ea50d
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
76 addition
and
14 deletion
+76
-14
paddle/framework/executor.cc
paddle/framework/executor.cc
+62
-1
paddle/framework/executor_test.cc
paddle/framework/executor_test.cc
+9
-8
paddle/framework/scope.cc
paddle/framework/scope.cc
+2
-2
paddle/framework/scope.h
paddle/framework/scope.h
+1
-1
paddle/operators/feed_op.h
paddle/operators/feed_op.h
+1
-1
paddle/operators/fetch_op.h
paddle/operators/fetch_op.h
+1
-1
未找到文件。
paddle/framework/executor.cc
浏览文件 @
f410622f
...
...
@@ -32,7 +32,68 @@ namespace framework {
const
std
::
string
kFeedOpType
=
"feed"
;
const
std
::
string
kFetchOpType
=
"fetch"
;
std
::
vector
<
bool
>
Prune
(
const
ProgramDesc
&
pdesc
,
int
block_id
)
{
Executor
::
Executor
(
const
std
::
vector
<
platform
::
Place
>&
places
)
{
PADDLE_ENFORCE_GT
(
places
.
size
(),
0
);
device_contexts_
.
resize
(
places
.
size
());
for
(
size_t
i
=
0
;
i
<
places
.
size
();
i
++
)
{
if
(
platform
::
is_cpu_place
(
places
[
i
]))
{
device_contexts_
[
i
]
=
new
platform
::
CPUDeviceContext
(
boost
::
get
<
platform
::
CPUPlace
>
(
places
[
i
]));
}
else
if
(
platform
::
is_gpu_place
(
places
[
i
]))
{
#ifdef PADDLE_WITH_CUDA
device_contexts_
[
i
]
=
new
platform
::
CUDADeviceContext
(
boost
::
get
<
platform
::
GPUPlace
>
(
places
[
i
]));
#else
PADDLE_THROW
(
"'GPUPlace' is not supported, Please re-compile with WITH_GPU "
"option"
);
#endif
}
}
}
Executor
::~
Executor
()
{
for
(
auto
&
device_context
:
device_contexts_
)
{
delete
device_context
;
}
}
void
Executor
::
Run
(
const
ProgramDesc
&
pdesc
,
Scope
*
scope
,
int
block_id
)
{
// TODO(tonyyang-svail):
// - only runs on the first device (i.e. no interdevice communication)
// - will change to use multiple blocks for RNN op and Cond Op
PADDLE_ENFORCE_GT
(
pdesc
.
blocks_size
(),
block_id
);
auto
&
block
=
pdesc
.
blocks
(
block_id
);
auto
&
device
=
device_contexts_
[
0
];
// Instantiate all the vars in the global scope
for
(
auto
&
var
:
block
.
vars
())
{
scope
->
NewVar
(
var
.
name
());
}
Scope
&
local_scope
=
scope
->
NewScope
();
std
::
vector
<
bool
>
should_run
=
Prune
(
pdesc
,
block_id
);
PADDLE_ENFORCE_EQ
(
should_run
.
size
(),
static_cast
<
size_t
>
(
block
.
ops_size
()));
for
(
size_t
i
=
0
;
i
<
should_run
.
size
();
++
i
)
{
if
(
should_run
[
i
])
{
for
(
auto
&
var
:
block
.
ops
(
i
).
outputs
())
{
for
(
auto
&
argu
:
var
.
arguments
())
{
if
(
local_scope
.
FindVar
(
argu
)
==
nullptr
)
{
local_scope
.
NewVar
(
argu
);
}
}
}
auto
op
=
paddle
::
framework
::
OpRegistry
::
CreateOp
(
block
.
ops
(
i
));
op
->
Run
(
local_scope
,
*
device
);
}
}
// TODO(tonyyang-svail):
// - Destroy local_scope
}
std
::
vector
<
bool
>
Executor
::
Prune
(
const
ProgramDesc
&
pdesc
,
int
block_id
)
{
// TODO(tonyyang-svail):
// - will change to use multiple blocks for RNN op and Cond Op
...
...
paddle/framework/executor_test.cc
浏览文件 @
f410622f
...
...
@@ -66,7 +66,7 @@ void AddOp(const std::string& type, const VariableNameMap& inputs,
template
<
typename
T
>
void
SetFeedVariable
(
const
std
::
vector
<
std
::
vector
<
T
>>&
inputs
,
const
std
::
vector
<
std
::
vector
<
int64_t
>>&
dims
)
{
Variable
*
g_feed_value
=
GetGlobalScope
()
->
FindVar
(
"feed_value"
);
Variable
*
g_feed_value
=
GetGlobalScope
()
.
FindVar
(
"feed_value"
);
auto
&
feed_inputs
=
*
(
g_feed_value
->
GetMutable
<
std
::
vector
<
paddle
::
framework
::
Tensor
>>
());
size_t
size
=
inputs
.
size
();
...
...
@@ -81,7 +81,7 @@ void SetFeedVariable(const std::vector<std::vector<T>>& inputs,
// So we can memcpy the data from fetch_value to vector<T>
template
<
typename
T
>
std
::
vector
<
std
::
vector
<
T
>>
GetFetchVariable
()
{
Variable
*
g_fetch_value
=
GetGlobalScope
()
->
FindVar
(
"fetch_value"
);
Variable
*
g_fetch_value
=
GetGlobalScope
()
.
FindVar
(
"fetch_value"
);
auto
&
fetch_outputs
=
*
(
g_fetch_value
->
GetMutable
<
std
::
vector
<
paddle
::
framework
::
Tensor
>>
());
...
...
@@ -231,8 +231,9 @@ TEST_F(ExecutorTesterRandom, CPU) {
std
::
unique_ptr
<
Executor
>
executor
(
new
Executor
(
places
));
executor
->
Run
(
init_pdesc_
,
GetGlobalScope
(),
0
);
executor
->
Run
(
pdesc_
,
GetGlobalScope
(),
0
);
executor
->
Run
(
init_pdesc_
,
&
GetGlobalScope
(),
0
);
SetFeedVariable
<
float
>
(
inputs_
,
dims_
);
executor
->
Run
(
pdesc_
,
&
GetGlobalScope
(),
0
);
std
::
vector
<
std
::
vector
<
float
>>
result
=
GetFetchVariable
<
float
>
();
}
...
...
@@ -251,7 +252,7 @@ TEST_F(ExecutorTesterFeedAndFetch, CPU) {
for
(
int
batch_id
=
0
;
batch_id
<
3
;
batch_id
++
)
{
SetFeedVariable
<
float
>
(
inputs_
,
dims_
);
executor
->
Run
(
pdesc_
,
GetGlobalScope
(),
0
);
executor
->
Run
(
pdesc_
,
&
GetGlobalScope
(),
0
);
std
::
vector
<
std
::
vector
<
float
>>
result
=
GetFetchVariable
<
float
>
();
PADDLE_ENFORCE_EQ
(
result
.
size
(),
inputs_
.
size
());
for
(
size_t
i
=
0
;
i
<
result
.
size
();
++
i
)
{
...
...
@@ -279,10 +280,10 @@ TEST_F(ExecutorTesterRandom, GPU) {
std
::
unique_ptr
<
Executor
>
executor
(
new
Executor
(
places
));
executor
->
Run
(
init_pdesc_
,
GetGlobalScope
(),
0
);
executor
->
Run
(
init_pdesc_
,
&
GetGlobalScope
(),
0
);
for
(
int
batch_id
=
0
;
batch_id
<
3
;
batch_id
++
)
{
SetFeedVariable
<
float
>
(
inputs_
,
dims_
);
executor
->
Run
(
pdesc_
,
GetGlobalScope
(),
0
);
executor
->
Run
(
pdesc_
,
&
GetGlobalScope
(),
0
);
}
}
...
...
@@ -303,7 +304,7 @@ TEST_F(ExecutorTesterFeedAndFetch, GPU) {
for
(
int
batch_id
=
0
;
batch_id
<
3
;
batch_id
++
)
{
SetFeedVariable
<
float
>
(
inputs_
,
dims_
);
executor
->
Run
(
pdesc_
,
GetGlobalScope
(),
0
);
executor
->
Run
(
pdesc_
,
&
GetGlobalScope
(),
0
);
std
::
vector
<
std
::
vector
<
float
>>
result
=
GetFetchVariable
<
float
>
();
PADDLE_ENFORCE_EQ
(
result
.
size
(),
inputs_
.
size
());
for
(
size_t
i
=
0
;
i
<
result
.
size
();
++
i
)
{
...
...
paddle/framework/scope.cc
浏览文件 @
f410622f
...
...
@@ -67,14 +67,14 @@ void Scope::DropKids() {
std
::
once_flag
feed_variable_flag
;
framework
::
Scope
*
GetGlobalScope
()
{
framework
::
Scope
&
GetGlobalScope
()
{
static
std
::
unique_ptr
<
framework
::
Scope
>
g_scope
{
nullptr
};
std
::
call_once
(
feed_variable_flag
,
[
&
]()
{
g_scope
.
reset
(
new
framework
::
Scope
());
g_scope
->
NewVar
(
"feed_value"
);
g_scope
->
NewVar
(
"fetch_value"
);
});
return
g_scope
.
get
(
);
return
*
(
g_scope
.
get
()
);
}
}
// namespace framework
...
...
paddle/framework/scope.h
浏览文件 @
f410622f
...
...
@@ -73,7 +73,7 @@ class Scope {
DISABLE_COPY_AND_ASSIGN
(
Scope
);
};
framework
::
Scope
*
GetGlobalScope
();
framework
::
Scope
&
GetGlobalScope
();
}
// namespace framework
}
// namespace paddle
paddle/operators/feed_op.h
浏览文件 @
f410622f
...
...
@@ -26,7 +26,7 @@ class FeedKernel : public framework::OpKernel<T> {
framework
::
Tensor
*
out
=
ctx
.
Output
<
framework
::
Tensor
>
(
"Out"
);
out
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
framework
::
Variable
*
g_feed_variable
=
framework
::
GetGlobalScope
()
->
FindVar
(
"feed_value"
);
framework
::
GetGlobalScope
()
.
FindVar
(
"feed_value"
);
const
auto
&
tensors
=
g_feed_variable
->
Get
<
std
::
vector
<
framework
::
Tensor
>>
();
int
col
=
ctx
.
template
Attr
<
int
>(
"col"
);
...
...
paddle/operators/fetch_op.h
浏览文件 @
f410622f
...
...
@@ -25,7 +25,7 @@ class FetchKernel : public framework::OpKernel<T> {
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
const
framework
::
Tensor
*
input
=
ctx
.
Input
<
framework
::
Tensor
>
(
"Input"
);
framework
::
Variable
*
g_fetch_variable
=
framework
::
GetGlobalScope
()
->
FindVar
(
"fetch_value"
);
framework
::
GetGlobalScope
()
.
FindVar
(
"fetch_value"
);
auto
*
tensors
=
g_fetch_variable
->
GetMutable
<
std
::
vector
<
framework
::
Tensor
>>
();
int
col
=
ctx
.
template
Attr
<
int
>(
"col"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录