25 #ifndef TVM_TIR_BLOCK_SCOPE_H_
26 #define TVM_TIR_BLOCK_SCOPE_H_
33 #include <unordered_map>
76 static constexpr
const char*
_type_key =
"tir.StmtSRef";
82 this->parent =
nullptr;
93 template <
typename StmtType>
96 return static_cast<const StmtType*
>(
stmt);
158 bool include_loops =
true) {
160 for (
const auto& kv :
mod->functions) {
161 const BaseFunc& base_func = kv.second;
163 auto func = opt.value();
164 creator.VisitStmt(func->body);
167 return std::move(creator.stmt2ref_);
171 explicit SRefTreeCreator(
bool include_loops) : include_loops_(include_loops) {}
177 void PushSRef(
const StmtNode* stmt);
180 void PopAndRecordSRef();
182 void VisitStmt_(
const ForNode* loop)
final;
184 void VisitStmt_(
const BlockRealizeNode* realize)
final;
186 void VisitStmt_(
const SeqStmtNode* seq_stmt)
final;
190 std::unordered_map<const StmtNode*, StmtSRef> stmt2ref_;
192 std::vector<StmtSRef> srefs_;
224 v->Visit(
"src", &
src);
225 v->Visit(
"dst", &
dst);
226 v->Visit(
"kind", &
kind);
229 static constexpr
const char*
_type_key =
"tir.Dependency";
272 static constexpr
const char*
_type_key =
"tir.BlockScope";
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 BaseFuncNode.
Definition: function.h:230
Managed reference class to IRModuleNode.
Definition: module.h:366
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Base class of all object reference.
Definition: object.h:519
ObjectPtr< Object > data_
Internal pointer that backs the reference.
Definition: object.h:605
const ObjectType * as() const
Try to downcast the internal Object to a raw pointer of a corresponding type.
Definition: object.h:910
base class of all object containers.
Definition: object.h:171
bool IsInstance() const
Definition: object.h:874
An object with 1-to-1 correspondence with each block reference in the sref tree. This data structure ...
Definition: block_scope.h:257
Array< Dependency > GetDepsByDst(const StmtSRef &dst) const
Get all dependencies whose dst equals dst
void VisitAttrs(AttrVisitor *v)
Definition: block_scope.h:270
Array< Dependency > GetDepsBySrc(const StmtSRef &src) const
Get all dependencies whose src equals src
std::unordered_map< StmtSRef, Array< Dependency >, ObjectPtrHash, ObjectPtrEqual > dst2deps
Lookup table for the dst of dependencies.
Definition: block_scope.h:266
std::unordered_map< StmtSRef, Array< Dependency >, ObjectPtrHash, ObjectPtrEqual > src2deps
Lookup table for the src of dependencies.
Definition: block_scope.h:264
std::unordered_map< Buffer, Array< StmtSRef >, ObjectPtrHash, ObjectPtrEqual > buffer_writers
The mapping from the buffer to the blocks who write it.
Definition: block_scope.h:268
TVM_DECLARE_FINAL_OBJECT_INFO(BlockScopeNode, Object)
static constexpr const char * _type_key
Definition: block_scope.h:272
Managed reference to BlockScopeNode.
Definition: block_scope.h:295
BlockScope()
The constructor creating an empty block scope with on dependency information.
BlockScope(const Array< StmtSRef > &child_block_srefs)
Create the object with the specific leaf blocks, and compute the dependency information between the l...
TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(BlockScope, ObjectRef, BlockScopeNode)
A tuple (src, dst, kind) representing certain types of dependency. For example, (A,...
Definition: block_scope.h:214
void VisitAttrs(AttrVisitor *v)
Definition: block_scope.h:223
StmtSRef dst
The destination of the dependency relation.
Definition: block_scope.h:219
StmtSRef src
The source of the dependency relation.
Definition: block_scope.h:217
static constexpr const char * _type_key
Definition: block_scope.h:229
DepKind kind
The dependency kind.
Definition: block_scope.h:221
TVM_DECLARE_FINAL_OBJECT_INFO(DependencyNode, Object)
Managed reference to DependencyNode.
Definition: block_scope.h:237
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(Dependency, ObjectRef, DependencyNode)
Dependency(StmtSRef src, StmtSRef dst, DepKind kind)
Constructor.
Managed reference to PrimFuncNode.
Definition: function.h:145
Definition: block_scope.h:150
static std::unordered_map< const StmtNode *, StmtSRef > Create(IRModule mod, bool include_loops=true)
StmtSRef Tree Creator.
Definition: block_scope.h:157
Base node of all statements.
Definition: stmt.h:38
An object that refers to schedulable elements (block/for-loop) in TensorIR, aka "sref".
Definition: block_scope.h:54
void Reset()
Reset the object inplace to the invalid state.
Definition: block_scope.h:80
int64_t seq_index
If the statement the sref points to is an element of a SeqStmt in the AST, then seq_index is set to i...
Definition: block_scope.h:68
TVM_DECLARE_FINAL_OBJECT_INFO(StmtSRefNode, Object)
StmtSRefNode * parent
The parent sref.
Definition: block_scope.h:63
const StmtNode * stmt
The block or for stmt the object refers to.
Definition: block_scope.h:61
void VisitAttrs(AttrVisitor *v)
Definition: block_scope.h:70
static constexpr const char * _type_key
Definition: block_scope.h:76
const StmtType * StmtAs() const
Get the referenced statement with proper type checking. It serves the same purpose as ObjectRef::as,...
Definition: block_scope.h:94
Managed reference to StmtSRefNode.
Definition: block_scope.h:107
static StmtSRef InlineMark()
StmtSRef(const StmtNode *stmt, StmtSRefNode *parent, int64_t seq_index)
The constructor.
TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(StmtSRef, ObjectRef, StmtSRefNode)
static StmtSRef RootMark()
StmtSRefNode * get() const
Definition: block_scope.h:119
StmtVisitor.
Definition: stmt_functor.h:139
IRModule that holds the functions and type definitions.
DepKind
Type of dependency. Right now we have 4 types of dependencies 1) Read-after-write (kRAW) 2) Write-aft...
Definition: block_scope.h:202
@ kOpaque
IterVar is opaque,.
Definition: var.h:234
tvm::PrimExpr mod(const tvm::PrimExpr &a, const tvm::PrimExpr &b)
Definition: broadcast.h:290
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
Functors for tir stmts utility functions to call common functors.
ObjectRef equal functor.
Definition: object.h:665
ObjectRef hash functor.
Definition: object.h:655