executor.md 896 字节
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
  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();
Y
Yang Yang(Tony) 已提交
19
  for (auto& op_desc : block.ops()) {
Y
Yang Yang(Tony) 已提交
20
    for (auto& var : op_desc.outputs()) {
Y
Yang Yang(Tony) 已提交
21
      for (auto& argu : var.arguments()) {
Y
Yang Yang(Tony) 已提交
22 23 24
        // 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
    auto op = paddle::framework::OpRegistry::CreateOp(op_desc);
Y
Yang Yang(Tony) 已提交
29
    op->Run(local_scope, *device);
Y
Yang Yang(Tony) 已提交
30 31 32
  }
}
```