24 #ifndef TVM_RELAY_DATAFLOW_PATTERN_H_
25 #define TVM_RELAY_DATAFLOW_PATTERN_H_
42 static constexpr
const char*
_type_key =
"DFPatternNode";
90 static constexpr
const char*
_type_key =
"relay.dataflow_pattern.ExprPattern";
123 static constexpr
const char*
_type_key =
"relay.dataflow_pattern.VarPattern";
142 static constexpr
const char*
_type_key =
"relay.dataflow_pattern.ConstantPattern";
172 v->Visit(
"args", &
args);
175 static constexpr
const char*
_type_key =
"relay.dataflow_pattern.CallPattern";
202 v->Visit(
"params", &
params);
203 v->Visit(
"body", &
body);
206 static constexpr
const char*
_type_key =
"relay.dataflow_pattern.FunctionPattern";
238 v->Visit(
"var", &
var);
239 v->Visit(
"value", &
value);
240 v->Visit(
"body", &
body);
243 static constexpr
const char*
_type_key =
"relay.dataflow_pattern.LetPattern";
273 static constexpr
const char*
_type_key =
"relay.dataflow_pattern.TuplePattern";
293 v->Visit(
"tuple", &
tuple);
294 v->Visit(
"index", &
index);
297 static constexpr
const char*
_type_key =
"relay.dataflow_pattern.TupleGetItemPattern";
306 v->Visit(
"cond", &
cond);
311 static constexpr
const char*
_type_key =
"relay.dataflow_pattern.IfPattern";
339 v->Visit(
"left", &
left);
340 v->Visit(
"right", &
right);
343 static constexpr
const char*
_type_key =
"relay.dataflow_pattern.AltPattern";
363 static constexpr
const char*
_type_key =
"relay.dataflow_pattern.WildcardPattern";
388 v->Visit(
"type", &
type);
391 static constexpr
const char*
_type_key =
"relay.dataflow_pattern.TypePattern";
417 v->Visit(
"shape", &
shape);
420 static constexpr
const char*
_type_key =
"relay.dataflow_pattern.ShapePattern";
446 v->Visit(
"dtype", &
dtype);
449 static constexpr
const char*
_type_key =
"relay.dataflow_pattern.DataTypePattern";
475 v->Visit(
"attrs", &
attrs);
478 static constexpr
const char*
_type_key =
"relay.dataflow_pattern.AttrPattern";
507 v->Visit(
"parent", &
parent);
508 v->Visit(
"path", &
path);
509 v->Visit(
"child", &
child);
512 static constexpr
const char*
_type_key =
"relay.dataflow_pattern.DominatorPattern";
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:433
Managed reference to TypeNode.
Definition: type.h:93
Pattern for Alternate Expressions.
Definition: dataflow_pattern.h:331
DFPattern right
The right optional pattern.
Definition: dataflow_pattern.h:336
DFPattern left
The left optional pattern.
Definition: dataflow_pattern.h:334
TVM_DECLARE_FINAL_OBJECT_INFO(AltPatternNode, DFPatternNode)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:338
static constexpr const char * _type_key
Definition: dataflow_pattern.h:343
A pattern which matches either of two patterns.
Definition: dataflow_pattern.h:350
TVM_DEFINE_OBJECT_REF_METHODS(AltPattern, DFPattern, AltPatternNode)
AltPattern(DFPattern left, DFPattern right)
Pattern for Attributes.
Definition: dataflow_pattern.h:466
DFPattern pattern
The pattern.
Definition: dataflow_pattern.h:469
DictAttrs attrs
The attribute to match.
Definition: dataflow_pattern.h:471
static constexpr const char * _type_key
Definition: dataflow_pattern.h:478
TVM_DECLARE_FINAL_OBJECT_INFO(AttrPatternNode, DFPatternNode)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:473
A pattern which matches attributes in another pattern.
Definition: dataflow_pattern.h:485
AttrPattern(DFPattern pattern, DictAttrs attrs)
TVM_DEFINE_OBJECT_REF_METHODS(AttrPattern, DFPattern, AttrPatternNode)
CallPattern container.
Definition: dataflow_pattern.h:157
TVM_DECLARE_FINAL_OBJECT_INFO(CallPatternNode, DFPatternNode)
static constexpr const char * _type_key
Definition: dataflow_pattern.h:175
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:170
tvm::Array< relay::DFPattern > args
The arguments(inputs) of the call.
Definition: dataflow_pattern.h:168
DFPattern op
The operator(function) being invoked.
Definition: dataflow_pattern.h:165
Definition: dataflow_pattern.h:179
CallPattern(DFPattern op, Array< DFPattern > args)
TVM_DEFINE_OBJECT_REF_METHODS(CallPattern, DFPattern, CallPatternNode)
Container for Constant.
Definition: dataflow_pattern.h:138
static constexpr const char * _type_key
Definition: dataflow_pattern.h:142
TVM_DECLARE_FINAL_OBJECT_INFO(ConstantPatternNode, DFPatternNode)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:140
Definition: dataflow_pattern.h:146
TVM_DEFINE_OBJECT_REF_METHODS(ConstantPattern, DFPattern, ConstantPatternNode)
Base type of all dataflow patterns.
Definition: dataflow_pattern.h:40
TVM_DECLARE_BASE_OBJECT_INFO(DFPatternNode, Object)
static constexpr const char * _type_key
Definition: dataflow_pattern.h:42
Managed reference to dataflow patterns.
Definition: dataflow_pattern.h:50
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:437
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:444
DataType dtype
The type to match.
Definition: dataflow_pattern.h:442
TVM_DECLARE_FINAL_OBJECT_INFO(DataTypePatternNode, DFPatternNode)
static constexpr const char * _type_key
Definition: dataflow_pattern.h:449
DFPattern pattern
The pattern.
Definition: dataflow_pattern.h:440
A pattern which matches a type in another pattern.
Definition: dataflow_pattern.h:456
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:497
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:506
static constexpr const char * _type_key
Definition: dataflow_pattern.h:512
DFPattern path
The path.
Definition: dataflow_pattern.h:502
TVM_DECLARE_FINAL_OBJECT_INFO(DominatorPatternNode, DFPatternNode)
DFPattern parent
The parent.
Definition: dataflow_pattern.h:500
DFPattern child
The child.
Definition: dataflow_pattern.h:504
A pattern which matches a variable length dominator path.
Definition: dataflow_pattern.h:519
TVM_DEFINE_OBJECT_REF_METHODS(DominatorPattern, DFPattern, DominatorPatternNode)
DominatorPattern(DFPattern parent, DFPattern path, DFPattern child)
Pattern for Relay Expression.
Definition: dataflow_pattern.h:83
Expr expr
The expression to match.
Definition: dataflow_pattern.h:86
TVM_DECLARE_FINAL_OBJECT_INFO(ExprPatternNode, DFPatternNode)
static constexpr const char * _type_key
Definition: dataflow_pattern.h:90
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:88
A pattern which matches a literal expression.
Definition: dataflow_pattern.h:100
TVM_DEFINE_OBJECT_REF_METHODS(ExprPattern, DFPattern, ExprPatternNode)
Relay Function container.
Definition: dataflow_pattern.h:189
static constexpr const char * _type_key
Definition: dataflow_pattern.h:206
tvm::Array< DFPattern > params
Function parameters.
Definition: dataflow_pattern.h:192
TVM_DECLARE_FINAL_OBJECT_INFO(FunctionPatternNode, DFPatternNode)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:201
DFPattern body
The expression which represents the computation of the function, the expression may reference the par...
Definition: dataflow_pattern.h:199
Managed reference to FunctionNode.
Definition: dataflow_pattern.h:214
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:301
TVM_DECLARE_FINAL_OBJECT_INFO(IfPatternNode, DFPatternNode)
DFPattern cond
Definition: dataflow_pattern.h:303
static constexpr const char * _type_key
Definition: dataflow_pattern.h:311
DFPattern true_branch
Definition: dataflow_pattern.h:303
DFPattern false_branch
Definition: dataflow_pattern.h:303
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:305
Definition: dataflow_pattern.h:315
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:228
DFPattern body
The body of the let binding.
Definition: dataflow_pattern.h:235
static constexpr const char * _type_key
Definition: dataflow_pattern.h:243
TVM_DECLARE_FINAL_OBJECT_INFO(LetPatternNode, DFPatternNode)
DFPattern value
The value we bind var to.
Definition: dataflow_pattern.h:233
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:237
DFPattern var
The variable we bind to.
Definition: dataflow_pattern.h:231
Let binding that binds a local var.
Definition: dataflow_pattern.h:250
TVM_DEFINE_OBJECT_REF_METHODS(LetPattern, DFPattern, LetPatternNode)
LetPattern(DFPattern var, DFPattern value, DFPattern body)
The constructor.
Pattern for Shapes.
Definition: dataflow_pattern.h:408
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:415
TVM_DECLARE_FINAL_OBJECT_INFO(ShapePatternNode, DFPatternNode)
Array< PrimExpr > shape
The type to match.
Definition: dataflow_pattern.h:413
DFPattern pattern
The pattern.
Definition: dataflow_pattern.h:411
static constexpr const char * _type_key
Definition: dataflow_pattern.h:420
A pattern which matches a type in another pattern.
Definition: dataflow_pattern.h:427
TVM_DEFINE_OBJECT_REF_METHODS(ShapePattern, DFPattern, ShapePatternNode)
ShapePattern(DFPattern pattern, Array< PrimExpr > type)
Definition: dataflow_pattern.h:285
static constexpr const char * _type_key
Definition: dataflow_pattern.h:297
DFPattern tuple
The tuple Expression.
Definition: dataflow_pattern.h:288
TVM_DECLARE_FINAL_OBJECT_INFO(TupleGetItemPatternNode, DFPatternNode)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:292
int index
which value to get
Definition: dataflow_pattern.h:290
Definition: dataflow_pattern.h:321
TVM_DEFINE_OBJECT_REF_METHODS(TupleGetItemPattern, DFPattern, TupleGetItemPatternNode)
TupleGetItemPattern(DFPattern tuple, int index)
Tuple container.
Definition: dataflow_pattern.h:266
static constexpr const char * _type_key
Definition: dataflow_pattern.h:273
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:271
TVM_DECLARE_FINAL_OBJECT_INFO(TuplePatternNode, DFPatternNode)
tvm::Array< DFPattern > fields
the fields of the tuple
Definition: dataflow_pattern.h:269
Definition: dataflow_pattern.h:277
TuplePattern(tvm::Array< DFPattern > fields)
TVM_DEFINE_OBJECT_REF_METHODS(TuplePattern, DFPattern, TuplePatternNode)
Pattern for Types.
Definition: dataflow_pattern.h:379
TVM_DECLARE_FINAL_OBJECT_INFO(TypePatternNode, DFPatternNode)
DFPattern pattern
The pattern.
Definition: dataflow_pattern.h:382
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:386
static constexpr const char * _type_key
Definition: dataflow_pattern.h:391
Type type
The type to match.
Definition: dataflow_pattern.h:384
A pattern which matches a type in another pattern.
Definition: dataflow_pattern.h:398
TypePattern(DFPattern pattern, Type type)
TVM_DEFINE_OBJECT_REF_METHODS(TypePattern, DFPattern, TypePatternNode)
Container for Var.
Definition: dataflow_pattern.h:111
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:121
String name
The name of the Var (optional).
Definition: dataflow_pattern.h:116
static constexpr const char * _type_key
Definition: dataflow_pattern.h:123
const String & name_hint() const
Definition: dataflow_pattern.h:119
TVM_DECLARE_FINAL_OBJECT_INFO(VarPatternNode, DFPatternNode)
Definition: dataflow_pattern.h:127
VarPattern(String name_hint)
TVM_DEFINE_OBJECT_REF_METHODS(VarPattern, DFPattern, VarPatternNode)
Wildcard Pattern.
Definition: dataflow_pattern.h:359
static constexpr const char * _type_key
Definition: dataflow_pattern.h:363
TVM_DECLARE_FINAL_OBJECT_INFO(WildcardPatternNode, DFPatternNode)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_pattern.h:361
A pattern which matches anything.
Definition: dataflow_pattern.h:370
TVM_DEFINE_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:42
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:515
base class of all object containers.
Definition: object.h:167
Reference to string objects.
Definition: string.h:98
DFPattern IsTuple(const Array< DFPattern > &fields)
Syntatic Sugar for creating a TuplePattern.
DFPattern IsConstant()
Syntatic Sugar for creating a ConstantPattern.
DFPattern IsTupleGetItem(const DFPattern tuple, int index=-1)
Syntatic Sugar for creating a TupleGetItemPattern.
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:1763
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
Relay expression language.