TVM  0.9.4
DependencyGraph.h
Go to the documentation of this file.
1 /* Copyright 2017-2020 CNRS-AIST JRL and CNRS-UM LIRMM */
2 
3 #pragma once
4 
5 #include <tvm/api.h>
6 
7 #include <cstddef>
8 #include <cstdint>
9 #include <set>
10 #include <stack>
11 #include <vector>
12 
13 namespace tvm::graph::internal
14 {
20 {
21 public:
23  size_t addNode();
25  void removeNode(size_t id);
30  bool addEdge(size_t from, size_t to);
36  std::pair<std::vector<std::vector<size_t>>, DependencyGraph> reduce() const;
38  std::vector<size_t> order() const;
43  std::vector<std::vector<size_t>> groupedOrder() const;
45  size_t size() const;
47  const std::set<std::pair<size_t, size_t>> & edges() const;
49  void clear();
50 
51 private:
60  class DisjointSet
61  {
62  public:
64  DisjointSet() = default;
65 
67  DisjointSet(size_t n);
68 
70  void resize(size_t n);
71 
74  size_t root(size_t node) const;
75 
86  void unify(size_t node1, size_t node2);
87 
89  bool isRoot(size_t i) const;
90 
91  private:
96  size_t rootCompr(size_t node);
97 
98  std::vector<size_t> parent_; // parent_[i] is the id of the parent of element i
99  std::vector<size_t> rank_; // rank of each element.
100  };
101 
118  void SCCUtil(std::vector<std::vector<size_t>> & ret,
119  size_t u,
120  std::vector<int> & disc,
121  std::vector<int> & low,
122  std::stack<size_t> & st,
123  std::vector<uint8_t> & stackMember,
124  int & time) const;
125 
127  std::pair<std::vector<size_t>, DisjointSet> order_() const;
128 
139  void orderUtil(size_t v,
140  std::vector<size_t> & order,
141  std::vector<uint8_t> & visited,
142  std::vector<uint8_t> & stack,
143  DisjointSet & components) const;
144 
145  std::vector<uint8_t> roots_; // roots_[i] is true iff the i-th node has no incoming edges
146  std::vector<std::vector<size_t>> children_; // children_[i] lists all the children of node i
147  std::set<std::pair<size_t, size_t>> edges_; // a list of edges (from, to)
148 };
149 } // namespace tvm::graph::internal
#define TVM_DLLAPI
Definition: api.h:35
Definition: DependencyGraph.h:20
std::vector< std::vector< size_t > > groupedOrder() const
std::pair< std::vector< std::vector< size_t > >, DependencyGraph > reduce() const
const std::set< std::pair< size_t, size_t > > & edges() const
std::vector< size_t > order() const
bool addEdge(size_t from, size_t to)
Definition: AbstractNode.h:30