forked from PaddlePaddle/Paddle
    
        
        - 
                Notifications
    
You must be signed in to change notification settings  - Fork 0
 
dagnet create
        乔龙飞 edited this page Jun 15, 2017 
        ·
        1 revision
      
    DAGNetBase::DAGNetBase(const NetDef& net_def) {
  std::map<string, int> blob_creator;
  std::map<string, std::set<int>> blob_readers;
  // Initialize the operators
  for (int idx = 0; idx < net_def.op_size(); ++idx) {
    // 1. 初始化operater.
    operator_nodes_[idx].operator_ = CreateOperator(net_def.op(idx), ws);
    // 2. 检查inputs. 设置parent,解决`read after write`的问题.
    for (const string& input : op_def.input()) {
      int parent = blob_creator[input];
      // 创建input的op是当前op的parent。
      operator_nodes_[idx].parents_.push_back(parent);
      // 当前op是创建input的op 的chirdren
      operator_nodes_[parent].children_.push_back(idx);
      // 当前op需要读这个input.
      blob_readers[input].insert(idx);
    }
    // 3. 检查 outputs.
    for (const string& output : op_def.output()) {
      if (blob_creator.count(output) != 0) {
        // 解决`write after write`的问题(假设是顺序写).
        int waw_parent = blob_creator[output];
        operator_nodes_[idx].parents_.push_back(waw_parent);
        operator_nodes_[waw_parent].children_.push_back(idx);
      }
      // 解决`write after read`的问题 - we will assume that writes
      // should only occur after all previous reads are finished.
      for (const int war_parent : blob_readers[output]) {
        operator_nodes_[idx].parents_.push_back(war_parent);
        operator_nodes_[war_parent].children_.push_back(idx);
      }
    }
  }
  // 4. 对每个node的parents_和children_做一些去重和排序的事儿。
  // 5. 生成执行的链表,方便并发执行。
}- 初始化operater.
 - 检查inputs. 设置parent和children,解决
read after write的问题. - 检查 outputs.设置parent和children,解决
write after write和write after read的问题。 - 对每个node的parents_和children_做一些去重和排序。
 - 生成执行的链表,方便并发执行。