24 #ifndef TVM_RELAY_EXPR_H_ 25 #define TVM_RELAY_EXPR_H_ 49 Optional<Type> opt_type = {}, Optional<VirtualDevice> opt_virtual_device = {},
50 Optional<Span> opt_span = {});
83 v->Visit(
"data", &data);
85 v->Visit(
"span", &
span);
95 static constexpr
const char*
_type_key =
"relay.Constant";
129 v->Visit(
"fields", &fields);
131 v->Visit(
"span", &
span);
137 if (fields.
size() == other->
fields.size() && fields.
size() == 0) {
146 if (fields.
size() != 0) {
211 v->Visit(
"vid", &vid);
212 v->Visit(
"type_annotation", &type_annotation);
214 v->Visit(
"span", &
span);
226 hash_reduce(type_annotation);
243 : Var(
Id(name_hint), type_annotation,
span) {}
260 static Var GenSym(
Type type_annotation = {},
Span span = {});
286 static void Deleter_(
Object* ptr);
325 v->Visit(
"args", &args);
326 v->Visit(
"attrs", &attrs);
327 v->Visit(
"type_args", &type_args);
329 v->Visit(
"span", &
span);
346 hash_reduce(type_args);
408 static void Deleter_(
Object* ptr);
419 v->Visit(
"var", &var);
420 v->Visit(
"value", &value);
421 v->Visit(
"body", &body);
423 v->Visit(
"span", &
span);
501 v->Visit(
"cond", &cond);
502 v->Visit(
"true_branch", &true_branch);
503 v->Visit(
"false_branch", &false_branch);
505 v->Visit(
"span", &
span);
518 hash_reduce(true_branch);
519 hash_reduce(false_branch);
562 v->Visit(
"tuple_value", &tuple);
563 v->Visit(
"index", &index);
565 v->Visit(
"span", &
span);
578 static constexpr
const char*
_type_key =
"relay.TupleGetItem";
614 v->Visit(
"value", &value);
616 v->Visit(
"span", &
span);
630 static constexpr
const char*
_type_key =
"relay.RefCreate";
664 v->Visit(
"ref", &ref);
666 v->Visit(
"span", &
span);
680 static constexpr
const char*
_type_key =
"relay.RefRead";
716 v->Visit(
"ref", &ref);
717 v->Visit(
"value", &value);
719 v->Visit(
"span", &
span);
734 static constexpr
const char*
_type_key =
"relay.RefWrite";
784 static constexpr
const char*
_type_key =
"relay.TempExpr";
806 using Handler =
typename Derived::template Handler<T>;
807 static_assert(std::is_base_of<Object, T>::value,
"make can only be used to create Object");
808 T* ptr = Handler::New(static_cast<Derived*>(
this));
809 ptr->type_index_ = T::RuntimeTypeIndex();
810 ptr->saved_deleter_ = Handler::Deleter();
821 using Handler =
typename Derived::template Handler<T>;
822 static_assert(std::is_base_of<Object, T>::value,
"make can only be used to create Object");
823 T* ptr = Handler::New(static_cast<Derived*>(
this));
824 ptr->type_index_ = T::RuntimeTypeIndex();
825 ptr->saved_deleter_ = Handler::Deleter();
833 #endif // TVM_RELAY_EXPR_H_ tvm::Span Span
Definition: base.h:65
Expr true_branch
The expression evaluated when condition is true.
Definition: expr.h:496
bool SEqualReduce(const LetNode *other, SEqualReducer equal) const
Definition: expr.h:427
bool DefEqual(const ObjectRef &lhs, const ObjectRef &rhs)
Reduce condition to comparison of two definitions, where free vars can be mapped. ...
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:625
tvm::Array< relay::Expr > args
The arguments(inputs) of the call.
Definition: expr.h:298
tvm::BaseFuncNode BaseFuncNode
Definition: expr.h:57
A custom smart pointer for Object.
Definition: object.h:358
Attrs attrs
The additional attributes.
Definition: expr.h:301
RealizeFrame Realize(tvm::tir::BufferRegion buffer_slice, String storage_scope, PrimExpr condition)
The realization.
Base class of the temporary expression.
Definition: expr.h:774
bool SEqualReduce(const VarNode *other, SEqualReducer equal) const
Definition: expr.h:218
bool SEqualReduce(const TupleNode *other, SEqualReducer equal) const
Definition: expr.h:135
Managed reference to TensorTypeNode.
Definition: tensor_type.h:99
Call container.
Definition: expr.h:282
A Reducer class to reduce the structural equality result of two objects.
Definition: structural_equal.h:124
Managed reference to BaseAttrsNode.
Definition: attrs.h:190
A compile time representation for where data is to be stored at runtime, and how to compile code to c...
static constexpr const bool _type_has_method_shash_reduce
Definition: expr.h:59
IRModule that holds the functions and type definitions.
Var(String name_hint, Type type_annotation, Span span=Span())
The constructor.
Definition: expr.h:242
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
A Reducer class to reduce the structural hash value.
Definition: structural_hash.h:110
Object::FDeleter saved_deleter_
Definition: expr.h:407
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:93
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:210
tvm::Array< relay::Expr > fields
the fields of the tuple
Definition: expr.h:126
static void Deleter_(Object *ptr)
PrimExpr equal(PrimExpr a, PrimExpr b, Span span=Span())
equal
Constant tensor type.
Definition: expr.h:71
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:515
bool is_scalar() const
Definition: expr.h:80
Expr cond
The condition.
Definition: expr.h:494
bool SEqualReduce(const RefWriteNode *other, SEqualReducer equal) const
Definition: expr.h:723
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:715
Type type_annotation
type annotaion of the variable. This field records user provided type annotation of the Var...
Definition: expr.h:205
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:561
static constexpr const char * _type_key
Definition: expr.h:95
tvm::BaseFunc BaseFunc
Definition: expr.h:56
Expr body
The body of the let binding.
Definition: expr.h:416
Clause WithFields(Clause clause, Optional< Pattern > opt_lhs=Optional< Pattern >(), Optional< Expr > opt_rhs=Optional< Expr >())
Returns clause with the given properties. A null property denotes 'no change'. Returns clause if all ...
base class of all object containers.
Definition: object.h:167
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:613
Managed NDArray. The array is backed by reference counted blocks.
Definition: ndarray.h:51
Container for Var.
Definition: expr.h:188
tvm::Array< Type > type_args
The type arguments passed to polymorphic(template) function.
Definition: expr.h:321
Expr ref
The Reference Expression.
Definition: expr.h:661
Helpers for attribute objects.
virtual void MarkGraphNode()=0
Mark current comparison as graph node equal comparison.
Expr tuple
The tuple Expression.
Definition: expr.h:557
Primitive operators(builtin intrinsics) and registry for them.
Expr op
The operator(function) being invoked.
Definition: expr.h:295
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:340
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
bool SEqualReduce(const IfNode *other, SEqualReducer equal) const
Definition: expr.h:509
Definition: source_map.h:120
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:224
tvm::GlobalVarNode GlobalVarNode
Definition: expr.h:59
A binding of a sub-network.
Definition: expr.h:404
size_t size() const
Definition: array.h:420
Span span
Span that points to the original source code. Reserved debug information.
Definition: expr.h:55
Var var
The variable we bind to.
Definition: expr.h:412
tvm::GlobalVar GlobalVar
Definition: expr.h:58
virtual void MarkGraphNode()=0
Mark current comparison as graph node in hashing. Graph node hash will depends on the graph structure...
Type checked_type_
Stores the result of type inference(type checking).
Definition: expr.h:369
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:728
static constexpr const bool _type_has_method_sequal_reduce
Definition: expr.h:58
bool IsPrimitiveOp(const RelayExpr &expr)
Check that an expression is a "primitive operator".
Definition: op.h:498
void(* FDeleter)(Object *self)
Object deleter.
Definition: object.h:173
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:323
Managed reference to GlobalVarNode.
Definition: expr.h:477
Expr false_branch
The expression evaluated when condition is false.
Definition: expr.h:498
Tuple container.
Definition: expr.h:123
bool SEqualReduce(const ConstantNode *other, SEqualReducer equal) const
Definition: expr.h:89
ObjectRef virtual_device_
The virtual device (VirtualDevice) for this node (the result of device planning). For first-order exp...
Definition: expr.h:409
TVM_DECLARE_FINAL_OBJECT_INFO(ConstantNode, ExprNode)
Reference to string objects.
Definition: string.h:98
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:675
Managed reference to RelayExprNode.
Definition: expr.h:433
#define TVM_DEFINE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:713
Object::FDeleter saved_deleter_
Definition: expr.h:285
bool SEqualReduce(const CallNode *other, SEqualReducer equal) const
Definition: expr.h:333
TVM_DECLARE_BASE_OBJECT_INFO(RelayExprNode, BaseExprNode)
Var var(std::string name_hint, DataType t=DataType::Int(32))
Construct a new Var expression.
#define TVM_DEFINE_OBJECT_REF_COW_METHOD(ObjectName)
Define CopyOnWrite function in an ObjectRef.
Definition: object.h:785
Base class of object allocators that implements make. Use curiously recurring template pattern...
Definition: memory.h:60
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:573
const String & name_hint() const
Definition: expr.h:208
TensorType tensor_type() const
GlobalVar WithFields(GlobalVar global_var, Optional< String > opt_name_hint={}, Optional< Type > opt_type={}, Optional< VirtualDevice > opt_virtual_device={}, Optional< Span > opt_span={})
Returns global_var with the given properties. A null property denotes 'no change'. Returns global_var if all properties are unchanged. Otherwise, returns a copy with the new fields.
bool SEqualReduce(const RefCreateNode *other, SEqualReducer equal) const
Definition: expr.h:620
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:145
Expr value
The initial value of the Reference.
Definition: expr.h:611
virtual ~TempExprNode()
virtual destructor
Definition: expr.h:777
Base node of all functions.
Definition: function.h:77
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:418
Expr ref
The Reference Expression.
Definition: expr.h:711
Expr value
The value we bind var to.
Definition: expr.h:414
static void Deleter_(Object *ptr)
Managed reference to BaseFuncNode.
Definition: function.h:143
Base classes for the Relay IR.
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:500
Managed reference to TypeNode.
Definition: type.h:93
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:82
Expr value
The value to write into.
Definition: expr.h:713
bool SEqualReduce(const TupleGetItemNode *other, SEqualReducer equal) const
Definition: expr.h:569
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:128
Global variable that lives in the top-level module.
Definition: expr.h:447
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:433
Base node of all non-primitive expressions.
Definition: expr.h:361
int index
which value to get
Definition: expr.h:559
runtime::NDArray data
The data of the tensor.
Definition: expr.h:74
static constexpr const uint32_t _type_child_slots
Definition: expr.h:425
container of If
Definition: expr.h:491
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:663
void DefHash(const ObjectRef &key) const
Push hash of key to the current sequence of hash values.
Definition: structural_hash.h:187
bool SEqualReduce(const RefReadNode *other, SEqualReducer equal) const
Definition: expr.h:670
Id vid
The unique identifier of the Var.
Definition: expr.h:199