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_RELAX_DATAFLOW_MATCHER_H_
25 #define TVM_RELAX_DATAFLOW_MATCHER_H_
26 
27 #include <tvm/ffi/function.h>
28 #include <tvm/ffi/optional.h>
30 
31 #include <memory>
32 
33 namespace tvm {
34 namespace relax {
35 
47 bool MatchExpr(DFPattern pattern, Expr expr,
48  ffi::Optional<ffi::Map<Var, Expr>> bindings = std::nullopt);
49 
50 /* \brief Similar to above, but return pairs of a matching pattern and an expression. */
51 ffi::Optional<ffi::Map<DFPattern, Expr>> ExtractMatchedExpr(
52  DFPattern pattern, Expr expr, ffi::Optional<ffi::Map<Var, Expr>> bindings = std::nullopt);
53 
60 TVM_DLL ffi::Optional<ffi::Map<DFPattern, Var>> MatchGraph(const PatternContext& ctx,
61  const DataflowBlock& dfb);
62 
73  const PatternContext& ctx,
74  ffi::TypedFunction<ffi::Map<Var, Expr>(ffi::Map<DFPattern, Var>, ffi::Map<Var, Expr>)> rewriter,
75  Function f);
76 
100 TVM_DLL Function RewriteCall(const DFPattern& pattern,
101  ffi::TypedFunction<Expr(Expr, ffi::Map<DFPattern, Expr>)> rewriter,
102  Function func);
103 
104 } // namespace relax
105 } // namespace tvm
106 
107 #endif // TVM_RELAX_DATAFLOW_MATCHER_H_
Managed reference to RelaxExprNode.
Definition: expr.h:439
Managed reference to dataflow patterns.
Definition: dataflow_pattern.h:101
Definition: expr.h:693
Definition: expr.h:830
Managed reference to a pattern context.
Definition: dataflow_pattern.h:275
A pattern language for matching dataflow properties.
ffi::Optional< ffi::Map< DFPattern, Expr > > ExtractMatchedExpr(DFPattern pattern, Expr expr, ffi::Optional< ffi::Map< Var, Expr >> bindings=std::nullopt)
Function RewriteCall(const DFPattern &pattern, ffi::TypedFunction< Expr(Expr, ffi::Map< DFPattern, Expr >)> rewriter, Function func)
Rewrite a function with the given pattern and the rewriter function.
ffi::Optional< ffi::Map< DFPattern, Var > > MatchGraph(const PatternContext &ctx, const DataflowBlock &dfb)
Match a sub-graph in a DataflowBlock with a graph of patterns and return the mapping.
bool MatchExpr(DFPattern pattern, Expr expr, ffi::Optional< ffi::Map< Var, Expr >> bindings=std::nullopt)
Determine if a pattern matches an expression.
RelaxExpr Expr
Definition: expr.h:39
Function RewriteBindings(const PatternContext &ctx, ffi::TypedFunction< ffi::Map< Var, Expr >(ffi::Map< DFPattern, Var >, ffi::Map< Var, Expr >)> rewriter, Function f)
Rewrite a function with the given pattern and the rewriter function.
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:37