tvm
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
expr.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 
24 // Acknowledgement: Many low-level IR nodes originate from Halide.
25 #ifndef TVM_TIR_EXPR_H_
26 #define TVM_TIR_EXPR_H_
27 
28 #include <tvm/ir/expr.h>
29 #include <tvm/node/functor.h>
30 #include <tvm/node/node.h>
35 #include <tvm/runtime/data_type.h>
36 #include <tvm/tir/buffer.h>
37 #include <tvm/tir/var.h>
38 
39 #include <algorithm>
40 #include <iostream>
41 #include <limits>
42 #include <string>
43 #include <unordered_map>
44 #include <utility>
45 
46 namespace tvm {
47 namespace tir {
48 
51 
53 class StringImmNode : public PrimExprNode {
54  public:
57 
59  v->Visit("dtype", &dtype);
60  v->Visit("value", &value);
61  v->Visit("span", &span);
62  }
63 
64  bool SEqualReduce(const StringImmNode* other, SEqualReducer equal) const {
65  return equal(value, other->value);
66  }
67 
68  void SHashReduce(SHashReducer hash_reduce) const { hash_reduce(value); }
69 
70  static constexpr const char* _type_key = "tir.StringImm";
72 };
73 
78 class StringImm : public PrimExpr {
79  public:
80  TVM_DLL StringImm(String value, Span span = Span());
83 };
84 
89 class CastNode : public PrimExprNode {
90  public:
93 
95  v->Visit("dtype", &dtype);
96  v->Visit("value", &value);
97  v->Visit("span", &span);
98  }
99 
100  bool SEqualReduce(const CastNode* other, SEqualReducer equal) const {
101  return equal(dtype, other->dtype) && equal(value, other->value);
102  }
103 
104  void SHashReduce(SHashReducer hash_reduce) const {
105  hash_reduce(dtype);
106  hash_reduce(value);
107  }
108 
109  static constexpr const char* _type_key = "tir.Cast";
111 };
112 
117 class Cast : public PrimExpr {
118  public:
119  TVM_DLL Cast(DataType dtype, PrimExpr value, Span span = Span());
122 };
123 
128 template <typename T>
129 class BinaryOpNode : public PrimExprNode {
130  public:
135 
137  v->Visit("dtype", &(this->dtype));
138  v->Visit("a", &a);
139  v->Visit("b", &b);
140  v->Visit("span", &span);
141  }
142 
143  bool SEqualReduce(const T* other, SEqualReducer equal) const {
144  return equal(dtype, other->dtype) && equal(a, other->a) && equal(b, other->b);
145  }
146 
147  void SHashReduce(SHashReducer hash_reduce) const {
148  hash_reduce(dtype);
149  hash_reduce(a);
150  hash_reduce(b);
151  }
152 
154 };
155 
157 class AddNode : public BinaryOpNode<AddNode> {
158  public:
159  static constexpr const char* _type_key = "tir.Add";
160 };
161 
166 class Add : public PrimExpr {
167  public:
168  TVM_DLL Add(PrimExpr a, PrimExpr b, Span span = Span());
171 };
172 
174 class SubNode : public BinaryOpNode<SubNode> {
175  public:
176  static constexpr const char* _type_key = "tir.Sub";
177 };
178 
183 class Sub : public PrimExpr {
184  public:
185  TVM_DLL Sub(PrimExpr a, PrimExpr b, Span span = Span());
188 };
189 
191 class MulNode : public BinaryOpNode<MulNode> {
192  public:
193  static constexpr const char* _type_key = "tir.Mul";
194 };
195 
200 class Mul : public PrimExpr {
201  public:
202  TVM_DLL Mul(PrimExpr a, PrimExpr b, Span span = Span());
205 };
206 
211 class DivNode : public BinaryOpNode<DivNode> {
212  public:
213  static constexpr const char* _type_key = "tir.Div";
214 };
215 
220 class Div : public PrimExpr {
221  public:
222  TVM_DLL Div(PrimExpr a, PrimExpr b, Span span = Span());
225 };
226 
231 class ModNode : public BinaryOpNode<ModNode> {
232  public:
233  static constexpr const char* _type_key = "tir.Mod";
234 };
235 
240 class Mod : public PrimExpr {
241  public:
242  TVM_DLL Mod(PrimExpr a, PrimExpr b, Span span = Span());
245 };
246 
248 class FloorDivNode : public BinaryOpNode<FloorDivNode> {
249  public:
250  static constexpr const char* _type_key = "tir.FloorDiv";
251 };
252 
257 class FloorDiv : public PrimExpr {
258  public:
259  TVM_DLL FloorDiv(PrimExpr a, PrimExpr b, Span span = Span());
262 };
263 
265 class FloorModNode : public BinaryOpNode<FloorModNode> {
266  public:
267  static constexpr const char* _type_key = "tir.FloorMod";
268 };
269 
274 class FloorMod : public PrimExpr {
275  public:
276  TVM_DLL FloorMod(PrimExpr a, PrimExpr b, Span span = Span());
279 };
280 
282 class MinNode : public BinaryOpNode<MinNode> {
283  public:
284  static constexpr const char* _type_key = "tir.Min";
285 };
286 
291 class Min : public PrimExpr {
292  public:
293  TVM_DLL Min(PrimExpr a, PrimExpr b, Span span = Span());
296 };
297 
299 class MaxNode : public BinaryOpNode<MaxNode> {
300  public:
301  static constexpr const char* _type_key = "tir.Max";
302 };
303 
308 class Max : public PrimExpr {
309  public:
310  TVM_DLL Max(PrimExpr a, PrimExpr b, Span span = Span());
313 };
314 
319 template <typename T>
320 class CmpOpNode : public PrimExprNode {
321  public:
326 
328  v->Visit("dtype", &(this->dtype));
329  v->Visit("a", &a);
330  v->Visit("b", &b);
331  v->Visit("span", &span);
332  }
333 
334  bool SEqualReduce(const T* other, SEqualReducer equal) const {
335  return equal(dtype, other->dtype) && equal(a, other->a) && equal(b, other->b);
336  }
337 
338  void SHashReduce(SHashReducer hash_reduce) const {
339  hash_reduce(dtype);
340  hash_reduce(a);
341  hash_reduce(b);
342  }
343 
345 };
346 
348 class EQNode : public CmpOpNode<EQNode> {
349  public:
350  static constexpr const char* _type_key = "tir.EQ";
351 };
352 
357 class EQ : public PrimExpr {
358  public:
359  TVM_DLL EQ(PrimExpr a, PrimExpr b, Span span = Span());
362 };
363 
365 class NENode : public CmpOpNode<NENode> {
366  public:
367  static constexpr const char* _type_key = "tir.NE";
368 };
369 
374 class NE : public PrimExpr {
375  public:
376  TVM_DLL NE(PrimExpr a, PrimExpr b, Span span = Span());
379 };
380 
382 class LTNode : public CmpOpNode<LTNode> {
383  public:
384  static constexpr const char* _type_key = "tir.LT";
385 };
386 
391 class LT : public PrimExpr {
392  public:
393  TVM_DLL LT(PrimExpr a, PrimExpr b, Span span = Span());
396 };
397 
399 struct LENode : public CmpOpNode<LENode> {
400  public:
401  static constexpr const char* _type_key = "tir.LE";
402 };
403 
408 class LE : public PrimExpr {
409  public:
410  TVM_DLL LE(PrimExpr a, PrimExpr b, Span span = Span());
413 };
414 
416 class GTNode : public CmpOpNode<GTNode> {
417  public:
418  static constexpr const char* _type_key = "tir.GT";
419 };
420 
425 class GT : public PrimExpr {
426  public:
427  TVM_DLL GT(PrimExpr a, PrimExpr b, Span span = Span());
430 };
431 
433 class GENode : public CmpOpNode<GENode> {
434  public:
435  static constexpr const char* _type_key = "tir.GE";
436 };
437 
442 class GE : public PrimExpr {
443  public:
444  TVM_DLL GE(PrimExpr a, PrimExpr b, Span span = Span());
447 };
448 
450 class AndNode : public PrimExprNode {
451  public:
456 
458  v->Visit("dtype", &(this->dtype));
459  v->Visit("a", &a);
460  v->Visit("b", &b);
461  v->Visit("span", &span);
462  }
463 
464  bool SEqualReduce(const AndNode* other, SEqualReducer equal) const {
465  return equal(dtype, other->dtype) && equal(a, other->a) && equal(b, other->b);
466  }
467 
468  void SHashReduce(SHashReducer hash_reduce) const {
469  hash_reduce(dtype);
470  hash_reduce(a);
471  hash_reduce(b);
472  }
473 
474  static constexpr const char* _type_key = "tir.And";
476 };
477 
482 class And : public PrimExpr {
483  public:
484  TVM_DLL And(PrimExpr a, PrimExpr b, Span span = Span());
487 };
488 
490 class OrNode : public PrimExprNode {
491  public:
496 
498  v->Visit("dtype", &dtype);
499  v->Visit("a", &a);
500  v->Visit("b", &b);
501  v->Visit("span", &span);
502  }
503 
504  bool SEqualReduce(const OrNode* other, SEqualReducer equal) const {
505  return equal(dtype, other->dtype) && equal(a, other->a) && equal(b, other->b);
506  }
507 
508  void SHashReduce(SHashReducer hash_reduce) const {
509  hash_reduce(dtype);
510  hash_reduce(a);
511  hash_reduce(b);
512  }
513 
514  static constexpr const char* _type_key = "tir.Or";
516 };
517 
522 class Or : public PrimExpr {
523  public:
524  TVM_DLL Or(PrimExpr a, PrimExpr b, Span span = Span());
527 };
528 
530 class NotNode : public PrimExprNode {
531  public:
534 
536  v->Visit("dtype", &dtype);
537  v->Visit("a", &a);
538  v->Visit("span", &span);
539  }
540 
541  bool SEqualReduce(const NotNode* other, SEqualReducer equal) const {
542  return equal(dtype, other->dtype) && equal(a, other->a);
543  }
544 
545  void SHashReduce(SHashReducer hash_reduce) const {
546  hash_reduce(dtype);
547  hash_reduce(a);
548  }
549 
550  static constexpr const char* _type_key = "tir.Not";
552 };
553 
558 class Not : public PrimExpr {
559  public:
560  TVM_DLL Not(PrimExpr a, Span span = Span());
563 };
564 
572 class SelectNode : public PrimExprNode {
573  public:
580 
582  v->Visit("dtype", &dtype);
583  v->Visit("condition", &condition);
584  v->Visit("true_value", &true_value);
585  v->Visit("false_value", &false_value);
586  v->Visit("span", &span);
587  }
588 
589  bool SEqualReduce(const SelectNode* other, SEqualReducer equal) const {
590  return equal(dtype, other->dtype) && equal(condition, other->condition) &&
592  }
593 
594  void SHashReduce(SHashReducer hash_reduce) const {
595  hash_reduce(dtype);
596  hash_reduce(condition);
597  hash_reduce(true_value);
598  hash_reduce(false_value);
599  }
600 
601  static constexpr const char* _type_key = "tir.Select";
603 };
604 
609 class Select : public PrimExpr {
610  public:
611  TVM_DLL Select(PrimExpr condition, PrimExpr true_value, PrimExpr false_value, Span span = Span());
612 
615 };
616 
627 class BufferLoadNode : public PrimExprNode {
628  public:
633 
635  v->Visit("dtype", &(this->dtype));
636  v->Visit("buffer", &buffer);
637  v->Visit("indices", &indices);
638  v->Visit("span", &span);
639  }
640 
641  bool SEqualReduce(const BufferLoadNode* other, SEqualReducer equal) const {
642  return equal(dtype, other->dtype) && equal(buffer, other->buffer) &&
643  equal(indices, other->indices);
644  }
645 
646  void SHashReduce(SHashReducer hash_reduce) const {
647  hash_reduce(dtype);
648  hash_reduce(buffer);
649  hash_reduce(indices);
650  }
651 
652  static constexpr const char* _type_key = "tir.BufferLoad";
654 
655  private:
665  void LegalizeDType();
666  friend class BufferLoad;
668  friend class VectorTypeRewriter;
669  friend class Vectorizer;
670 };
671 
676 class BufferLoad : public PrimExpr {
677  public:
678  TVM_DLL explicit BufferLoad(Buffer buffer, Array<PrimExpr> indices, Span span = Span());
681 };
682 
693  public:
698 
700  v->Visit("dtype", &(this->dtype));
701  v->Visit("producer", &producer);
702  v->Visit("indices", &indices);
703  v->Visit("span", &span);
704  }
705 
706  bool SEqualReduce(const ProducerLoadNode* other, SEqualReducer equal) const {
707  return equal(dtype, other->dtype) && equal(producer, other->producer) &&
708  equal(indices, other->indices);
709  }
710 
711  void SHashReduce(SHashReducer hash_reduce) const {
712  hash_reduce(dtype);
713  hash_reduce(producer);
714  hash_reduce(indices);
715  }
716 
717  static constexpr const char* _type_key = "tir.ProducerLoad";
719 };
720 
725 class ProducerLoad : public PrimExpr {
726  public:
727  TVM_DLL explicit ProducerLoad(DataProducer producer, Array<PrimExpr> indices, Span span = Span());
728 
731 };
732 
742 class RampNode : public PrimExprNode {
743  public:
749  int lanes;
750 
752  v->Visit("dtype", &dtype);
753  v->Visit("base", &base);
754  v->Visit("stride", &stride);
755  v->Visit("lanes", &lanes);
756  v->Visit("span", &span);
757  }
758 
759  bool SEqualReduce(const RampNode* other, SEqualReducer equal) const {
760  return equal(dtype, other->dtype) && equal(base, other->base) && equal(stride, other->stride) &&
761  equal(lanes, other->lanes);
762  }
763 
764  void SHashReduce(SHashReducer hash_reduce) const {
765  hash_reduce(dtype);
766  hash_reduce(base);
767  hash_reduce(stride);
768  hash_reduce(lanes);
769  }
770 
771  static constexpr const char* _type_key = "tir.Ramp";
773 };
774 
779 class Ramp : public PrimExpr {
780  public:
781  TVM_DLL Ramp(PrimExpr base, PrimExpr stride, int lanes, Span span = Span());
784 };
785 
787 class BroadcastNode : public PrimExprNode {
788  public:
792  int lanes;
793 
795  v->Visit("dtype", &dtype);
796  v->Visit("value", &value);
797  v->Visit("lanes", &lanes);
798  v->Visit("span", &span);
799  }
800 
801  bool SEqualReduce(const BroadcastNode* other, SEqualReducer equal) const {
802  return equal(dtype, other->dtype) && equal(value, other->value) && equal(lanes, other->lanes);
803  }
804 
805  void SHashReduce(SHashReducer hash_reduce) const {
806  hash_reduce(dtype);
807  hash_reduce(value);
808  hash_reduce(lanes);
809  }
810 
811  static constexpr const char* _type_key = "tir.Broadcast";
813 };
814 
819 class Broadcast : public PrimExpr {
820  public:
821  TVM_DLL Broadcast(PrimExpr value, int lanes, Span span = Span());
824 };
825 
829 class LetNode : public PrimExprNode {
830  public:
837 
839  v->Visit("dtype", &dtype);
840  v->Visit("var", &var);
841  v->Visit("value", &value);
842  v->Visit("body", &body);
843  v->Visit("span", &span);
844  }
845 
846  bool SEqualReduce(const LetNode* other, SEqualReducer equal) const {
847  return equal(dtype, other->dtype) && equal.DefEqual(var, other->var) &&
848  equal(value, other->value) && equal(body, other->body);
849  }
850 
851  void SHashReduce(SHashReducer hash_reduce) const {
852  hash_reduce(dtype);
853  hash_reduce.DefHash(var);
854  hash_reduce(value);
855  hash_reduce(body);
856  }
857 
858  static constexpr const char* _type_key = "tir.Let";
860 };
861 
866 class Let : public PrimExpr {
867  public:
868  TVM_DLL Let(Var var, PrimExpr value, PrimExpr body, Span span = Span());
871 };
872 
876 class CallNode : public PrimExprNode {
877  public:
885 
889  v->Visit("dtype", &dtype);
890  v->Visit("op", &op);
891  v->Visit("args", &args);
892  v->Visit("span", &span);
893  }
894 
895  bool SEqualReduce(const CallNode* other, SEqualReducer equal) const {
896  return equal(dtype, other->dtype) && equal(op, other->op) && equal(args, other->args);
897  }
898 
899  void SHashReduce(SHashReducer hash_reduce) const {
900  hash_reduce(dtype);
901  hash_reduce(op);
902  hash_reduce(args);
903  }
904 
905  static constexpr const char* _type_key = "tir.Call";
907 };
908 
913 class Call : public PrimExpr {
914  public:
915  TVM_DLL Call(DataType dtype, RelayExpr op, Array<PrimExpr> args, Span span = Span());
918 };
919 
925 class ShuffleNode : public PrimExprNode {
926  public:
931 
933  v->Visit("dtype", &dtype);
934  v->Visit("vectors", &vectors);
935  v->Visit("indices", &indices);
936  v->Visit("span", &span);
937  }
938 
939  bool SEqualReduce(const ShuffleNode* other, SEqualReducer equal) const {
940  return equal(dtype, other->dtype) && equal(vectors, other->vectors) &&
941  equal(indices, other->indices);
942  }
943 
944  void SHashReduce(SHashReducer hash_reduce) const {
945  hash_reduce(dtype);
946  hash_reduce(vectors);
947  hash_reduce(indices);
948  }
949 
950  static constexpr const char* _type_key = "tir.Shuffle";
952 };
953 
958 class Shuffle : public PrimExpr {
959  public:
960  TVM_DLL Shuffle(Array<PrimExpr> vectors, Array<PrimExpr> indices, Span span = Span());
961  TVM_DLL static PrimExpr Concat(Array<PrimExpr> vectors, Span span = Span());
962  TVM_DLL static PrimExpr ExtractElement(PrimExpr vector, int index, Span span = Span());
963 
966 };
967 
968 // Reduce operator
973 class CommReducerNode : public Object {
974  public:
993  mutable Span span;
994 
996  v->Visit("lhs", &lhs);
997  v->Visit("rhs", &rhs);
998  v->Visit("result", &result);
999  v->Visit("identity_element", &identity_element);
1000  v->Visit("span", &span);
1001  }
1002 
1003  bool SEqualReduce(const CommReducerNode* other, SEqualReducer equal) const {
1004  return equal.DefEqual(lhs, other->lhs) && equal.DefEqual(rhs, other->rhs) &&
1006  }
1007 
1008  void SHashReduce(SHashReducer hash_reduce) const {
1009  hash_reduce.DefHash(lhs);
1010  hash_reduce.DefHash(rhs);
1011  hash_reduce(result);
1012  hash_reduce(identity_element);
1013  }
1014 
1015  static constexpr const char* _type_key = "tir.CommReducer";
1016  static constexpr const bool _type_has_method_sequal_reduce = true;
1017  static constexpr const bool _type_has_method_shash_reduce = true;
1019 };
1020 
1025 class CommReducer : public ObjectRef {
1026  public:
1028  Array<PrimExpr> identity_element, Span span = Span());
1029 
1031 };
1032 
1034 class ReduceNode : public PrimExprNode {
1035  public:
1051 
1053  v->Visit("dtype", &dtype);
1054  v->Visit("combiner", &combiner);
1055  v->Visit("source", &source);
1056  v->Visit("init", &init);
1057  v->Visit("axis", &axis);
1058  v->Visit("condition", &condition);
1059  v->Visit("value_index", &value_index);
1060  v->Visit("span", &span);
1061  }
1062 
1063  bool SEqualReduce(const ReduceNode* other, SEqualReducer equal) const {
1064  // check axis first so IterVars can define the necessary variables.
1065  return equal(dtype, other->dtype) && equal(axis, other->axis) &&
1066  equal(combiner, other->combiner) && equal(source, other->source) &&
1067  equal(init, other->init) && equal(condition, other->condition) &&
1068  equal(value_index, other->value_index);
1069  }
1070 
1071  void SHashReduce(SHashReducer hash_reduce) const {
1072  hash_reduce(dtype);
1073  hash_reduce(axis);
1074  hash_reduce(combiner);
1075  hash_reduce(source);
1076  hash_reduce(init);
1077  hash_reduce(condition);
1078  hash_reduce(value_index);
1079  }
1080 
1081  static constexpr const char* _type_key = "tir.Reduce";
1083 };
1084 
1089 class Reduce : public PrimExpr {
1090  public:
1091  TVM_DLL Reduce(CommReducer combiner, Array<PrimExpr> src, Array<IterVar> rdom, PrimExpr condition,
1092  int value_index, Array<PrimExpr> init, Span span = Span());
1093 
1096 };
1097 
1099 class AnyNode : public PrimExprNode {
1100  public:
1102  v->Visit("dtype", &dtype);
1103  v->Visit("span", &span);
1104  }
1105 
1106  bool SEqualReduce(const AnyNode* other, SEqualReducer equal) const {
1107  return equal(dtype, other->dtype);
1108  }
1109 
1110  void SHashReduce(SHashReducer hash_reduce) const {}
1111 
1113  Var ToVar() const { return Var("any_dim", DataType::Int(32)); }
1114 
1116  SizeVar ToSizeVar() const { return SizeVar("any_dim", DataType::Int(32)); }
1117 
1118  static constexpr const char* _type_key = "tir.Any";
1120 };
1121 
1126 class Any : public PrimExpr {
1127  public:
1128  TVM_DLL Any(Span span = Span());
1129 
1132 };
1133 
1134 /*
1135  * \brief Template function to convert Map to unordered_map
1136  * Sometimes useful for API gluing when internal uses unordered_map
1137  * \param dmap The container map
1138  * \return The corresponding unordered_map.
1139  * \tparam K the key of the Map.
1140  * \tparam V the value of the Map.
1141  */
1142 template <typename K, typename V>
1143 inline std::unordered_map<K, V> as_unordered_map(const Map<K, V>& dmap) {
1144  std::unordered_map<K, V> ret;
1145  for (auto kv : dmap) {
1146  ret[kv.first] = kv.second;
1147  }
1148  return ret;
1149 }
1150 } // namespace tir
1151 } // namespace tvm
1152 
1153 namespace std {
1154 template <>
1155 struct hash<::tvm::tir::IterVar> : public ::tvm::ObjectPtrHash {};
1156 } // namespace std
1157 #endif // TVM_TIR_EXPR_H_
Runtime Array container types.
Symbolic n-dimensional array, to represent a memory buffer.
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
Span span
Span that points to the original source code. Reserved debug information.
Definition: expr.h:55
Constant floating point literals in the program.
Definition: expr.h:538
Constant integer literals in the program.
Definition: expr.h:491
Base node of all primitive expressions.
Definition: expr.h:85
DataType dtype
The runtime data type of the primitive expression.
Definition: expr.h:101
Reference to PrimExprNode.
Definition: expr.h:114
DataType dtype() const
Definition: expr.h:128
Managed reference to RelayExprNode.
Definition: expr.h:433
A Reducer class to reduce the structural equality result of two objects.
Definition: structural_equal.h:124
A Reducer class to reduce the structural hash value.
Definition: structural_hash.h:110
void DefHash(const ObjectRef &key) const
Push hash of key to the current sequence of hash values.
Definition: structural_hash.h:187
Definition: source_map.h:120
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Runtime primitive data type.
Definition: data_type.h:42
static DataType Int(int bits, int lanes=1)
Construct an int type.
Definition: data_type.h:176
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics,...
Definition: map.h:1271
Base class of all object reference.
Definition: object.h:517
base class of all object containers.
Definition: object.h:169
Reference to string objects.
Definition: string.h:98
a + b
Definition: expr.h:157
static constexpr const char * _type_key
Definition: expr.h:159
Managed reference to AddNode.
Definition: expr.h:166
TVM_DEFINE_OBJECT_REF_COW_METHOD(AddNode)
TVM_DEFINE_OBJECT_REF_METHODS(Add, PrimExpr, AddNode)
Add(PrimExpr a, PrimExpr b, Span span=Span())
a && b
Definition: expr.h:450
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:468
PrimExpr a
The left operand.
Definition: expr.h:453
bool SEqualReduce(const AndNode *other, SEqualReducer equal) const
Definition: expr.h:464
static constexpr const char * _type_key
Definition: expr.h:474
PrimExpr b
The right operand.
Definition: expr.h:455
void VisitAttrs(AttrVisitor *v)
Definition: expr.h:457
TVM_DECLARE_FINAL_OBJECT_INFO(AndNode, PrimExprNode)
Managed reference to AndNode.
Definition: expr.h:482
TVM_DEFINE_OBJECT_REF_COW_METHOD(AndNode)
And(PrimExpr a, PrimExpr b, Span span=Span())
TVM_DEFINE_OBJECT_REF_METHODS(And, PrimExpr, AndNode)
Any shape.
Definition: expr.h:1099
void VisitAttrs(AttrVisitor *v)
Definition: expr.h:1101
TVM_DECLARE_FINAL_OBJECT_INFO(AnyNode, PrimExprNode)
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:1110
SizeVar ToSizeVar() const
Convert to SizeVar.
Definition: expr.h:1116
bool SEqualReduce(const AnyNode *other, SEqualReducer equal) const
Definition: expr.h:1106
static constexpr const char * _type_key
Definition: expr.h:1118
Var ToVar() const
Convert to var.
Definition: expr.h:1113
Managed reference to AnyNode.
Definition: expr.h:1126
TVM_DEFINE_OBJECT_REF_COW_METHOD(AnyNode)
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(Any, PrimExpr, AnyNode)
Any(Span span=Span())
Base template to implement binary ops.
Definition: expr.h:129
PrimExpr b
The right operand.
Definition: expr.h:134
bool SEqualReduce(const T *other, SEqualReducer equal) const
Definition: expr.h:143
TVM_DECLARE_FINAL_OBJECT_INFO(T, PrimExprNode)
void VisitAttrs(AttrVisitor *v)
Definition: expr.h:136
PrimExpr a
The left operand.
Definition: expr.h:132
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:147
Create a vector where all the elements are value.
Definition: expr.h:787
void VisitAttrs(AttrVisitor *v)
Definition: expr.h:794
static constexpr const char * _type_key
Definition: expr.h:811
int lanes
The number of lanes.
Definition: expr.h:792
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:805
TVM_DECLARE_FINAL_OBJECT_INFO(BroadcastNode, PrimExprNode)
bool SEqualReduce(const BroadcastNode *other, SEqualReducer equal) const
Definition: expr.h:801
PrimExpr value
The base value.
Definition: expr.h:790
Managed reference to BroadcastNode.
Definition: expr.h:819
Broadcast(PrimExpr value, int lanes, Span span=Span())
TVM_DEFINE_OBJECT_REF_METHODS(Broadcast, PrimExpr, BroadcastNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(BroadcastNode)
Load value from the high dimension buffer.
Definition: expr.h:627
friend class VectorTypeRewriter
Definition: expr.h:668
friend class CustomDatatypesLowerer
Definition: expr.h:667
TVM_DECLARE_FINAL_OBJECT_INFO(BufferLoadNode, PrimExprNode)
Array< PrimExpr > indices
The indices location to be loaded.
Definition: expr.h:632
void VisitAttrs(AttrVisitor *v)
Definition: expr.h:634
friend class Vectorizer
Definition: expr.h:669
Buffer buffer
The buffer variable.
Definition: expr.h:630
bool SEqualReduce(const BufferLoadNode *other, SEqualReducer equal) const
Definition: expr.h:641
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:646
static constexpr const char * _type_key
Definition: expr.h:652
Managed reference to BufferLoadNode.
Definition: expr.h:676
TVM_DEFINE_OBJECT_REF_COW_METHOD(BufferLoadNode)
BufferLoad(Buffer buffer, Array< PrimExpr > indices, Span span=Span())
TVM_DEFINE_OBJECT_REF_METHODS(BufferLoad, PrimExpr, BufferLoadNode)
Buffer is a symbolic n-darray structure. It is a composition of primitive symbolic types,...
Definition: buffer.h:162
Call node.
Definition: expr.h:876
RelayExpr op
The operator(function) being invoked.
Definition: expr.h:884
bool SEqualReduce(const CallNode *other, SEqualReducer equal) const
Definition: expr.h:895
static constexpr const char * _type_key
Definition: expr.h:905
Array< PrimExpr > args
The arguments.
Definition: expr.h:887
TVM_DECLARE_FINAL_OBJECT_INFO(CallNode, PrimExprNode)
void VisitAttrs(AttrVisitor *v)
Definition: expr.h:888
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:899
Managed reference to CallNode.
Definition: expr.h:913
TVM_DEFINE_OBJECT_REF_COW_METHOD(CallNode)
TVM_DEFINE_OBJECT_REF_METHODS(Call, PrimExpr, CallNode)
Call(DataType dtype, RelayExpr op, Array< PrimExpr > args, Span span=Span())
Cast value from one data type to another.
Definition: expr.h:89
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:104
PrimExpr value
Original data type.
Definition: expr.h:92
bool SEqualReduce(const CastNode *other, SEqualReducer equal) const
Definition: expr.h:100
void VisitAttrs(AttrVisitor *v)
Definition: expr.h:94
TVM_DECLARE_FINAL_OBJECT_INFO(CastNode, PrimExprNode)
static constexpr const char * _type_key
Definition: expr.h:109
Managed reference to CastNode.
Definition: expr.h:117
TVM_DEFINE_OBJECT_REF_COW_METHOD(CastNode)
TVM_DEFINE_OBJECT_REF_METHODS(Cast, PrimExpr, CastNode)
Cast(DataType dtype, PrimExpr value, Span span=Span())
Base template to implement comparison ops.
Definition: expr.h:320
void VisitAttrs(AttrVisitor *v)
Definition: expr.h:327
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:338
bool SEqualReduce(const T *other, SEqualReducer equal) const
Definition: expr.h:334
TVM_DECLARE_FINAL_OBJECT_INFO(T, PrimExprNode)
PrimExpr a
The left operand.
Definition: expr.h:323
PrimExpr b
The right operand.
Definition: expr.h:325
A commutative reducer node to represent a commutative binary operator with identity element.
Definition: expr.h:973
static constexpr const bool _type_has_method_shash_reduce
Definition: expr.h:1017
Array< Var > rhs
The right argument of reducer.
Definition: expr.h:978
Array< Var > lhs
The left argument of reducer.
Definition: expr.h:976
static constexpr const char * _type_key
Definition: expr.h:1015
static constexpr const bool _type_has_method_sequal_reduce
Definition: expr.h:1016
bool SEqualReduce(const CommReducerNode *other, SEqualReducer equal) const
Definition: expr.h:1003
Array< PrimExpr > operator()(Array< PrimExpr > a, Array< PrimExpr > b) const
Function call operator to combine a and b.
Array< PrimExpr > result
The result of reducer.
Definition: expr.h:980
TVM_DECLARE_FINAL_OBJECT_INFO(CommReducerNode, Object)
void VisitAttrs(AttrVisitor *v)
Definition: expr.h:995
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:1008
Span span
Span that points to the original source code. Reserved debug information.
Definition: expr.h:993
Array< PrimExpr > identity_element
The identity element of reducer, which leaves other elements unchanged when combined with it,...
Definition: expr.h:986
Managed reference to CommReducerNode.
Definition: expr.h:1025
CommReducer(Array< Var > lhs, Array< Var > rhs, Array< PrimExpr > result, Array< PrimExpr > identity_element, Span span=Span())
TVM_DEFINE_OBJECT_REF_METHODS(CommReducer, ObjectRef, CommReducerNode)
Managed reference to DataProducerNode.
Definition: buffer.h:295
a / b in the C semnatics.
Definition: expr.h:211
static constexpr const char * _type_key
Definition: expr.h:213
Managed reference to DivNode.
Definition: expr.h:220
TVM_DEFINE_OBJECT_REF_COW_METHOD(DivNode)
Div(PrimExpr a, PrimExpr b, Span span=Span())
TVM_DEFINE_OBJECT_REF_METHODS(Div, PrimExpr, DivNode)
a == b
Definition: expr.h:348
static constexpr const char * _type_key
Definition: expr.h:350
Managed reference to EQNode.
Definition: expr.h:357
TVM_DEFINE_OBJECT_REF_METHODS(EQ, PrimExpr, EQNode)
EQ(PrimExpr a, PrimExpr b, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(EQNode)
Floor division, floor(a/b)
Definition: expr.h:248
static constexpr const char * _type_key
Definition: expr.h:250
Managed reference to FloorDivNode.
Definition: expr.h:257
TVM_DEFINE_OBJECT_REF_METHODS(FloorDiv, PrimExpr, FloorDivNode)
FloorDiv(PrimExpr a, PrimExpr b, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(FloorDivNode)
The remainder of the floordiv.
Definition: expr.h:265
static constexpr const char * _type_key
Definition: expr.h:267
Managed reference to FloorModNode.
Definition: expr.h:274
TVM_DEFINE_OBJECT_REF_COW_METHOD(FloorModNode)
TVM_DEFINE_OBJECT_REF_METHODS(FloorMod, PrimExpr, FloorModNode)
FloorMod(PrimExpr a, PrimExpr b, Span span=Span())
a >= b
Definition: expr.h:433
static constexpr const char * _type_key
Definition: expr.h:435
Managed reference to GENode.
Definition: expr.h:442
TVM_DEFINE_OBJECT_REF_METHODS(GE, PrimExpr, GENode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(GENode)
GE(PrimExpr a, PrimExpr b, Span span=Span())
a > b
Definition: expr.h:416
static constexpr const char * _type_key
Definition: expr.h:418
Managed reference to GTNode.
Definition: expr.h:425
TVM_DEFINE_OBJECT_REF_METHODS(GT, PrimExpr, GTNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(GTNode)
GT(PrimExpr a, PrimExpr b, Span span=Span())
Iteration Variable, represents an iteration over an integer interval.
Definition: var.h:314
Managed reference to LENode.
Definition: expr.h:408
LE(PrimExpr a, PrimExpr b, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(LENode)
TVM_DEFINE_OBJECT_REF_METHODS(LE, PrimExpr, LENode)
a < b
Definition: expr.h:382
static constexpr const char * _type_key
Definition: expr.h:384
Managed reference to LTNode.
Definition: expr.h:391
TVM_DEFINE_OBJECT_REF_COW_METHOD(LTNode)
LT(PrimExpr a, PrimExpr b, Span span=Span())
TVM_DEFINE_OBJECT_REF_METHODS(LT, PrimExpr, LTNode)
Let binding. Bind var to value then evaluate body.
Definition: expr.h:829
Var var
The variable.
Definition: expr.h:832
static constexpr const char * _type_key
Definition: expr.h:858
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:851
PrimExpr value
The value to be binded.
Definition: expr.h:834
TVM_DECLARE_FINAL_OBJECT_INFO(LetNode, PrimExprNode)
bool SEqualReduce(const LetNode *other, SEqualReducer equal) const
Definition: expr.h:846
void VisitAttrs(AttrVisitor *v)
Definition: expr.h:838
PrimExpr body
The result expression.
Definition: expr.h:836
Managed reference to LetNode.
Definition: expr.h:866
TVM_DEFINE_OBJECT_REF_METHODS(Let, PrimExpr, LetNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(LetNode)
Let(Var var, PrimExpr value, PrimExpr body, Span span=Span())
max(a, b)
Definition: expr.h:299
static constexpr const char * _type_key
Definition: expr.h:301
Managed reference to MaxNode.
Definition: expr.h:308
TVM_DEFINE_OBJECT_REF_METHODS(Max, PrimExpr, MaxNode)
Max(PrimExpr a, PrimExpr b, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(MaxNode)
min(a, b)
Definition: expr.h:282
static constexpr const char * _type_key
Definition: expr.h:284
Managed reference to MinNode.
Definition: expr.h:291
Min(PrimExpr a, PrimExpr b, Span span=Span())
TVM_DEFINE_OBJECT_REF_METHODS(Min, PrimExpr, MinNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(MinNode)
a % b in the C semnatics.
Definition: expr.h:231
static constexpr const char * _type_key
Definition: expr.h:233
Managed reference to ModNode.
Definition: expr.h:240
TVM_DEFINE_OBJECT_REF_METHODS(Mod, PrimExpr, ModNode)
Mod(PrimExpr a, PrimExpr b, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(ModNode)
a * b
Definition: expr.h:191
static constexpr const char * _type_key
Definition: expr.h:193
Managed reference to MulNode.
Definition: expr.h:200
Mul(PrimExpr a, PrimExpr b, Span span=Span())
TVM_DEFINE_OBJECT_REF_METHODS(Mul, PrimExpr, MulNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(MulNode)
a != b
Definition: expr.h:365
static constexpr const char * _type_key
Definition: expr.h:367
Managed reference to NENode.
Definition: expr.h:374
NE(PrimExpr a, PrimExpr b, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(NENode)
TVM_DEFINE_OBJECT_REF_METHODS(NE, PrimExpr, NENode)
!a
Definition: expr.h:530
TVM_DECLARE_FINAL_OBJECT_INFO(NotNode, PrimExprNode)
PrimExpr a
The input operand.
Definition: expr.h:533
static constexpr const char * _type_key
Definition: expr.h:550
void VisitAttrs(AttrVisitor *v)
Definition: expr.h:535
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:545
bool SEqualReduce(const NotNode *other, SEqualReducer equal) const
Definition: expr.h:541
Managed reference to NotNode.
Definition: expr.h:558
TVM_DEFINE_OBJECT_REF_COW_METHOD(NotNode)
Not(PrimExpr a, Span span=Span())
TVM_DEFINE_OBJECT_REF_METHODS(Not, PrimExpr, NotNode)
a || b
Definition: expr.h:490
bool SEqualReduce(const OrNode *other, SEqualReducer equal) const
Definition: expr.h:504
PrimExpr b
The right operand.
Definition: expr.h:495
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:508
PrimExpr a
The left operand.
Definition: expr.h:493
TVM_DECLARE_FINAL_OBJECT_INFO(OrNode, PrimExprNode)
static constexpr const char * _type_key
Definition: expr.h:514
void VisitAttrs(AttrVisitor *v)
Definition: expr.h:497
Managed reference to OrNode.
Definition: expr.h:522
TVM_DEFINE_OBJECT_REF_METHODS(Or, PrimExpr, OrNode)
Or(PrimExpr a, PrimExpr b, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(OrNode)
Load value from the result produced by the producer.
Definition: expr.h:692
static constexpr const char * _type_key
Definition: expr.h:717
Array< PrimExpr > indices
The location arguments.
Definition: expr.h:697
void VisitAttrs(AttrVisitor *v)
Definition: expr.h:699
bool SEqualReduce(const ProducerLoadNode *other, SEqualReducer equal) const
Definition: expr.h:706
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:711
DataProducer producer
The buffer producer.
Definition: expr.h:695
TVM_DECLARE_FINAL_OBJECT_INFO(ProducerLoadNode, PrimExprNode)
Managed reference to ProducerLoadNode.
Definition: expr.h:725
TVM_DEFINE_OBJECT_REF_METHODS(ProducerLoad, PrimExpr, ProducerLoadNode)
ProducerLoad(DataProducer producer, Array< PrimExpr > indices, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(ProducerLoadNode)
Construct a vector with lanes elements where its i-th element equals base + i * stride....
Definition: expr.h:742
int lanes
Total number of lanes.
Definition: expr.h:749
static constexpr const char * _type_key
Definition: expr.h:771
void VisitAttrs(AttrVisitor *v)
Definition: expr.h:751
PrimExpr stride
The stride of each step.
Definition: expr.h:747
TVM_DECLARE_FINAL_OBJECT_INFO(RampNode, PrimExprNode)
bool SEqualReduce(const RampNode *other, SEqualReducer equal) const
Definition: expr.h:759
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:764
PrimExpr base
The base value.
Definition: expr.h:745
Managed reference to RampNode.
Definition: expr.h:779
TVM_DEFINE_OBJECT_REF_COW_METHOD(RampNode)
TVM_DEFINE_OBJECT_REF_METHODS(Ramp, PrimExpr, RampNode)
Ramp(PrimExpr base, PrimExpr stride, int lanes, Span span=Span())
Reduction operator.
Definition: expr.h:1034
Array< PrimExpr > init
The init operand.
Definition: expr.h:1041
int value_index
the index of this reduce node
Definition: expr.h:1050
static constexpr const char * _type_key
Definition: expr.h:1081
TVM_DECLARE_FINAL_OBJECT_INFO(ReduceNode, PrimExprNode)
Array< IterVar > axis
The reduction axis.
Definition: expr.h:1043
CommReducer combiner
The commutative combiner.
Definition: expr.h:1037
void VisitAttrs(AttrVisitor *v)
Definition: expr.h:1052
bool SEqualReduce(const ReduceNode *other, SEqualReducer equal) const
Definition: expr.h:1063
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:1071
Array< PrimExpr > source
The source operand.
Definition: expr.h:1039
PrimExpr condition
Predicate on the reduction Only add the body to reduction if condition is true.
Definition: expr.h:1048
Managed reference to ReduceNode.
Definition: expr.h:1089
TVM_DEFINE_OBJECT_REF_COW_METHOD(ReduceNode)
TVM_DEFINE_OBJECT_REF_METHODS(Reduce, PrimExpr, ReduceNode)
Reduce(CommReducer combiner, Array< PrimExpr > src, Array< IterVar > rdom, PrimExpr condition, int value_index, Array< PrimExpr > init, Span span=Span())
return true_value if condition is true, otherwise return false_value.
Definition: expr.h:572
PrimExpr condition
The condition.
Definition: expr.h:575
PrimExpr true_value
value to be returned when condition is true.
Definition: expr.h:577
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:594
static constexpr const char * _type_key
Definition: expr.h:601
bool SEqualReduce(const SelectNode *other, SEqualReducer equal) const
Definition: expr.h:589
TVM_DECLARE_FINAL_OBJECT_INFO(SelectNode, PrimExprNode)
PrimExpr false_value
value to be returned when condition is false.
Definition: expr.h:579
void VisitAttrs(AttrVisitor *v)
Definition: expr.h:581
Managed reference to SelectNode.
Definition: expr.h:609
TVM_DEFINE_OBJECT_REF_COW_METHOD(SelectNode)
TVM_DEFINE_OBJECT_REF_METHODS(Select, PrimExpr, SelectNode)
Select(PrimExpr condition, PrimExpr true_value, PrimExpr false_value, Span span=Span())
Shuffle instruction. vec = concat(vectors) result = (vec[indices[0]], vec[indices[1]] ....
Definition: expr.h:925
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:944
Array< PrimExpr > indices
The indices of each element.
Definition: expr.h:930
static constexpr const char * _type_key
Definition: expr.h:950
TVM_DECLARE_FINAL_OBJECT_INFO(ShuffleNode, PrimExprNode)
Array< PrimExpr > vectors
the input vectors.
Definition: expr.h:928
void VisitAttrs(AttrVisitor *v)
Definition: expr.h:932
bool SEqualReduce(const ShuffleNode *other, SEqualReducer equal) const
Definition: expr.h:939
Managed reference to ShuffleNode.
Definition: expr.h:958
static PrimExpr Concat(Array< PrimExpr > vectors, Span span=Span())
Shuffle(Array< PrimExpr > vectors, Array< PrimExpr > indices, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(ShuffleNode)
TVM_DEFINE_OBJECT_REF_METHODS(Shuffle, PrimExpr, ShuffleNode)
static PrimExpr ExtractElement(PrimExpr vector, int index, Span span=Span())
a named variable represents a tensor index size
Definition: var.h:150
String constants, only used in asserts.
Definition: expr.h:53
String value
The constant value content.
Definition: expr.h:56
bool SEqualReduce(const StringImmNode *other, SEqualReducer equal) const
Definition: expr.h:64
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:68
static constexpr const char * _type_key
Definition: expr.h:70
TVM_DECLARE_FINAL_OBJECT_INFO(StringImmNode, PrimExprNode)
void VisitAttrs(AttrVisitor *v)
Definition: expr.h:58
Managed reference to StringImmNode.
Definition: expr.h:78
StringImm(String value, Span span=Span())
TVM_DEFINE_OBJECT_REF_COW_METHOD(StringImmNode)
TVM_DEFINE_OBJECT_REF_METHODS(StringImm, PrimExpr, StringImmNode)
a - b
Definition: expr.h:174
static constexpr const char * _type_key
Definition: expr.h:176
Managed reference to SubNode.
Definition: expr.h:183
Sub(PrimExpr a, PrimExpr b, Span span=Span())
TVM_DEFINE_OBJECT_REF_METHODS(Sub, PrimExpr, SubNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(SubNode)
a named variable in TIR
Definition: var.h:88
Defines the Functor data structures.
Base expr nodes in TVM.
Runtime Map container types.
tvm::Span Span
Definition: base.h:65
Var var(std::string name_hint, DataType t=DataType::Int(32))
Construct a new Var expression.
std::unordered_map< K, V > as_unordered_map(const Map< K, V > &dmap)
Definition: expr.h:1143
tvm::FloatImmNode FloatImmNode
Definition: expr.h:50
tvm::IntImmNode IntImmNode
Definition: expr.h:49
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
PrimExpr ret(PrimExpr value, Span span=Span())
Return the value.
PrimExpr equal(PrimExpr a, PrimExpr b, Span span=Span())
equal
Definitions and helper macros for IR/AST nodes.
Runtime String container types.
ObjectRef hash functor.
Definition: object.h:653
a <= b
Definition: expr.h:399
static constexpr const char * _type_key
Definition: expr.h:401
Variables in the TIR.