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 thread_return(Span span = Span());
101 
108 TVM_DLL PrimExpr max_value(const DataType& dtype, Span span = Span());
109 
116 TVM_DLL PrimExpr min_value(const DataType& dtype, Span span = Span());
117 
124 TVM_DLL PrimExpr infinity(const DataType& dtype, Span span = Span());
125 
135 TVM_DLL PrimExpr cast(const DataType& t, PrimExpr value, Span span = Span());
145 TVM_DLL PrimExpr reinterpret(const DataType& t, PrimExpr value, Span span = Span());
156 TVM_DLL PrimExpr add(PrimExpr a, PrimExpr b, Span span = Span());
167 TVM_DLL PrimExpr sub(PrimExpr a, PrimExpr b, Span span = Span());
177 TVM_DLL PrimExpr neg(PrimExpr a, Span span = Span());
188 TVM_DLL PrimExpr mul(PrimExpr a, PrimExpr b, Span span = Span());
199 TVM_DLL PrimExpr left_shift(PrimExpr a, PrimExpr b, Span span = Span());
210 TVM_DLL PrimExpr right_shift(PrimExpr a, PrimExpr b, Span span = Span());
221 TVM_DLL PrimExpr greater(PrimExpr a, PrimExpr b, Span span = Span());
243 TVM_DLL PrimExpr less(PrimExpr a, PrimExpr b, Span span = Span());
254 TVM_DLL PrimExpr less_equal(PrimExpr a, PrimExpr b, Span span = Span());
265 TVM_DLL PrimExpr equal(PrimExpr a, PrimExpr b, Span span = Span());
276 TVM_DLL PrimExpr not_equal(PrimExpr a, PrimExpr b, Span span = Span());
286 TVM_DLL PrimExpr logical_and(PrimExpr a, PrimExpr b, Span span = Span());
296 TVM_DLL PrimExpr logical_or(PrimExpr a, PrimExpr b, Span span = Span());
305 TVM_DLL PrimExpr logical_not(PrimExpr a, Span span = Span());
320 TVM_DLL PrimExpr div(PrimExpr a, PrimExpr b, Span span = Span());
333 TVM_DLL PrimExpr truncdiv(PrimExpr a, PrimExpr b, Span span = Span());
346 TVM_DLL PrimExpr truncmod(PrimExpr a, PrimExpr b, Span span = Span());
362 TVM_DLL PrimExpr indexdiv(PrimExpr a, PrimExpr b, Span span = Span());
378 TVM_DLL PrimExpr shapediv(PrimExpr a, PrimExpr b, Span span = Span());
393 TVM_DLL PrimExpr indexmod(PrimExpr a, PrimExpr b, Span span = Span());
404 TVM_DLL PrimExpr floordiv(PrimExpr a, PrimExpr b, Span span = Span());
413 TVM_DLL PrimExpr logaddexp(PrimExpr a, PrimExpr b, Span span = Span());
425 TVM_DLL PrimExpr ceildiv(PrimExpr a, PrimExpr b, Span span = Span());
436 TVM_DLL PrimExpr floormod(PrimExpr a, PrimExpr b, Span span = Span());
447 TVM_DLL PrimExpr max(PrimExpr a, PrimExpr b, Span span = Span());
458 TVM_DLL PrimExpr min(PrimExpr a, PrimExpr b, Span span = Span());
469 TVM_DLL PrimExpr bitwise_and(PrimExpr a, PrimExpr b, Span span = Span());
480 TVM_DLL PrimExpr bitwise_or(PrimExpr a, PrimExpr b, Span span = Span());
491 TVM_DLL PrimExpr bitwise_xor(PrimExpr a, PrimExpr b, Span span = Span());
501 TVM_DLL PrimExpr bitwise_neg(PrimExpr a, Span span = Span());
513 TVM_DLL PrimExpr if_then_else(PrimExpr cond, PrimExpr true_value, PrimExpr false_value,
514  Span span = Span());
521 TVM_DLL PrimExpr likely(PrimExpr cond, Span span = Span());
528 TVM_DLL PrimExpr pow(PrimExpr x, PrimExpr y, Span span = Span());
536 TVM_DLL PrimExpr abs(PrimExpr x, Span span = Span());
543 TVM_DLL PrimExpr isnan(PrimExpr x, Span span = Span());
544 
551 TVM_DLL PrimExpr isfinite(PrimExpr x, Span span = Span());
552 
559 TVM_DLL PrimExpr isinf(PrimExpr x, Span span = Span());
560 
569 TVM_DLL PrimExpr sum(PrimExpr source, Array<tir::IterVar> axis, Array<PrimExpr> init = {},
570  Span span = Span());
571 
579 TVM_DLL PrimExpr all(PrimExpr source, Array<tir::IterVar> axis, Array<PrimExpr> init = {},
580  Span span = Span());
581 
590 TVM_DLL PrimExpr any(PrimExpr source, Array<tir::IterVar> axis, Array<PrimExpr> init = {},
591  Span span = Span());
592 
601 TVM_DLL PrimExpr max(PrimExpr source, Array<tir::IterVar> axis, Array<PrimExpr> init = {},
602  Span span = Span());
603 
612 TVM_DLL PrimExpr min(PrimExpr source, Array<tir::IterVar> axis, Array<PrimExpr> init = {},
613  Span span = Span());
614 
623 TVM_DLL PrimExpr prod(PrimExpr source, Array<tir::IterVar> axis, Array<PrimExpr> init = {},
624  Span span = Span());
625 
632 TVM_DLL PrimExpr floor(PrimExpr x, Span span = Span());
633 
640 TVM_DLL PrimExpr ceil(PrimExpr x, Span span = Span());
641 
648 TVM_DLL PrimExpr round(PrimExpr x, Span span = Span());
649 
657 TVM_DLL PrimExpr nearbyint(PrimExpr x, Span span = Span());
658 
665 TVM_DLL PrimExpr trunc(PrimExpr x, Span span = Span());
666 
675 TVM_DLL PrimExpr LargeUIntImm(DataType dtype, int64_t low, int64_t high, Span span = Span());
676 
698  Span span = Span());
699 
707 TVM_DLL PrimExpr fast_erf_float_expr(PrimExpr arg, int bits);
708 
709 // Intrinsic operators
710 #define TVM_DECLARE_INTRIN_UNARY(OpName) \
711  inline PrimExpr OpName(PrimExpr x, Span span = Span()) { \
712  static const Op& op = Op::Get("tir." #OpName); \
713  if (x.dtype().is_bfloat16()) { \
714  DataType bf16_dtype = x.dtype(); \
715  DataType fp32_dtype(kDLFloat, 32, bf16_dtype.lanes()); \
716  PrimExpr x_fp32 = tir::Cast(fp32_dtype, {x}, span); \
717  PrimExpr result_fp32 = tir::Call(fp32_dtype, op, {x_fp32}, span); \
718  return tir::Cast(bf16_dtype, {result_fp32}, span); \
719  } else { \
720  return tir::Call(x.dtype(), op, {x}, span); \
721  } \
722  }
723 
749 
750 #define TVM_DECLARE_INTRIN_BINARY(OpName) \
751  inline PrimExpr OpName(PrimExpr x, PrimExpr y, Span span = Span()) { \
752  static const Op& op = Op::Get("tir." #OpName); \
753  return tir::Call(x.dtype(), op, {x, y}, span); \
754  }
755 
761 
762 namespace tir {
763 
770 inline bool IsPointerType(const Type& type, const DataType& element_type) {
771  if (!type.defined()) return false;
772  if (const auto* ptr_type = type.as<PointerTypeNode>()) {
773  if (const auto* prim_type = ptr_type->element_type.as<PrimTypeNode>()) {
774  return prim_type->dtype == element_type;
775  }
776  }
777  return false;
778 }
779 
788 template <typename ValueType,
789  typename = typename std::enable_if<std::is_pod<ValueType>::value>::type>
790 inline PrimExpr make_const(DataType t, ValueType value, Span span = Span());
797 inline PrimExpr make_zero(DataType t, Span span = Span());
804 inline PrimExpr const_true(int lanes = 1, Span span = Span()) {
805  return make_const(DataType::UInt(1, lanes), 1);
806 }
813 inline PrimExpr const_false(int lanes = 1, Span span = Span()) {
814  return make_const(DataType::UInt(1, lanes), 0);
815 }
822 inline const int64_t* as_const_int(const PrimExpr& x) {
823  if (!x.defined()) return nullptr;
824  if (const tir::IntImmNode* op = x.as<tir::IntImmNode>()) {
825  return &(op->value);
826  }
827 
828  return nullptr;
829 }
830 
837 inline bool is_const_int(const PrimExpr& x, int64_t value);
838 
844 inline bool is_no_op(const tir::Stmt& stmt);
845 
852 inline bool is_one(const PrimExpr& x) { return is_const_int(x, 1); }
853 
860 inline bool is_zero(const PrimExpr& x) { return is_const_int(x, 0); }
861 
867 inline bool is_const_int(const PrimExpr& x);
868 
874 inline bool is_const_number(const PrimExpr& x);
875 
885 template <typename FReduce>
886 inline PrimExpr foldl(FReduce freduce, PrimExpr init_value, const Array<PrimExpr>& values,
887  Span span = Span()) {
888  for (PrimExpr val : values) {
889  init_value = freduce(init_value, val, span);
890  }
891  return init_value;
892 }
893 
902 TVM_DLL bool is_const_power_of_two_integer(const PrimExpr& x, int* shift);
903 
904 // Implementation details after this
905 inline bool is_const_int(const PrimExpr& x) { return as_const_int(x); }
906 
907 inline bool is_const_number(const PrimExpr& x) {
908  if (x.as<tir::IntImmNode>()) {
909  return true;
910  } else if (x.as<tir::FloatImmNode>()) {
911  return true;
912  } else if (const auto* op = x.as<tir::BroadcastNode>()) {
913  return (op->value->IsInstance<tir::IntImmNode>() || op->value->IsInstance<tir::FloatImmNode>());
914  }
915  return false;
916 }
917 
918 inline bool is_positive_const(const PrimExpr& a) {
919  const int64_t* as_int = as_const_int(a);
920  return as_int && (*as_int > 0);
921 }
922 
923 inline bool is_negative_const(const PrimExpr& a) {
924  const int64_t* as_int = as_const_int(a);
925  return as_int && (*as_int < 0);
926 }
927 
928 inline bool is_const_int(const PrimExpr& x, int64_t value) {
929  const int64_t* as_int = as_const_int(x);
930  return as_int && (*as_int == value);
931 }
932 
933 inline bool is_no_op(const tir::Stmt& stmt) {
934  if (!stmt.defined()) return true;
935  if (const auto* op = stmt.as<tir::EvaluateNode>()) {
936  return is_const_int(op->value);
937  }
938  if (const auto* op = stmt.as<tir::SeqStmtNode>()) {
939  return op->seq.size() == 0;
940  }
941  return false;
942 }
943 
944 template <typename ValueType>
945 inline PrimExpr MakeConstScalar(DataType t, ValueType value, Span span = Span()) {
946  if (t.is_int()) return IntImm(t, static_cast<int64_t>(value), span);
947  if (t.is_uint()) {
948  // Use IntImm if it is a small integer
949  uint64_t uval = static_cast<uint64_t>(value);
950  if (value < static_cast<ValueType>(0)) {
951  LOG(FATAL) << "cannot make uint from negative value " << value;
952  } else if (uval <= static_cast<uint64_t>(std::numeric_limits<int64_t>::max())) {
953  return IntImm(t, static_cast<int64_t>(value), span);
954  } else {
955  uint64_t mask = (static_cast<uint64_t>(1) << 32U) - 1U;
956  uint64_t low = uval & mask;
957  uint64_t high = uval >> 32U;
958  return LargeUIntImm(t, static_cast<int64_t>(low), static_cast<int64_t>(high), span);
959  }
960  }
961  if (t.is_float() || t.is_bfloat16() || t.is_float8() || t.is_float6() || t.is_float4())
962  return FloatImm(t, static_cast<double>(value), span);
963  // For now, we store const scalar values of custom datatypes within doubles; later, during the
964  // datatypes lowering pass, we will lower the value to its true representation in the format
965  // specified by the datatype.
966  // TODO(gus) when do we need to start worrying about doubles not being precise enough?
967  if (static_cast<uint8_t>(t.code()) >= static_cast<uint8_t>(DataType::kCustomBegin)) {
968  return FloatImm(t, static_cast<double>(value), span);
969  }
970  LOG(FATAL) << "cannot make const for type " << t;
971  throw;
972 }
973 
974 template <>
975 inline PrimExpr MakeConstScalar(DataType t, bool value, Span span) {
976  return MakeConstScalar(t, static_cast<int>(value), span);
977 }
978 
979 template <typename ValueType, typename>
980 inline PrimExpr make_const(DataType t, ValueType value, Span span) {
981  if (t.is_scalar()) {
982  return MakeConstScalar(t, value, span);
983  } else {
984  if (t.is_fixed_length_vector()) {
985  return tir::Broadcast(MakeConstScalar(t.element_of(), value, span), t.lanes(), span);
986  } else {
987  PrimExpr lanes =
989  return tir::Broadcast(MakeConstScalar(t.element_of(), value, span), lanes, span);
990  }
991  }
992 }
993 
994 inline PrimExpr make_zero(DataType t, Span span) {
995  if (t.is_handle()) {
996  return reinterpret(t, make_const(DataType::UInt(64), 0, span));
997  }
998  return make_const(t, 0, span);
999 }
1000 
1001 } // namespace tir
1002 
1003 // additional const expression overloading
1004 #define TVM_DEFINE_ASSIGN_OP_OVERLOAD(Name, OpFunc) \
1005  inline PrimExpr Name(PrimExpr& a, PrimExpr b) { \
1006  a = OpFunc(a, b); \
1007  return a; \
1008  }
1009 
1010 #define TVM_DEFINE_BINOP_CONST_VAL_OVERLOAD(Name) \
1011  inline PrimExpr Name(const PrimExpr& a, float b) { return Name(a, PrimExpr(b)); } \
1012  inline PrimExpr Name(float a, const PrimExpr& b) { return Name(PrimExpr(a), b); } \
1013  inline PrimExpr Name(int a, const PrimExpr& b) { \
1014  return Name(tir::make_const(b.dtype(), a), b); \
1015  } \
1016  inline PrimExpr Name(const PrimExpr& a, int b) { \
1017  return Name(a, tir::make_const(a.dtype(), b)); \
1018  } \
1019  inline PrimExpr Name(const PrimExpr& a, double b) { \
1020  return Name(a, tir::make_const(DataType::Float(64), b)); \
1021  }
1022 
1023 #define TVM_DEFINE_BINOP_CONST_VAL_OVERLOAD_SPANNED(Name) \
1024  inline PrimExpr Name(const PrimExpr& a, float b, Span span = Span()) { \
1025  return Name(a, PrimExpr(b), span); \
1026  } \
1027  inline PrimExpr Name(float a, const PrimExpr& b, Span span = Span()) { \
1028  return Name(PrimExpr(a), b, span); \
1029  } \
1030  inline PrimExpr Name(int a, const PrimExpr& b, Span span = Span()) { \
1031  return Name(tir::make_const(b.dtype(), a), b, span); \
1032  } \
1033  inline PrimExpr Name(const PrimExpr& a, int b, Span span = Span()) { \
1034  return Name(a, tir::make_const(a.dtype(), b), span); \
1035  } \
1036  inline PrimExpr Name(const PrimExpr& a, double b, Span span = Span()) { \
1037  return Name(a, tir::make_const(DataType::Float(64), b), span); \
1038  }
1039 
1040 #define TVM_DEFINE_LOGICAL_OP_CONST_VAL_OVERLOAD(Name) \
1041  inline PrimExpr Name(const PrimExpr& a, bool b) { return Name(a, PrimExpr(b)); } \
1042  inline PrimExpr Name(bool a, const PrimExpr& b) { return Name(PrimExpr(a), b); }
1043 
1044 #define TVM_DEFINE_LOGICAL_OP_CONST_VAL_OVERLOAD_SPANNED(Name) \
1045  inline PrimExpr Name(const PrimExpr& a, bool b, Span span = Span()) { \
1046  return Name(a, PrimExpr(b), span); \
1047  } \
1048  inline PrimExpr Name(bool a, const PrimExpr& b, Span span = Span()) { \
1049  return Name(PrimExpr(a), b, span); \
1050  }
1051 
1052 #define TVM_DEFINE_INT_OP_CONST_VAL_OVERLOAD(Name) \
1053  inline PrimExpr Name(const PrimExpr& a, int b) { \
1054  return Name(a, tir::make_const(a.dtype(), b)); \
1055  } \
1056  inline PrimExpr Name(int a, const PrimExpr& b) { return Name(tir::make_const(b.dtype(), a), b); }
1057 
1058 #define TVM_DEFINE_INT_OP_CONST_VAL_OVERLOAD_SPANNED(Name) \
1059  inline PrimExpr Name(const PrimExpr& a, int b, Span span = Span()) { \
1060  return Name(a, tir::make_const(a.dtype(), b), span); \
1061  } \
1062  inline PrimExpr Name(int a, const PrimExpr& b, Span span = Span()) { \
1063  return Name(tir::make_const(b.dtype(), a), b, span); \
1064  }
1065 
1066 TVM_DEFINE_ASSIGN_OP_OVERLOAD(operator+=, operator+);
1067 TVM_DEFINE_ASSIGN_OP_OVERLOAD(operator-=, operator-);
1068 TVM_DEFINE_ASSIGN_OP_OVERLOAD(operator*=, operator*);
1072 TVM_DEFINE_BINOP_CONST_VAL_OVERLOAD(operator>); // NOLINT(*)
1074 TVM_DEFINE_BINOP_CONST_VAL_OVERLOAD(operator<); // NOLINT(*)
1086 // integer related ops
1099 TVM_DEFINE_INT_OP_CONST_VAL_OVERLOAD(operator>>); // NOLINT(*)
1100 TVM_DEFINE_INT_OP_CONST_VAL_OVERLOAD(operator<<); // NOLINT(*)
1104 // logical ops
1109 
1115 template <typename TA>
1116 inline void DivAmbiguityError(const TA& a) {
1117  constexpr bool div_ambiguity = !std::is_class<TA>::value;
1118  static_assert(div_ambiguity,
1119  "TVM supports multiple types of integer divisions, "
1120  "please call div, indexdiv/indexmod, "
1121  "floordiv/floormod or truncdiv/truncmod directly "
1122  "to avoid ambiguity in the code. "
1123  "Checkout these functions in tir/op.h.");
1124 }
1125 
1126 // The following code are not intended to be used in the codebase.
1127 // Instead, they generate clear compiler errors that ask developers
1128 // to use the specific division function.
1129 // The second template argument is necessary to make sure the
1130 // code compiles lazily by the compiler during invocation.
1131 template <typename TB>
1132 inline PrimExpr operator/(const PrimExpr& a, const TB& b) {
1133  DivAmbiguityError(a);
1134  return a;
1135 }
1136 
1137 template <typename TB>
1138 inline PrimExpr operator/=(const PrimExpr& a, const TB& b) {
1139  DivAmbiguityError(a);
1140  return a;
1141 }
1142 
1143 template <typename TB>
1144 inline PrimExpr operator%(const PrimExpr& a, const TB& b) {
1145  DivAmbiguityError(a);
1146  return a;
1147 }
1148 } // namespace tvm
1149 #endif // TVM_TIR_OP_H_
Constant floating point literals in the program.
Definition: expr.h:538
Managed reference class to FloatImmNode.
Definition: expr.h:557
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:520
Low-level raw pointer type.
Definition: type.h:156
Reference to PrimExprNode.
Definition: expr.h:129
Primitive data types used in the low-level IR.
Definition: type.h:114
Definition: source_map.h:113
Managed reference to TypeNode.
Definition: type.h:101
Runtime primitive data type.
Definition: data_type.h:47
bool is_handle() const
Definition: data_type.h:194
bool is_uint() const
Definition: data_type.h:192
bool is_float6() const
Definition: data_type.h:155
DataType element_of() const
Get the scalar version of the type.
Definition: data_type.h:236
@ kCustomBegin
Definition: data_type.h:74
bool is_int() const
Definition: data_type.h:190
int code() const
Definition: data_type.h:113
int lanes() const
Definition: data_type.h:119
int vscale_factor() const
Definition: data_type.h:127
bool is_fixed_length_vector() const
Definition: data_type.h:201
static DataType Int(int bits, int lanes=1)
Construct an int type.
Definition: data_type.h:274
bool is_scalar() const
Definition: data_type.h:139
bool is_float8() const
Definition: data_type.h:147
bool is_bfloat16() const
Definition: data_type.h:188
bool is_float4() const
Definition: data_type.h:160
static DataType UInt(int bits, int lanes=1, bool is_scalable=false)
Construct an uint type.
Definition: data_type.h:282
bool is_float() const
Definition: data_type.h:143
Create a vector where all the elements are value.
Definition: expr.h:671
Managed reference to BroadcastNode.
Definition: expr.h:693
Managed reference to CallNode.
Definition: expr.h:764
Evaluates an expression. This is mostly used for putting a Call node into Stmt.
Definition: stmt.h:492
Managed reference to MulNode.
Definition: expr.h:172
The container of seq statement. Represent a sequence of statements.
Definition: stmt.h:465
Container of all statements.
Definition: stmt.h:64
Base expr nodes in TVM.
Primitive operators(builtin intrinsics) and registry for them.
IR/AST nodes for the unified type system in TVM.
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:945
PrimExpr make_const(DataType t, ValueType value, Span span=Span())
Make a const value with certain data type.
Definition: op.h:980
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:860
bool IsPointerType(const Type &type, const DataType &element_type)
Check if type is a pointer to a runtime element type.
Definition: op.h:770
bool is_negative_const(const PrimExpr &a)
Definition: op.h:923
bool is_const_number(const PrimExpr &x)
Check whether x is an integer/float constant.
Definition: op.h:907
bool is_const_int(const PrimExpr &x, int64_t value)
Check whether x is a constant integer expression.
Definition: op.h:928
PrimExpr foldl(FReduce freduce, PrimExpr init_value, const Array< PrimExpr > &values, Span span=Span())
Left fold.
Definition: op.h:886
bool is_positive_const(const PrimExpr &a)
Definition: op.h:918
PrimExpr const_false(int lanes=1, Span span=Span())
Make a constant false expression.
Definition: op.h:813
PrimExpr const_true(int lanes=1, Span span=Span())
Make a constant true expression.
Definition: op.h:804
bool is_no_op(const tir::Stmt &stmt)
Check whether stmt is nop.
Definition: op.h:933
bool is_one(const PrimExpr &x)
Check whether x is a constant integer 1.
Definition: op.h:852
const int64_t * as_const_int(const PrimExpr &x)
Get x as constant int expression.
Definition: op.h:822
PrimExpr make_zero(DataType t, Span span=Span())
Make a const zero expr.
Definition: op.h:994
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
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:37
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:728
PrimExpr erf(PrimExpr x, Span span=Span())
Definition: op.h:727
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:734
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:759
PrimExpr log1p(PrimExpr x, Span span=Span())
Definition: op.h:735
void DivAmbiguityError(const TA &a)
Helper function to raise a compiler error about division ambiguity.
Definition: op.h:1116
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:756
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:739
PrimExpr logical_or(PrimExpr a, PrimExpr b, Span span=Span())
or
PrimExpr thread_return(Span span=Span())
Return from a thread.
PrimExpr atan(PrimExpr x, Span span=Span())
Definition: op.h:744
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:725
PrimExpr rsqrt(PrimExpr x, Span span=Span())
Definition: op.h:731
PrimExpr operator/=(const PrimExpr &a, const TB &b)
Definition: op.h:1138
PrimExpr asinh(PrimExpr x, Span span=Span())
Definition: op.h:746
PrimExpr less(PrimExpr a, PrimExpr b, Span span=Span())
less
PrimExpr sin(PrimExpr x, Span span=Span())
Definition: op.h:740
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:726
PrimExpr copysign(PrimExpr x, PrimExpr y, Span span=Span())
Definition: op.h:758
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:724
PrimExpr logaddexp(PrimExpr a, PrimExpr b, Span span=Span())
Compute log(exp(a) + exp(b)).
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:757
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:742
PrimExpr sigmoid(PrimExpr x, Span span=Span())
Definition: op.h:729
PrimExpr max(const PrimExpr &a, double b, Span span=Span())
Definition: op.h:1076
PrimExpr acos(PrimExpr x, Span span=Span())
Definition: op.h:743
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:1144
PrimExpr abs(PrimExpr x, Span span=Span())
Calculate absolute value of x.
PrimExpr atanh(PrimExpr x, Span span=Span())
Definition: op.h:747
PrimExpr sqrt(PrimExpr x, Span span=Span())
Definition: op.h:730
PrimExpr isinf(PrimExpr x, Span span=Span())
Check if x is infinite.
PrimExpr log2(PrimExpr x, Span span=Span())
Definition: op.h:733
PrimExpr not_equal(PrimExpr a, PrimExpr b, Span span=Span())
not_equal
PrimExpr ldexp(PrimExpr x, PrimExpr y, Span span=Span())
Definition: op.h:760
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:736
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:741
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:732
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:748
PrimExpr floordiv(PrimExpr a, PrimExpr b, Span span=Span())
compute floor(a / b)
PrimExpr acosh(PrimExpr x, Span span=Span())
Definition: op.h:745
PrimExpr tan(PrimExpr x, Span span=Span())
Definition: op.h:737
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:738
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:710
#define TVM_DEFINE_INT_OP_CONST_VAL_OVERLOAD(Name)
Definition: op.h:1052
#define TVM_DEFINE_LOGICAL_OP_CONST_VAL_OVERLOAD_SPANNED(Name)
Definition: op.h:1044
#define TVM_DEFINE_ASSIGN_OP_OVERLOAD(Name, OpFunc)
Definition: op.h:1004
#define TVM_DEFINE_BINOP_CONST_VAL_OVERLOAD_SPANNED(Name)
Definition: op.h:1023
#define TVM_DEFINE_BINOP_CONST_VAL_OVERLOAD(Name)
Definition: op.h:1010
#define TVM_DEFINE_LOGICAL_OP_CONST_VAL_OVERLOAD(Name)
Definition: op.h:1040
#define TVM_DECLARE_INTRIN_BINARY(OpName)
Definition: op.h:750
#define TVM_DEFINE_INT_OP_CONST_VAL_OVERLOAD_SPANNED(Name)
Definition: op.h:1058