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 = {});
84 v->Visit(
"data", &data);
86 v->Visit(
"span", &
span);
96 static constexpr
const char*
_type_key =
"relay.Constant";
130 v->Visit(
"fields", &fields);
132 v->Visit(
"span", &
span);
138 if (fields.
size() == other->
fields.size() && fields.
size() == 0) {
147 if (fields.
size() != 0) {
212 v->Visit(
"vid", &vid);
213 v->Visit(
"type_annotation", &type_annotation);
215 v->Visit(
"span", &
span);
227 hash_reduce(type_annotation);
244 : Var(
Id(name_hint), type_annotation,
span) {}
261 static Var GenSym(
Type type_annotation = {},
Span span = {});
287 static void Deleter_(
Object* ptr);
326 v->Visit(
"args", &args);
327 v->Visit(
"attrs", &attrs);
328 v->Visit(
"type_args", &type_args);
330 v->Visit(
"span", &
span);
347 hash_reduce(type_args);
409 static void Deleter_(
Object* ptr);
420 v->Visit(
"var", &var);
421 v->Visit(
"value", &value);
422 v->Visit(
"body", &body);
424 v->Visit(
"span", &
span);
502 v->Visit(
"cond", &cond);
503 v->Visit(
"true_branch", &true_branch);
504 v->Visit(
"false_branch", &false_branch);
506 v->Visit(
"span", &
span);
519 hash_reduce(true_branch);
520 hash_reduce(false_branch);
563 v->Visit(
"tuple_value", &tuple);
564 v->Visit(
"index", &index);
566 v->Visit(
"span", &
span);
579 static constexpr
const char*
_type_key =
"relay.TupleGetItem";
615 v->Visit(
"value", &value);
617 v->Visit(
"span", &
span);
631 static constexpr
const char*
_type_key =
"relay.RefCreate";
665 v->Visit(
"ref", &ref);
667 v->Visit(
"span", &
span);
681 static constexpr
const char*
_type_key =
"relay.RefRead";
717 v->Visit(
"ref", &ref);
718 v->Visit(
"value", &value);
720 v->Visit(
"span", &
span);
735 static constexpr
const char*
_type_key =
"relay.RefWrite";
785 static constexpr
const char*
_type_key =
"relay.TempExpr";
807 using Handler =
typename Derived::template Handler<T>;
808 static_assert(std::is_base_of<Object, T>::value,
"make can only be used to create Object");
809 T* ptr = Handler::New(static_cast<Derived*>(
this));
810 ptr->type_index_ = T::RuntimeTypeIndex();
811 ptr->saved_deleter_ = Handler::Deleter();
822 using Handler =
typename Derived::template Handler<T>;
823 static_assert(std::is_base_of<Object, T>::value,
"make can only be used to create Object");
824 T* ptr = Handler::New(static_cast<Derived*>(
this));
825 ptr->type_index_ = T::RuntimeTypeIndex();
826 ptr->saved_deleter_ = Handler::Deleter();
834 #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:497
bool SEqualReduce(const LetNode *other, SEqualReducer equal) const
Definition: expr.h:428
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:626
tvm::Array< relay::Expr > args
The arguments(inputs) of the call.
Definition: expr.h:299
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:302
RealizeFrame Realize(tvm::tir::BufferRegion buffer_slice, String storage_scope, PrimExpr condition)
The realization.
Base class of the temporary expression.
Definition: expr.h:775
bool SEqualReduce(const VarNode *other, SEqualReducer equal) const
Definition: expr.h:219
bool SEqualReduce(const TupleNode *other, SEqualReducer equal) const
Definition: expr.h:136
Managed reference to TensorTypeNode.
Definition: tensor_type.h:99
Call container.
Definition: expr.h:283
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:243
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
A Reducer class to reduce the structural hash value.
Definition: structural_hash.h:102
Object::FDeleter saved_deleter_
Definition: expr.h:408
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:94
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:211
tvm::Array< relay::Expr > fields
the fields of the tuple
Definition: expr.h:127
static void Deleter_(Object *ptr)
PrimExpr equal(PrimExpr a, PrimExpr b, Span span=Span())
equal
Constant tensor type.
Definition: expr.h:72
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:516
bool is_scalar() const
Definition: expr.h:81
Expr cond
The condition.
Definition: expr.h:495
bool SEqualReduce(const RefWriteNode *other, SEqualReducer equal) const
Definition: expr.h:724
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:716
Type type_annotation
type annotaion of the variable. This field records user provided type annotation of the Var...
Definition: expr.h:206
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:562
static constexpr const char * _type_key
Definition: expr.h:96
tvm::BaseFunc BaseFunc
Definition: expr.h:56
Expr body
The body of the let binding.
Definition: expr.h:417
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:614
Managed NDArray. The array is backed by reference counted blocks.
Definition: ndarray.h:59
Container for Var.
Definition: expr.h:189
tvm::Array< Type > type_args
The type arguments passed to polymorphic(template) function.
Definition: expr.h:322
Expr ref
The Reference Expression.
Definition: expr.h:662
Helpers for attribute objects.
virtual void MarkGraphNode()=0
Mark current comparison as graph node equal comparison.
Expr tuple
The tuple Expression.
Definition: expr.h:558
Primitive operators(builtin intrinsics) and registry for them.
Expr op
The operator(function) being invoked.
Definition: expr.h:296
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:341
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:510
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:225
tvm::GlobalVarNode GlobalVarNode
Definition: expr.h:59
A binding of a sub-network.
Definition: expr.h:405
size_t size() const
Definition: array.h:418
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:413
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:367
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:729
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:509
void(* FDeleter)(Object *self)
Object deleter.
Definition: object.h:173
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:324
Managed reference to GlobalVarNode.
Definition: expr.h:475
Expr false_branch
The expression evaluated when condition is false.
Definition: expr.h:499
Tuple container.
Definition: expr.h:124
bool SEqualReduce(const ConstantNode *other, SEqualReducer equal) const
Definition: expr.h:90
ObjectRef virtual_device_
The virtual device (VirtualDevice) for this node (the result of device planning). For first-order exp...
Definition: expr.h:407
TVM_DECLARE_FINAL_OBJECT_INFO(ConstantNode, ExprNode)
Reference to string objects.
Definition: string.h:97
LetFrame Let(Var var, PrimExpr value)
The let binding.
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:676
Managed reference to RelayExprNode.
Definition: expr.h:431
#define TVM_DEFINE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:713
Object::FDeleter saved_deleter_
Definition: expr.h:286
bool SEqualReduce(const CallNode *other, SEqualReducer equal) const
Definition: expr.h:334
TVM_DECLARE_BASE_OBJECT_INFO(RelayExprNode, BaseExprNode)
String PrettyPrint(const ObjectRef &node)
Pretty print a node for debug purposes.
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:574
const String & name_hint() const
Definition: expr.h:209
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:621
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:146
Expr value
The initial value of the Reference.
Definition: expr.h:612
virtual ~TempExprNode()
virtual destructor
Definition: expr.h:778
Base node of all functions.
Definition: function.h:77
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:419
Expr ref
The Reference Expression.
Definition: expr.h:712
Expr value
The value we bind var to.
Definition: expr.h:415
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:501
Managed reference to TypeNode.
Definition: type.h:93
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:83
Expr value
The value to write into.
Definition: expr.h:714
bool SEqualReduce(const TupleGetItemNode *other, SEqualReducer equal) const
Definition: expr.h:570
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:129
Global variable that lives in the top-level module.
Definition: expr.h:445
void SHashReduce(SHashReducer hash_reduce) const
Definition: expr.h:434
Base node of all non-primitive expressions.
Definition: expr.h:359
int index
which value to get
Definition: expr.h:560
runtime::NDArray data
The data of the tensor.
Definition: expr.h:75
static constexpr const uint32_t _type_child_slots
Definition: expr.h:423
container of If
Definition: expr.h:492
void VisitAttrs(tvm::AttrVisitor *v)
Definition: expr.h:664
void DefHash(const ObjectRef &key) const
Push hash of key to the current sequence of hash values.
Definition: structural_hash.h:179
bool SEqualReduce(const RefReadNode *other, SEqualReducer equal) const
Definition: expr.h:671
Id vid
The unique identifier of the Var.
Definition: expr.h:200