tvm
dataflow_pattern.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_DATAFLOW_PATTERN_H_
25 #define TVM_RELAY_DATAFLOW_PATTERN_H_
26 
27 #include <tvm/relay/expr.h>
28 #include <tvm/relay/type.h>
29 
30 #include <string>
31 #include <unordered_map>
32 #include <utility>
33 #include <vector>
34 
35 namespace tvm {
36 namespace relay {
37 
42 class DFPatternNode : public Object {
43  public:
44  static constexpr const char* _type_key = "DFPatternNode";
46 };
47 
52 class DFPattern : public ObjectRef {
53  public:
55  DFPattern operator()(const std::vector<DFPattern>& args) const;
57  DFPattern operator+(const DFPattern& other) const;
59  DFPattern operator-(const DFPattern& other) const;
61  DFPattern operator*(const DFPattern& other) const;
63  DFPattern operator/(const DFPattern& other) const;
65  DFPattern operator||(const DFPattern& other) const;
67  DFPattern Optional(const std::function<DFPattern(const DFPattern&)>& func) const;
71  DFPattern HasType(const Type& type) const;
73  DFPattern HasDtype(const DataType& dtype) const;
75  DFPattern HasDtype(const std::string& dtype) const;
78 
80 };
81 
86  public:
89 
90  void VisitAttrs(tvm::AttrVisitor* v) { v->Visit("expr", &expr); }
91 
92  static constexpr const char* _type_key = "relay.dataflow_pattern.ExprPattern";
94 };
95 
102 class ExprPattern : public DFPattern {
103  public:
104  TVM_DLL explicit ExprPattern(Expr expr);
106 };
107 
111 class VarPattern;
114  public:
119 
121  const String& name_hint() const { return name; }
122 
123  void VisitAttrs(tvm::AttrVisitor* v) { v->Visit("name", &name); }
124 
125  static constexpr const char* _type_key = "relay.dataflow_pattern.VarPattern";
127 };
128 
129 class VarPattern : public DFPattern {
130  public:
131  TVM_DLL VarPattern(String name_hint);
133 };
134 
138 class ConstantPattern;
141  public:
143 
144  static constexpr const char* _type_key = "relay.dataflow_pattern.ConstantPattern";
146 };
147 
148 class ConstantPattern : public DFPattern {
149  public:
151 };
152 
157 class CallPattern;
160  public:
168 
171 
173  v->Visit("op", &op);
174  v->Visit("args", &args);
175  }
176 
177  static constexpr const char* _type_key = "relay.dataflow_pattern.CallPattern";
179 };
180 
181 class CallPattern : public DFPattern {
182  public:
185 };
186 
192  public:
202 
204  v->Visit("params", &params);
205  v->Visit("body", &body);
206  }
207 
208  static constexpr const char* _type_key = "relay.dataflow_pattern.FunctionPattern";
210 };
211 
216 class FunctionPattern : public DFPattern {
217  public:
224 
227 };
228 
231  public:
238 
240  v->Visit("var", &var);
241  v->Visit("value", &value);
242  v->Visit("body", &body);
243  }
244 
245  static constexpr const char* _type_key = "relay.dataflow_pattern.LetPattern";
247 };
248 
252 class LetPattern : public DFPattern {
253  public:
260  TVM_DLL LetPattern(DFPattern var, DFPattern value, DFPattern body);
261 
263 };
264 
266 class TuplePattern;
269  public:
272 
273  void VisitAttrs(tvm::AttrVisitor* v) { v->Visit("fields", &fields); }
274 
275  static constexpr const char* _type_key = "relay.dataflow_pattern.TuplePattern";
277 };
278 
279 class TuplePattern : public DFPattern {
280  public:
281  TVM_DLL explicit TuplePattern(tvm::Array<DFPattern> fields);
283 };
284 
286 class TupleGetItemPattern;
288  public:
292  int index;
293 
295  v->Visit("tuple", &tuple);
296  v->Visit("index", &index);
297  }
298 
299  static constexpr const char* _type_key = "relay.dataflow_pattern.TupleGetItemPattern";
301 };
302 
303 class IfPatternNode : public DFPatternNode {
304  public:
306 
308  v->Visit("cond", &cond);
309  v->Visit("true_branch", &true_branch);
310  v->Visit("false_branch", &false_branch);
311  }
312 
313  static constexpr const char* _type_key = "relay.dataflow_pattern.IfPattern";
315 };
316 
317 class IfPattern : public DFPattern {
318  public:
319  TVM_DLL IfPattern(DFPattern cond, DFPattern then_clause, DFPattern else_clause);
321 };
322 
324  public:
325  TVM_DLL TupleGetItemPattern(DFPattern tuple, int index);
327 };
328 
329 class AltPattern;
334  public:
339 
341  v->Visit("left", &left);
342  v->Visit("right", &right);
343  }
344 
345  static constexpr const char* _type_key = "relay.dataflow_pattern.AltPattern";
347 };
348 
352 class AltPattern : public DFPattern {
353  public:
354  TVM_DLL AltPattern(DFPattern left, DFPattern right);
356 };
357 
362  public:
364 
368 
369  static constexpr const char* _type_key = "relay.dataflow_pattern.WildcardPattern";
371 };
372 
376 class WildcardPattern : public DFPattern {
377  public:
379 
380  void redirect_to(DFPattern pat) const;
381 };
382 
383 class TypePattern;
388  public:
393 
395  v->Visit("pattern", &pattern);
396  v->Visit("type", &type);
397  }
398 
399  static constexpr const char* _type_key = "relay.dataflow_pattern.TypePattern";
401 };
402 
406 class TypePattern : public DFPattern {
407  public:
408  TVM_DLL TypePattern(DFPattern pattern, Type type);
410 };
411 
412 class ShapePattern;
417  public:
422 
424  v->Visit("pattern", &pattern);
425  v->Visit("shape", &shape);
426  }
427 
428  static constexpr const char* _type_key = "relay.dataflow_pattern.ShapePattern";
430 };
431 
435 class ShapePattern : public DFPattern {
436  public:
437  TVM_DLL ShapePattern(DFPattern pattern, Array<PrimExpr> type);
439 };
440 
441 class DataTypePattern;
446  public:
451 
453  v->Visit("pattern", &pattern);
454  v->Visit("dtype", &dtype);
455  }
456 
457  static constexpr const char* _type_key = "relay.dataflow_pattern.DataTypePattern";
459 };
460 
464 class DataTypePattern : public DFPattern {
465  public:
466  TVM_DLL DataTypePattern(DFPattern pattern, DataType dtype);
468 };
469 
470 class AttrPattern;
475  public:
480 
482  v->Visit("pattern", &pattern);
483  v->Visit("attrs", &attrs);
484  }
485 
486  static constexpr const char* _type_key = "relay.dataflow_pattern.AttrPattern";
488 };
489 
493 class AttrPattern : public DFPattern {
494  public:
495  TVM_DLL AttrPattern(DFPattern pattern, DictAttrs attrs);
497 };
498 
499 class DominatorPattern;
506  public:
513 
515  v->Visit("parent", &parent);
516  v->Visit("path", &path);
517  v->Visit("child", &child);
518  }
519 
520  static constexpr const char* _type_key = "relay.dataflow_pattern.DominatorPattern";
522 };
523 
527 class DominatorPattern : public DFPattern {
528  public:
529  TVM_DLL DominatorPattern(DFPattern parent, DFPattern path, DFPattern child);
531 };
532 
534 DFPattern IsVar(const String& name);
540 DFPattern IsExpr(const Expr& expr);
542 DFPattern IsOp(const String& op_name);
546 DFPattern IsTupleGetItem(const DFPattern tuple, int index = -1);
547 
550  public:
551  std::stringstream string_stream{};
552 
553  std::unordered_map<DFPattern, std::pair<size_t, std::string>, ObjectPtrHash, ObjectPtrEqual>
554  memo_{};
559  std::vector<DFPattern> auxiliary_patterns{};
560 
561  DFPatternPrinter(std::ostream& stream) // NOLINT(*)
562  : ReprPrinter(stream) {}
563  TVM_DLL void Print(const ObjectRef& node);
564  using FType = NodeFunctor<void(const ObjectRef&, DFPatternPrinter*)>;
565  TVM_DLL static FType& vtable();
566 };
567 
568 inline std::ostream& operator<<(std::ostream& os,
569  const DFPattern& n) { // NOLINT(*)
570  std::stringstream string_stream{}, tmp_stream{};
571  DFPatternPrinter printer{tmp_stream};
572  printer.Print(n);
573  string_stream << "Main pattern:" << std::endl;
574  string_stream << printer.string_stream.str();
575  string_stream << std::endl;
576  string_stream << "Auxiliary patterns:";
577  for (const DFPattern& pat : printer.auxiliary_patterns) {
578  string_stream << std::endl;
579  string_stream << printer.memo_[pat].second;
580  }
581  os << string_stream.str();
582  return os;
583 }
584 
585 String PrettyPrint(const DFPattern& pattern);
586 
587 } // namespace relay
588 } // namespace tvm
589 #endif // TVM_RELAY_DATAFLOW_PATTERN_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 DictAttrsNode.
Definition: attrs.h:227
A dynamically dispatched functor on the type of the first argument.
Definition: functor.h:64
Managed reference to RelayExprNode.
Definition: expr.h:442
A printer class to print the AST/IR nodes.
Definition: repr_printer.h:34
std::ostream & stream
The output stream.
Definition: repr_printer.h:37
Managed reference to TypeNode.
Definition: type.h:93
Pattern for Alternate Expressions.
Definition: dataflow_pattern.h:333
DFPattern right
The right optional pattern.
Definition: dataflow_pattern.h:338
DFPattern left
The left optional pattern.
Definition: dataflow_pattern.h:336
TVM_DECLARE_FINAL_OBJECT_INFO(AltPatternNode, DFPatternNode)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:340
static constexpr const char * _type_key
Definition: dataflow_pattern.h:345
A pattern which matches either of two patterns.
Definition: dataflow_pattern.h:352
TVM_DEFINE_OBJECT_REF_METHODS(AltPattern, DFPattern, AltPatternNode)
AltPattern(DFPattern left, DFPattern right)
Pattern for Attributes.
Definition: dataflow_pattern.h:474
DFPattern pattern
The pattern.
Definition: dataflow_pattern.h:477
DictAttrs attrs
The attribute to match.
Definition: dataflow_pattern.h:479
static constexpr const char * _type_key
Definition: dataflow_pattern.h:486
TVM_DECLARE_FINAL_OBJECT_INFO(AttrPatternNode, DFPatternNode)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:481
A pattern which matches attributes in another pattern.
Definition: dataflow_pattern.h:493
AttrPattern(DFPattern pattern, DictAttrs attrs)
TVM_DEFINE_OBJECT_REF_METHODS(AttrPattern, DFPattern, AttrPatternNode)
CallPattern container.
Definition: dataflow_pattern.h:159
TVM_DECLARE_FINAL_OBJECT_INFO(CallPatternNode, DFPatternNode)
static constexpr const char * _type_key
Definition: dataflow_pattern.h:177
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:172
tvm::Array< relay::DFPattern > args
The arguments(inputs) of the call.
Definition: dataflow_pattern.h:170
DFPattern op
The operator(function) being invoked.
Definition: dataflow_pattern.h:167
Definition: dataflow_pattern.h:181
CallPattern(DFPattern op, Array< DFPattern > args)
TVM_DEFINE_OBJECT_REF_METHODS(CallPattern, DFPattern, CallPatternNode)
Container for Constant.
Definition: dataflow_pattern.h:140
static constexpr const char * _type_key
Definition: dataflow_pattern.h:144
TVM_DECLARE_FINAL_OBJECT_INFO(ConstantPatternNode, DFPatternNode)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:142
Definition: dataflow_pattern.h:148
TVM_DEFINE_OBJECT_REF_METHODS(ConstantPattern, DFPattern, ConstantPatternNode)
Base type of all dataflow patterns.
Definition: dataflow_pattern.h:42
TVM_DECLARE_BASE_OBJECT_INFO(DFPatternNode, Object)
static constexpr const char * _type_key
Definition: dataflow_pattern.h:44
A printer class to print pattern.
Definition: dataflow_pattern.h:549
std::vector< DFPattern > auxiliary_patterns
Subpatterns that are encountered more than once during printing. If a subpattern has already printed,...
Definition: dataflow_pattern.h:559
std::stringstream string_stream
Definition: dataflow_pattern.h:551
DFPatternPrinter(std::ostream &stream)
Definition: dataflow_pattern.h:561
std::unordered_map< DFPattern, std::pair< size_t, std::string >, ObjectPtrHash, ObjectPtrEqual > memo_
Definition: dataflow_pattern.h:554
void Print(const ObjectRef &node)
Managed reference to dataflow patterns.
Definition: dataflow_pattern.h:52
DFPattern operator*(const DFPattern &other) const
Syntatic Sugar for creating a CallPattern with a "multiply" op.
DFPattern HasType(const Type &type) const
Syntatic Sugar for creating a TypePattern.
DFPattern HasDtype(const DataType &dtype) const
Syntatic Sugar for creating a DataTypePattern with a DataType.
TVM_DEFINE_OBJECT_REF_METHODS(DFPattern, ObjectRef, DFPatternNode)
DFPattern operator()(const std::vector< DFPattern > &args) const
Syntatic Sugar for creating a CallPattern.
DFPattern operator+(const DFPattern &other) const
Syntatic Sugar for creating a CallPattern with an "add" op.
DFPattern Optional(const std::function< DFPattern(const DFPattern &)> &func) const
Syntatic Sugar for creating an Optional Pattern.
DFPattern HasShape(const Array< PrimExpr > shape) const
Syntatic Sugar for creating a ShapePattern.
DFPattern operator||(const DFPattern &other) const
Syntatic Sugar for creating an AltPattern.
DFPattern operator/(const DFPattern &other) const
Syntatic Sugar for creating a CallPattern with a "divide" op.
DFPattern operator-(const DFPattern &other) const
Syntatic Sugar for creating a CallPattern with a "subtract" op.
DFPattern HasAttr(const Map< String, ObjectRef > &attrs) const
Syntatic Sugar for creating an AttrPattern.
DFPattern HasDtype(const std::string &dtype) const
Syntatic Sugar for creating a DataTypePattern with a data type's name.
Pattern for Types.
Definition: dataflow_pattern.h:445
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:452
DataType dtype
The type to match.
Definition: dataflow_pattern.h:450
TVM_DECLARE_FINAL_OBJECT_INFO(DataTypePatternNode, DFPatternNode)
static constexpr const char * _type_key
Definition: dataflow_pattern.h:457
DFPattern pattern
The pattern.
Definition: dataflow_pattern.h:448
A pattern which matches a type in another pattern.
Definition: dataflow_pattern.h:464
DataTypePattern(DFPattern pattern, DataType dtype)
TVM_DEFINE_OBJECT_REF_METHODS(DataTypePattern, DFPattern, DataTypePatternNode)
Dominated Graph Pattern Pattern for fuzzy subgraphs where all outputs of the parent are used finally ...
Definition: dataflow_pattern.h:505
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:514
static constexpr const char * _type_key
Definition: dataflow_pattern.h:520
DFPattern path
The path.
Definition: dataflow_pattern.h:510
TVM_DECLARE_FINAL_OBJECT_INFO(DominatorPatternNode, DFPatternNode)
DFPattern parent
The parent.
Definition: dataflow_pattern.h:508
DFPattern child
The child.
Definition: dataflow_pattern.h:512
A pattern which matches a variable length dominator path.
Definition: dataflow_pattern.h:527
TVM_DEFINE_OBJECT_REF_METHODS(DominatorPattern, DFPattern, DominatorPatternNode)
DominatorPattern(DFPattern parent, DFPattern path, DFPattern child)
Pattern for Relay Expression.
Definition: dataflow_pattern.h:85
Expr expr
The expression to match.
Definition: dataflow_pattern.h:88
TVM_DECLARE_FINAL_OBJECT_INFO(ExprPatternNode, DFPatternNode)
static constexpr const char * _type_key
Definition: dataflow_pattern.h:92
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:90
A pattern which matches a literal expression.
Definition: dataflow_pattern.h:102
TVM_DEFINE_OBJECT_REF_METHODS(ExprPattern, DFPattern, ExprPatternNode)
Relay Function container.
Definition: dataflow_pattern.h:191
static constexpr const char * _type_key
Definition: dataflow_pattern.h:208
tvm::Array< DFPattern > params
Function parameters.
Definition: dataflow_pattern.h:194
TVM_DECLARE_FINAL_OBJECT_INFO(FunctionPatternNode, DFPatternNode)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:203
DFPattern body
The expression which represents the computation of the function, the expression may reference the par...
Definition: dataflow_pattern.h:201
Managed reference to FunctionNode.
Definition: dataflow_pattern.h:216
FunctionPattern(tvm::Array< DFPattern > params, DFPattern body)
Constructor.
TVM_DEFINE_OBJECT_REF_COW_METHOD(FunctionPatternNode)
TVM_DEFINE_OBJECT_REF_METHODS(FunctionPattern, DFPattern, FunctionPatternNode)
Definition: dataflow_pattern.h:303
TVM_DECLARE_FINAL_OBJECT_INFO(IfPatternNode, DFPatternNode)
DFPattern cond
Definition: dataflow_pattern.h:305
static constexpr const char * _type_key
Definition: dataflow_pattern.h:313
DFPattern true_branch
Definition: dataflow_pattern.h:305
DFPattern false_branch
Definition: dataflow_pattern.h:305
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:307
Definition: dataflow_pattern.h:317
IfPattern(DFPattern cond, DFPattern then_clause, DFPattern else_clause)
TVM_DEFINE_OBJECT_REF_METHODS(IfPattern, DFPattern, IfPatternNode)
A binding of a sub-network.
Definition: dataflow_pattern.h:230
DFPattern body
The body of the let binding.
Definition: dataflow_pattern.h:237
static constexpr const char * _type_key
Definition: dataflow_pattern.h:245
TVM_DECLARE_FINAL_OBJECT_INFO(LetPatternNode, DFPatternNode)
DFPattern value
The value we bind var to.
Definition: dataflow_pattern.h:235
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:239
DFPattern var
The variable we bind to.
Definition: dataflow_pattern.h:233
Let binding that binds a local var.
Definition: dataflow_pattern.h:252
TVM_DEFINE_OBJECT_REF_METHODS(LetPattern, DFPattern, LetPatternNode)
LetPattern(DFPattern var, DFPattern value, DFPattern body)
The constructor.
Pattern for Shapes.
Definition: dataflow_pattern.h:416
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:423
TVM_DECLARE_FINAL_OBJECT_INFO(ShapePatternNode, DFPatternNode)
Array< PrimExpr > shape
The type to match.
Definition: dataflow_pattern.h:421
DFPattern pattern
The pattern.
Definition: dataflow_pattern.h:419
static constexpr const char * _type_key
Definition: dataflow_pattern.h:428
A pattern which matches a type in another pattern.
Definition: dataflow_pattern.h:435
TVM_DEFINE_OBJECT_REF_METHODS(ShapePattern, DFPattern, ShapePatternNode)
ShapePattern(DFPattern pattern, Array< PrimExpr > type)
Definition: dataflow_pattern.h:287
static constexpr const char * _type_key
Definition: dataflow_pattern.h:299
DFPattern tuple
The tuple Expression.
Definition: dataflow_pattern.h:290
TVM_DECLARE_FINAL_OBJECT_INFO(TupleGetItemPatternNode, DFPatternNode)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:294
int index
which value to get
Definition: dataflow_pattern.h:292
Definition: dataflow_pattern.h:323
TVM_DEFINE_OBJECT_REF_METHODS(TupleGetItemPattern, DFPattern, TupleGetItemPatternNode)
TupleGetItemPattern(DFPattern tuple, int index)
Tuple container.
Definition: dataflow_pattern.h:268
static constexpr const char * _type_key
Definition: dataflow_pattern.h:275
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:273
TVM_DECLARE_FINAL_OBJECT_INFO(TuplePatternNode, DFPatternNode)
tvm::Array< DFPattern > fields
the fields of the tuple
Definition: dataflow_pattern.h:271
Definition: dataflow_pattern.h:279
TuplePattern(tvm::Array< DFPattern > fields)
TVM_DEFINE_OBJECT_REF_METHODS(TuplePattern, DFPattern, TuplePatternNode)
Pattern for Types.
Definition: dataflow_pattern.h:387
TVM_DECLARE_FINAL_OBJECT_INFO(TypePatternNode, DFPatternNode)
DFPattern pattern
The pattern.
Definition: dataflow_pattern.h:390
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:394
static constexpr const char * _type_key
Definition: dataflow_pattern.h:399
Type type
The type to match.
Definition: dataflow_pattern.h:392
A pattern which matches a type in another pattern.
Definition: dataflow_pattern.h:406
TypePattern(DFPattern pattern, Type type)
TVM_DEFINE_OBJECT_REF_METHODS(TypePattern, DFPattern, TypePatternNode)
Container for Var.
Definition: dataflow_pattern.h:113
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:123
String name
The name of the Var (optional).
Definition: dataflow_pattern.h:118
static constexpr const char * _type_key
Definition: dataflow_pattern.h:125
const String & name_hint() const
Definition: dataflow_pattern.h:121
TVM_DECLARE_FINAL_OBJECT_INFO(VarPatternNode, DFPatternNode)
Definition: dataflow_pattern.h:129
VarPattern(String name_hint)
TVM_DEFINE_OBJECT_REF_METHODS(VarPattern, DFPattern, VarPatternNode)
Wildcard Pattern.
Definition: dataflow_pattern.h:361
static constexpr const char * _type_key
Definition: dataflow_pattern.h:369
TVM_DECLARE_FINAL_OBJECT_INFO(WildcardPatternNode, DFPatternNode)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:363
Optional< DFPattern > pattern
If the wildcard is redirected, then pattern is not nullptr, and the wildcard redirects to the pattern...
Definition: dataflow_pattern.h:367
A pattern which matches anything.
Definition: dataflow_pattern.h:376
TVM_DEFINE_OBJECT_REF_METHODS(WildcardPattern, DFPattern, WildcardPatternNode)
void redirect_to(DFPattern pat) const
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Runtime primitive data type.
Definition: data_type.h:43
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics,...
Definition: map.h:1271
Base class of all object reference.
Definition: object.h:519
base class of all object containers.
Definition: object.h:171
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Reference to string objects.
Definition: string.h:98
DFPattern IsTuple(const Array< DFPattern > &fields)
Syntatic Sugar for creating a TuplePattern.
String PrettyPrint(const ObjectRef &node)
Pretty print a node for debug purposes.
DFPattern IsConstant()
Syntatic Sugar for creating a ConstantPattern.
DFPattern IsTupleGetItem(const DFPattern tuple, int index=-1)
Syntatic Sugar for creating a TupleGetItemPattern.
std::ostream & operator<<(std::ostream &os, const DFPattern &n)
Definition: dataflow_pattern.h:568
DFPattern IsWildcard()
Syntatic Sugar for creating a WildcardPattern.
DFPattern IsExpr(const Expr &expr)
Syntatic Sugar for creating a ExprPattern.
DFPattern IsOp(const String &op_name)
Syntatic Sugar for creating a ExprPattern base on an Op.
DFPattern IsVar(const String &name)
Syntatic Sugar for creating a VarPattern with a name.
Var var(std::string name_hint, DataType t=DataType::Int(32))
Construct a new Var expression.
Tensor shape(const Tensor &src, DataType dtype, const std::string name="T_shape", const std::string tag=kInjective)
Get the shape of input tensor.
Definition: transform.h:1913
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
Relay expression language.
Relay typed AST nodes.
ObjectRef equal functor.
Definition: object.h:665
ObjectRef hash functor.
Definition: object.h:655