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);
140 equal->MarkGraphNode();
211 v->Visit(
"vid", &
vid);
214 v->Visit(
"span", &
span);
219 equal->MarkGraphNode();
243 :
Var(
Id(name_hint), type_annotation, span) {}
325 v->Visit(
"args", &
args);
326 v->Visit(
"attrs", &
attrs);
329 v->Visit(
"span", &
span);
335 equal->MarkGraphNode();
419 v->Visit(
"var", &
var);
420 v->Visit(
"value", &
value);
421 v->Visit(
"body", &
body);
423 v->Visit(
"span", &
span);
428 equal->MarkGraphNode();
501 v->Visit(
"cond", &
cond);
505 v->Visit(
"span", &
span);
510 equal->MarkGraphNode();
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);
621 equal->MarkGraphNode();
630 static constexpr
const char*
_type_key =
"relay.RefCreate";
664 v->Visit(
"ref", &
ref);
666 v->Visit(
"span", &
span);
671 equal->MarkGraphNode();
680 static constexpr
const char*
_type_key =
"relay.RefRead";
716 v->Visit(
"ref", &
ref);
717 v->Visit(
"value", &
value);
719 v->Visit(
"span", &
span);
724 equal->MarkGraphNode();
734 static constexpr
const char*
_type_key =
"relay.RefWrite";
784 static constexpr
const char*
_type_key =
"relay.TempExpr";
803 ObjAllocatorBase<SimpleObjAllocator>::make_object<relay::LetNode>() {
804 using Derived = SimpleObjAllocator;
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();
817 inline ObjectPtr<relay::CallNode>
818 ObjAllocatorBase<SimpleObjAllocator>::make_object<relay::CallNode>() {
819 using Derived = SimpleObjAllocator;
820 using T = relay::CallNode;
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();
827 return ObjectPtr<T>(ptr);
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
Managed reference to BaseAttrsNode.
Definition: attrs.h:190
Span span
Span that points to the original source code. Reserved debug information.
Definition: expr.h:56
Base node of all functions.
Definition: function.h:139
Managed reference to BaseFuncNode.
Definition: function.h:230
Global variable that lives in the top-level module.
Definition: expr.h:456
Managed reference to GlobalVarNode.
Definition: expr.h:487
Base node of all non-primitive expressions.
Definition: expr.h:362
ObjectRef virtual_device_
The virtual device (VirtualDevice) for this node (the result of device planning). For first-order exp...
Definition: expr.h:418
Type checked_type_
Stores the result of type inference(type checking).
Definition: expr.h:370
Managed reference to RelayExprNode.
Definition: expr.h:442
A Reducer class to reduce the structural equality result of two objects.
Definition: structural_equal.h:137
virtual void MarkGraphNode()=0
Mark current comparison as graph node in hashing. Graph node hash will depends on the graph structure...
A Reducer class to reduce the structural hash value.
Definition: structural_hash.h:121
void DefHash(const ObjectRef &key) const
Push hash of key to the current sequence of hash values.
Definition: structural_hash.h:198
Definition: source_map.h:120
Managed reference to TensorTypeNode.
Definition: tensor_type.h:99
Managed reference to TypeNode.
Definition: type.h:93
Call container.
Definition: expr.h:282
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:340
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:323
static void Deleter_(Object *ptr)
bool SEqualReduce(const CallNode *other, SEqualReducer equal) const
Definition: expr.h:333
tvm::Array< relay::Expr > args
The arguments(inputs) of the call.
Definition: expr.h:298
Object::FDeleter saved_deleter_
Definition: expr.h:285
static constexpr const char * _type_key
Definition: expr.h:350
Attrs attrs
The additional attributes.
Definition: expr.h:301
tvm::Array< Type > type_args
The type arguments passed to polymorphic(template) function.
Definition: expr.h:321
Expr op
The operator(function) being invoked.
Definition: expr.h:295
TVM_DECLARE_FINAL_OBJECT_INFO(CallNode, ExprNode)
Call(Expr op, Array< Expr > args, Attrs attrs=Attrs(), Array< Type > type_args=Array< Type >(), Span span=Span())
The constructor.
TVM_DEFINE_OBJECT_REF_COW_METHOD(CallNode)
TVM_DEFINE_OBJECT_REF_METHODS(Call, RelayExpr, CallNode)
Constant tensor type.
Definition: expr.h:71
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:82
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:93
static constexpr const char * _type_key
Definition: expr.h:95
bool SEqualReduce(const ConstantNode *other, SEqualReducer equal) const
Definition: expr.h:89
TensorType tensor_type() const
TVM_DECLARE_FINAL_OBJECT_INFO(ConstantNode, ExprNode)
bool is_scalar() const
Definition: expr.h:80
runtime::NDArray data
The data of the tensor.
Definition: expr.h:74
TVM_DEFINE_OBJECT_REF_COW_METHOD(ConstantNode)
TVM_DEFINE_OBJECT_REF_METHODS(Constant, RelayExpr, ConstantNode)
Constant(runtime::NDArray data, Span span=Span())
The constructor.
container of If
Definition: expr.h:491
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:515
TVM_DECLARE_FINAL_OBJECT_INFO(IfNode, ExprNode)
static constexpr const char * _type_key
Definition: expr.h:522
Expr cond
The condition.
Definition: expr.h:494
Expr true_branch
The expression evaluated when condition is true.
Definition: expr.h:496
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:500
bool SEqualReduce(const IfNode *other, SEqualReducer equal) const
Definition: expr.h:509
Expr false_branch
The expression evaluated when condition is false.
Definition: expr.h:498
If(Expr cond, Expr true_branch, Expr false_branch, Span span=Span())
The constructor.
TVM_DEFINE_OBJECT_REF_COW_METHOD(IfNode)
TVM_DEFINE_OBJECT_REF_METHODS(If, RelayExpr, IfNode)
A binding of a sub-network.
Definition: expr.h:404
static constexpr const char * _type_key
Definition: expr.h:440
Var var
The variable we bind to.
Definition: expr.h:412
TVM_DECLARE_FINAL_OBJECT_INFO(LetNode, ExprNode)
static void Deleter_(Object *ptr)
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:433
Expr body
The body of the let binding.
Definition: expr.h:416
Expr value
The value we bind var to.
Definition: expr.h:414
Object::FDeleter saved_deleter_
Definition: expr.h:407
bool SEqualReduce(const LetNode *other, SEqualReducer equal) const
Definition: expr.h:427
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:418
TVM_DEFINE_OBJECT_REF_COW_METHOD(LetNode)
Let(Var var, Expr value, Expr body, Span span=Span())
The constructor.
TVM_DEFINE_OBJECT_REF_METHODS(Let, RelayExpr, LetNode)
static constexpr const char * _type_key
Definition: expr.h:630
Expr value
The initial value of the Reference.
Definition: expr.h:611
TVM_DECLARE_FINAL_OBJECT_INFO(RefCreateNode, ExprNode)
bool SEqualReduce(const RefCreateNode *other, SEqualReducer equal) const
Definition: expr.h:620
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:625
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:613
TVM_DEFINE_OBJECT_REF_COW_METHOD(RefCreateNode)
TVM_DEFINE_OBJECT_REF_METHODS(RefCreate, RelayExpr, RefCreateNode)
RefCreate(Expr value, Span span=Span())
The constructor.
static constexpr const char * _type_key
Definition: expr.h:680
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:675
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:663
bool SEqualReduce(const RefReadNode *other, SEqualReducer equal) const
Definition: expr.h:670
Expr ref
The Reference Expression.
Definition: expr.h:661
TVM_DECLARE_FINAL_OBJECT_INFO(RefReadNode, ExprNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(RefReadNode)
TVM_DEFINE_OBJECT_REF_METHODS(RefRead, RelayExpr, RefReadNode)
RefRead(Expr ref, Span span=Span())
The constructor.
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:728
bool SEqualReduce(const RefWriteNode *other, SEqualReducer equal) const
Definition: expr.h:723
Expr value
The value to write into.
Definition: expr.h:713
Expr ref
The Reference Expression.
Definition: expr.h:711
TVM_DECLARE_FINAL_OBJECT_INFO(RefWriteNode, ExprNode)
static constexpr const char * _type_key
Definition: expr.h:734
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:715
TVM_DEFINE_OBJECT_REF_METHODS(RefWrite, RelayExpr, RefWriteNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(RefWriteNode)
RefWrite(Expr ref, Expr value, Span span=Span())
The constructor.
Base class of the temporary expression.
Definition: expr.h:774
virtual ~TempExprNode()
virtual destructor
Definition: expr.h:777
TVM_DECLARE_BASE_OBJECT_INFO(TempExprNode, ExprNode)
virtual Expr Realize() const =0
Convert the expression to a normal(non-temp) Expr.
static constexpr const uint32_t _type_child_slots
Definition: expr.h:787
static constexpr const char * _type_key
Definition: expr.h:784
static constexpr const bool _type_has_method_shash_reduce
Definition: expr.h:786
static constexpr const bool _type_has_method_sequal_reduce
Definition: expr.h:785
TVM_DEFINE_OBJECT_REF_METHODS(TempExpr, RelayExpr, TempExprNode)
bool SEqualReduce(const TupleGetItemNode *other, SEqualReducer equal) const
Definition: expr.h:569
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:573
int index
which value to get
Definition: expr.h:559
Expr tuple
The tuple Expression.
Definition: expr.h:557
static constexpr const char * _type_key
Definition: expr.h:578
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:561
TVM_DECLARE_FINAL_OBJECT_INFO(TupleGetItemNode, ExprNode)
TVM_DEFINE_OBJECT_REF_COW_METHOD(TupleGetItemNode)
TupleGetItem(Expr tuple, int index, Span span=Span())
The constructor.
TVM_DEFINE_OBJECT_REF_METHODS(TupleGetItem, RelayExpr, TupleGetItemNode)
Tuple container.
Definition: expr.h:123
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:145
tvm::Array< relay::Expr > fields
the fields of the tuple
Definition: expr.h:126
static constexpr const char * _type_key
Definition: expr.h:152
TVM_DECLARE_FINAL_OBJECT_INFO(TupleNode, ExprNode)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:128
bool SEqualReduce(const TupleNode *other, SEqualReducer equal) const
Definition: expr.h:135
TVM_DEFINE_OBJECT_REF_COW_METHOD(TupleNode)
Tuple(tvm::Array< relay::Expr > fields, Span span=Span())
The constructor.
TVM_DEFINE_OBJECT_REF_METHODS(Tuple, RelayExpr, TupleNode)
Container for Var.
Definition: expr.h:188
bool SEqualReduce(const VarNode *other, SEqualReducer equal) const
Definition: expr.h:218
Type type_annotation
type annotaion of the variable. This field records user provided type annotation of the Var....
Definition: expr.h:205
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:224
const String & name_hint() const
Definition: expr.h:208
static constexpr const char * _type_key
Definition: expr.h:230
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:210
TVM_DECLARE_FINAL_OBJECT_INFO(VarNode, ExprNode)
Id vid
The unique identifier of the Var.
Definition: expr.h:199
Var(String name_hint, Type type_annotation, Span span=Span())
The constructor.
Definition: expr.h:242
static Var GenSym(Type type_annotation={}, Span span={})
Return a globally fresh name. Helps with debugging to follow the same variable between passes and sub...
TVM_DEFINE_OBJECT_REF_COW_METHOD(VarNode)
Var(Id vid, Type type_annotation, Span span=Span())
The constructor.
TVM_DEFINE_OBJECT_REF_METHODS(Var, RelayExpr, VarNode)
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Managed NDArray. The array is backed by reference counted blocks.
Definition: ndarray.h:51
Base class of object allocators that implements make. Use curiously recurring template pattern.
Definition: memory.h:60
A custom smart pointer for Object.
Definition: object.h:362
base class of all object containers.
Definition: object.h:171
void(* FDeleter)(Object *self)
Object deleter.
Definition: object.h:177
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Reference to string objects.
Definition: string.h:98
Helpers for attribute objects.
IRModule that holds the functions and type definitions.
Primitive operators(builtin intrinsics) and registry for them.
tvm::BaseFuncNode BaseFuncNode
Definition: expr.h:57
tvm::GlobalVar GlobalVar
Definition: expr.h:58
tvm::BaseFunc BaseFunc
Definition: expr.h:56
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 ...
tvm::Span Span
Definition: base.h:65
tvm::GlobalVarNode GlobalVarNode
Definition: expr.h:59
Var var(std::string name_hint, DataType t=DataType::Int(32))
Construct a new Var expression.
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
PrimExpr equal(PrimExpr a, PrimExpr b, Span span=Span())
equal
bool IsPrimitiveOp(const RelayExpr &expr)
Check that an expression is a "primitive operator".
Definition: op.h:498
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'....
A compile time representation for where data is to be stored at runtime, and how to compile code to c...