Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
91f5d2b9
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
提交
91f5d2b9
编写于
10月 06, 2017
作者:
Q
qijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
follow comments and create local_scope inside executor run method
上级
e8a678e1
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
16 addition
and
22 deletion
+16
-22
paddle/framework/executor.cc
paddle/framework/executor.cc
+2
-4
paddle/framework/executor_test.cc
paddle/framework/executor_test.cc
+6
-6
paddle/framework/scope.cc
paddle/framework/scope.cc
+1
-1
paddle/framework/scope.h
paddle/framework/scope.h
+1
-1
paddle/operators/feed_op.cc
paddle/operators/feed_op.cc
+1
-1
paddle/operators/feed_op.h
paddle/operators/feed_op.h
+2
-4
paddle/operators/fetch_op.cc
paddle/operators/fetch_op.cc
+1
-1
paddle/operators/fetch_op.h
paddle/operators/fetch_op.h
+2
-4
未找到文件。
paddle/framework/executor.cc
浏览文件 @
91f5d2b9
...
...
@@ -56,9 +56,7 @@ void Executor::Run(const ProgramDesc& pdesc, Scope* scope) {
auto
&
block
=
pdesc
.
blocks
(
0
);
auto
&
device
=
device_contexts_
[
0
];
// TODO(tonyyang-svail):
// - runs on a new local scope
// Scope& local_scope = scope->NewScope();
Scope
&
local_scope
=
scope
->
NewScope
();
for
(
auto
&
var
:
block
.
vars
())
{
scope
->
NewVar
(
var
.
name
());
...
...
@@ -67,7 +65,7 @@ void Executor::Run(const ProgramDesc& pdesc, Scope* scope) {
for
(
auto
&
op_desc
:
block
.
ops
())
{
auto
op
=
paddle
::
framework
::
OpRegistry
::
CreateOp
(
op_desc
);
std
::
cout
<<
op
->
DebugString
()
<<
std
::
endl
;
op
->
Run
(
*
scope
,
*
device
);
op
->
Run
(
local_
scope
,
*
device
);
}
// TODO(tonyyang-svail): need to test gpu device
...
...
paddle/framework/executor_test.cc
浏览文件 @
91f5d2b9
...
...
@@ -131,7 +131,7 @@ 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
=
GetScope
()
->
FindVar
(
"feed_value"
);
Variable
*
g_feed_value
=
Get
Global
Scope
()
->
FindVar
(
"feed_value"
);
FeedInputs
&
feed_inputs
=
*
(
g_feed_value
->
GetMutable
<
FeedInputs
>
());
auto
size
=
inputs
.
size
();
feed_inputs
.
resize
(
size
);
...
...
@@ -146,7 +146,7 @@ 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
=
GetScope
()
->
FindVar
(
"fetch_value"
);
Variable
*
g_fetch_value
=
Get
Global
Scope
()
->
FindVar
(
"fetch_value"
);
FetchOutputs
&
fetch_outputs
=
*
(
g_fetch_value
->
GetMutable
<
FetchOutputs
>
());
auto
size
=
fetch_outputs
.
size
();
...
...
@@ -252,7 +252,7 @@ TEST_F(ExecutorTesterRandom, CPU) {
paddle
::
memory
::
Used
(
cpu_place
);
Executor
*
executor
=
new
Executor
(
places
);
executor
->
Run
(
pdesc_
,
GetScope
());
executor
->
Run
(
pdesc_
,
Get
Global
Scope
());
std
::
vector
<
std
::
vector
<
float
>>
result
=
get_fetch_variable
<
float
>
();
for
(
auto
&
vec
:
result
)
{
for
(
auto
&
num
:
vec
)
{
...
...
@@ -281,7 +281,7 @@ TEST_F(ExecutorTesterFeed, CPU) {
// need to set feed variable before Executor::Run
std
::
cout
<<
"start mini-batch "
<<
i
<<
std
::
endl
;
set_feed_variable
<
float
>
(
inputs_
);
executor
->
Run
(
pdesc_
,
GetScope
());
executor
->
Run
(
pdesc_
,
Get
Global
Scope
());
std
::
vector
<
std
::
vector
<
float
>>
result
=
get_fetch_variable
<
float
>
();
for
(
auto
&
vec
:
result
)
{
for
(
auto
&
num
:
vec
)
{
...
...
@@ -309,7 +309,7 @@ TEST_F(ExecutorTesterRandom, GPU) {
paddle
::
memory
::
Used
(
gpu_place
);
Executor
*
executor
=
new
Executor
(
places
);
executor
->
Run
(
pdesc_
,
GetScope
());
executor
->
Run
(
pdesc_
,
Get
Global
Scope
());
delete
executor
;
}
...
...
@@ -333,7 +333,7 @@ TEST_F(ExecutorTesterFeed, GPU) {
// need to set feed variable before Executor::Run
std
::
cout
<<
"start mini-batch "
<<
i
<<
std
::
endl
;
set_feed_variable
<
float
>
(
inputs_
);
executor
->
Run
(
pdesc_
,
GetScope
());
executor
->
Run
(
pdesc_
,
Get
Global
Scope
());
std
::
vector
<
std
::
vector
<
float
>>
result
=
get_fetch_variable
<
float
>
();
for
(
auto
&
vec
:
result
)
{
for
(
auto
&
num
:
vec
)
{
...
...
paddle/framework/scope.cc
浏览文件 @
91f5d2b9
...
...
@@ -66,7 +66,7 @@ void Scope::DropKids() {
std
::
once_flag
feed_variable_flag
;
framework
::
Scope
*
GetScope
()
{
framework
::
Scope
*
Get
Global
Scope
()
{
static
std
::
unique_ptr
<
framework
::
Scope
>
g_scope
{
nullptr
};
std
::
call_once
(
feed_variable_flag
,
[
&
]()
{
g_scope
.
reset
(
new
framework
::
Scope
());
...
...
paddle/framework/scope.h
浏览文件 @
91f5d2b9
...
...
@@ -73,7 +73,7 @@ class Scope {
DISABLE_COPY_AND_ASSIGN
(
Scope
);
};
framework
::
Scope
*
GetScope
();
framework
::
Scope
*
Get
Global
Scope
();
}
// namespace framework
}
// namespace paddle
paddle/operators/feed_op.cc
浏览文件 @
91f5d2b9
...
...
@@ -27,7 +27,7 @@ class FeedOp : public framework::OperatorWithKernel {
PADDLE_ENFORCE
(
ctx
->
HasOutput
(
"Out"
),
"Output should be not null."
);
int
col
=
ctx
->
Attrs
().
Get
<
int
>
(
"col"
);
framework
::
Variable
*
g_feed_variable
=
framework
::
GetScope
()
->
FindVar
(
"feed_value"
);
framework
::
Get
Global
Scope
()
->
FindVar
(
"feed_value"
);
const
FeedInputs
&
tensors
=
g_feed_variable
->
Get
<
FeedInputs
>
();
...
...
paddle/operators/feed_op.h
浏览文件 @
91f5d2b9
...
...
@@ -19,17 +19,15 @@ limitations under the License. */
namespace
paddle
{
namespace
operators
{
using
Tensor
=
framework
::
Tensor
;
template
<
typename
T
>
class
FeedKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
typedef
std
::
vector
<
framework
::
Tensor
>
FeedInputs
;
Tensor
*
out
=
ctx
.
Output
<
Tensor
>
(
"Out"
);
framework
::
Tensor
*
out
=
ctx
.
Output
<
framework
::
Tensor
>
(
"Out"
);
out
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
framework
::
Variable
*
g_feed_variable
=
framework
::
GetScope
()
->
FindVar
(
"feed_value"
);
framework
::
Get
Global
Scope
()
->
FindVar
(
"feed_value"
);
int
col
=
ctx
.
template
Attr
<
int
>(
"col"
);
const
FeedInputs
&
tensors
=
g_feed_variable
->
Get
<
FeedInputs
>
();
out
->
CopyFrom
<
T
>
(
tensors
[
col
],
ctx
.
GetPlace
());
...
...
paddle/operators/fetch_op.cc
浏览文件 @
91f5d2b9
...
...
@@ -27,7 +27,7 @@ class FetchOp : public framework::OperatorWithKernel {
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Input"
),
"Input should be not null."
);
int
col
=
ctx
->
Attrs
().
Get
<
int
>
(
"col"
);
framework
::
Variable
*
g_fetch_variable
=
framework
::
GetScope
()
->
FindVar
(
"fetch_value"
);
framework
::
Get
Global
Scope
()
->
FindVar
(
"fetch_value"
);
FetchOutputs
*
tensors
=
g_fetch_variable
->
GetMutable
<
FetchOutputs
>
();
if
(
tensors
->
size
()
<
static_cast
<
size_t
>
(
col
+
1
))
{
...
...
paddle/operators/fetch_op.h
浏览文件 @
91f5d2b9
...
...
@@ -19,17 +19,15 @@ limitations under the License. */
namespace
paddle
{
namespace
operators
{
using
Tensor
=
framework
::
Tensor
;
template
<
typename
T
>
class
FetchKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
typedef
std
::
vector
<
framework
::
Tensor
>
FetchOutputs
;
const
Tensor
*
input
=
ctx
.
Input
<
Tensor
>
(
"Input"
);
const
framework
::
Tensor
*
input
=
ctx
.
Input
<
framework
::
Tensor
>
(
"Input"
);
int
col
=
ctx
.
template
Attr
<
int
>(
"col"
);
framework
::
Variable
*
g_fetch_variable
=
framework
::
GetScope
()
->
FindVar
(
"fetch_value"
);
framework
::
Get
Global
Scope
()
->
FindVar
(
"fetch_value"
);
FetchOutputs
*
tensors
=
g_fetch_variable
->
GetMutable
<
FetchOutputs
>
();
(
*
tensors
)[
col
].
mutable_data
<
T
>
(
platform
::
CPUPlace
());
(
*
tensors
)[
col
].
CopyFrom
<
T
>
(
*
input
,
platform
::
CPUPlace
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录