tvm
analysis.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_ANALYSIS_H_
25 #define TVM_RELAY_ANALYSIS_H_
26 
27 #include <tvm/ir/module.h>
28 #include <tvm/relay/adt.h>
29 #include <tvm/relay/expr.h>
30 #include <tvm/relay/function.h>
31 #include <tvm/relay/type.h>
32 #include <tvm/runtime/logging.h>
33 
34 #include <string>
35 #include <unordered_map>
36 
37 namespace tvm {
38 namespace relay {
39 
57 TVM_DLL Kind KindCheck(const Type& t, const IRModule& mod,
59 
70 TVM_DLL bool ConstantCheck(const Expr& e);
71 
79 TVM_DLL bool BasicBlockNormalFormCheck(const Expr& e);
80 
94 TVM_DLL bool WellFormed(const Expr& expr,
96 
107 TVM_DLL tvm::Array<Var> BoundVars(const Expr& expr);
108 
119 TVM_DLL tvm::Array<Var> BoundVars(const Pattern& pat);
120 
131 TVM_DLL tvm::Array<Var> FreeVars(const Expr& expr);
132 
140 TVM_DLL tvm::Array<Var> AllVars(const Expr& expr);
141 
153 TVM_DLL tvm::Array<TypeVar> FreeTypeVars(const Expr& expr, const IRModule& mod);
154 
167 
179 TVM_DLL tvm::Array<TypeVar> BoundTypeVars(const Expr& expr, const IRModule& mod);
180 
193 
202 TVM_DLL tvm::Array<TypeVar> AllTypeVars(const Expr& expr, const IRModule& mod);
203 
212 TVM_DLL tvm::Array<TypeVar> AllTypeVars(const Type& t, const IRModule& mod);
213 
224 TVM_DLL Array<Pattern> UnmatchedCases(const Match& match, const IRModule& mod);
225 
233 TVM_DLL std::unordered_map<const Object*, size_t> GetExprRefCount(const Expr& body);
234 
243 
252 
253 } // namespace relay
254 } // namespace tvm
255 
256 #endif // TVM_RELAY_ANALYSIS_H_
Managed reference class to IRModuleNode.
Definition: module.h:366
Managed reference to RelayExprNode.
Definition: expr.h:442
Managed reference to TypeNode.
Definition: type.h:93
Definition: adt.h:316
Pattern is the base type for an ADT match pattern in Relay.
Definition: adt.h:63
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
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
IRModule that holds the functions and type definitions.
tvm::Array< Var > BoundVars(const Expr &expr)
Get all bound variables from expression expr.
Map< GlobalVar, Array< Integer > > GetCalibrateOutputMap(const IRModule &mod)
Get the output map between subgrpahs and its inputs/output.
tvm::Array< TypeVar > BoundTypeVars(const Expr &expr, const IRModule &mod)
Get all bound type variables from expression expr.
std::unordered_map< const Object *, size_t > GetExprRefCount(const Expr &body)
Get reference counter of each internal ExprNode in body.
bool WellFormed(const Expr &expr, Optional< DiagnosticContext > diag_ctx=Optional< DiagnosticContext >())
Check that each Var is only bound once.
tvm::Array< Var > AllVars(const Expr &expr)
Get all variables from expression expr.
Kind KindCheck(const Type &t, const IRModule &mod, Optional< DiagnosticContext > diag_ctx=Optional< DiagnosticContext >())
Check that types are well kinded by applying "kinding rules".
Array< Pattern > UnmatchedCases(const Match &match, const IRModule &mod)
Finds cases that the given match expression does not catch, if any.
bool ConstantCheck(const Expr &e)
Check whether an expression is constant.
tvm::Array< TypeVar > FreeTypeVars(const Expr &expr, const IRModule &mod)
Get free TypeVars from expression expr.
bool BasicBlockNormalFormCheck(const Expr &e)
Check whether an expression is in the basic block normal form.
tvm::Array< TypeVar > AllTypeVars(const Expr &expr, const IRModule &mod)
Get all type variables in expression expr.
IRModule GetCalibrateModule(IRModule mod)
Get the updated module for collecting calibration data.
tvm::Array< Var > FreeVars(const Expr &expr)
Get free type parameters from expression expr.
tvm::PrimExpr mod(const tvm::PrimExpr &a, const tvm::PrimExpr &b)
Definition: broadcast.h:290
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
TypeKind
Possible kinds of TypeVars.
Definition: type.h:201
Algebraic data types for Relay.
Relay expression language.
Relay Function.
Relay typed AST nodes.