tvm
Loading...
Searching...
No Matches
iter_var.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
23#ifndef TVM_S_TIR_ITER_VAR_H_
24#define TVM_S_TIR_ITER_VAR_H_
25
26#include <tvm/ffi/optional.h>
27#include <tvm/ir/cow.h>
28#include <tvm/ir/expr.h>
29
30namespace tvm {
31namespace s_tir {
39enum IterVarType : int {
82 // The following are possible additional
83 // types that are provided during schedule
99 kTensorized = 8
101
109 public:
110 explicit IterVarNode(ffi::UnsafeInit tag) : var(tag) {}
111
112 explicit IterVarNode(PrimVar var) : var(std::move(var)) { ty = this->var.ty(); }
113
118 ffi::Optional<Range> dom;
127 ffi::String thread_tag;
128 static void RegisterReflection() {
129 namespace refl = tvm::ffi::reflection;
130 refl::ObjectDef<IterVarNode>()
131 .def_ro("dom", &IterVarNode::dom)
132 .def_ro("var", &IterVarNode::var, refl::AttachFieldFlag::SEqHashDefSimple())
133 .def_ro("iter_type", &IterVarNode::iter_type)
134 .def_ro("thread_tag", &IterVarNode::thread_tag);
135 }
136
137 static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindTreeNode;
139};
140
147class IterVar : public PrimExpr {
148 public:
149 TVM_DLL IterVar(ffi::Optional<Range> dom, PrimVar var, IterVarType iter_type,
150 ffi::String thread_tag = "", Location loc = UnknownLoc());
151
152 explicit IterVar(ffi::ObjectPtr<IterVarNode> node) : PrimExpr(std::move(node)) {}
153
155 static constexpr bool _type_container_is_exact = true;
157};
158
159inline const char* IterVarType2String(IterVarType t) {
160 switch (t) {
161 case kDataPar:
162 return "DataPar";
163 case kThreadIndex:
164 return "ThreadIndex";
165 case kCommReduce:
166 return "CommReduce";
167 case kOrdered:
168 return "Ordered";
169 case kOpaque:
170 return "Opaque";
171 case kUnrolled:
172 return "Unrolled";
173 case kVectorized:
174 return "Vectorized";
175 case kParallelized:
176 return "Parallelized";
177 case kTensorized:
178 return "Tensorized";
179 }
180 return "Unknown";
181}
182} // namespace s_tir
183} // namespace tvm
184
185namespace std {
186template <>
187struct hash<::tvm::s_tir::IterVar> : public ::tvm::ffi::ObjectPtrHash {};
188} // namespace std
189
190#endif // TVM_S_TIR_ITER_VAR_H_
Type ty
The deduced or annotated type of the expression.
Definition base_expr.h:338
Non-nullable source-location metadata.
Definition location.h:91
Base node for opaque construction-time expressions.
Definition base_expr.h:394
Typed reference/view over any Expr whose ExprNode::ty is PrimType.
Definition base_expr.h:447
Checked scalar view over a VarNode.
Definition expr.h:742
ExpectedType ty() const
Definition base_expr.h:424
Reference to the shared immutable unknown location.
Definition location.h:105
An iteration variable representing an iteration over a one dimensional interval.
Definition iter_var.h:108
PrimVar var
The looping variable.
Definition iter_var.h:120
static void RegisterReflection()
Definition iter_var.h:128
IterVarType iter_type
The type of the IterVar.
Definition iter_var.h:122
IterVarNode(ffi::UnsafeInit tag)
Definition iter_var.h:110
IterVarNode(PrimVar var)
Definition iter_var.h:112
ffi::String thread_tag
additional tag on the iteration variable, set this if this is bound already to a known thread tag.
Definition iter_var.h:127
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition iter_var.h:137
ffi::Optional< Range > dom
the domain of iteration, if known, can be None For the intermediate schedule node,...
Definition iter_var.h:118
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.IterVar", IterVarNode, OpaqueExprNode)
Iteration Variable, represents an iteration over an integer interval.
Definition iter_var.h:147
IterVar(ffi::ObjectPtr< IterVarNode > node)
Definition iter_var.h:152
TVM_DEFINE_OBJECT_REF_COW_METHOD(IterVarNode)
IterVar(ffi::Optional< Range > dom, PrimVar var, IterVarType iter_type, ffi::String thread_tag="", Location loc=UnknownLoc())
static constexpr bool _type_container_is_exact
Definition iter_var.h:155
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(IterVar, PrimExpr, IterVarNode)
Copy-on-write helper macro for IR ffi::ObjectRef types.
Base expr nodes in TVM.
const char * IterVarType2String(IterVarType t)
Definition iter_var.h:159
IterVarType
Type of iteration variable. Each IterVar have a specific type.
Definition iter_var.h:39
@ kOrdered
Serial loops with loop carry dependency, the iteration must execute in order. Cannot be re-ordered.
Definition iter_var.h:71
@ kTensorized
Marks boundary of tensorization intrinsic.
Definition iter_var.h:99
@ kThreadIndex
The IterVar itself is a thread-index of a fixed thread launching group. Note that this is already ass...
Definition iter_var.h:56
@ kParallelized
The loop is parallelized.
Definition iter_var.h:95
@ kCommReduce
Communicative reduction. Cannot be directly parallelized.
Definition iter_var.h:63
@ kOpaque
IterVar is opaque,.
Definition iter_var.h:81
@ kDataPar
Data parallel iteration. This normally corresponds to axis of Tensor. Allow all IterVar manipulations...
Definition iter_var.h:48
@ kUnrolled
The execution is unrolled.
Definition iter_var.h:87
@ kVectorized
The loop is vectorized.
Definition iter_var.h:91
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23