executor.md 2.0 KB
Newer Older
Y
Yang Yang(Tony) 已提交
1 2 3
# Executor Design Doc

## Motivation
D
dzhwinter 已提交
4 5
In the [fluid](https://github.com/PaddlePaddle/Paddle/blob/develop/doc/design/fluid.md), we encourage user use deep learning programming paradigms to describe training process. When the user-written Python program is executed, it will create a protobuf message
[`ProgramDesc`](https://github.com/PaddlePaddle/Paddle/blob/a91efdde6910ce92a78e3aa7157412c4c88d9ee8/paddle/framework/framework.proto#L145) that describes the process and is conceptually like an [abstract syntax tree](https://en.wikipedia.org/wiki/Abstract_syntax_tree).
Y
Yang Yang(Tony) 已提交
6

D
dzhwinter 已提交
7
The executor runs the `ProgramDesc` like an interpreter. `ProgramDesc` contains intrinsics/operators and variables which will be used, executor explicitly execute the stored precompiled code.
Y
Yang Yang(Tony) 已提交
8 9 10

## Overview

Y
Yang Yang(Tony) 已提交
11 12
An executor takes a `ProgramDesc`, a `block_id` and a `Scope`.  The `ProgramDesc` is a list of blocks and each block contains the protobuf definition of all the parameters and operators. The `block_id` specifies the entrance block. And the `Scope` is the container of all the variable instance, which is persistent throughout different runs.

D
dzhwinter 已提交
13
## Executor
Y
Yang Yang(Tony) 已提交
14

D
dzhwinter 已提交
15
`Executor` explicitly executes all the intrinsics/operators in the `block_id`th block of a `ProgramDesc`. Essentially, it instantiates Variables and Operators, then runs all the operators in sequence. It is very similar to push stack frame when entering the block, it will destroy the temporary variables when mini-batch is finished, but it does not have stack frame pop process.
Y
Yang Yang(Tony) 已提交
16

D
dzhwinter 已提交
17 18 19 20 21
### Interface
```c++
  Executor(places);
```
A executor does not own any computing resources, user can only construct an executor with specified places.
Y
Yang Yang(Tony) 已提交
22 23


D
dzhwinter 已提交
24 25 26 27
```
  void Run(ProgramDesc, Scope, block_id, create_local_scope);
```
A executor only provides an unified way to execute `ProgramDesc`. `ProgramDesc` is the target will be executed, scope specifies the variable container. `block_id` indicates the entrance block, `create_local_scope` means if it will destroy the temporary variables after execution finished.