TVM  0.9.4
CallGraph.h
Go to the documentation of this file.
1 
3 #pragma once
4 
5 #include <tvm/api.h>
6 
9 
10 namespace tvm
11 {
12 
13 namespace graph
14 {
15 
23 {
24 public:
26  void add(std::shared_ptr<internal::Inputs> inputs);
27 
29  void update();
30 
32  inline void execute() const { plan_.execute(); }
33 
35  void clear();
36 
37 protected:
39  struct Call
40  {
42  int id;
43  inline void operator()() const { node->update(id); }
44  };
45 
47  struct CompareCall
48  {
49  bool operator()(const Call & c1, const Call & c2) const
50  { return (c1.node < c2.node) || (c1.node == c2.node && c1.id < c2.id); }
51  };
52 
54  struct Plan
55  {
57  void build(const CallGraph & graph);
58 
60  void clear();
61 
63  inline void execute() const
64  {
65  for(auto & c : plan_)
66  {
67  c();
68  }
69  }
70 
71  private:
73  std::vector<Call> plan_;
74  };
75 
76 protected:
84  std::vector<int> addOutput(abstract::Outputs * source, int output);
85 
92  int addCall(Call c);
93 
95  std::vector<std::shared_ptr<internal::Inputs>> inputs_;
97  std::map<Call, int, CompareCall> callId_;
99  std::vector<Call> calls_;
102 
104  std::map<std::intptr_t, std::map<int, std::vector<int>>> visited_;
105 
108 };
109 
110 } // namespace graph
111 
112 } // namespace tvm
#define TVM_DLLAPI
Definition: api.h:35
Definition: CallGraph.h:23
void add(std::shared_ptr< internal::Inputs > inputs)
void execute() const
Definition: CallGraph.h:32
std::map< Call, int, CompareCall > callId_
Definition: CallGraph.h:97
std::vector< Call > calls_
Definition: CallGraph.h:99
std::vector< std::shared_ptr< internal::Inputs > > inputs_
Definition: CallGraph.h:95
std::vector< int > addOutput(abstract::Outputs *source, int output)
std::map< std::intptr_t, std::map< int, std::vector< int > > > visited_
Definition: CallGraph.h:104
Plan plan_
Definition: CallGraph.h:107
internal::DependencyGraph dependencyGraph_
Definition: CallGraph.h:101
Definition: Outputs.h:31
Definition: AbstractNode.h:37
void update(int i)
Definition: AbstractNode.h:105
Definition: DependencyGraph.h:20
Definition: Clock.h:12
Definition: CallGraph.h:40
int id
Definition: CallGraph.h:42
void operator()() const
Definition: CallGraph.h:43
internal::AbstractNode * node
Definition: CallGraph.h:41
Definition: CallGraph.h:48
bool operator()(const Call &c1, const Call &c2) const
Definition: CallGraph.h:49
Definition: CallGraph.h:55
void build(const CallGraph &graph)
void execute() const
Definition: CallGraph.h:63