TVM  0.9.4
Outputs.h
Go to the documentation of this file.
1 
3 #pragma once
4 
5 #include <tvm/api.h>
6 
7 #include <tvm/internal/enums.h>
8 
9 #include <type_traits>
10 
11 namespace tvm
12 {
13 
14 namespace graph
15 {
16 
17 class CallGraph;
18 
19 namespace abstract
20 {
21 
31 {
32 public:
33  friend class tvm::graph::CallGraph;
34 
35  virtual ~Outputs() = default;
36 
38  enum class Output_
39  {
40  };
42  struct Output
43  {};
44 
46  static constexpr unsigned int OutputSize = 0;
47 
50 
53 
55  static constexpr auto OutputBaseName = "Outputs";
56 
58  static constexpr const char * OutputName(Output_) { return "INVALID"; }
59 
63  template<typename EnumT>
64  bool isOutputEnabled(EnumT e) const
65  {
66  // FIXME is there a way to check that the enum has the good type here ?
67  int i = static_cast<int>(e);
68  return isOutputEnabled(i);
69  }
70 
72  bool isOutputEnabled(int i) const { return isOutputStaticallyEnabled(i) && isOutputCustomEnabled(i); }
73 
81  virtual bool isOutputStaticallyEnabled(int) const { return true; }
82 
88  virtual bool isOutputCustomEnabled(int) const { return true; }
89 
95  template<typename EnumT>
96  static constexpr bool OutputStaticallyEnabled(EnumT)
97  { return true; }
98 
99 protected:
101  bool is_node_ = false;
102 };
103 
113 #define SET_OUTPUTS(SelfT, ...) PP_ID(EXTEND_ENUM(Output, SelfT, __VA_ARGS__))
114 
118 #define DISABLE_OUTPUTS(...) PP_ID(DISABLE_SIGNALS(Output, __VA_ARGS__))
119 
121 #define CLEAR_DISABLED_OUTPUTS() PP_ID(CLEAR_DISABLED_SIGNALS(Output))
122 
124 template<typename T, typename EnumT>
125 constexpr bool is_valid_output(EnumT v)
126 {
127  static_assert(std::is_base_of<Outputs, T>::value,
128  "Cannot test output validity for a type that is not derived of Outputs");
129  static_assert(std::is_enum<EnumT>::value, "Cannot test output validity for a value that is not an enumeration");
130  return std::is_same<typename T::Output_, EnumT>::value
131  || ((!std::is_same<typename T::OutputParent, typename T::OutputBase>::value)
132  && is_valid_output<typename T::OutputParent>(v));
133 }
134 
136 template<typename T, typename EnumT, typename... Args>
137 constexpr bool is_valid_output(EnumT v, Args... args)
138 { return is_valid_output<T>(v) && is_valid_output<T>(args...); }
139 
140 } // namespace abstract
141 
142 } // namespace graph
143 
144 } // namespace tvm
#define TVM_DLLAPI
Definition: api.h:35
Definition: CallGraph.h:23
Definition: Outputs.h:31
bool isOutputEnabled(EnumT e) const
Definition: Outputs.h:64
static constexpr const char * OutputName(Output_)
Definition: Outputs.h:58
virtual ~Outputs()=default
virtual bool isOutputStaticallyEnabled(int) const
Definition: Outputs.h:81
Output_
Definition: Outputs.h:39
bool isOutputEnabled(int i) const
Definition: Outputs.h:72
static constexpr bool OutputStaticallyEnabled(EnumT)
Definition: Outputs.h:96
virtual bool isOutputCustomEnabled(int) const
Definition: Outputs.h:88
constexpr bool is_valid_output(EnumT v)
Definition: Outputs.h:125
Definition: Clock.h:12