tvm
op.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 
27 // Acknowledgement: Most operator APIs originate from Halide.
28 #ifndef TVM_TIR_OP_H_
29 #define TVM_TIR_OP_H_
30 
31 #include <tvm/ir/expr.h>
32 #include <tvm/ir/op.h>
33 #include <tvm/ir/type.h>
34 #include <tvm/tir/builtin.h>
35 #include <tvm/tir/expr.h>
36 #include <tvm/tir/stmt.h>
37 
38 #include <algorithm>
39 #include <limits>
40 #include <type_traits>
41 
42 namespace tvm {
43 
44 #define TVM_TIR_REGISTER_OP(OpName) \
45  TVM_REGISTER_OP("tir." OpName).set_attr<TScriptPrinterName>("TScriptPrinterName", OpName)
46 
47 // Most common operators can be overloaded by argument type(PrimExpr).
48 // So we put them under the root namespace.
49 //
50 // We put more developer oriented APIs -- make_const and is_const under tir
51 // as they are more specific to the tir namespace.
52 
64 TVM_DLL Type GetType(const PrimExpr& expr);
65 
74 
84 
92 TVM_DLL PrimExpr ret(PrimExpr value, Span span = Span());
93 
100 TVM_DLL PrimExpr max_value(const DataType& dtype, Span span = Span());
101 
108 TVM_DLL PrimExpr min_value(const DataType& dtype, Span span = Span());
109 
116 TVM_DLL PrimExpr infinity(const DataType& dtype, Span span = Span());
117 
127 TVM_DLL PrimExpr cast(const DataType& t, PrimExpr value, Span span = Span());
137 TVM_DLL PrimExpr reinterpret(const DataType& t, PrimExpr value, Span span = Span());
148 TVM_DLL PrimExpr add(PrimExpr a, PrimExpr b, Span span = Span());
159 TVM_DLL PrimExpr sub(PrimExpr a, PrimExpr b, Span span = Span());
169 TVM_DLL PrimExpr neg(PrimExpr a, Span span = Span());
180 TVM_DLL PrimExpr mul(PrimExpr a, PrimExpr b, Span span = Span());
191 TVM_DLL PrimExpr left_shift(PrimExpr a, PrimExpr b, Span span = Span());
202 TVM_DLL PrimExpr right_shift(PrimExpr a, PrimExpr b, Span span = Span());
213 TVM_DLL PrimExpr greater(PrimExpr a, PrimExpr b, Span span = Span());
235 TVM_DLL PrimExpr less(PrimExpr a, PrimExpr b, Span span = Span());
246 TVM_DLL PrimExpr less_equal(PrimExpr a, PrimExpr b, Span span = Span());
257 TVM_DLL PrimExpr equal(PrimExpr a, PrimExpr b, Span span = Span());
268 TVM_DLL PrimExpr not_equal(PrimExpr a, PrimExpr b, Span span = Span());
278 TVM_DLL PrimExpr logical_and(PrimExpr a, PrimExpr b, Span span = Span());
288 TVM_DLL PrimExpr logical_or(PrimExpr a, PrimExpr b, Span span = Span());
297 TVM_DLL PrimExpr logical_not(PrimExpr a, Span span = Span());
312 TVM_DLL PrimExpr div(PrimExpr a, PrimExpr b, Span span = Span());
325 TVM_DLL PrimExpr truncdiv(PrimExpr a, PrimExpr b, Span span = Span());
338 TVM_DLL PrimExpr truncmod(PrimExpr a, PrimExpr b, Span span = Span());
354 TVM_DLL PrimExpr indexdiv(PrimExpr a, PrimExpr b, Span span = Span());
370 TVM_DLL PrimExpr shapediv(PrimExpr a, PrimExpr b, Span span = Span());
385 TVM_DLL PrimExpr indexmod(PrimExpr a, PrimExpr b, Span span = Span());
396 TVM_DLL PrimExpr floordiv(PrimExpr a, PrimExpr b, Span span = Span());
407 TVM_DLL PrimExpr ceildiv(PrimExpr a, PrimExpr b, Span span = Span());
418 TVM_DLL PrimExpr floormod(PrimExpr a, PrimExpr b, Span span = Span());
429 TVM_DLL PrimExpr max(PrimExpr a, PrimExpr b, Span span = Span());
440 TVM_DLL PrimExpr min(PrimExpr a, PrimExpr b, Span span = Span());
451 TVM_DLL PrimExpr bitwise_and(PrimExpr a, PrimExpr b, Span span = Span());
462 TVM_DLL PrimExpr bitwise_or(PrimExpr a, PrimExpr b, Span span = Span());
473 TVM_DLL PrimExpr bitwise_xor(PrimExpr a, PrimExpr b, Span span = Span());
483 TVM_DLL PrimExpr bitwise_neg(PrimExpr a, Span span = Span());
495 TVM_DLL PrimExpr if_then_else(PrimExpr cond, PrimExpr true_value, PrimExpr false_value,
496  Span span = Span());
503 TVM_DLL PrimExpr likely(PrimExpr cond, Span span = Span());
510 TVM_DLL PrimExpr pow(PrimExpr x, PrimExpr y, Span span = Span());
518 TVM_DLL PrimExpr abs(PrimExpr x, Span span = Span());
525 TVM_DLL PrimExpr isnan(PrimExpr x, Span span = Span());
526 
533 TVM_DLL PrimExpr isfinite(PrimExpr x, Span span = Span());
534 
541 TVM_DLL PrimExpr isinf(PrimExpr x, Span span = Span());
542 
551 TVM_DLL PrimExpr sum(PrimExpr source, Array<tir::IterVar> axis, Array<PrimExpr> init = {},
552  Span span = Span());
553 
561 TVM_DLL PrimExpr all(PrimExpr source, Array<tir::IterVar> axis, Array<PrimExpr> init = {},
562  Span span = Span());
563 
572 TVM_DLL PrimExpr any(PrimExpr source, Array<tir::IterVar> axis, Array<PrimExpr> init = {},
573  Span span = Span());
574 
583 TVM_DLL PrimExpr max(PrimExpr source, Array<tir::IterVar> axis, Array<PrimExpr> init = {},
584  Span span = Span());
585 
594 TVM_DLL PrimExpr min(PrimExpr source, Array<tir::IterVar> axis, Array<PrimExpr> init = {},
595  Span span = Span());
596 
605 TVM_DLL PrimExpr prod(PrimExpr source, Array<tir::IterVar> axis, Array<PrimExpr> init = {},
606  Span span = Span());
607 
614 TVM_DLL PrimExpr floor(PrimExpr x, Span span = Span());
615 
622 TVM_DLL PrimExpr ceil(PrimExpr x, Span span = Span());
623 
630 TVM_DLL PrimExpr round(PrimExpr x, Span span = Span());
631 
639 TVM_DLL PrimExpr nearbyint(PrimExpr x, Span span = Span());
640 
647 TVM_DLL PrimExpr trunc(PrimExpr x, Span span = Span());
648 
657 TVM_DLL PrimExpr LargeUIntImm(DataType dtype, int64_t low, int64_t high, Span span = Span());
658 
680  Span span = Span());
681 
689 TVM_DLL PrimExpr fast_erf_float_expr(PrimExpr arg, int bits);
690 
691 // Intrinsic operators
692 #define TVM_DECLARE_INTRIN_UNARY(OpName) \
693  inline PrimExpr OpName(PrimExpr x, Span span = Span()) { \
694  static const Op& op = Op::Get("tir." #OpName); \
695  if (x.dtype().is_bfloat16()) { \
696  DataType bf16_dtype = x.dtype(); \
697  DataType fp32_dtype(kDLFloat, 32, bf16_dtype.lanes()); \
698  PrimExpr x_fp32 = tir::Cast(fp32_dtype, {x}, span); \
699  PrimExpr result_fp32 = tir::Call(fp32_dtype, op, {x_fp32}, span); \
700  return tir::Cast(bf16_dtype, {result_fp32}, span); \
701  } else { \
702  return tir::Call(x.dtype(), op, {x}, span); \
703  } \
704  }
705 
731 
732 #define TVM_DECLARE_INTRIN_BINARY(OpName) \
733  inline PrimExpr OpName(PrimExpr x, PrimExpr y, Span span = Span()) { \
734  static const Op& op = Op::Get("tir." #OpName); \
735  return tir::Call(x.dtype(), op, {x, y}, span); \
736  }
737 
743 
744 namespace tir {
745 
752 inline bool IsPointerType(const Type& type, const DataType& element_type) {
753  if (!type.defined()) return false;
754  if (const auto* ptr_type = type.as<PointerTypeNode>()) {
755  if (const auto* prim_type = ptr_type->element_type.as<PrimTypeNode>()) {
756  return prim_type->dtype == element_type;
757  }
758  }
759  return false;
760 }
761 
770 template <typename ValueType,
771  typename = typename std::enable_if<std::is_pod<ValueType>::value>::type>
772 inline PrimExpr make_const(DataType t, ValueType value, Span span = Span());
779 inline PrimExpr make_zero(DataType t, Span span = Span());
786 inline PrimExpr const_true(int lanes = 1, Span span = Span()) {
787  return make_const(DataType::UInt(1, lanes), 1);
788 }
795 inline PrimExpr const_false(int lanes = 1, Span span = Span()) {
796  return make_const(DataType::UInt(1, lanes), 0);
797 }
804 inline const int64_t* as_const_int(const PrimExpr& x) {
805  if (!x.defined()) return nullptr;
806  if (const tir::IntImmNode* op = x.as<tir::IntImmNode>()) {
807  return &(op->value);
808  }
809 
810  return nullptr;
811 }
812 
819 inline bool is_const_int(const PrimExpr& x, int64_t value);
820 
826 inline bool is_no_op(const tir::Stmt& stmt);
827 
834 inline bool is_one(const PrimExpr& x) { return is_const_int(x, 1); }
835 
842 inline bool is_zero(const PrimExpr& x) { return is_const_int(x, 0); }
843 
849 inline bool is_const_int(const PrimExpr& x);
850 
856 inline bool is_const_number(const PrimExpr& x);
857 
867 template <typename FReduce>
868 inline PrimExpr foldl(FReduce freduce, PrimExpr init_value, const Array<PrimExpr>& values,
869  Span span = Span()) {
870  for (PrimExpr val : values) {
871  init_value = freduce(init_value, val, span);
872  }
873  return init_value;
874 }
875 
884 TVM_DLL bool is_const_power_of_two_integer(const PrimExpr& x, int* shift);
885 
886 // Implementation details after this
887 inline bool is_const_int(const PrimExpr& x) { return as_const_int(x); }
888 
889 inline bool is_const_number(const PrimExpr& x) {
890  if (x.as<tir::IntImmNode>()) {
891  return true;
892  } else if (x.as<tir::FloatImmNode>()) {
893  return true;
894  } else if (const auto* op = x.as<tir::BroadcastNode>()) {
895  return (op->value->IsInstance<tir::IntImmNode>() || op->value->IsInstance<tir::FloatImmNode>());
896  }
897  return false;
898 }
899 
900 inline bool is_positive_const(const PrimExpr& a) {
901  const int64_t* as_int = as_const_int(a);
902  return as_int && (*as_int > 0);
903 }
904 
905 inline bool is_negative_const(const PrimExpr& a) {
906  const int64_t* as_int = as_const_int(a);
907  return as_int && (*as_int < 0);
908 }
909 
910 inline bool is_const_int(const PrimExpr& x, int64_t value) {
911  const int64_t* as_int = as_const_int(x);
912  return as_int && (*as_int == value);
913 }
914 
915 inline bool is_no_op(const tir::Stmt& stmt) {
916  if (!stmt.defined()) return true;
917  if (const auto* op = stmt.as<tir::EvaluateNode>()) {
918  return is_const_int(op->value);
919  }
920  if (const auto* op = stmt.as<tir::SeqStmtNode>()) {
921  return op->seq.size() == 0;
922  }
923  return false;
924 }
925 
926 template <typename ValueType>
927 inline PrimExpr MakeConstScalar(DataType t, ValueType value, Span span = Span()) {
928  if (t.is_int()) return IntImm(t, static_cast<int64_t>(value), span);
929  if (t.is_uint()) {
930  // Use IntImm if it is a small integer
931  uint64_t uval = static_cast<uint64_t>(value);
932  if (value < static_cast<ValueType>(0)) {
933  LOG(FATAL) << "cannot make uint from negative value " << value;
934  } else if (uval <= static_cast<uint64_t>(std::numeric_limits<int64_t>::max())) {
935  return IntImm(t, static_cast<int64_t>(value), span);
936  } else {
937  uint64_t mask = (static_cast<uint64_t>(1) << 32U) - 1U;
938  uint64_t low = uval & mask;
939  uint64_t high = uval >> 32U;
940  return LargeUIntImm(t, static_cast<int64_t>(low), static_cast<int64_t>(high), span);
941  }
942  }
943  if (t.is_float() || t.is_bfloat16() || t.is_float8())
944  return FloatImm(t, static_cast<double>(value), span);
945  // For now, we store const scalar values of custom datatypes within doubles; later, during the
946  // datatypes lowering pass, we will lower the value to its true representation in the format
947  // specified by the datatype.
948  // TODO(gus) when do we need to start worrying about doubles not being precise enough?
949  if (static_cast<uint8_t>(t.code()) >= static_cast<uint8_t>(DataType::kCustomBegin)) {
950  return FloatImm(t, static_cast<double>(value), span);
951  }
952  LOG(FATAL) << "cannot make const for type " << t;
953  throw;
954 }
955 
956 template <>
957 inline PrimExpr MakeConstScalar(DataType t, bool value, Span span) {
958  return MakeConstScalar(t, static_cast<int>(value), span);
959 }
960 
961 template <typename ValueType, typename>
962 inline PrimExpr make_const(DataType t, ValueType value, Span span) {
963  if (t.is_scalar()) {
964  return MakeConstScalar(t, value, span);
965  } else {
966  if (t.is_fixed_length_vector()) {
967  return tir::Broadcast(MakeConstScalar(t.element_of(), value, span), t.lanes(), span);
968  } else {
969  PrimExpr lanes =
971  return tir::Broadcast(MakeConstScalar(t.element_of(), value, span), lanes, span);
972  }
973  }
974 }
975 
976 inline PrimExpr make_zero(DataType t, Span span) {
977  if (t.is_handle()) {
978  return reinterpret(t, make_const(DataType::UInt(64), 0, span));
979  }
980  return make_const(t, 0, span);
981 }
982 
983 } // namespace tir
984 
985 // additional const expression overloading
986 #define TVM_DEFINE_ASSIGN_OP_OVERLOAD(Name, OpFunc) \
987  inline PrimExpr Name(PrimExpr& a, PrimExpr b) { \
988  a = OpFunc(a, b); \
989  return a; \
990  }
991 
992 #define TVM_DEFINE_BINOP_CONST_VAL_OVERLOAD(Name) \
993  inline PrimExpr Name(const PrimExpr& a, float b) { return Name(a, PrimExpr(b)); } \
994  inline PrimExpr Name(float a, const PrimExpr& b) { return Name(PrimExpr(a), b); } \
995  inline PrimExpr Name(int a, const PrimExpr& b) { \
996  return Name(tir::make_const(b.dtype(), a), b); \
997  } \
998  inline PrimExpr Name(const PrimExpr& a, int b) { \
999  return Name(a, tir::make_const(a.dtype(), b)); \
1000  } \
1001  inline PrimExpr Name(const PrimExpr& a, double b) { \
1002  return Name(a, tir::make_const(DataType::Float(64), b)); \
1003  }
1004 
1005 #define TVM_DEFINE_BINOP_CONST_VAL_OVERLOAD_SPANNED(Name) \
1006  inline PrimExpr Name(const PrimExpr& a, float b, Span span = Span()) { \
1007  return Name(a, PrimExpr(b), span); \
1008  } \
1009  inline PrimExpr Name(float a, const PrimExpr& b, Span span = Span()) { \
1010  return Name(PrimExpr(a), b, span); \
1011  } \
1012  inline PrimExpr Name(int a, const PrimExpr& b, Span span = Span()) { \
1013  return Name(tir::make_const(b.dtype(), a), b, span); \
1014  } \
1015  inline PrimExpr Name(const PrimExpr& a, int b, Span span = Span()) { \
1016  return Name(a, tir::make_const(a.dtype(), b), span); \
1017  } \
1018  inline PrimExpr Name(const PrimExpr& a, double b, Span span = Span()) { \
1019  return Name(a, tir::make_const(DataType::Float(64), b), span); \
1020  }
1021 
1022 #define TVM_DEFINE_LOGICAL_OP_CONST_VAL_OVERLOAD(Name) \
1023  inline PrimExpr Name(const PrimExpr& a, bool b) { return Name(a, PrimExpr(b)); } \
1024  inline PrimExpr Name(bool a, const PrimExpr& b) { return Name(PrimExpr(a), b); }
1025 
1026 #define TVM_DEFINE_LOGICAL_OP_CONST_VAL_OVERLOAD_SPANNED(Name) \
1027  inline PrimExpr Name(const PrimExpr& a, bool b, Span span = Span()) { \
1028  return Name(a, PrimExpr(b), span); \
1029  } \
1030  inline PrimExpr Name(bool a, const PrimExpr& b, Span span = Span()) { \
1031  return Name(PrimExpr(a), b, span); \
1032  }
1033 
1034 #define TVM_DEFINE_INT_OP_CONST_VAL_OVERLOAD(Name) \
1035  inline PrimExpr Name(const PrimExpr& a, int b) { \
1036  return Name(a, tir::make_const(a.dtype(), b)); \
1037  } \
1038  inline PrimExpr Name(int a, const PrimExpr& b) { return Name(tir::make_const(b.dtype(), a), b); }
1039 
1040 #define TVM_DEFINE_INT_OP_CONST_VAL_OVERLOAD_SPANNED(Name) \
1041  inline PrimExpr Name(const PrimExpr& a, int b, Span span = Span()) { \
1042  return Name(a, tir::make_const(a.dtype(), b), span); \
1043  } \
1044  inline PrimExpr Name(int a, const PrimExpr& b, Span span = Span()) { \
1045  return Name(tir::make_const(b.dtype(), a), b, span); \
1046  }
1047 
1048 TVM_DEFINE_ASSIGN_OP_OVERLOAD(operator+=, operator+);
1049 TVM_DEFINE_ASSIGN_OP_OVERLOAD(operator-=, operator-);
1050 TVM_DEFINE_ASSIGN_OP_OVERLOAD(operator*=, operator*);
1054 TVM_DEFINE_BINOP_CONST_VAL_OVERLOAD(operator>); // NOLINT(*)
1056 TVM_DEFINE_BINOP_CONST_VAL_OVERLOAD(operator<); // NOLINT(*)
1068 // integer related ops
1080 TVM_DEFINE_INT_OP_CONST_VAL_OVERLOAD(operator>>); // NOLINT(*)
1081 TVM_DEFINE_INT_OP_CONST_VAL_OVERLOAD(operator<<); // NOLINT(*)
1085 // logical ops
1090 
1096 template <typename TA>
1097 inline void DivAmbiguityError(const TA& a) {
1098  constexpr bool div_ambiguity = !std::is_class<TA>::value;
1099  static_assert(div_ambiguity,
1100  "TVM supports multiple types of integer divisions, "
1101  "please call div, indexdiv/indexmod, "
1102  "floordiv/floormod or truncdiv/truncmod directly "
1103  "to avoid ambiguity in the code. "
1104  "Checkout these functions in tir/op.h.");
1105 }
1106 
1107 // The following code are not intended to be used in the codebase.
1108 // Instead, they generate clear compiler errors that ask developers
1109 // to use the specific division function.
1110 // The second template argument is necessary to make sure the
1111 // code compiles lazily by the compiler during invocation.
1112 template <typename TB>
1113 inline PrimExpr operator/(const PrimExpr& a, const TB& b) {
1114  DivAmbiguityError(a);
1115  return a;
1116 }
1117 
1118 template <typename TB>
1119 inline PrimExpr operator/=(const PrimExpr& a, const TB& b) {
1120  DivAmbiguityError(a);
1121  return a;
1122 }
1123 
1124 template <typename TB>
1125 inline PrimExpr operator%(const PrimExpr& a, const TB& b) {
1126  DivAmbiguityError(a);
1127  return a;
1128 }
1129 } // namespace tvm
1130 #endif // TVM_TIR_OP_H_
Constant floating point literals in the program.
Definition: expr.h:548
Managed reference class to FloatImmNode.
Definition: expr.h:577
Constant integer literals in the program.
Definition: expr.h:501
int64_t value
the Internal value.
Definition: expr.h:504
Managed reference class to IntImmNode.
Definition: expr.h:530
Low-level raw pointer type.
Definition: type.h:151
Reference to PrimExprNode.
Definition: expr.h:115
Primitive data types used in the low-level IR.
Definition: type.h:106
Definition: source_map.h:120
Managed reference to TypeNode.
Definition: type.h:93
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Runtime primitive data type.
Definition: data_type.h:43
bool is_handle() const
Definition: data_type.h:141
bool is_uint() const
Definition: data_type.h:139
DataType element_of() const
Get the scalar version of the type.
Definition: data_type.h:181
@ kCustomBegin
Definition: data_type.h:61
bool is_int() const
Definition: data_type.h:137
int code() const
Definition: data_type.h:92
int lanes() const
Definition: data_type.h:98
int vscale_factor() const
Definition: data_type.h:106
bool is_fixed_length_vector() const
Definition: data_type.h:148
static DataType Int(int bits, int lanes=1)
Construct an int type.
Definition: data_type.h:219
bool is_scalar() const
Definition: data_type.h:118
bool is_float8() const
Definition: data_type.h:124
bool is_bfloat16() const
Definition: data_type.h:135
static DataType UInt(int bits, int lanes=1, bool is_scalable=false)
Construct an uint type.
Definition: data_type.h:227
bool is_float() const
Definition: data_type.h:122
bool defined() const
Definition: object.h:552
const ObjectType * as() const
Try to downcast the internal Object to a raw pointer of a corresponding type.
Definition: object.h:910
Create a vector where all the elements are value.
Definition: expr.h:792
Managed reference to BroadcastNode.
Definition: expr.h:824
Managed reference to CallNode.
Definition: expr.h:918
Evaluates an expression. This is mostly used for putting a Call node into Stmt.
Definition: stmt.h:703
Managed reference to MulNode.
Definition: expr.h:200
The container of seq statement. Represent a sequence of statements.
Definition: stmt.h:670
Container of all statements.
Definition: stmt.h:59
Base expr nodes in TVM.
Primitive operators(builtin intrinsics) and registry for them.
IR/AST nodes for the unified type system in TVM.
tvm::Span Span
Definition: base.h:65
const Op & vscale()
Get the target's vscale value. It will be lowered to llvm.vscale intrinsic (https://llvm....
PrimExpr MakeConstScalar(DataType t, ValueType value, Span span=Span())
Definition: op.h:927
PrimExpr make_const(DataType t, ValueType value, Span span=Span())
Make a const value with certain data type.
Definition: op.h:962
bool is_const_power_of_two_integer(const PrimExpr &x, int *shift)
Check whether x is a constant power of two If x is power of two, write the power to the shift.
bool is_zero(const PrimExpr &x)
Check whether x is a constant integer 0.
Definition: op.h:842
bool IsPointerType(const Type &type, const DataType &element_type)
Check if type is a pointer to a runtime element type.
Definition: op.h:752
bool is_negative_const(const PrimExpr &a)
Definition: op.h:905
bool is_const_number(const PrimExpr &x)
Check whether x is an integer/float constant.
Definition: op.h:889
bool is_const_int(const PrimExpr &x, int64_t value)
Check whether x is a constant integer expression.
Definition: op.h:910
PrimExpr foldl(FReduce freduce, PrimExpr init_value, const Array< PrimExpr > &values, Span span=Span())
Left fold.
Definition: op.h:868
bool is_positive_const(const PrimExpr &a)
Definition: op.h:900
PrimExpr const_false(int lanes=1, Span span=Span())
Make a constant false expression.
Definition: op.h:795
PrimExpr const_true(int lanes=1, Span span=Span())
Make a constant true expression.
Definition: op.h:786
bool is_no_op(const tir::Stmt &stmt)
Check whether stmt is nop.
Definition: op.h:915
bool is_one(const PrimExpr &x)
Check whether x is a constant integer 1.
Definition: op.h:834
const int64_t * as_const_int(const PrimExpr &x)
Get x as constant int expression.
Definition: op.h:804
PrimExpr make_zero(DataType t, Span span=Span())
Make a const zero expr.
Definition: op.h:976
std::function< PrimExpr(PrimExpr source, const Array< IterVar > &axis, Array< PrimExpr > init, Span span)> FReduce
The operation to use for CommReduce.
Definition: reduction.h:47
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
runtime::DataType GetRuntimeDataType(const Type &type)
Get the implied DataType for storing values with type during runtime.
PrimExpr isfinite(PrimExpr x, Span span=Span())
Check if x is finite.
PrimExpr ceildiv(PrimExpr a, PrimExpr b, Span span=Span())
compute ceil(a / b)
PrimExpr ret(PrimExpr value, Span span=Span())
Return the value.
PrimExpr max(PrimExpr a, PrimExpr b, Span span=Span())
take maximum of two values
PrimExpr tanh(PrimExpr x, Span span=Span())
Definition: op.h:710
PrimExpr erf(PrimExpr x, Span span=Span())
Definition: op.h:709
PrimExpr shapediv(PrimExpr a, PrimExpr b, Span span=Span())
compute ceil(a / b) where a and b are non-negative.
PrimExpr log10(PrimExpr x, Span span=Span())
Definition: op.h:716
PrimExpr div(PrimExpr a, PrimExpr b, Span span=Span())
compute division in C semantics.
PrimExpr operator/(PrimExpr a, PrimExpr b)
division operator
PrimExpr equal(PrimExpr a, PrimExpr b, Span span=Span())
equal
PrimExpr truncmod(PrimExpr a, PrimExpr b, Span span=Span())
compute the remainder of truncdiv
PrimExpr logical_and(PrimExpr a, PrimExpr b, Span span=Span())
and
PrimExpr hypot(PrimExpr x, PrimExpr y, Span span=Span())
Definition: op.h:741
PrimExpr log1p(PrimExpr x, Span span=Span())
Definition: op.h:717
void DivAmbiguityError(const TA &a)
Helper function to raise a compiler error about division ambiguity.
Definition: op.h:1097
PrimExpr prod(PrimExpr source, Array< tir::IterVar > axis, Array< PrimExpr > init={}, Span span=Span())
product of source expression over axis
PrimExpr likely(PrimExpr cond, Span span=Span())
Mark condition as likely.
PrimExpr reinterpret(const DataType &t, PrimExpr value, Span span=Span())
perform reinterpret cast value to type.
PrimExpr atan2(PrimExpr x, PrimExpr y, Span span=Span())
Definition: op.h:738
PrimExpr if_then_else(PrimExpr cond, PrimExpr true_value, PrimExpr false_value, Span span=Span())
Conditional expression.
PrimExpr min_value(const DataType &dtype, Span span=Span())
PrimExpr bitwise_neg(PrimExpr a, Span span=Span())
take bitwise negation of two values
PrimExpr cosh(PrimExpr x, Span span=Span())
Definition: op.h:721
PrimExpr logical_or(PrimExpr a, PrimExpr b, Span span=Span())
or
PrimExpr atan(PrimExpr x, Span span=Span())
Definition: op.h:726
Type GetType(const PrimExpr &expr)
Get the type of the expression under the unified type system.
PrimExpr isnan(PrimExpr x, Span span=Span())
Check if x is NaN.
PrimExpr cast(const DataType &t, PrimExpr value, Span span=Span())
cast value to type.
PrimExpr max_value(const DataType &dtype, Span span=Span())
PrimExpr exp2(PrimExpr x, Span span=Span())
Definition: op.h:707
PrimExpr rsqrt(PrimExpr x, Span span=Span())
Definition: op.h:713
PrimExpr operator/=(const PrimExpr &a, const TB &b)
Definition: op.h:1119
PrimExpr asinh(PrimExpr x, Span span=Span())
Definition: op.h:728
PrimExpr less(PrimExpr a, PrimExpr b, Span span=Span())
less
PrimExpr sin(PrimExpr x, Span span=Span())
Definition: op.h:722
PrimExpr trunc(PrimExpr x, Span span=Span())
Calculate trunc(x)
PrimExpr round(PrimExpr x, Span span=Span())
Calculate round(x)
Type GetTypeFromRuntimeDataType(const DataType &dtype)
Get the type corresponding to DataType.
PrimExpr neg(PrimExpr a, Span span=Span())
negation.
PrimExpr ceil(PrimExpr x, Span span=Span())
Calculate ceil(x)
PrimExpr any(PrimExpr source, Array< tir::IterVar > axis, Array< PrimExpr > init={}, Span span=Span())
logical Or of source expression over axis
PrimExpr pow(PrimExpr x, PrimExpr y, Span span=Span())
Calculate power(x, y)
PrimExpr logical_not(PrimExpr a, Span span=Span())
not
PrimExpr exp10(PrimExpr x, Span span=Span())
Definition: op.h:708
PrimExpr copysign(PrimExpr x, PrimExpr y, Span span=Span())
Definition: op.h:740
PrimExpr bitwise_xor(PrimExpr a, PrimExpr b, Span span=Span())
take bitwise xor of two values
PrimExpr less_equal(PrimExpr a, PrimExpr b, Span span=Span())
less_equal
PrimExpr greater(PrimExpr a, PrimExpr b, Span span=Span())
greater
PrimExpr exp(PrimExpr x, Span span=Span())
Definition: op.h:706
PrimExpr floormod(PrimExpr a, PrimExpr b, Span span=Span())
compute the remainder of floordiv
PrimExpr infinity(const DataType &dtype, Span span=Span())
PrimExpr sub(PrimExpr a, PrimExpr b, Span span=Span())
subtraction operator
PrimExpr indexdiv(PrimExpr a, PrimExpr b, Span span=Span())
compute floor(a / b) where a and b are non-negative.
PrimExpr nextafter(PrimExpr x, PrimExpr y, Span span=Span())
Definition: op.h:739
PrimExpr LargeUIntImm(DataType dtype, int64_t low, int64_t high, Span span=Span())
Construct a large uint constant by its low 32 bits and high 32bits.
PrimExpr asin(PrimExpr x, Span span=Span())
Definition: op.h:724
PrimExpr sigmoid(PrimExpr x, Span span=Span())
Definition: op.h:711
PrimExpr max(const PrimExpr &a, double b, Span span=Span())
Definition: op.h:1058
PrimExpr acos(PrimExpr x, Span span=Span())
Definition: op.h:725
PrimExpr mul(PrimExpr a, PrimExpr b, Span span=Span())
multiplication operator
PrimExpr min(PrimExpr a, PrimExpr b, Span span=Span())
take minimum of two values
PrimExpr floor(PrimExpr x, Span span=Span())
Calculate floor(x)
PrimExpr greater_equal(PrimExpr a, PrimExpr b, Span span=Span())
greater_equal
PrimExpr operator%(const PrimExpr &a, const TB &b)
Definition: op.h:1125
PrimExpr abs(PrimExpr x, Span span=Span())
Calculate absolute value of x.
PrimExpr atanh(PrimExpr x, Span span=Span())
Definition: op.h:729
PrimExpr sqrt(PrimExpr x, Span span=Span())
Definition: op.h:712
PrimExpr isinf(PrimExpr x, Span span=Span())
Check if x is infinite.
PrimExpr log2(PrimExpr x, Span span=Span())
Definition: op.h:715
PrimExpr not_equal(PrimExpr a, PrimExpr b, Span span=Span())
not_equal
PrimExpr ldexp(PrimExpr x, PrimExpr y, Span span=Span())
Definition: op.h:742
PrimExpr truncdiv(PrimExpr a, PrimExpr b, Span span=Span())
compute trunc(a / b)
PrimExpr q_multiply_shift(PrimExpr x, PrimExpr y, PrimExpr q, PrimExpr s, Span span=Span())
Execute a multiplication between two Q-numbers x and y followed by a right shift s....
PrimExpr popcount(PrimExpr x, Span span=Span())
Definition: op.h:718
PrimExpr bitwise_and(PrimExpr a, PrimExpr b, Span span=Span())
take bitwise and of two values
PrimExpr left_shift(PrimExpr a, PrimExpr b, Span span=Span())
left shift operator
PrimExpr sinh(PrimExpr x, Span span=Span())
Definition: op.h:723
PrimExpr indexmod(PrimExpr a, PrimExpr b, Span span=Span())
compute the remainder floor(a / b) where a and b are non-negative.
PrimExpr all(PrimExpr source, Array< tir::IterVar > axis, Array< PrimExpr > init={}, Span span=Span())
logical And of source expression over axis
PrimExpr add(PrimExpr a, PrimExpr b, Span span=Span())
add operator
PrimExpr log(PrimExpr x, Span span=Span())
Definition: op.h:714
PrimExpr nearbyint(PrimExpr x, Span span=Span())
Calculates std::nearbyint(x)
PrimExpr right_shift(PrimExpr a, PrimExpr b, Span span=Span())
right shift operator
PrimExpr bitwise_or(PrimExpr a, PrimExpr b, Span span=Span())
take bitwise or of two values
PrimExpr clz(PrimExpr x, Span span=Span())
Definition: op.h:730
PrimExpr floordiv(PrimExpr a, PrimExpr b, Span span=Span())
compute floor(a / b)
PrimExpr acosh(PrimExpr x, Span span=Span())
Definition: op.h:727
PrimExpr tan(PrimExpr x, Span span=Span())
Definition: op.h:719
PrimExpr sum(PrimExpr source, Array< tir::IterVar > axis, Array< PrimExpr > init={}, Span span=Span())
sum of source expression over axis
PrimExpr cos(PrimExpr x, Span span=Span())
Definition: op.h:720
PrimExpr fast_erf_float_expr(PrimExpr arg, int bits)
Fast_erf_float expression from Eigen.
TIR statements.
TIR builtin intrinsics.
TIR expressions.
#define TVM_DECLARE_INTRIN_UNARY(OpName)
Definition: op.h:692
#define TVM_DEFINE_INT_OP_CONST_VAL_OVERLOAD(Name)
Definition: op.h:1034
#define TVM_DEFINE_LOGICAL_OP_CONST_VAL_OVERLOAD_SPANNED(Name)
Definition: op.h:1026
#define TVM_DEFINE_ASSIGN_OP_OVERLOAD(Name, OpFunc)
Definition: op.h:986
#define TVM_DEFINE_BINOP_CONST_VAL_OVERLOAD_SPANNED(Name)
Definition: op.h:1005
#define TVM_DEFINE_BINOP_CONST_VAL_OVERLOAD(Name)
Definition: op.h:992
#define TVM_DEFINE_LOGICAL_OP_CONST_VAL_OVERLOAD(Name)
Definition: op.h:1022
#define TVM_DECLARE_INTRIN_BINARY(OpName)
Definition: op.h:732
#define TVM_DEFINE_INT_OP_CONST_VAL_OVERLOAD_SPANNED(Name)
Definition: op.h:1040