tvm
dataflow_matcher.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_MATCHER_H_
25 #define TVM_RELAY_DATAFLOW_MATCHER_H_
26 
29 
30 #include <string>
31 #include <unordered_map>
32 #include <utility>
33 
34 namespace tvm {
35 namespace relay {
36 
37 class DFPatternCallback;
42 class DFPatternCallbackNode : public Object {
43  public:
47  PackedFunc function;
52 
54  v->Visit("pattern", &pattern);
55  v->Visit("require_type", &require_type);
56  v->Visit("rewrite_once", &rewrite_once);
57  }
58 
59  static constexpr const char* _type_key = "DFPatternCallbackNode";
61 };
62 
67 class DFPatternCallback : public ObjectRef {
68  public:
69  TVM_DLL DFPatternCallback(DFPattern pattern, PackedFunc callback, bool require_type,
70  bool rewrite_once = false);
72 };
73 
82 bool MatchPattern(DFPattern pattern, Expr expr);
83 
95 
108 
118 Expr InferType(const Expr& expr);
119 
120 } // namespace relay
121 } // namespace tvm
122 
123 #endif // TVM_RELAY_DATAFLOW_MATCHER_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 class to IRModuleNode.
Definition: module.h:366
Managed reference to RelayExprNode.
Definition: expr.h:442
Base type of all dataflow pattern callbacks.
Definition: dataflow_matcher.h:42
TVM_DECLARE_BASE_OBJECT_INFO(DFPatternCallbackNode, Object)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: dataflow_matcher.h:53
bool rewrite_once
Run the callback only once.
Definition: dataflow_matcher.h:51
static constexpr const char * _type_key
Definition: dataflow_matcher.h:59
bool require_type
Require InferType to be run before the callback.
Definition: dataflow_matcher.h:49
DFPattern pattern
Pattern this callback matches.
Definition: dataflow_matcher.h:45
Managed reference to dataflow pattern callbacks.
Definition: dataflow_matcher.h:67
TVM_DEFINE_OBJECT_REF_METHODS(DFPatternCallback, ObjectRef, DFPatternCallbackNode)
DFPatternCallback(DFPattern pattern, PackedFunc callback, bool require_type, bool rewrite_once=false)
Managed reference to dataflow patterns.
Definition: dataflow_pattern.h:52
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
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
Packed function is a type-erased function. The arguments are passed by packed format.
Definition: packed_func.h:141
Expr PartitionPattern(DFPattern pattern, Expr expr, Map< String, ObjectRef > attrs, PackedFunc check)
Partition all matches of a DFPattern inside an Expr into separate Function calls.
Expr InferType(const Expr &expr)
Infer the type of an expression.
bool MatchPattern(DFPattern pattern, Expr expr)
Determine if a pattern matches an expression.
Expr RewritePatterns(Array< DFPatternCallback > callbacks, Expr expr, IRModule mod=IRModule())
Rewrite an expression based on some number of DFPatternCallbacks.
IRModuleFrame IRModule()
The IRModule declaration statement.
Definition: module.h:359
tvm::PrimExpr mod(const tvm::PrimExpr &a, const tvm::PrimExpr &b)
Definition: broadcast.h:290
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
A pattern language for matching dataflow properties.
A set of passes for operating on pattern graphs.