tvm
Loading...
Searching...
No Matches
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_S_TIR_ANALYSIS_H_
25#define TVM_S_TIR_ANALYSIS_H_
26
27#include <tvm/base.h>
28#include <tvm/ir/module.h>
29#include <tvm/ir/prim/expr.h>
30#include <tvm/ir/transform.h>
31#include <tvm/s_tir/stmt.h>
32#include <tvm/target/target.h>
33#include <tvm/tirx/function.h>
34#include <tvm/tirx/stmt.h>
35
36#include <optional>
37
38namespace tvm {
39namespace tirx {
52TVM_DLL ffi::Array<ffi::Array<TensorRegion>> GetSBlockAccessRegion(
53 const s_tir::SBlock& block, const ffi::Map<Var, TensorVar>& tensor_var_map);
54
63TVM_DLL ffi::Array<ffi::Array<TensorRegion>> GetSBlockReadWriteRegion(
64 const s_tir::SBlock& block, const ffi::Map<Var, TensorVar>& tensor_var_map);
65
74TVM_DLL ffi::Map<TensorVar, ffi::Optional<Stmt>> DetectTensorAccessLCA(const Function& func);
75
91
92} // namespace tirx
93
94namespace sym {
95class AnalyzerObj;
96class Analyzer;
97} // namespace sym
98
99namespace s_tir {
100using namespace tvm::tirx;
101
103TVM_DLL void CheckWellFormed(const tirx::Function& func);
105TVM_DLL void CheckWellFormed(const IRModule& mod);
106
112TVM_DLL double EstimateTIRFlops(const Stmt& stmt);
113
119TVM_DLL double EstimateTIRFlops(const IRModule& mod);
120
127TVM_DLL bool IsPureFunction(const Function& func, bool assert_on_error = false);
128
135TVM_DLL bool VerifyGPUCode(const Function& func, ffi::Map<ffi::String, PrimExpr> constraints);
136
142
148TVM_DLL std::optional<MemCpyDetails> IdentifyMemCpy(const For& loop, const sym::Analyzer& analyzer);
149
158TVM_DLL ffi::Array<ffi::Optional<Range>> DomainTouched(const Stmt& body, const TensorVar& tensor,
159 bool consider_loads, bool consider_stores);
160
166TVM_DLL ffi::Map<ffi::String, ffi::Map<ffi::String, int64_t>> CalculateAllocatedBytes(
167 const Function& func);
168
174TVM_DLL ffi::Map<ffi::String, ffi::Map<ffi::String, int64_t>> CalculateAllocatedBytes(
175 const IRModule& mod);
176
181TVM_DLL ffi::Array<tvm::transform::Pass> GetVTCMCompactionPasses();
182
189TVM_DLL bool VerifyVTCMLimit(const IRModule& mod, int64_t limit);
190
197TVM_DLL bool VerifyVTCMLimit(const Function& func, int64_t limit);
198
199namespace transform {
200
203
209TVM_DLL Pass VerifyGPUCode(ffi::Map<ffi::String, PrimExpr> constraints);
210
216TVM_DLL Pass VerifyVTCMLimit(ffi::Optional<Target> default_target = std::nullopt);
217
222TVM_DLL Pass OOBChecker();
223
224} // namespace transform
225} // namespace s_tir
226} // namespace tvm
227#endif // TVM_S_TIR_ANALYSIS_H_
TIR expressions.
Utilities for IR transformations.
TIR Function.
TIRx statements and shared statement entry header.
Managed reference to ForObj.
Definition stmt.h:527
Managed reference class to IRModuleObj.
Definition module.h:292
Container of all statements.
Definition stmt.h:61
Managed reference to TensorRegionObj.
Definition expr.h:944
A block is a basic schedule unit in TIR.
Definition stmt.h:112
Managed reference to SBlockObj.
Definition stmt.h:164
Managed reference to AnalyzerObj.
Definition analyzer.h:750
Managed reference to FunctionObj.
Definition function.h:107
Checked zero-state view over an ordinary VarObj with TensorType.
Definition expr.h:48
PassContext that is used to configure the pass behavior.
Definition transform.h:64
Definition transform.h:307
Parent compiler symbol visibility.
S-TIR (Schedulable TIR) statements and attributes.
IRModule that holds the functions and type definitions.
Pass VerifyGPUCode(ffi::Map< ffi::String, PrimExpr > constraints)
Pass to verify GPU code constraints.
Pass VerifyVTCMLimit(ffi::Optional< Target > default_target=std::nullopt)
Pass to check if VTCM usage is within limit.
Pass OOBChecker()
Statically check TIR code for out of bounds array access.
bool IsPureFunction(const Function &func, bool assert_on_error=false)
Analyze the side effect of a function.
bool VerifyVTCMLimit(const IRModule &mod, int64_t limit)
Verifies that the VTCM usage for all functions in the given IRModule.
ffi::Array< tvm::transform::Pass > GetVTCMCompactionPasses()
Get the list of lowering passes to calculate the compacted VTCM allocation size.
bool VerifyGPUCode(const Function &func, ffi::Map< ffi::String, PrimExpr > constraints)
Verify the correctness of a GPU code.
double EstimateTIRFlops(const Stmt &stmt)
Estimate the FLOPs of a TIR fragment.
ffi::Map< ffi::String, ffi::Map< ffi::String, int64_t > > CalculateAllocatedBytes(const Function &func)
Calculate the allocated memory per scope in bytes needed inside the TIR Function.
ffi::Array< ffi::Optional< Range > > DomainTouched(const Stmt &body, const TensorVar &tensor, bool consider_loads, bool consider_stores)
Infer the domain touched by tensor accesses within a statement.
std::optional< MemCpyDetails > IdentifyMemCpy(const For &loop, const sym::Analyzer &analyzer)
Identify whether a For loop is semantically equivalent to MemCpy.
void CheckWellFormed(const tirx::Function &func)
Verify variable/tensor definitions, load types and schedulable block boundaries.
Definition axis_group_graph.h:41
ffi::Map< TensorVar, ffi::Optional< Stmt > > DetectTensorAccessLCA(const Function &func)
Detect the lowest common ancestor(LCA) of tensor access, including both high-level access(TensorLoad,...
const s_tir::SBlockObj * FindAnchorBlock(const IRModule &mod)
Find the "anchor block" of the given module. We define the anchor block to be the block with (1) an i...
ffi::Array< ffi::Array< TensorRegion > > GetSBlockAccessRegion(const s_tir::SBlock &block, const ffi::Map< Var, TensorVar > &tensor_var_map)
Auto detect the block access region according to its body stmt It will detect the access region as an...
ffi::Array< ffi::Array< TensorRegion > > GetSBlockReadWriteRegion(const s_tir::SBlock &block, const ffi::Map< Var, TensorVar > &tensor_var_map)
Auto detect the block read/write region according to its body stmt. An opaque access will be counted ...
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analysis.h:41
Helper struct for return value of IdentifyMemCpy.
Definition analysis.h:138
TensorRegion source
Definition analysis.h:139
TensorRegion dest
Definition analysis.h:140
Compilation target object.