executor.md 917 字节
Newer Older
Y
Yang Yang(Tony) 已提交
1 2 3 4 5 6 7
# Executor Desgin Doc

## Overview

`Executor` evaluates a `ProgramDesc`. Essentially, it instantializes Variables and Operators, then run all the operators

```c++
Y
Yang Yang(Tony) 已提交
8 9
void Executor::Run(const ProgramDesc& pdesc, Scope* scope, int block_id) {
  auto& block = pdesc.blocks(block_id);
Y
Yang Yang(Tony) 已提交
10 11 12 13 14 15 16 17 18 19
  auto& device = device_contexts_[0];

  // Instantiate all the vars in the global scope
  for (auto& var : block.vars()) {
    scope->NewVar(var.name());
  }

  // Run the block
  Scope& local_scope = scope->NewScope();
  for (size_t i = 0; i < should_run.size(); ++i) {
Y
Yang Yang(Tony) 已提交
20 21 22 23 24
    for (auto var : block.ops(i).outputs()) {
      for (auto argu : var.arguments()) {
        // Create temp variable in the local_scope
        if (local_scope.FindVar(argu) == nullptr) {
          local_scope.NewVar(argu);
Y
Yang Yang(Tony) 已提交
25 26 27
        }
      }
    }
Y
Yang Yang(Tony) 已提交
28 29
    auto op = paddle::framework::OpRegistry::CreateOp(block.ops(i));
    op->Run(local_scope, *device);
Y
Yang Yang(Tony) 已提交
30 31 32
  }
}
```