24 #ifndef TVM_RELAX_DATAFLOW_PATTERN_H_
25 #define TVM_RELAX_DATAFLOW_PATTERN_H_
57 class StructInfoPattern;
59 class DataTypePattern;
61 class SameShapeConstraint;
93 static constexpr
const char*
_type_key =
"DFPatternNode";
104 template <
typename... Args>
201 static constexpr
const char*
_type_key =
"DFConstraintNode";
221 static constexpr
const char*
_type_key =
"relax.dpl.PatternSeq";
261 std::map<DFPattern, std::vector<std::pair<DFPattern, std::vector<PairCons>>>>
edge_constraints;
270 static constexpr
const char*
_type_key =
"relax.dpl.PatternContext";
284 ICHECK(
get() !=
nullptr);
289 ICHECK(
get() !=
nullptr);
301 auto& pairs = (*this)->edge_constraints[producer];
302 auto it = std::find_if(pairs.begin(), pairs.end(),
303 [consumer](
auto p) { return p.first == consumer; });
304 if (it == pairs.end()) {
305 pairs.emplace_back(consumer, std::vector{cons});
307 auto& vec = it->second;
308 ICHECK(std::find(vec.cbegin(), vec.cend(), cons) == vec.cend())
309 <<
"Constraint already exists";
313 auto& patterns = (*this)->src_ordered;
314 if (std::find(patterns.begin(), patterns.end(), producer) == patterns.end()) {
315 patterns.push_back(producer);
325 (*this)->validation_constraints.push_back(constraint);
350 static constexpr
const char*
_type_key =
"relax.dpl.ExprPattern";
375 static constexpr
const char*
_type_key =
"relax.dpl.VarPattern";
400 static constexpr
const char*
_type_key =
"relax.dpl.DataflowVarPattern";
421 static constexpr
const char*
_type_key =
"relax.dpl.GlobalVarPattern";
443 static constexpr
const char*
_type_key =
"relax.dpl.ConstantPattern";
481 v->Visit(
"args", &
args);
484 static constexpr
const char*
_type_key =
"relax.dpl.CallPattern";
503 static constexpr
const char*
_type_key =
"relax.dpl.PrimArrPattern";
534 v->Visit(
"params", &
params);
535 v->Visit(
"body", &
body);
538 static constexpr
const char*
_type_key =
"relax.dpl.FunctionPattern";
568 static constexpr
const char*
_type_key =
"relax.dpl.TuplePattern";
592 static constexpr
const char*
_type_key =
"relax.dpl.UnorderedTuplePattern";
617 v->Visit(
"tuple", &
tuple);
618 v->Visit(
"index", &
index);
621 static constexpr
const char*
_type_key =
"relax.dpl.TupleGetItemPattern";
645 v->Visit(
"left", &
left);
646 v->Visit(
"right", &
right);
649 static constexpr
const char*
_type_key =
"relax.dpl.AndPattern";
673 v->Visit(
"left", &
left);
674 v->Visit(
"right", &
right);
677 static constexpr
const char*
_type_key =
"relax.dpl.OrPattern";
701 static constexpr
const char*
_type_key =
"relax.dpl.NotPattern";
723 static constexpr
const char*
_type_key =
"relax.dpl.WildcardPattern";
754 v->Visit(
"type", &
type);
757 static constexpr
const char*
_type_key =
"relax.dpl.TypePattern";
785 static constexpr
const char*
_type_key =
"relax.dpl.StructInfoPattern";
806 v->Visit(
"shape", &
shape);
809 static constexpr
const char*
_type_key =
"relax.dpl.ShapePattern";
838 static constexpr
const char*
_type_key =
"relax.dpl.SameShapeConstraint";
863 v->Visit(
"dtype", &
dtype);
866 static constexpr
const char*
_type_key =
"relax.dpl.DataTypePattern";
891 v->Visit(
"attrs", &
attrs);
894 static constexpr
const char*
_type_key =
"relax.dpl.AttrPattern";
921 static constexpr
const char*
_type_key =
"relax.dpl.ExternFuncPattern";
960 template <
typename... Args>
Runtime Array container types.
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
Managed reference to RelayExprNode.
Definition: expr.h:442
Managed reference to TypeNode.
Definition: type.h:93
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition: with.h:58
Match a conjunction of other patterns.
Definition: dataflow_pattern.h:639
DFPattern left
Definition: dataflow_pattern.h:641
DFPattern right
Definition: dataflow_pattern.h:642
static constexpr const char * _type_key
Definition: dataflow_pattern.h:649
TVM_DECLARE_FINAL_OBJECT_INFO(AndPatternNode, DFPatternNode)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:644
Managed reference to AndPatternNode.
Definition: dataflow_pattern.h:657
AndPattern(DFPattern lhs, DFPattern rhs)
TVM_DEFINE_OBJECT_REF_METHODS(AndPattern, DFPattern, AndPatternNode)
A pattern that asserting a root pattern has certain attributes.
Definition: dataflow_pattern.h:884
DictAttrs attrs
Definition: dataflow_pattern.h:887
DFPattern pattern
Definition: dataflow_pattern.h:886
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:889
TVM_DECLARE_FINAL_OBJECT_INFO(AttrPatternNode, DFPatternNode)
static constexpr const char * _type_key
Definition: dataflow_pattern.h:894
Managed reference to AttrPatternNode.
Definition: dataflow_pattern.h:902
TVM_DEFINE_OBJECT_REF_METHODS(AttrPattern, DFPattern, AttrPatternNode)
AttrPattern(DFPattern pattern, DictAttrs attrs)
A pattern to match a callable node in Relax.
Definition: dataflow_pattern.h:460
TVM_DECLARE_FINAL_OBJECT_INFO(CallPatternNode, DFPatternNode)
bool varg_default_wildcard
Definition: dataflow_pattern.h:475
static constexpr const char * _type_key
Definition: dataflow_pattern.h:484
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:479
tvm::Array< DFPattern > args
Definition: dataflow_pattern.h:468
DFPattern op
Definition: dataflow_pattern.h:467
Definition: dataflow_pattern.h:488
CallPattern(DFPattern op, Array< DFPattern > args, bool varg_default_wildcard=false)
TVM_DEFINE_OBJECT_REF_METHODS(CallPattern, DFPattern, CallPatternNode)
A Pattern to Match a Relax Constant.
Definition: dataflow_pattern.h:439
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:441
TVM_DECLARE_FINAL_OBJECT_INFO(ConstantPatternNode, DFPatternNode)
static constexpr const char * _type_key
Definition: dataflow_pattern.h:443
Managed reference to a ConstantPattern.
Definition: dataflow_pattern.h:451
TVM_DEFINE_OBJECT_REF_METHODS(ConstantPattern, DFPattern, ConstantPatternNode)
Additional constraints on the graph.
Definition: dataflow_pattern.h:166
TVM_DECLARE_BASE_OBJECT_INFO(DFConstraintNode, Object)
virtual Array< DFPattern > GetDependentPatterns() const =0
Return the patterns on which the constraint depends.
static constexpr const uint32_t _type_child_slots
Definition: dataflow_pattern.h:202
virtual std::tuple< PrimExpr, bool > AsPrimExpr(std::function< Optional< Var >(const DFPatternNode *)> match_state) const =0
Convert the constraint to a PrimExpr.
static constexpr const char * _type_key
Definition: dataflow_pattern.h:201
Definition: dataflow_pattern.h:206
TVM_DEFINE_OBJECT_REF_METHODS(DFConstraint, ObjectRef, DFConstraintNode)
Base type of all dataflow patterns.
Definition: dataflow_pattern.h:91
TVM_DECLARE_BASE_OBJECT_INFO(DFPatternNode, Object)
static constexpr const char * _type_key
Definition: dataflow_pattern.h:93
Managed reference to dataflow patterns.
Definition: dataflow_pattern.h:101
CallPattern operator()(const std::vector< DFPattern > &args) const
Syntatic Sugar for creating a CallPattern.
ShapePattern HasShape(const Array< PrimExpr > &shape) const
Syntatic Sugar for creating a ShapePattern.
DataTypePattern HasDtype(const DataType &dtype) const
Syntatic Sugar for creating a DataTypePattern with a DataType.
SameShapeConstraint HasSameShapeAs(const DFPattern &other) const
Syntatic Sugar for creating a ShapePattern.
OrPattern operator|(const DFPattern &other) const
Syntatic Sugar for creating an OrPattern.
CallPattern operator()(Args &&... args) const
Syntatic Sugar for creating a CallPattern.
Definition: dataflow_pattern.h:961
TVM_DEFINE_OBJECT_REF_METHODS(DFPattern, ObjectRef, DFPatternNode)
TypePattern HasType(const Type &type) const
Syntatic Sugar for creating a TypePattern.
StructInfoPattern HasStructInfo(const StructInfo &struct_info) const
Syntatic Sugar for creating a StructInfoPattern.
AndPattern operator&(const DFPattern &other) const
Syntatic Sugar for creating an AndPattern.
DFPattern dup() const
Syntatic Sugar for duplicating the current pattern.
NotPattern operator~() const
Syntatic Sugar for creating a NotPattern.
AttrPattern HasAttr(const Map< String, ObjectRef > &attrs) const
Syntatic Sugar for creating an AttrPattern.
DataTypePattern HasDtype(const std::string &dtype) const
Syntatic Sugar for creating a DataTypePattern with a data type's name.
A pattern that asserting a root pattern has a certain data type.
Definition: dataflow_pattern.h:856
DFPattern pattern
Definition: dataflow_pattern.h:858
TVM_DECLARE_FINAL_OBJECT_INFO(DataTypePatternNode, DFPatternNode)
DataType dtype
Definition: dataflow_pattern.h:859
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:861
static constexpr const char * _type_key
Definition: dataflow_pattern.h:866
Managed reference to DataTypePatternNode.
Definition: dataflow_pattern.h:874
DataTypePattern(DFPattern pattern, DataType dtype)
TVM_DEFINE_OBJECT_REF_METHODS(DataTypePattern, DFPattern, DataTypePatternNode)
A Pattern to Match a Relax Dataflow Variable.
Definition: dataflow_pattern.h:398
TVM_DECLARE_FINAL_OBJECT_INFO(DataflowVarPatternNode, DFPatternNode)
static constexpr const char * _type_key
Definition: dataflow_pattern.h:400
Managed reference to a DataflowVarPattern.
Definition: dataflow_pattern.h:408
DataflowVarPattern(String name_hint)
TVM_DEFINE_OBJECT_REF_METHODS(DataflowVarPattern, DFPattern, DataflowVarPatternNode)
Pattern for Relax Expression.
Definition: dataflow_pattern.h:344
Expr expr
Definition: dataflow_pattern.h:346
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:348
TVM_DECLARE_FINAL_OBJECT_INFO(ExprPatternNode, DFPatternNode)
static constexpr const char * _type_key
Definition: dataflow_pattern.h:350
Managed reference to an ExprPattern.
Definition: dataflow_pattern.h:358
TVM_DEFINE_OBJECT_REF_METHODS(ExprPattern, DFPattern, ExprPatternNode)
A pattern of external function.
Definition: dataflow_pattern.h:913
const String & global_symbol() const
The external function name.
Definition: dataflow_pattern.h:918
String global_symbol_
Definition: dataflow_pattern.h:915
TVM_DECLARE_FINAL_OBJECT_INFO(ExternFuncPatternNode, DFPatternNode)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:919
static constexpr const char * _type_key
Definition: dataflow_pattern.h:921
Managed reference to ExternFuncPatternNode.
Definition: dataflow_pattern.h:929
ExternFuncPattern(String global_symbol)
TVM_DEFINE_OBJECT_REF_METHODS(ExternFuncPattern, DFPattern, ExternFuncPatternNode)
A pattern to match a Relax Function.
Definition: dataflow_pattern.h:522
DFPattern body
Definition: dataflow_pattern.h:531
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:533
static constexpr const char * _type_key
Definition: dataflow_pattern.h:538
TVM_DECLARE_FINAL_OBJECT_INFO(FunctionPatternNode, DFPatternNode)
tvm::Array< DFPattern > params
Definition: dataflow_pattern.h:524
Managed reference to FunctionPatternNode.
Definition: dataflow_pattern.h:546
FunctionPattern(tvm::Array< DFPattern > params, DFPattern body)
Constructor.
TVM_DEFINE_OBJECT_REF_METHODS(FunctionPattern, DFPattern, FunctionPatternNode)
A Pattern to Match a Relax Global Variable.
Definition: dataflow_pattern.h:419
TVM_DECLARE_FINAL_OBJECT_INFO(GlobalVarPatternNode, DFPatternNode)
static constexpr const char * _type_key
Definition: dataflow_pattern.h:421
Managed reference to a GlobalVarPattern.
Definition: dataflow_pattern.h:429
GlobalVarPattern(String name_hint)
TVM_DEFINE_OBJECT_REF_METHODS(GlobalVarPattern, DFPattern, GlobalVarPatternNode)
Pattern for rejecting a certain pattern.
Definition: dataflow_pattern.h:695
DFPattern reject
Definition: dataflow_pattern.h:697
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:699
TVM_DECLARE_FINAL_OBJECT_INFO(NotPatternNode, DFPatternNode)
static constexpr const char * _type_key
Definition: dataflow_pattern.h:701
Managed reference to NotPatternNode.
Definition: dataflow_pattern.h:709
NotPattern(DFPattern reject)
TVM_DEFINE_OBJECT_REF_METHODS(NotPattern, DFPattern, NotPatternNode)
Match a disjunction of other patterns.
Definition: dataflow_pattern.h:667
DFPattern left
Definition: dataflow_pattern.h:669
DFPattern right
Definition: dataflow_pattern.h:670
TVM_DECLARE_FINAL_OBJECT_INFO(OrPatternNode, DFPatternNode)
static constexpr const char * _type_key
Definition: dataflow_pattern.h:677
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:672
Managed reference to OrPatternNode.
Definition: dataflow_pattern.h:685
TVM_DEFINE_OBJECT_REF_METHODS(OrPattern, DFPattern, OrPatternNode)
OrPattern(DFPattern left, DFPattern right)
A context to manage the graph-level pattern matching.
Definition: dataflow_pattern.h:251
ExternUse
Constrainting matched graph with assertion to external uses.
Definition: dataflow_pattern.h:254
@ kMustNot
Definition: dataflow_pattern.h:256
@ kMay
Definition: dataflow_pattern.h:255
TVM_DECLARE_FINAL_OBJECT_INFO(PatternContextNode, Object)
std::vector< DFConstraint > validation_constraints
Definition: dataflow_pattern.h:268
static constexpr const char * _type_key
Definition: dataflow_pattern.h:270
enum tvm::relax::PatternContextNode::ExternUse allow_extern_use
std::map< DFPattern, std::vector< std::pair< DFPattern, std::vector< PairCons > > > > edge_constraints
Definition: dataflow_pattern.h:261
std::vector< DFPattern > src_ordered
Definition: dataflow_pattern.h:265
Managed reference to a pattern context.
Definition: dataflow_pattern.h:278
void add_constraint(DFConstraint constraint)
Add a validation constraint.
Definition: dataflow_pattern.h:324
void ExitWithScope() const
The RAII-like exit of a constraint context scope.
PatternContextNode * operator->()
Definition: dataflow_pattern.h:288
static Optional< PatternContext > Current()
Get the constraint context object on the top of the stack.
void add_constraint(DFPattern producer, DFPattern consumer, PairCons cons)
Build an edge constraint between two patterns (producer and consumer).
Definition: dataflow_pattern.h:300
const PatternContextNode * operator->() const
Definition: dataflow_pattern.h:283
PatternContext(bool incremental=false)
PatternContext(ObjectPtr< Object > n)
Definition: dataflow_pattern.h:280
void EnterWithScope() const
The RAII-like entry of a constraint context scope.
A sequence of DFPatterns that the previous DFPattern is connected to the next one.
Definition: dataflow_pattern.h:215
TVM_DECLARE_BASE_OBJECT_INFO(PatternSeqNode, Object)
tvm::Array< DFPattern > patterns
Definition: dataflow_pattern.h:217
static constexpr const char * _type_key
Definition: dataflow_pattern.h:221
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:220
std::vector< PairCons > pair_constraints
Definition: dataflow_pattern.h:218
Managed reference to pattern sequences.
Definition: dataflow_pattern.h:229
PatternSeq(tvm::Array< DFPattern > patterns, bool only_used_by=false)
PatternSeq OnlyUsedBy(PatternSeq other, int index=-1) const
TVM_DEFINE_OBJECT_REF_METHODS(PatternSeq, ObjectRef, PatternSeqNode)
PatternSeq UsedBy(PatternSeq other, int index=-1) const
friend PatternSeq UsedBy(const PatternSeq &lhs, const PatternSeq &rhs, int index)
Create used-by relationship between lhs[-1] and rhs[0], with [*lhs, *rhs] returned.
PatternSeq(DFPattern init_pattern)
friend PatternSeq OnlyUsedBy(const PatternSeq &lhs, const PatternSeq &rhs, int index)
Create only-used-by relationship between lhs[-1] and rhs[0], with [*lhs, *rhs] returned.
PatternSeq dup() const
Syntatic Sugar for duplicating the current pattern sequence.
A pattern to match an array of PrimExpr.
Definition: dataflow_pattern.h:499
TVM_DECLARE_FINAL_OBJECT_INFO(PrimArrPatternNode, DFPatternNode)
Array< PrimExpr > fields
Definition: dataflow_pattern.h:501
static constexpr const char * _type_key
Definition: dataflow_pattern.h:503
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:502
Managed reference to a PrimArrPattern.
Definition: dataflow_pattern.h:511
TVM_DEFINE_OBJECT_REF_METHODS(PrimArrPattern, DFPattern, PrimArrPatternNode)
PrimArrPattern(Array< PrimExpr > arr)
A pattern that asserting multiple root patterns have the same shape.
Definition: dataflow_pattern.h:827
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:836
Array< DFPattern > args
Definition: dataflow_pattern.h:829
TVM_DECLARE_FINAL_OBJECT_INFO(SameShapeConstraintNode, DFConstraintNode)
std::tuple< PrimExpr, bool > AsPrimExpr(std::function< Optional< Var >(const DFPatternNode *)> match_state) const override
Convert the constraint to a PrimExpr.
static constexpr const char * _type_key
Definition: dataflow_pattern.h:838
Array< DFPattern > GetDependentPatterns() const override
Return the patterns on which the constraint depends.
Definition: dataflow_pattern.h:831
Managed reference to SameShapePatternNode.
Definition: dataflow_pattern.h:846
TVM_DEFINE_OBJECT_REF_METHODS(SameShapeConstraint, DFConstraint, SameShapeConstraintNode)
SameShapeConstraint(Array< DFPattern > args)
A pattern that asserting a root pattern has a certain shape.
Definition: dataflow_pattern.h:799
static constexpr const char * _type_key
Definition: dataflow_pattern.h:809
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:804
TVM_DECLARE_FINAL_OBJECT_INFO(ShapePatternNode, DFPatternNode)
DFPattern pattern
Definition: dataflow_pattern.h:801
Array< PrimExpr > shape
Definition: dataflow_pattern.h:802
Managed reference to ShapePatternNode.
Definition: dataflow_pattern.h:817
TVM_DEFINE_OBJECT_REF_METHODS(ShapePattern, DFPattern, ShapePatternNode)
ShapePattern(DFPattern pattern, Array< PrimExpr > type)
Pattern for matching a certain struct info.
Definition: dataflow_pattern.h:775
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:780
StructInfo struct_info
Definition: dataflow_pattern.h:778
static constexpr const char * _type_key
Definition: dataflow_pattern.h:785
TVM_DECLARE_FINAL_OBJECT_INFO(StructInfoPatternNode, DFPatternNode)
DFPattern pattern
Definition: dataflow_pattern.h:777
Definition: dataflow_pattern.h:789
TVM_DEFINE_OBJECT_REF_METHODS(StructInfoPattern, DFPattern, StructInfoPatternNode)
StructInfoPattern(DFPattern pattern, StructInfo struct_info)
Managed reference to StructInfoNode.
Definition: expr.h:129
A pattern to match n'th indexing to a tuple.
Definition: dataflow_pattern.h:611
static constexpr const char * _type_key
Definition: dataflow_pattern.h:621
TVM_DECLARE_FINAL_OBJECT_INFO(TupleGetItemPatternNode, DFPatternNode)
DFPattern tuple
Definition: dataflow_pattern.h:613
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:616
int index
Definition: dataflow_pattern.h:614
Managed reference to TupleGetItemPatternNode.
Definition: dataflow_pattern.h:629
TVM_DEFINE_OBJECT_REF_METHODS(TupleGetItemPattern, DFPattern, TupleGetItemPatternNode)
TupleGetItemPattern(DFPattern tuple, int index)
Pattern to match a tuple of ordered expressions.
Definition: dataflow_pattern.h:562
tvm::Array< DFPattern > fields
Definition: dataflow_pattern.h:564
TVM_DECLARE_FINAL_OBJECT_INFO(TuplePatternNode, DFPatternNode)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:566
static constexpr const char * _type_key
Definition: dataflow_pattern.h:568
Managed reference to TuplePatternNode.
Definition: dataflow_pattern.h:576
TVM_DEFINE_OBJECT_REF_METHODS(TuplePattern, DFPattern, TuplePatternNode)
TuplePattern(tvm::Array< DFPattern > fields)
Pattern for matching a certain type.
Definition: dataflow_pattern.h:747
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:752
TVM_DECLARE_FINAL_OBJECT_INFO(TypePatternNode, DFPatternNode)
DFPattern pattern
Definition: dataflow_pattern.h:749
Type type
Definition: dataflow_pattern.h:750
static constexpr const char * _type_key
Definition: dataflow_pattern.h:757
Managed reference to TypePatternNode.
Definition: dataflow_pattern.h:765
TVM_DEFINE_OBJECT_REF_METHODS(TypePattern, DFPattern, TypePatternNode)
TypePattern(DFPattern pattern, Type type)
A pattern to match multiple expressions unorderedly.
Definition: dataflow_pattern.h:586
tvm::Array< DFPattern > fields
Definition: dataflow_pattern.h:588
static constexpr const char * _type_key
Definition: dataflow_pattern.h:592
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:590
TVM_DECLARE_FINAL_OBJECT_INFO(UnorderedTuplePatternNode, DFPatternNode)
Managed reference to UnorderedTuplePatternNode.
Definition: dataflow_pattern.h:600
UnorderedTuplePattern(tvm::Array< DFPattern > fields)
TVM_DEFINE_OBJECT_REF_METHODS(UnorderedTuplePattern, DFPattern, UnorderedTuplePatternNode)
A Pattern to Match a Relax Variable.
Definition: dataflow_pattern.h:369
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:373
String name
Definition: dataflow_pattern.h:371
const String & name_hint() const
Definition: dataflow_pattern.h:372
static constexpr const char * _type_key
Definition: dataflow_pattern.h:375
TVM_DECLARE_BASE_OBJECT_INFO(VarPatternNode, DFPatternNode)
Managed reference to a VarPattern.
Definition: dataflow_pattern.h:383
TVM_DEFINE_OBJECT_REF_METHODS(VarPattern, DFPattern, VarPatternNode)
VarPattern(String name_hint)
Create a pattern matching by variable name.
Wildcard Pattern is a pattern that can match anything.
Definition: dataflow_pattern.h:719
static constexpr const char * _type_key
Definition: dataflow_pattern.h:723
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:721
TVM_DECLARE_FINAL_OBJECT_INFO(WildcardPatternNode, DFPatternNode)
Managed reference to WildcardPatternNode.
Definition: dataflow_pattern.h:731
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(WildcardPattern, DFPattern, WildcardPatternNode)
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
A custom smart pointer for Object.
Definition: object.h:362
Base class of all object reference.
Definition: object.h:519
const Object * get() const
Definition: object.h:554
Object * get_mutable() const
Definition: object.h:607
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
CallPattern IsCallTIR(const String &name, Optional< TuplePattern > args=NullOpt)
Syntatic Sugar for call_tir (return a tensor)
PatternSeq operator^(const PatternSeq &lhs, const PatternSeq &rhs)
Syntax sugar of UsedBy(lhs, rhs, -1).
CallPattern IsCallDPSPacked(const String &name, Optional< TuplePattern > args=NullOpt)
Syntatic Sugar for call_dps_packed (return a tensor)
ExprPattern IsOp(const String &op_name)
Syntatic Sugar for creating a ExprPattern base on an Op.
DFPattern IsTuple(const Array< DFPattern > &fields, bool unordered=false)
Syntatic Sugar for creating TuplePattern or UnorderedTuplePattern (unordered=true)
WildcardPattern Wildcard()
Syntatic Sugar for creating a WildcardPattern.
ConstantPattern IsConst()
Syntatic Sugar for creating a ConstantPattern.
PatternSeq UsedBy(const PatternSeq &lhs, const PatternSeq &rhs, int index=-1)
Create used-by relationship between lhs[-1] and rhs[0], with [*lhs, *rhs] returned.
PatternSeq OnlyUsedBy(const PatternSeq &lhs, const PatternSeq &rhs, int index=-1)
Create only-used-by relationship between lhs[-1] and rhs[0], with [*lhs, *rhs] returned.
ExprPattern IsExpr(const Expr &expr)
Syntatic Sugar for creating a ExprPattern.
PatternSeq operator>>(const PatternSeq &lhs, const PatternSeq &rhs)
Syntax sugar of OnlyUsedBy(lhs, rhs, -1).
TupleGetItemPattern IsTupleGetItem(const DFPattern tuple, int index=-1)
Syntatic Sugar for creating a TupleGetItemPattern.
VarPattern IsVar(const String &name)
Syntatic Sugar for creating a VarPattern with a name.
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
constexpr runtime::NullOptType NullOpt
Definition: optional.h:169
Runtime Optional container types.
Constraint of a DFPattern edge (producer -> consumer) in graph-level matching.
Definition: dataflow_pattern.h:138
int index
Definition: dataflow_pattern.h:144
bool operator==(const PairCons &other) const
Definition: dataflow_pattern.h:154
enum tvm::relax::PairCons::Type type
Type
Constraint types of the edge.
Definition: dataflow_pattern.h:140
@ kOnlyUsedBy
Definition: dataflow_pattern.h:142
@ kUsedBy
Definition: dataflow_pattern.h:141
PairCons(Type t, int index=-1)
Construct a new PairCons object.
Definition: dataflow_pattern.h:152
RAII wrapper function to enter and exit a context object similar to python's with syntax.