graph_executor_eager.cpp 1.04 KB
Newer Older
Mccaskey, Alex's avatar
Mccaskey, Alex committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "graph_executor_eager.hpp"

namespace exatn {
namespace runtime {

void EagerGraphExecutor::execute(TensorGraph & dag) {
  int nodes_executed=0, execnode_id;
  auto num_nodes = dag.getNumNodes();

  while(nodes_executed <= num_nodes) {
    execnode_id = nextExecutableNodeId(dag);
    node_executor_->execute(*((dag.getNodeProperties(execnode_id)).getOperation()));
    //TODO: update output tensor execution table
    dag.setNodeExecuted(execnode_id);
    nodes_executed++;
    num_nodes = dag.getNumNodes();
  }
}

int EagerGraphExecutor::nextExecutableNodeId(TensorGraph & dag){
  auto num_nodes = dag.getNumNodes();
  int i;
  for(i = 0; i < num_nodes; i++) {
    if(!dag.nodeExecuted(i)) {
      if(dag.degree(i)==0)
        break;
      else {
        auto n_list = dag.getNeighborList(i);
        int j;
        for(j = 0; j < n_list.size(); j++)
          if(!dag.nodeExecuted(j))
            break;
        if(j >= n_list.size())
          break;
      }
    }
  }

  assert(i < num_nodes);

  return i;
}

} //namespace runtime
} //namespace exatn