27#ifndef TVM_S_TIR_STMT_H_
28#define TVM_S_TIR_STMT_H_
31#include <tvm/ffi/container/tuple.h>
63 namespace refl = tvm::ffi::reflection;
64 refl::ObjectDef<MatchTensorRegionObj>()
80 : ffi::ObjectRef(tag) {
81 data_ = std::move(data);
144 namespace refl = tvm::ffi::reflection;
145 refl::ObjectDef<SBlockObj>()
151 refl::AttachFieldFlag::SEqHashDefSimple())
167 ffi::Array<s_tir::IterVar> iter_vars, ffi::Array<TensorRegion> reads,
168 ffi::Array<TensorRegion> writes, ffi::String name_hint,
SeqStmt body,
169 ffi::Optional<SeqStmt> init = std::nullopt,
170 ffi::Array<tirx::TensorVar> alloc_tensors = ffi::Array<tirx::TensorVar>(),
171 ffi::Array<MatchTensorRegion> match_tensors = ffi::Array<MatchTensorRegion>(),
172 ffi::Map<ffi::String, ffi::Any> annotations = ffi::Map<ffi::String, ffi::Any>(),
176 ffi::Array<tirx::TensorVar> alloc_tensors = ffi::Array<tirx::TensorVar>(),
179 explicit SBlock(ffi::ObjectPtr<SBlockObj> node) :
Stmt(std::move(node)) {}
206 namespace refl = tvm::ffi::reflection;
207 refl::ObjectDef<SBlockRealizeObj>()
241inline constexpr ffi::reflection::AttrKey<ffi::String>
kThreadBinding{
"thread_binding"};
252inline constexpr ffi::reflection::AttrKey<ffi::String>
kFragmentShape{
"fragment_shape"};
257inline constexpr ffi::reflection::AttrKey<ffi::String>
kFragmentLayout{
"fragment_layout"};
270 "meta_schedule.tiling_structure"};
277 "meta_schedule.cooperative_fetch"};
281 "meta_schedule.thread_extent_low_inclusive"};
285 "meta_schedule.thread_extent_high_inclusive"};
289 "meta_schedule.random_compute_producer"};
296 "meta_schedule.vectorize"};
300 "meta_schedule.unroll_explicit"};
304 "meta_schedule.unroll_implicit"};
308 "meta_schedule.auto_tensorize"};
312 "meta_schedule.layout_rewrite_preproc"};
318 "meta_schedule.auto_tensorize_init"};
322 "meta_schedule.inline_rule"};
330 "s_tir.tensor_allocated_addr"};
340 "tirx.script_parsing_detect_access"};
349 "software_pipeline_stage"};
353 "software_pipeline_order"};
360 "software_pipeline_async_stages"};
364 "tirx.manifest_shared_memory_local_stage"};
372inline constexpr ffi::reflection::AttrKey<
373 ffi::Array<ffi::Tuple<int32_t, int32_t, int32_t, int32_t>>>
380 "explicit_read_region"};
386 "explicit_write_region"};
392inline constexpr ffi::reflection::AttrKey<int64_t>
kAutoCopy{
"auto_copy"};
395inline constexpr ffi::reflection::AttrKey<int64_t>
kLocalStage{
"local_stage"};
398inline constexpr ffi::reflection::AttrKey<int64_t>
kVectorBytes{
"vector_bytes"};
404inline constexpr ffi::reflection::AttrKey<int64_t>
kWarpExecution{
"warp_execution"};
408inline constexpr ffi::reflection::AttrKey<ffi::String>
kScheduleRule{
"schedule_rule"};
411 "s_tir.meta_schedule.write_cache_level"};
419 <<
"thread_binding requires a parallel loop";
420 TVM_FFI_CHECK(tag->as<ffi::String>().has_value(), TypeError)
421 <<
"thread_binding annotation must be a string";
422 TVM_FFI_CHECK(loop->
HasTrivialStep(), ValueError) <<
"Thread binding loops require a unit step";
423 return tag->cast<ffi::String>();
TIRx statements and shared statement entry header.
A for loop, with possible type annotations.
Definition stmt.h:471
ffi::Map< ffi::String, ffi::Any > annotations
Additional annotations about the loop.
Definition stmt.h:501
ForKind kind
The kind of the for loop.
Definition stmt.h:492
TVM_TIRX_DLL bool HasTrivialStep() const
Check it is a loop without nontrivial loop step.
Managed reference to ForObj.
Definition stmt.h:527
Non-nullable source-location metadata.
Definition location.h:91
Reference-counted handle to a canonical named operator.
Definition op.h:140
Typed reference/view over any Expr whose ExprObj::ty is PrimType.
Definition expr.h:187
Sequence statement.
Definition stmt.h:91
Base node of all statements.
Definition stmt.h:37
Container of all statements.
Definition stmt.h:61
Managed reference to TensorRegionObj.
Definition expr.h:944
Reference to the shared immutable unknown location.
Definition location.h:105
Match introduces a constraint that the source tensor region can be remapped to the data layout specif...
Definition stmt.h:50
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition stmt.h:69
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.MatchTensorRegion", MatchTensorRegionObj, ffi::Object)
static void RegisterReflection()
Definition stmt.h:62
tirx::TensorVar tensor
The target tensor.
Definition stmt.h:58
MatchTensorRegionObj(tirx::TensorVar tensor, TensorRegion source)
Definition stmt.h:54
TensorRegion source
The source tensor region.
Definition stmt.h:60
MatchTensorRegionObj(ffi::UnsafeInit tag)
Definition stmt.h:52
Managed reference to MatchTensorRegionObj.
Definition stmt.h:77
MatchTensorRegion(tirx::TensorVar tensor, TensorRegion source)
TVM_DEFINE_OBJECT_REF_COW_METHOD(MatchTensorRegionObj)
MatchTensorRegion(ffi::UnsafeInit tag, ffi::ObjectPtr< MatchTensorRegionObj > data)
Definition stmt.h:79
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(MatchTensorRegion, ffi::ObjectRef, MatchTensorRegionObj)
A block is a basic schedule unit in TIR.
Definition stmt.h:112
SBlockObj(SeqStmt body)
Definition stmt.h:116
static void RegisterReflection()
Definition stmt.h:143
ffi::Array< MatchTensorRegion > match_tensors
The match tensor regions.
Definition stmt.h:129
ffi::Array< tirx::TensorVar > alloc_tensors
The tensor allocated in the block.
Definition stmt.h:127
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.SBlock", SBlockObj, StmtObj)
SBlockObj(ffi::UnsafeInit tag)
Definition stmt.h:114
SeqStmt body
The body of the block.
Definition stmt.h:141
ffi::Array< TensorRegion > writes
The write tensor regions of the block.
Definition stmt.h:123
ffi::Array< s_tir::IterVar > iter_vars
The variables of the block.
Definition stmt.h:119
ffi::String name_hint
The name_hint of the block.
Definition stmt.h:125
ffi::Map< ffi::String, ffi::Any > annotations
The annotation of the block.
Definition stmt.h:131
ffi::Optional< SeqStmt > init
The init statement is executed during the first iteration of reduction loops in a reduction block....
Definition stmt.h:139
ffi::Array< TensorRegion > reads
The read tensor regions of the block.
Definition stmt.h:121
A block realization node represents execution of the block at the binding values.
Definition stmt.h:188
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.SBlockRealize", SBlockRealizeObj, StmtObj)
PrimExpr predicate
The predicate of the block realization, the block will only be executed when the predicate is true.
Definition stmt.h:201
ffi::Array< PrimExpr > iter_values
The corresponding values of the iter vars.
Definition stmt.h:196
SBlockRealizeObj(ffi::UnsafeInit tag)
Definition stmt.h:190
SBlockRealizeObj(PrimExpr predicate, SBlock block)
Definition stmt.h:192
static void RegisterReflection()
Definition stmt.h:205
SBlock block
The block to be realized.
Definition stmt.h:203
Managed reference to BlockRealizeNode.
Definition stmt.h:219
SBlockRealize(ffi::ObjectPtr< SBlockRealizeObj > node)
Definition stmt.h:224
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(SBlockRealize, Stmt, SBlockRealizeObj)
TVM_DEFINE_OBJECT_REF_COW_METHOD(SBlockRealizeObj)
SBlockRealize(ffi::Array< PrimExpr > iter_values, PrimExpr predicate, SBlock block, Location loc=UnknownLoc())
Managed reference to SBlockObj.
Definition stmt.h:164
SBlock(ffi::Array< s_tir::IterVar > iter_vars, ffi::Array< TensorRegion > reads, ffi::Array< TensorRegion > writes, ffi::String name_hint, SeqStmt body, ffi::Optional< SeqStmt > init=std::nullopt, ffi::Array< tirx::TensorVar > alloc_tensors=ffi::Array< tirx::TensorVar >(), ffi::Array< MatchTensorRegion > match_tensors=ffi::Array< MatchTensorRegion >(), ffi::Map< ffi::String, ffi::Any > annotations=ffi::Map< ffi::String, ffi::Any >(), Location loc=UnknownLoc())
SBlock(ffi::ObjectPtr< SBlockObj > node)
Definition stmt.h:179
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(SBlock, Stmt, SBlockObj)
SBlock(ffi::String name_hint, SeqStmt body, ffi::Array< tirx::TensorVar > alloc_tensors=ffi::Array< tirx::TensorVar >(), Location loc=UnknownLoc())
TVM_DEFINE_OBJECT_REF_COW_METHOD(SBlockObj)
Checked zero-state view over an ordinary VarObj with TensorType.
Definition expr.h:48
Parent compiler symbol visibility.
Axis metadata for schedulable tensor computations.
constexpr ffi::reflection::AttrKey< int64_t > kMetaScheduleThreadExtentLowInclusive
The allowed range of thread extent in thread bindings.
Definition stmt.h:280
constexpr ffi::reflection::AttrKey< ffi::Array< int64_t > > kExplicitWriteRegion
Mark that a block has an explicitly specified write region. This is used to override the default writ...
Definition stmt.h:385
constexpr ffi::reflection::AttrKey< ffi::Array< int64_t > > kMetaScheduleWriteCacheLevel
Definition stmt.h:410
constexpr ffi::reflection::AttrKey< PrimExpr > kLoopPartitionHint
For annotation requesting partitioning when its PrimExpr value is provably true.
Definition stmt.h:262
constexpr ffi::reflection::AttrKey< int64_t > kManifestSharedMemoryLocalStage
Mark the local stage for the shared memory access should be added.
Definition stmt.h:363
constexpr ffi::reflection::AttrKey< int64_t > kMetaScheduleUnrollExplicit
Mark auto-unroll setting on the block.
Definition stmt.h:299
constexpr ffi::reflection::AttrKey< ffi::String > kMetaScheduleAutoTensorize
Mark that a block should be further rewritten using tensorization.
Definition stmt.h:307
constexpr ffi::reflection::AttrKey< int64_t > kLocalStage
Mark local stage constraint on data copy.
Definition stmt.h:395
constexpr ffi::reflection::AttrKey< ffi::String > kThreadBinding
Hardware thread axis bound to a parallel loop during S-TIR scheduling.
Definition stmt.h:241
constexpr ffi::reflection::AttrKey< ffi::Array< int64_t > > kExplicitReadRegion
Mark that a block has an explicitly specified read region. This is used to override the default read ...
Definition stmt.h:379
constexpr ffi::reflection::AttrKey< ffi::Array< int64_t > > kSoftwarePipelineAsyncStages
List stages in the software pipeline that should run asynchronously.
Definition stmt.h:359
constexpr ffi::reflection::AttrKey< int64_t > kIrregularLoopMark
,ark a ForObj represent an irregular loop of non-structural control flow edges.
Definition stmt.h:389
constexpr ffi::reflection::AttrKey< int64_t > kAutoCopy
Mark auto copy for memhammer.
Definition stmt.h:392
constexpr ffi::reflection::AttrKey< ffi::String > kMetaScheduleTilingStructure
Mark the tiling structure of blocks that are applied by rule Multi-Level-Tiling.
Definition stmt.h:269
constexpr ffi::reflection::AttrKey< ffi::Array< int64_t > > kSoftwarePipelineOrder
Mark the order of a statement in the software pipeline.
Definition stmt.h:352
constexpr ffi::reflection::AttrKey< int64_t > kDoubleBufferScope
SBlock annotation selecting a write-tensor index for double buffering in InjectSoftwarePipeline.
Definition stmt.h:247
constexpr ffi::reflection::AttrKey< int64_t > kScriptParsingDetectAccess
Mark whether the script-completer need to fill in missing access region during script parsing.
Definition stmt.h:339
constexpr ffi::reflection::AttrKey< ffi::String > kScheduleRule
Definition stmt.h:408
constexpr ffi::reflection::AttrKey< int64_t > kVectorBytes
Mark vectorization length constraint on block.
Definition stmt.h:398
constexpr ffi::reflection::AttrKey< ffi::String > kMetaScheduleInlineRule
Mark that a block is disallowed in auto inline.
Definition stmt.h:321
constexpr ffi::reflection::AttrKey< TensorAllocatedAddresses > kTensorAllocatedAddr
TensorAllocatedAddresses for block-owned allocations and match tensors.
Definition stmt.h:329
constexpr ffi::reflection::AttrKey< int64_t > kMetaScheduleVectorize
Mark auto-vectorize setting on the block.
Definition stmt.h:295
constexpr ffi::reflection::AttrKey< ffi::String > kMetaScheduleAutoTensorizeInit
Mark that the init statement of a block should be further rewritten using tensorization.
Definition stmt.h:317
constexpr ffi::reflection::AttrKey< ffi::Array< ffi::Tuple< int32_t, int32_t, int32_t, int32_t > > > kTensorDimAlign
Mark alignment of tensor dimension The annotation value is an array of explicit tuples (tensor_index,...
Definition stmt.h:374
constexpr ffi::reflection::AttrKey< int64_t > kMetaScheduleParallel
Mark auto-parallel setting on the block.
Definition stmt.h:292
constexpr ffi::reflection::AttrKey< int64_t > kMetaScheduleUnrollImplicit
Mark auto-unroll setting on the block.
Definition stmt.h:303
constexpr ffi::reflection::AttrKey< int64_t > kWarpExecution
Mark that a block is executed by a warp. This implies the extend of threadIdx.x is warp size.
Definition stmt.h:404
constexpr ffi::reflection::AttrKey< int64_t > kMetaScheduleRandomComputeProducer
Mark the block whose producer needs to be applied by rule Random-Compute-Location.
Definition stmt.h:288
constexpr ffi::reflection::AttrKey< bool > kMetaScheduleLayoutRewritePreproc
Mark that a block is a preprocessor block for layout rewrite.
Definition stmt.h:311
constexpr ffi::reflection::AttrKey< ffi::String > kFragmentShape
String-valued allocation Call attribute containing the TensorCore fragment shape.
Definition stmt.h:252
constexpr ffi::reflection::AttrKey< int64_t > kMetaScheduleThreadExtentHighInclusive
The allowed range of thread extent in thread bindings.
Definition stmt.h:284
constexpr const char * kRequireBlockVarBoundPredicate
Mark that the block need to add predicate for block var bounds during lowering.
Definition stmt.h:345
constexpr ffi::reflection::AttrKey< ffi::String > kFragmentLayout
String-valued allocation Call attribute containing the TensorCore fragment layout.
Definition stmt.h:257
constexpr const char * kPermutedLayout
Definition stmt.h:406
constexpr ffi::reflection::AttrKey< int64_t > kMetaScheduleCooperativeFetch
Mark that the loop should be further skip and bound to environment threads to enable cooperative fetc...
Definition stmt.h:276
constexpr ffi::reflection::AttrKey< ffi::Array< int64_t > > kSoftwarePipelineStage
Mark the stage of a statement in the software pipeline.
Definition stmt.h:348
const Op & async_commit()
Commit the preceding asynchronous copies to a queue.
const Op & async_copy_scope()
Region marking copies eligible for asynchronous lowering.
const Op & manual_sync()
Region whose author manages cross-thread synchronization explicitly.
const Op & async_wait()
Wait until at most the given number of committed groups remain in flight.
ffi::Array< ffi::Tuple< Var, ffi::Array< PrimExpr > > > TensorAllocatedAddresses
Placement entries owned by a block, traversable with their tensor references.
Definition stmt.h:39
ffi::Optional< ffi::String > GetThreadBinding(const ForObj *loop)
Interpret and validate S-TIR thread placement on a shared loop.
Definition stmt.h:416
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analysis.h:41
@ kParallel
Parallel execution.