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/base.h>
27#include <tvm/ffi/optional.h>
28#include <tvm/ir/cow.h>
29#include <tvm/ir/expr.h>
30
31namespace tvm {
32namespace s_tir {
40enum IterVarType : int {
83 // The following are possible additional
84 // types that are provided during schedule
100 kTensorized = 8
102
109class IterVarObj : public OpaqueExprObj {
110 public:
111 explicit IterVarObj(ffi::UnsafeInit tag) : var(tag) {}
112
113 explicit IterVarObj(PrimVar var) : var(std::move(var)) { ty = this->var.ty(); }
114
119 ffi::Optional<Range> dom;
128 ffi::String thread_tag;
129 static void RegisterReflection() {
130 namespace refl = tvm::ffi::reflection;
131 refl::ObjectDef<IterVarObj>()
132 .def_ro("dom", &IterVarObj::dom)
133 .def_ro("var", &IterVarObj::var, refl::AttachFieldFlag::SEqHashDefSimple())
134 .def_ro("iter_type", &IterVarObj::iter_type)
135 .def_ro("thread_tag", &IterVarObj::thread_tag);
136 }
137
138 static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindTreeNode;
140};
141
148class IterVar : public PrimExpr {
149 public:
150 TVM_DLL IterVar(ffi::Optional<Range> dom, PrimVar var, IterVarType iter_type,
151 ffi::String thread_tag = "", Location loc = UnknownLoc());
152
153 explicit IterVar(ffi::ObjectPtr<IterVarObj> node) : PrimExpr(std::move(node)) {}
154
156 static constexpr bool _type_container_is_exact = true;
158};
159
160inline const char* IterVarType2String(IterVarType t) {
161 switch (t) {
162 case kDataPar:
163 return "DataPar";
164 case kThreadIndex:
165 return "ThreadIndex";
166 case kCommReduce:
167 return "CommReduce";
168 case kOrdered:
169 return "Ordered";
170 case kOpaque:
171 return "Opaque";
172 case kUnrolled:
173 return "Unrolled";
174 case kVectorized:
175 return "Vectorized";
176 case kParallelized:
177 return "Parallelized";
178 case kTensorized:
179 return "Tensorized";
180 }
181 return "Unknown";
182}
183} // namespace s_tir
184} // namespace tvm
185
186namespace std {
187template <>
188struct hash<::tvm::s_tir::IterVar> : public ::tvm::ffi::ObjectPtrHash {};
189} // namespace std
190
191#endif // TVM_S_TIR_ITER_VAR_H_
Base expr nodes in TVM.
Type ty
The deduced or annotated type of the expression.
Definition expr.h:80
Non-nullable source-location metadata.
Definition location.h:91
Base node for opaque construction-time expressions.
Definition expr.h:136
Typed reference/view over any Expr whose ExprObj::ty is PrimType.
Definition expr.h:187
Checked scalar view over a VarObj.
Definition expr.h:598
ExpectedType ty() const
Definition expr.h:164
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:109
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:128
static void RegisterReflection()
Definition iter_var.h:129
IterVarObj(PrimVar var)
Definition iter_var.h:113
IterVarType iter_type
The type of the IterVar.
Definition iter_var.h:123
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition iter_var.h:138
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.IterVar", IterVarObj, OpaqueExprObj)
ffi::Optional< Range > dom
the domain of iteration, if known, can be None For the intermediate schedule node,...
Definition iter_var.h:119
IterVarObj(ffi::UnsafeInit tag)
Definition iter_var.h:111
PrimVar var
The looping variable.
Definition iter_var.h:121
Iteration Variable, represents an iteration over an integer interval.
Definition iter_var.h:148
IterVar(ffi::ObjectPtr< IterVarObj > node)
Definition iter_var.h:153
TVM_DEFINE_OBJECT_REF_COW_METHOD(IterVarObj)
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:156
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(IterVar, PrimExpr, IterVarObj)
Copy-on-write helper macro for IR ffi::ObjectRef types.
Parent compiler symbol visibility.
const char * IterVarType2String(IterVarType t)
Definition iter_var.h:160
IterVarType
Type of iteration variable. Each IterVar have a specific type.
Definition iter_var.h:40
@ kOrdered
Serial loops with loop carry dependency, the iteration must execute in order. Cannot be re-ordered.
Definition iter_var.h:72
@ kTensorized
Marks boundary of tensorization intrinsic.
Definition iter_var.h:100
@ kThreadIndex
The IterVar itself is a thread-index of a fixed thread launching group. Note that this is already ass...
Definition iter_var.h:57
@ kParallelized
The loop is parallelized.
Definition iter_var.h:96
@ kCommReduce
Communicative reduction. Cannot be directly parallelized.
Definition iter_var.h:64
@ kOpaque
IterVar is opaque,.
Definition iter_var.h:82
@ kDataPar
Data parallel iteration. This normally corresponds to axis of Tensor. Allow all IterVar manipulations...
Definition iter_var.h:49
@ kUnrolled
The execution is unrolled.
Definition iter_var.h:88
@ kVectorized
The loop is vectorized.
Definition iter_var.h:92
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analysis.h:41