Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
b630d401
P
Paddle
项目概览
PaddlePaddle
/
Paddle
接近 2 年 前同步成功
通知
2320
Star
20933
Fork
5424
代码
文件
提交
分支
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看板
提交
b630d401
编写于
9月 30, 2017
作者:
Q
qijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add scope
上级
d4be9730
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
18 addition
and
8 deletion
+18
-8
paddle/framework/CMakeLists.txt
paddle/framework/CMakeLists.txt
+1
-1
paddle/framework/executor.cc
paddle/framework/executor.cc
+17
-7
未找到文件。
paddle/framework/CMakeLists.txt
浏览文件 @
b630d401
...
...
@@ -44,5 +44,5 @@ add_custom_command(TARGET framework_py_proto POST_BUILD
cc_library
(
backward SRCS backward.cc DEPS net_op
)
cc_test
(
backward_test SRCS backward_test.cc DEPS backward recurrent_op device_context
)
cc_library
(
executor SRCS executor.cc DEPS device_context framework_proto
)
cc_library
(
executor SRCS executor.cc DEPS device_context
scope
framework_proto
)
cc_test
(
executor_test SRCS executor_test.cc DEPS executor
)
paddle/framework/executor.cc
浏览文件 @
b630d401
...
...
@@ -14,6 +14,7 @@ limitations under the License. */
#include "paddle/framework/executor.h"
#include <memory>
#include "paddle/framework/scope.h"
#include "paddle/platform/device_context.h"
namespace
paddle
{
...
...
@@ -58,9 +59,10 @@ void GraphView::Initialize(const ProgramDesc*) {
class
ExecutorImpl
:
public
Executor
{
public:
ExecutorImpl
(
const
platform
::
DeviceContext
*
ctx
,
const
ProgramDesc
*
pdesc
,
bool
is_linear
)
:
device_context_
(
ctx
),
ExecutorImpl
(
Scope
*
scope
,
const
platform
::
DeviceContext
*
ctx
,
const
ProgramDesc
*
pdesc
,
bool
is_linear
)
:
scope_
(
scope
),
device_context_
(
ctx
),
program_desc_
(
pdesc
),
view_
(
ProgramDescView
::
Create
(
is_linear
))
{}
...
...
@@ -73,6 +75,7 @@ class ExecutorImpl : public Executor {
void
Initialize
();
private:
Scope
*
scope_
;
const
platform
::
DeviceContext
*
device_context_
;
const
ProgramDesc
*
program_desc_
;
ProgramDescView
*
view_
;
...
...
@@ -80,23 +83,29 @@ class ExecutorImpl : public Executor {
template
<
typename
T
,
typename
...
Args
>
std
::
unique_ptr
<
T
>
make_unique
(
Args
&&
...
args
)
{
return
std
::
unique_ptr
<
T
>
(
new
T
(
std
::
forward
<
Args
>
(
args
)...));
return
std
::
unique_ptr
<
T
>
(
new
T
(
std
::
forward
<
Args
>
(
args
)...));
}
platform
::
CPUDeviceContext
*
GetCPUDeviceContext
()
{
static
std
::
unique_ptr
<
platform
::
CPUDeviceContext
>
g_cpu_device_context
=
make_unique
<
platform
::
CPUDeviceContext
>
(
platform
::
CPUPlace
());
make_unique
<
platform
::
CPUDeviceContext
>
(
platform
::
CPUPlace
());
return
g_cpu_device_context
.
get
();
}
#ifndef PADDLE_ONLY_CPU
platform
::
CUDADeviceContext
*
GetCUDADeviceContext
()
{
static
std
::
unique_ptr
<
platform
::
CUDADeviceContext
>
g_cuda_device_context
=
make_unique
<
platform
::
CUDADeviceContext
>
(
platform
::
GPUPlace
(
0
));
make_unique
<
platform
::
CUDADeviceContext
>
(
platform
::
GPUPlace
(
0
));
return
g_cuda_device_context
.
get
();
}
#endif
framework
::
Scope
*
GetScope
()
{
static
std
::
unique_ptr
<
framework
::
Scope
>
g_scope
=
make_unique
<
framework
::
Scope
>
();
return
g_scope
.
get
();
}
Executor
*
NewLocalExecutor
(
const
platform
::
Place
&
place
,
const
ProgramDesc
&
pdesc
,
bool
is_linear
)
{
platform
::
DeviceContext
*
device_context
=
nullptr
;
...
...
@@ -110,11 +119,12 @@ Executor* NewLocalExecutor(const platform::Place& place,
PADDLE_THROW
(
"'GPUPlace' is not supported in CPU only device."
);
}
#endif
return
new
ExecutorImpl
(
device_context
,
&
pdesc
,
is_linear
);
return
new
ExecutorImpl
(
GetScope
(),
device_context
,
&
pdesc
,
is_linear
);
}
void
ExecutorImpl
::
Run
()
{
// operators running
scope_
->
NewVar
();
device_context_
->
Wait
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录