24 #ifndef TVM_IR_EXPR_H_ 25 #define TVM_IR_EXPR_H_ 36 #include <type_traits> 57 static constexpr
const char*
_type_key =
"BaseExpr";
123 TVM_DLL PrimExpr(
float value);
133 TVM_DLL
static PrimExpr FromObject_(
ObjectRef ref);
371 inline const Type& checked_type()
const;
382 template <
typename TTypeNode>
383 inline const TTypeNode* type_as()
const;
451 v->Visit(
"name_hint", &name_hint);
452 v->Visit(
"virtual_device_", &virtual_device_);
453 v->Visit(
"span", &
span);
454 v->Visit(
"_checked_type_", &checked_type_);
463 hash_reduce(name_hint);
495 v->Visit(
"dtype", &dtype);
496 v->Visit(
"value", &value);
497 v->Visit(
"span", &
span);
542 v->Visit(
"dtype", &dtype);
543 v->Visit(
"value", &value);
544 v->Visit(
"span", &
span);
589 operator bool()
const {
return (*this)->value != 0; }
598 return Bool(a.operator
bool() || b.operator
bool());
603 return Bool(a.operator
bool() && b.operator
bool());
609 return a.operator bool() == b.operator bool();
641 template <typename Enum, typename = typename std::enable_if<std::is_enum<Enum>::value>::type>
643 static_assert(std::is_same<
int,
typename std::underlying_type<Enum>::type>::value,
644 "declare enum to be enum int to use visitor");
651 data_ = ObjectRef::GetDataPtr<Object>(other);
658 ICHECK(data_ !=
nullptr) <<
" Trying to reference a null Integer";
659 return (*this)->value;
663 if (data_ ==
nullptr)
return Bool(
false);
664 return Bool((*this)->value == other);
667 template <typename Enum, typename = typename std::enable_if<std::is_enum<Enum>::value>::type>
669 return *
this ==
static_cast<int>(other);
671 template <typename Enum, typename = typename std::enable_if<std::is_enum<Enum>::value>::type>
673 return *
this !=
static_cast<int>(other);
689 : min(min), extent(extent), span(span) {}
692 v->Visit(
"min", &min);
693 v->Visit(
"extent", &extent);
694 v->Visit(
"span", &span);
739 ICHECK(checked_type_.defined()) <<
"internal error: the type checker has " 740 <<
"not populated the checked_type " 741 <<
"field for " << GetRef<RelayExpr>(
this);
742 return this->checked_type_;
745 template <
typename TTypeNode>
747 static_assert(std::is_base_of<TypeNode, TTypeNode>::value,
748 "TType must be a special case of type");
749 ICHECK(checked_type_.defined())
750 <<
"Type inference for this Expr has not completed. Try to call infer_type pass.";
751 const TTypeNode* node = checked_type_.as<TTypeNode>();
752 ICHECK(node !=
nullptr) <<
"Expected type to be " << TTypeNode::_type_key <<
", but get " 753 << checked_type_->GetTypeKey();
769 int64_t value = val.operator int64_t();
790 return Integer(val.operator
int());
803 int v = val.operator int();
804 ICHECK(v == 0 || v == 1) <<
"ValueError: boolean value can only be 0 or 1, but get " << v;
805 return Bool(static_cast<bool>(v));
813 #endif // TVM_IR_EXPR_H_ Integer(Enum value)
Constructor from enum.
Definition: expr.h:642
PrimExpr operator!=(PrimExpr a, PrimExpr b)
not_equal
tvm::Span Span
Definition: base.h:65
static constexpr const char * _type_key
Definition: expr.h:57
void FreeVarHashImpl(const runtime::Object *var) const
Implementation for hash for a free var.
Definition: structural_hash.h:185
PrimExpr operator<(PrimExpr a, PrimExpr b)
less
double value
The constant value content.
Definition: expr.h:539
PrimExpr min
beginning of the node
Definition: expr.h:681
const Type & checked_type() const
Definition: expr.h:738
PrimExpr min(PrimExpr a, PrimExpr b, Span span=Span())
take minimum of two values
A custom smart pointer for Object.
Definition: object.h:358
PrimExpr operator||(PrimExpr a, PrimExpr b)
or
Boolean constant.
Definition: expr.h:585
Definitions and helper macros for IR/AST nodes.
Runtime String container types.
Internal base class to handle conversion to POD values.
Definition: packed_func.h:541
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:701
bool FreeVarEqualImpl(const runtime::Object *lhs, const runtime::Object *rhs) const
Implementation for equality rule of var type objects(e.g. TypeVar, tir::Var).
Definition: structural_equal.h:277
A Reducer class to reduce the structural equality result of two objects.
Definition: structural_equal.h:124
static constexpr const bool _type_has_method_shash_reduce
Definition: expr.h:59
Integer()
Definition: expr.h:622
String name_hint
The name of the variable, this only acts as a hint.
Definition: expr.h:448
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
Span span
the location of this range in the source
Definition: expr.h:685
A Reducer class to reduce the structural hash value.
Definition: structural_hash.h:102
Definition: c_runtime_api.h:168
Bool operator==(int other) const
Definition: expr.h:662
PrimExpr equal(PrimExpr a, PrimExpr b, Span span=Span())
equal
Constant floating point literals in the program.
Definition: expr.h:536
Definition: loop_state.h:456
bool SEqualReduce(const IntImmNode *other, SEqualReducer equal) const
Definition: expr.h:500
DataType dtype() const
Definition: expr.h:126
Integer(int value, Span span=Span())
Construct integer from int value.
Definition: expr.h:630
base class of all object containers.
Definition: object.h:167
PrimExpr operator-(PrimExpr a, PrimExpr b)
subtraction operator
Integer & operator=(const IntImm &other)
Assign an expression to integer.
Definition: expr.h:650
Integer(IntImm other)
Construct integer from int imm.
Definition: expr.h:635
Managed reference to BaseExprNode.
Definition: expr.h:68
Constant integer literals in the program.
Definition: expr.h:489
PrimExpr extent
the extend of range
Definition: expr.h:683
PrimExpr operator &&(PrimExpr a, PrimExpr b)
and
Span information for debugging purposes.
Integer(ObjectPtr< Object > node)
constructor from node.
Definition: expr.h:626
Managed reference class to FloatImmNode.
Definition: expr.h:565
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
PrimExpr operator &(PrimExpr a, PrimExpr b)
take bitwise and of two values
static tvm::Bool From(const TVMPODValue_ &val)
Definition: expr.h:798
bool SEqualReduce(const FloatImmNode *other, SEqualReducer equal) const
Definition: expr.h:547
Managed reference class to VirtualDeviceNode.
Definition: virtual_device.h:261
Range constainer.
Definition: expr.h:713
PrimExpr operator!(PrimExpr a)
not
Span span
Span that points to the original source code. Reserved debug information.
Definition: expr.h:55
int64_t IntValue() const
convert to int64_t
Definition: expr.h:657
static constexpr const uint32_t _type_child_slots
Definition: expr.h:60
IR/AST nodes for the unified type system in TVM.
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:462
bool SEqualReduce(const RangeNode *other, SEqualReducer equal) const
Definition: expr.h:697
Runtime primitive data type.
Definition: data_type.h:41
Base type of all the expressions.
Definition: expr.h:49
tvm::GlobalVar GlobalVar
Definition: expr.h:58
static DataType Float(int bits, int lanes=1)
Construct an float type.
Definition: data_type.h:178
static PrimExpr From(const TVMPODValue_ &val)
Definition: expr.h:764
static constexpr const bool _type_has_method_sequal_reduce
Definition: expr.h:58
void VisitAttrs(AttrVisitor *v)
Definition: expr.h:541
Bool operator!() const
Definition: expr.h:588
Managed reference class to IntImmNode.
Definition: expr.h:518
PrimExpr operator<<(PrimExpr a, PrimExpr b)
left shift operator
Managed reference to GlobalVarNode.
Definition: expr.h:475
PrimExpr operator^(PrimExpr a, PrimExpr b)
take bitwise xor of two values
RangeNode(PrimExpr min, PrimExpr extent, Span span=Span())
Definition: expr.h:688
ObjectRef virtual_device_
The virtual device (VirtualDevice) for this node (the result of device planning). For first-order exp...
Definition: expr.h:407
TObjectRef AsObjectRef() const
Definition: packed_func.h:1822
PrimExpr max(PrimExpr a, PrimExpr b, Span span=Span())
take maximum of two values
int64_t value
the Internal value.
Definition: expr.h:492
Reference to string objects.
Definition: string.h:97
Managed reference to RelayExprNode.
Definition: expr.h:431
#define TVM_DEFINE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:713
void VisitAttrs(AttrVisitor *v)
Definition: expr.h:494
PrimExpr operator>>(PrimExpr a, PrimExpr b)
right shift operator
bool SEqualReduce(const GlobalVarNode *other, SEqualReducer equal) const
Definition: expr.h:457
PrimExpr operator==(PrimExpr a, PrimExpr b)
equal
Bool operator!=(Enum other) const
Definition: expr.h:672
tvm::Type Type
Definition: type.h:47
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:504
PrimExpr operator>=(PrimExpr a, PrimExpr b)
greater_equal
Bool operator!=(int other) const
Definition: expr.h:666
Base class of all object reference.
Definition: object.h:511
#define TVM_DEFINE_OBJECT_REF_COW_METHOD(ObjectName)
Define CopyOnWrite function in an ObjectRef.
Definition: object.h:785
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:551
PrimExpr operator*(PrimExpr a, PrimExpr b)
multiplication operator
A managed object in the TVM runtime.
#define TVM_DECLARE_FINAL_OBJECT_INFO(TypeName, ParentType)
helper macro to declare type information in a final class.
Definition: object.h:671
RangeNode()
constructor
Definition: expr.h:687
static tvm::Integer From(const TVMPODValue_ &val)
Definition: expr.h:785
void VisitAttrs(AttrVisitor *v)
Definition: expr.h:691
void VisitAttrs(AttrVisitor *v)
Definition: expr.h:450
const TTypeNode * type_as() const
Check if the inferred(checked) type of the Expr is backed by a TTypeNode and return it...
Definition: expr.h:746
DataType dtype
The runtime data type of the primitive expression.
Definition: expr.h:101
Definition: c_runtime_api.h:171
PrimExpr operator/(PrimExpr a, PrimExpr b)
division operator
int type_code() const
Definition: packed_func.h:610
Bool(bool value, Span span=Span())
Definition: expr.h:587
PrimExpr operator<=(PrimExpr a, PrimExpr b)
less_equal
Managed reference to TypeNode.
Definition: type.h:93
TVM_DECLARE_BASE_OBJECT_INFO(BaseExprNode, Object)
PrimExpr operator~(PrimExpr a)
take bitwise negation of two values
Reference to PrimExprNode.
Definition: expr.h:112
Global variable that lives in the top-level module.
Definition: expr.h:445
PrimExpr operator|(PrimExpr a, PrimExpr b)
take bitwise or of two values
Base node of all non-primitive expressions.
Definition: expr.h:359
#define TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:728
PrimExpr operator+(PrimExpr a, PrimExpr b)
add operator
Bool operator==(Enum other) const
Definition: expr.h:668
Type trait to specify special value conversion rules from TVMArgValue and TVMRetValue.
Definition: packed_func.h:1096
static DataType Int(int bits, int lanes=1)
Construct an int type.
Definition: data_type.h:164
Base node of all primitive expressions.
Definition: expr.h:85
Container of constant int that adds more constructors.
Definition: expr.h:620
PrimExpr operator>(PrimExpr a, PrimExpr b)
greater
range over one dimension
Definition: expr.h:678