tvm
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
instruction.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 #ifndef TVM_TIR_SCHEDULE_INSTRUCTION_H_
20 #define TVM_TIR_SCHEDULE_INSTRUCTION_H_
21 
22 #include <tvm/node/reflection.h>
23 
24 #include <utility>
25 
26 namespace tvm {
27 
28 // Forward declaration
29 template <typename, typename>
31 
32 namespace tir {
33 
34 // Forward declaration
35 class Schedule;
36 
46  Schedule sch, const Array<ObjectRef>& inputs, const Array<ObjectRef>& attrs,
47  const Optional<ObjectRef>& decision)>;
48 
58  const Array<ObjectRef>& inputs, const Array<ObjectRef>& attrs,
59  const Optional<ObjectRef>& decision, const Array<String>& outputs)>;
60 
68 
76 
90  public:
99  bool is_pure{false};
114 
116  v->Visit("name", &name);
117  v->Visit("_is_pure", &is_pure);
118  // not visited: f_apply_to_schedule
119  // not visited: f_as_python
120  // not visited: f_attrs_as_json
121  // not visited: f_attrs_from_json
122  }
123 
125  bool IsPostproc() const;
126 
127  static constexpr const char* _type_key = "tir.InstructionKind";
129 };
130 
136  public:
142  static InstructionKind Get(const String& name);
144 };
145 
148  public:
176 
178  v->Visit("kind", &kind);
179  v->Visit("inputs", &inputs);
180  v->Visit("attrs", &attrs);
181  v->Visit("outputs", &outputs);
182  }
183 
184  static constexpr const char* _type_key = "tir.Instruction";
186 };
187 
193  public:
202  Array<ObjectRef> outputs);
203 
205 };
206 
212 #define TVM_INST_KIND_REGISTER_VAR_DEF \
213  static DMLC_ATTRIBUTE_UNUSED ::tvm::tir::InstructionKindRegEntry& __make_##InstructionKind
214 
232 #define TVM_REGISTER_INST_KIND(InstructionKindName) \
233  TVM_STR_CONCAT(TVM_INST_KIND_REGISTER_VAR_DEF, __COUNTER__) = \
234  ::tvm::tir::InstructionKindRegEntry::RegisterOrGet(InstructionKindName).set_name()
235 
238  public:
240 
242  get_mutable()->name = this->name;
243  return *this;
244  }
245 
247  get_mutable()->is_pure = is_pure;
248  return *this;
249  }
250 
252  get_mutable()->f_apply_to_schedule = std::move(f_apply_to_schedule);
253  return *this;
254  }
255 
257  get_mutable()->f_as_python = std::move(f_as_python);
258  return *this;
259  }
260 
262  get_mutable()->f_attrs_as_json = std::move(f_attrs_as_json);
263  return *this;
264  }
265 
267  get_mutable()->f_attrs_from_json = std::move(f_attrs_from_json);
268  return *this;
269  }
270 
271  private:
273  explicit InstructionKindRegEntry(uint32_t reg_index);
275  InstructionKindNode* get_mutable() const {
276  return const_cast<InstructionKindNode*>(inst_kind_.get());
277  }
278 
280  String name;
282  InstructionKind inst_kind_;
283  template <typename, typename>
284  friend class ::tvm::AttrRegistry;
285  friend class InstructionKind;
286 };
287 
288 } // namespace tir
289 } // namespace tvm
290 
291 #endif // TVM_TIR_SCHEDULE_INSTRUCTION_H_
Definition: instruction.h:30
Visitor class to get the attributes of an AST/IR node. The content is going to be called for each fie...
Definition: reflection.h:52
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Base class of all object reference.
Definition: object.h:520
const Object * get() const
Definition: object.h:555
base class of all object containers.
Definition: object.h:172
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Reference to string objects.
Definition: string.h:97
Kind of an instruction, e.g. Split, Reorder, etc. Besides the name, every kind of instruction has its...
Definition: instruction.h:89
String name
The name of a kind of instructions.
Definition: instruction.h:92
TVM_DECLARE_FINAL_OBJECT_INFO(InstructionKindNode, runtime::Object)
FInstructionApply f_apply_to_schedule
A functor that applies the instruction to a TensorIR schedule.
Definition: instruction.h:101
bool IsPostproc() const
Checks if the instruction kind is EnterPostproc.
FInstructionAttrsAsJSON f_attrs_as_json
A functor that serialize its attributes to JSON.
Definition: instruction.h:108
static constexpr const char * _type_key
Definition: instruction.h:127
void VisitAttrs(tvm::AttrVisitor *v)
Definition: instruction.h:115
FInstructionAttrsFromJSON f_attrs_from_json
A functor that deserialize its attributes from JSON.
Definition: instruction.h:113
bool is_pure
Indicates if the instruction is pure, i.e. removing it alone doesn't mutate the schedule state....
Definition: instruction.h:99
FInstructionAsPython f_as_python
A functor that converts the instruction to a statement in python syntax.
Definition: instruction.h:103
An entry in the registry of InstructionKind.
Definition: instruction.h:237
InstructionKindRegEntry & set_attrs_from_json(FInstructionAttrsFromJSON f_attrs_from_json)
Definition: instruction.h:266
InstructionKindRegEntry & set_attrs_as_json(FInstructionAttrsAsJSON f_attrs_as_json)
Definition: instruction.h:261
InstructionKindRegEntry & set_apply_to_schedule(FInstructionApply f_apply_to_schedule)
Definition: instruction.h:251
static InstructionKindRegEntry & RegisterOrGet(const String &name)
InstructionKindRegEntry & set_name()
Definition: instruction.h:241
InstructionKindRegEntry & set_as_python(FInstructionAsPython f_as_python)
Definition: instruction.h:256
InstructionKindRegEntry & set_is_pure(bool is_pure)
Definition: instruction.h:246
friend class InstructionKind
Definition: instruction.h:285
Managed reference to InstructionKindNode.
Definition: instruction.h:135
static InstructionKind Get(const String &name)
Retrieve an InstructionKind using its name.
TVM_DEFINE_OBJECT_REF_METHODS(InstructionKind, runtime::ObjectRef, InstructionKindNode)
Schedule instructions each corresponds to a schedule primitive.
Definition: instruction.h:147
void VisitAttrs(tvm::AttrVisitor *v)
Definition: instruction.h:177
Array< ObjectRef > outputs
The output random variables of the instruction, and the type of each element can be one of the follow...
Definition: instruction.h:175
InstructionKind kind
The kind of the instruction.
Definition: instruction.h:150
Array< ObjectRef > attrs
The attributes of the instruction. Similar to attributes of an operator, attributes of an instruction...
Definition: instruction.h:168
static constexpr const char * _type_key
Definition: instruction.h:184
Array< ObjectRef > inputs
The input random variables of the instruction, and the type of each element can be one of the followi...
Definition: instruction.h:162
TVM_DECLARE_FINAL_OBJECT_INFO(InstructionNode, runtime::Object)
Managed reference to InstructionNode.
Definition: instruction.h:192
Instruction(InstructionKind kind, Array< ObjectRef > inputs, Array< ObjectRef > attrs, Array< ObjectRef > outputs)
Constructor.
TVM_DEFINE_OBJECT_REF_METHODS(Instruction, runtime::ObjectRef, InstructionNode)
Managed reference to ScheduleNode.
Definition: schedule.h:877
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:36
Reflection and serialization of compiler IR/AST nodes.