tvm
expr.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 
24 #ifndef TVM_RELAY_EXPR_H_
25 #define TVM_RELAY_EXPR_H_
26 
27 #include <tvm/ir/attrs.h>
28 #include <tvm/ir/expr.h>
29 #include <tvm/ir/module.h>
30 #include <tvm/ir/op.h>
32 
33 #include <functional>
34 #include <stack>
35 #include <string>
36 #include <utility>
37 
38 #include "./base.h"
39 #include "./type.h"
40 
41 namespace tvm {
42 
48 GlobalVar WithFields(GlobalVar global_var, Optional<String> opt_name_hint = {},
49  Optional<Type> opt_type = {}, Optional<VirtualDevice> opt_virtual_device = {},
50  Optional<Span> opt_span = {});
51 
52 namespace relay {
53 
60 
67 class Constant;
71 class ConstantNode : public ExprNode {
72  public:
75 
78 
80  bool is_scalar() const { return data->ndim == 0; }
81 
83  v->Visit("data", &data);
84  v->Visit("virtual_device_", &virtual_device_);
85  v->Visit("span", &span);
86  v->Visit("_checked_type_", &checked_type_);
87  }
88 
89  bool SEqualReduce(const ConstantNode* other, SEqualReducer equal) const {
90  return equal(data, other->data);
91  }
92 
93  void SHashReduce(SHashReducer hash_reduce) const { hash_reduce(data); }
94 
95  static constexpr const char* _type_key = "relay.Constant";
97 };
98 
99 class Constant : public Expr {
100  public:
106  TVM_DLL explicit Constant(runtime::NDArray data, Span span = Span());
107 
110 };
111 
118  Optional<VirtualDevice> opt_virtual_device = {}, Optional<Span> opt_span = {});
119 
121 class Tuple;
123 class TupleNode : public ExprNode {
124  public:
127 
129  v->Visit("fields", &fields);
130  v->Visit("virtual_device_", &virtual_device_);
131  v->Visit("span", &span);
132  v->Visit("_checked_type_", &checked_type_);
133  }
134 
135  bool SEqualReduce(const TupleNode* other, SEqualReducer equal) const {
136  // specially handle empty tuple as a constant is not a graph node.
137  if (fields.size() == other->fields.size() && fields.size() == 0) {
138  return true;
139  } else {
140  equal->MarkGraphNode();
141  return equal(fields, other->fields);
142  }
143  }
144 
145  void SHashReduce(SHashReducer hash_reduce) const {
146  if (fields.size() != 0) {
147  hash_reduce->MarkGraphNode();
148  hash_reduce(fields);
149  }
150  }
151 
152  static constexpr const char* _type_key = "relay.Tuple";
154 };
155 
156 class Tuple : public Expr {
157  public:
163  TVM_DLL explicit Tuple(tvm::Array<relay::Expr> fields, Span span = Span());
164 
167 };
168 
175  Optional<VirtualDevice> opt_virtual_device = Optional<VirtualDevice>(),
176  Optional<Span> opt_span = Optional<Span>());
177 
186 class Var;
188 class VarNode : public ExprNode {
189  public:
206 
208  const String& name_hint() const { return vid->name_hint; }
209 
211  v->Visit("vid", &vid);
212  v->Visit("type_annotation", &type_annotation);
213  v->Visit("virtual_device_", &virtual_device_);
214  v->Visit("span", &span);
215  v->Visit("_checked_type_", &checked_type_);
216  }
217 
218  bool SEqualReduce(const VarNode* other, SEqualReducer equal) const {
219  equal->MarkGraphNode();
220  return equal(type_annotation, other->type_annotation) && equal(vid, other->vid) &&
222  }
223 
224  void SHashReduce(SHashReducer hash_reduce) const {
225  hash_reduce->MarkGraphNode();
226  hash_reduce(type_annotation);
227  hash_reduce(vid);
228  }
229 
230  static constexpr const char* _type_key = "relay.Var";
232 };
233 
234 class Var : public Expr {
235  public:
242  TVM_DLL Var(String name_hint, Type type_annotation, Span span = Span())
243  : Var(Id(name_hint), type_annotation, span) {}
244 
251  TVM_DLL Var(Id vid, Type type_annotation, Span span = Span());
252 
260  static Var GenSym(Type type_annotation = {}, Span span = {});
261 
264 };
265 
272  Optional<Type> opt_type_annotation = Optional<Type>(),
273  Optional<VirtualDevice> opt_virtual_device = Optional<VirtualDevice>(),
274  Optional<Span> opt_span = Optional<Span>());
275 
280 class Call;
282 class CallNode : public ExprNode {
283  protected:
284  // CallNode uses own deleter to indirectly call non-recursive destructor
286  static void Deleter_(Object* ptr);
287 
288  public:
296 
299 
302 
322 
324  v->Visit("op", &op);
325  v->Visit("args", &args);
326  v->Visit("attrs", &attrs);
327  v->Visit("type_args", &type_args);
328  v->Visit("virtual_device_", &virtual_device_);
329  v->Visit("span", &span);
330  v->Visit("_checked_type_", &checked_type_);
331  }
332 
333  bool SEqualReduce(const CallNode* other, SEqualReducer equal) const {
334  // skip type_args check for primitive ops.
335  equal->MarkGraphNode();
336  return equal(op, other->op) && equal(args, other->args) && equal(attrs, other->attrs) &&
337  (IsPrimitiveOp(op) || equal(type_args, other->type_args));
338  }
339 
340  void SHashReduce(SHashReducer hash_reduce) const {
341  hash_reduce->MarkGraphNode();
342  hash_reduce(op);
343  hash_reduce(args);
344  hash_reduce(attrs);
345  if (!IsPrimitiveOp(op)) {
346  hash_reduce(type_args);
347  }
348  }
349 
350  static constexpr const char* _type_key = "relay.Call";
352  template <typename>
354  friend class Call;
355 };
356 
357 class Call : public Expr {
358  public:
362  ~Call();
363 
372  TVM_DLL Call(Expr op, Array<Expr> args, Attrs attrs = Attrs(),
373  Array<Type> type_args = Array<Type>(), Span span = Span());
374 
377 };
378 
385  Optional<Array<Expr>> opt_args = Optional<Array<Expr>>(),
386  Optional<Attrs> opt_attrs = Optional<Attrs>(),
387  Optional<Array<Type>> opt_type_args = Optional<Array<Type>>(),
388  Optional<VirtualDevice> opt_virtual_device = Optional<VirtualDevice>(),
389  Optional<Span> opt_span = Optional<Span>());
390 
402 class Let;
404 class LetNode : public ExprNode {
405  protected:
406  // LetNode uses own deleter to indirectly call non-recursive destructor
408  static void Deleter_(Object* ptr);
409 
410  public:
417 
419  v->Visit("var", &var);
420  v->Visit("value", &value);
421  v->Visit("body", &body);
422  v->Visit("virtual_device_", &virtual_device_);
423  v->Visit("span", &span);
424  v->Visit("_checked_type_", &checked_type_);
425  }
426 
427  bool SEqualReduce(const LetNode* other, SEqualReducer equal) const {
428  equal->MarkGraphNode();
429  return equal.DefEqual(var, other->var) && equal(value, other->value) &&
430  equal(body, other->body);
431  }
432 
433  void SHashReduce(SHashReducer hash_reduce) const {
434  hash_reduce->MarkGraphNode();
435  hash_reduce.DefHash(var);
436  hash_reduce(value);
437  hash_reduce(body);
438  }
439 
440  static constexpr const char* _type_key = "relay.Let";
442  template <typename>
444  friend class Let;
445 };
446 
447 class Let : public Expr {
448  public:
452  ~Let();
453 
461  TVM_DLL Let(Var var, Expr value, Expr body, Span span = Span());
462 
465 };
466 
473  Optional<Expr> opt_value = Optional<Expr>(),
474  Optional<Expr> opt_body = Optional<Expr>(),
475  Optional<VirtualDevice> opt_virtual_device = Optional<VirtualDevice>(),
476  Optional<Span> opt_span = Optional<Span>());
477 
489 class If;
491 class IfNode : public ExprNode {
492  public:
499 
501  v->Visit("cond", &cond);
502  v->Visit("true_branch", &true_branch);
503  v->Visit("false_branch", &false_branch);
504  v->Visit("virtual_device_", &virtual_device_);
505  v->Visit("span", &span);
506  v->Visit("_checked_type_", &checked_type_);
507  }
508 
509  bool SEqualReduce(const IfNode* other, SEqualReducer equal) const {
510  equal->MarkGraphNode();
511  return equal(cond, other->cond) && equal(true_branch, other->true_branch) &&
513  }
514 
515  void SHashReduce(SHashReducer hash_reduce) const {
516  hash_reduce->MarkGraphNode();
517  hash_reduce(cond);
518  hash_reduce(true_branch);
519  hash_reduce(false_branch);
520  }
521 
522  static constexpr const char* _type_key = "relay.If";
524 };
525 
526 class If : public Expr {
527  public:
535  TVM_DLL If(Expr cond, Expr true_branch, Expr false_branch, Span span = Span());
536 
539 };
540 
547  Optional<Expr> opt_true_branch = Optional<Expr>(),
548  Optional<Expr> opt_false_branch = Optional<Expr>(),
549  Optional<VirtualDevice> opt_virtual_device = Optional<VirtualDevice>(),
550  Optional<Span> opt_span = Optional<Span>());
551 
553 class TupleGetItem;
554 class TupleGetItemNode : public ExprNode {
555  public:
559  int index;
560 
562  v->Visit("tuple_value", &tuple);
563  v->Visit("index", &index);
564  v->Visit("virtual_device_", &virtual_device_);
565  v->Visit("span", &span);
566  v->Visit("_checked_type_", &checked_type_);
567  }
568 
569  bool SEqualReduce(const TupleGetItemNode* other, SEqualReducer equal) const {
570  return equal(tuple, other->tuple) && equal(index, other->index);
571  }
572 
573  void SHashReduce(SHashReducer hash_reduce) const {
574  hash_reduce(tuple);
575  hash_reduce(index);
576  }
577 
578  static constexpr const char* _type_key = "relay.TupleGetItem";
580 };
581 
582 class TupleGetItem : public Expr {
583  public:
590  TVM_DLL TupleGetItem(Expr tuple, int index, Span span = Span());
591 
594 };
595 
602  Optional<Integer> opt_index = Optional<Integer>(),
603  Optional<VirtualDevice> opt_virtual_device = Optional<VirtualDevice>(),
604  Optional<Span> opt_span = Optional<Span>());
605 
607 class RefCreate;
608 class RefCreateNode : public ExprNode {
609  public:
612 
614  v->Visit("value", &value);
615  v->Visit("virtual_device_", &virtual_device_);
616  v->Visit("span", &span);
617  v->Visit("_checked_type_", &checked_type_);
618  }
619 
620  bool SEqualReduce(const RefCreateNode* other, SEqualReducer equal) const {
621  equal->MarkGraphNode();
622  return equal(value, other->value);
623  }
624 
625  void SHashReduce(SHashReducer hash_reduce) const {
626  hash_reduce->MarkGraphNode();
627  hash_reduce(value);
628  }
629 
630  static constexpr const char* _type_key = "relay.RefCreate";
632 };
633 
634 class RefCreate : public Expr {
635  public:
641  TVM_DLL explicit RefCreate(Expr value, Span span = Span());
642 
645 };
646 
653  Optional<VirtualDevice> opt_virtual_device = Optional<VirtualDevice>(),
654  Optional<Span> opt_span = Optional<Span>());
655 
657 class RefRead;
658 class RefReadNode : public ExprNode {
659  public:
662 
664  v->Visit("ref", &ref);
665  v->Visit("virtual_device_", &virtual_device_);
666  v->Visit("span", &span);
667  v->Visit("_checked_type_", &checked_type_);
668  }
669 
670  bool SEqualReduce(const RefReadNode* other, SEqualReducer equal) const {
671  equal->MarkGraphNode();
672  return equal(ref, other->ref);
673  }
674 
675  void SHashReduce(SHashReducer hash_reduce) const {
676  hash_reduce->MarkGraphNode();
677  hash_reduce(ref);
678  }
679 
680  static constexpr const char* _type_key = "relay.RefRead";
682 };
683 
684 class RefRead : public Expr {
685  public:
691  TVM_DLL explicit RefRead(Expr ref, Span span = Span());
692 
695 };
696 
703  Optional<VirtualDevice> opt_virtual_device = Optional<VirtualDevice>(),
704  Optional<Span> opt_span = Optional<Span>());
705 
707 class RefWrite;
708 class RefWriteNode : public ExprNode {
709  public:
714 
716  v->Visit("ref", &ref);
717  v->Visit("value", &value);
718  v->Visit("virtual_device_", &virtual_device_);
719  v->Visit("span", &span);
720  v->Visit("_checked_type_", &checked_type_);
721  }
722 
723  bool SEqualReduce(const RefWriteNode* other, SEqualReducer equal) const {
724  equal->MarkGraphNode();
725  return equal(ref, other->ref) && equal(value, other->value);
726  }
727 
728  void SHashReduce(SHashReducer hash_reduce) const {
729  hash_reduce->MarkGraphNode();
730  hash_reduce(ref);
731  hash_reduce(value);
732  }
733 
734  static constexpr const char* _type_key = "relay.RefWrite";
736 };
737 
738 class RefWrite : public Expr {
739  public:
746  TVM_DLL RefWrite(Expr ref, Expr value, Span span = Span());
747 
750 };
751 
758  Optional<Expr> opt_value = Optional<Expr>(),
759  Optional<VirtualDevice> opt_virtual_device = Optional<VirtualDevice>(),
760  Optional<Span> opt_span = Optional<Span>());
761 
774 class TempExprNode : public ExprNode {
775  public:
777  virtual ~TempExprNode() {}
782  virtual Expr Realize() const = 0;
783 
784  static constexpr const char* _type_key = "relay.TempExpr";
785  static constexpr const bool _type_has_method_sequal_reduce = false;
786  static constexpr const bool _type_has_method_shash_reduce = false;
787  static constexpr const uint32_t _type_child_slots = 0;
789 };
790 
791 class TempExpr : public Expr {
792  public:
793  TVM_DEFINE_OBJECT_REF_METHODS(TempExpr, RelayExpr, TempExprNode);
794 };
795 
796 } // namespace relay
797 
798 namespace runtime {
799 
800 template <>
801 template <>
803 ObjAllocatorBase<SimpleObjAllocator>::make_object<relay::LetNode>() {
804  using Derived = SimpleObjAllocator;
805  using T = relay::LetNode;
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();
811  ptr->deleter_ = relay::LetNode::Deleter_;
812  return ObjectPtr<T>(ptr);
813 }
814 
815 template <>
816 template <>
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();
826  ptr->deleter_ = relay::CallNode::Deleter_;
827  return ObjectPtr<T>(ptr);
828 }
829 
830 } // namespace runtime
831 
832 } // namespace tvm
833 #endif // TVM_RELAY_EXPR_H_
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)
Definition: expr.h:357
Call(Expr op, Array< Expr > args, Attrs attrs=Attrs(), Array< Type > type_args=Array< Type >(), Span span=Span())
The constructor.
~Call()
The destructor.
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
Definition: expr.h:99
TVM_DEFINE_OBJECT_REF_COW_METHOD(ConstantNode)
TVM_DEFINE_OBJECT_REF_METHODS(Constant, RelayExpr, ConstantNode)
Constant(runtime::NDArray data, Span span=Span())
The constructor.
Definition: base.h:112
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
Definition: expr.h:526
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
Definition: expr.h:447
~Let()
The destructor.
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)
Definition: expr.h:608
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
Definition: expr.h:634
TVM_DEFINE_OBJECT_REF_COW_METHOD(RefCreateNode)
TVM_DEFINE_OBJECT_REF_METHODS(RefCreate, RelayExpr, RefCreateNode)
RefCreate(Expr value, Span span=Span())
The constructor.
Definition: expr.h:658
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)
Definition: expr.h:684
TVM_DEFINE_OBJECT_REF_COW_METHOD(RefReadNode)
TVM_DEFINE_OBJECT_REF_METHODS(RefRead, RelayExpr, RefReadNode)
RefRead(Expr ref, Span span=Span())
The constructor.
Definition: expr.h:708
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
Definition: expr.h:738
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
Definition: expr.h:791
TVM_DEFINE_OBJECT_REF_METHODS(TempExpr, RelayExpr, TempExprNode)
Definition: expr.h:554
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)
Definition: expr.h:582
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
Definition: expr.h:156
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
Definition: expr.h:234
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.
Base expr nodes in TVM.
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'....
Relay typed AST nodes.
A compile time representation for where data is to be stored at runtime, and how to compile code to c...