tvm
block_dependence_info.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  */
31 #ifndef TVM_TIR_BLOCK_DEPENDENCE_INFO_H_
32 #define TVM_TIR_BLOCK_DEPENDENCE_INFO_H_
33 
34 #include <tvm/tir/block_scope.h>
35 
36 #include <unordered_map>
37 
38 namespace tvm {
39 namespace tir {
40 
54  public:
59  std::unordered_map<StmtSRef, BlockScope, ObjectPtrHash, ObjectPtrEqual> sref2scope;
61  std::unordered_map<const StmtNode*, StmtSRef> stmt2ref;
62 
63  void VisitAttrs(AttrVisitor* v) {}
64 
65  static constexpr const char* _type_key = "tir.BlockDependenceInfo";
67 
73  BlockScope GetBlockScope(const StmtSRef& scope_root) const {
74  auto it = sref2scope.find(scope_root);
75  CHECK(it != sref2scope.end())
76  << "IndexError: Cannot find the corresponding BlockScope to the block sref:\n"
77  << GetRef<Stmt>(scope_root->stmt);
78  return it->second;
79  }
80 };
81 
89  TVM_DLL BlockDependenceInfo();
90 
91  public:
95 
98 };
99 
100 } // namespace tir
101 } // namespace tvm
102 #endif // TVM_TIR_BLOCK_DEPENDENCE_INFO_H_
Definition of two pillar data structure for TensorIR scheduling: StmtSRef, 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 class to IRModuleNode.
Definition: module.h:366
Base class of all object reference.
Definition: object.h:519
base class of all object containers.
Definition: object.h:171
An object that helps build and query block level dependences using the 2 core objects BlockScope and ...
Definition: block_dependence_info.h:53
static constexpr const char * _type_key
Definition: block_dependence_info.h:65
TVM_DECLARE_FINAL_OBJECT_INFO(BlockDependenceInfoNode, Object)
std::unordered_map< const StmtNode *, StmtSRef > stmt2ref
The reverse mapping from block/for-loop to their corresponding srefs.
Definition: block_dependence_info.h:61
std::unordered_map< StmtSRef, BlockScope, ObjectPtrHash, ObjectPtrEqual > sref2scope
Mapping from a block sref to its correpsonding BlockScope, tracking the dependency inside the block s...
Definition: block_dependence_info.h:59
BlockScope GetBlockScope(const StmtSRef &scope_root) const
Get the BlockScope correpsonding to the sref of scope root block.
Definition: block_dependence_info.h:73
void VisitAttrs(AttrVisitor *v)
Definition: block_dependence_info.h:63
Managed reference to BlockDependenceInfoNode.
Definition: block_dependence_info.h:86
BlockDependenceInfo(IRModule mod)
Construct a BlockDependenceInfo from IRModule.
TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(BlockDependenceInfo, ObjectRef, BlockDependenceInfoNode)
Managed reference to BlockScopeNode.
Definition: block_scope.h:295
Managed reference to StmtSRefNode.
Definition: block_scope.h:107
tvm::PrimExpr mod(const tvm::PrimExpr &a, const tvm::PrimExpr &b)
Definition: broadcast.h:290
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36