tvm
Loading...
Searching...
No Matches
frame.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#ifndef TVM_S_TIR_SCRIPT_IR_BUILDER_FRAME_H_
20#define TVM_S_TIR_SCRIPT_IR_BUILDER_FRAME_H_
21
22#include <tvm/s_tir/stmt.h>
24
25namespace tvm {
26namespace script {
27namespace ir_builder {
28namespace s_tir {
29
32 public:
34 ffi::Array<tvm::tirx::TensorVar> root_alloc_tensors;
37
38 static void RegisterReflection() {
39 namespace refl = tvm::ffi::reflection;
40 refl::ObjectDef<FunctionFrameObj>()
41 .def_ro("root_alloc_tensors", &FunctionFrameObj::root_alloc_tensors)
42 .def_ro("root_allocated_addresses", &FunctionFrameObj::root_allocated_addresses);
43 }
44 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.ir_builder.s_tir.FunctionFrame", FunctionFrameObj,
48 ffi::Array<PrimExpr> allocated_addr);
50};
51
53 public:
54 explicit FunctionFrame(ffi::ObjectPtr<FunctionFrameObj> data)
55 : tirx::FunctionFrame(std::move(data)) {}
58};
59
66 public:
68 ffi::String name;
70 ffi::Array<tvm::s_tir::IterVar> iter_vars;
72 ffi::Optional<ffi::Array<tvm::TensorRegion>> reads;
74 ffi::Optional<ffi::Array<tvm::TensorRegion>> writes;
76 ffi::Optional<tvm::SeqStmt> init;
78 ffi::Array<tvm::tirx::TensorVar> alloc_tensors;
80 ffi::Array<tvm::s_tir::MatchTensorRegion> match_tensors;
84 ffi::Optional<ffi::Map<ffi::String, Any>> annotations;
86 ffi::Array<PrimExpr> iter_values;
91 ffi::Optional<PrimExpr> predicate;
94
95 static void RegisterReflection() {
96 namespace refl = tvm::ffi::reflection;
97 refl::ObjectDef<SBlockFrameObj>()
98 .def_ro("name", &SBlockFrameObj::name)
99 .def_ro("iter_vars", &SBlockFrameObj::iter_vars)
100 .def_ro("reads", &SBlockFrameObj::reads)
101 .def_ro("writes", &SBlockFrameObj::writes)
102 .def_ro("init", &SBlockFrameObj::init)
103 .def_ro("alloc_tensors", &SBlockFrameObj::alloc_tensors)
104 .def_ro("match_tensors", &SBlockFrameObj::match_tensors)
105 .def_ro("allocated_addresses", &SBlockFrameObj::allocated_addresses)
106 .def_ro("annotations", &SBlockFrameObj::annotations)
107 .def_ro("iter_values", &SBlockFrameObj::iter_values)
108 .def_ro("predicate", &SBlockFrameObj::predicate)
109 .def_ro("no_realize", &SBlockFrameObj::no_realize);
110 }
111 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.ir_builder.s_tir.SBlockFrame", SBlockFrameObj,
113
114 public:
119 void ExitWithScope() final;
120};
121
128class SBlockFrame : public ir::StmtFrame {
129 public:
130 explicit SBlockFrame(ffi::ObjectPtr<SBlockFrameObj> data) : ir::StmtFrame(ffi::UnsafeInit{}) {
131 TVM_FFI_ICHECK(data != nullptr);
132 data_ = std::move(data);
133 }
135};
136
143 public:
144 static void RegisterReflection() {
145 namespace refl = tvm::ffi::reflection;
146 refl::ObjectDef<BlockInitFrameObj>();
147 }
148 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.ir_builder.s_tir.BlockInitFrame", BlockInitFrameObj,
150
151 public:
156 void EnterWithScope() final;
161 void ExitWithScope() final;
162};
163
169class BlockInitFrame : public ir::StmtFrame {
170 public:
171 explicit BlockInitFrame(ffi::ObjectPtr<BlockInitFrameObj> data)
172 : ir::StmtFrame(ffi::UnsafeInit{}) {
173 TVM_FFI_ICHECK(data != nullptr);
174 data_ = std::move(data);
175 }
177};
178
179} // namespace s_tir
180} // namespace ir_builder
181} // namespace script
182} // namespace tvm
183
184#endif // TVM_S_TIR_SCRIPT_IR_BUILDER_FRAME_H_
Managed reference to TensorRegionNode.
Definition expr.h:1079
A shared frame containing a sequence of core IR statements.
Definition frame.h:84
Managed reference to StmtFrameObj.
Definition frame.h:96
A frame that represents the block initialization statment.
Definition frame.h:142
static void RegisterReflection()
Definition frame.h:144
void EnterWithScope() final
The method called when entering RAII scope.
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.ir_builder.s_tir.BlockInitFrame", BlockInitFrameObj, ir::StmtFrameObj)
Managed reference to BlockInitFrameObj.
Definition frame.h:169
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(BlockInitFrame, ir::StmtFrame, BlockInitFrameObj)
BlockInitFrame(ffi::ObjectPtr< BlockInitFrameObj > data)
Definition frame.h:171
Function frame owning schedulable TIR construction.
Definition frame.h:31
ffi::Array< tvm::tirx::TensorVar > root_alloc_tensors
Tensors allocated in the implicit root block.
Definition frame.h:34
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.ir_builder.s_tir.FunctionFrame", FunctionFrameObj, tirx::FunctionFrameObj)
static void BindTensorRegion(tvm::tirx::TensorVar tensor, tvm::TensorRegion region, ffi::Array< PrimExpr > allocated_addr)
Register an alias in the current block, including standalone block construction.
tvm::tirx::Function FinalizeFunction(tvm::tirx::Function func) final
Complete dialect-specific function construction before publication.
static void RegisterReflection()
Definition frame.h:38
tvm::s_tir::TensorAllocatedAddresses root_allocated_addresses
Placement of allocations owned by the implicit root block.
Definition frame.h:36
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(FunctionFrame, tirx::FunctionFrame, FunctionFrameObj)
FunctionFrame(ffi::ObjectPtr< FunctionFrameObj > data)
Definition frame.h:54
A frame that represents the block.
Definition frame.h:65
ffi::Optional< PrimExpr > predicate
The predicate of the block realization, the block will only be executed when the predicate is true.
Definition frame.h:91
ffi::Array< PrimExpr > iter_values
The corresponding values of the iter vars.
Definition frame.h:86
ffi::Optional< ffi::Array< tvm::TensorRegion > > writes
The write tensor regions of the block.
Definition frame.h:74
bool no_realize
The flag whether to construct BlockRealize or Block.
Definition frame.h:93
ffi::Optional< ffi::Map< ffi::String, Any > > annotations
The annotation of the block.
Definition frame.h:84
tvm::s_tir::TensorAllocatedAddresses allocated_addresses
Placement attached to the block's allocations and aliases.
Definition frame.h:82
static void RegisterReflection()
Definition frame.h:95
ffi::Array< tvm::s_tir::MatchTensorRegion > match_tensors
The match tensor regions.
Definition frame.h:80
void ExitWithScope() final
The method called when exiting RAII scope.
ffi::String name
The name of the block.
Definition frame.h:68
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("script.ir_builder.s_tir.SBlockFrame", SBlockFrameObj, ir::StmtFrameObj)
ffi::Optional< ffi::Array< tvm::TensorRegion > > reads
The read tensor regions of the block.
Definition frame.h:72
ffi::Array< tvm::s_tir::IterVar > iter_vars
The variables of the block.
Definition frame.h:70
ffi::Array< tvm::tirx::TensorVar > alloc_tensors
The tensor allocated in the block.
Definition frame.h:78
ffi::Optional< tvm::SeqStmt > init
The init statement of the bolck.
Definition frame.h:76
Managed reference to SBlockFrameObj.
Definition frame.h:128
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(SBlockFrame, ir::StmtFrame, SBlockFrameObj)
SBlockFrame(ffi::ObjectPtr< SBlockFrameObj > data)
Definition frame.h:130
A frame that represents the Function containing TIR statements.
Definition frame.h:57
Managed reference to FunctionFrameObj.
Definition frame.h:114
Managed reference to FunctionNode.
Definition function.h:105
Checked zero-state view over an ordinary VarNode with TensorType.
Definition expr.h:50
ffi::Array< ffi::Tuple< Var, ffi::Array< PrimExpr > > > TensorAllocatedAddresses
Placement entries owned by a block, traversable with their tensor references.
Definition stmt.h:38
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
S-TIR (Schedulable TIR) statements and attributes.