tilelang.language.loopΒΆ
Loop related language interfaces in TileLang.
FunctionsΒΆ
|
Tools to construct nested parallel for loop. |
|
Tools to construct persistent for loop. |
|
Tools to construct pipelined for loop. |
|
The serial For statement. |
|
The unrolled For statement. |
|
Alias of T.serial. |
|
Alias of T.unroll. |
|
The vectorized For statement. |
|
Alias of T.vectorized. |
Module ContentsΒΆ
- tilelang.language.loop.Parallel(*extents, coalesced_width=None, loop_layout=None, prefer_async=None, annotations=None)ΒΆ
- Tools to construct nested parallel for loop.
This can be used to create element-wise tensor expression.
- Parameters:
extents (PrimExpr) β The extents of the iteration.
coalesced_width (Optional[int]) β The coalesced width of the parallel loop.
loop_layout (to the outermost generated loop only. If you omit) β A layout annotation for the parallel loop nest, expressed as a
T.Fragment. When provided, it is attached as the"parallel_loop_layout"annotation on the outermost parallel loop. For a k-dimensionalT.Parallel(...)nest, the fragmentβsInputDimmust equalk.prefer_async (Optional[bool]) β Optional hint for PTX async-copy rewrite in this parallel loop subtree. When set to
True, it requests cp.async injection even outside pipelined loops.False/Nonekeeps default behavior. Internally lowered as loop annotation"parallel_prefer_async".annotations (Optional[Dict[str, Any]]) β Optional user-provided loop annotations attached to the outermost generated parallel loop. For example:
{"parallel_async_without_async_commit_wait": True}.constraints (Notes on layout)
---------------------------
during (TileLang validates parallel loop layout annotations)
ParallelLoopLayoutValidator. (tl.transform.LayoutInference with)
are (The key constraints)
after (- Every parallel loop must be covered by a layout annotation) β layout inference. For a nested parallel nest, this annotation must live on the outermost loop; inner parallel loops must not carry the layout annotation themselves.
k (- For a nest depth of) β
InputDim == k.satisfy (the layout must) β
InputDim == k.loop (- Violations (missing annotation on the outermost) β inner loops, or mismatched
InputDim) cause a compilation error.on (outermost loop can manage its inner nest. Therefore the layout is placed) β inner loops, or mismatched
InputDim) cause a compilation error.Rationale (inner loops cannot control/annotate their outer loops, while the)
on
region. (the outermost loop so lowering passes can rewrite the entire)
easy (To make this)
loop_layout
loop_layout
the (compiler will try to infer a valid layout and attach it during)
the
pass. (LayoutInference)
- Returns:
res β The ForFrame.
- Return type:
frame.ForFrame
- tilelang.language.loop.Persistent(domain, wave_size, index, group_size=8)ΒΆ
Tools to construct persistent for loop.
- Parameters:
domain (List[tirx.PrimExpr]) β The list of dominators.
wave_size (int) β The wave size.
index (int) β The tile index in one wave.
group_size (tirx.PrimExpr) β The group size.
- Return type:
tvm.tirx.script.builder.frame.ForFrame
- tilelang.language.loop.Pipelined(start, stop=None, num_stages=0, order=None, stage=None, sync=None, group=None)ΒΆ
Tools to construct pipelined for loop.
- Parameters:
start (PrimExpr) β The minimum value of iteration.
stop (PrimExpr) β The maximum value of iteration.
num_stages (int) β The max number of buffer used between pipeline producers and consumers. For compiler-inferred pipelines, if
num_stagesis 0, pipeline will not be enabled. For manually scheduled pipelines, prefer specifyingorderandstagewithoutnum_stages; the pipeline depth is inferred asmax(stage) + 1.order (Optional[List[int]]) β Optional manual emission order for scheduled statements in the loop body. This list should describe executable pipeline statements such as copies, fills, GEMMs, reductions, stores, waits, or commits.
stage (Optional[List[int]]) β Optional manual pipeline stage for each scheduled statement in the loop body. The list is aligned with
orderand follows the same statement counting rule.sync (Optional[List[List[int]]]) β Optional synchronization metadata for manual pipeline lowering.
group (Optional[List[List[int]]]) β Optional producer grouping metadata for manual pipeline lowering.
- Return type:
tvm.tirx.script.builder.frame.ForFrame
Notes
Replayable scalar
Bindstatements created by local aliases are not scheduled pipeline operations and should not consume entries inorderorstage. For example, in the body below only the copy and store need annotation entries;baseis replayed automatically at each use:for i in T.Pipelined(n, order=[1, 0], stage=[0, 1]): base: T.int32 = i * block T.copy(A[base], shared) T.copy(shared, B[base])
A replayable
Bindmay also read a buffer that is not written by the pipeline body, such asidx = Ids[i]. If aBindreads a buffer that is written inside the same pipeline body, it is kept as a scheduled statement because the load has a pipeline dependency and cannot be freely replayed.Older code that included replayable scalar
Bindentries inorder/stageis accepted for compatibility, but those entries are ignored by the pipeline passes. New code should annotate only the scheduled statements. Avoid settingnum_stagestogether with manualorder/stageunless you intentionally need an explicit depth override.- Returns:
res β The ForFrame.
- Return type:
frame.ForFrame
- Parameters:
start (tvm.tirx.PrimExpr)
stop (tvm.tirx.PrimExpr | None)
num_stages (int)
order (list[int] | None)
stage (list[int] | None)
sync (list[list[int]] | None)
group (list[list[int]] | None)
- tilelang.language.loop.serial(start, stop=None, step=None, *, annotations=None)ΒΆ
The serial For statement.
- Parameters:
start (PrimExpr) β The minimum value of iteration.
stop (PrimExpr) β The maximum value of iteration.
step (PrimExpr) β The step size of the iteration.
annotations (Dict[str, Any]) β The optional annotations of the For statement.
- Returns:
res β The ForFrame.
- Return type:
frame.ForFrame
- tilelang.language.loop.unroll(start, stop=None, step=None, *, explicit=False, unroll_factor=None, annotations=None)ΒΆ
The unrolled For statement.
- Parameters:
start (PrimExpr) β The minimum value of iteration.
stop (PrimExpr) β The maximum value of iteration.
step (PrimExpr) β The step size of the iteration.
explicit (bool) β Whether to explicitly unroll the loop.
unroll_factor (int) β The unroll factor of the loop.
annotations (Dict[str, Any]) β The optional annotations of the For statement.
- Returns:
res β The ForFrame.
- Return type:
frame.ForFrame
- tilelang.language.loop.Serial(start, stop=None, step=None, *, annotations=None)ΒΆ
Alias of T.serial.
- Parameters:
start (tvm.tirx.PrimExpr)
stop (tvm.tirx.PrimExpr | None)
step (tvm.tirx.PrimExpr | None)
annotations (dict[str, Any] | None)
- Return type:
tvm.tirx.script.builder.frame.ForFrame
- tilelang.language.loop.Unroll(start, stop=None, step=None, *, explicit=False, unroll_factor=None, annotations=None)ΒΆ
Alias of T.unroll.
- Parameters:
start (tvm.tirx.PrimExpr)
stop (tvm.tirx.PrimExpr | None)
step (tvm.tirx.PrimExpr | None)
explicit (bool)
unroll_factor (int | None)
annotations (dict[str, Any] | None)
- Return type:
tvm.tirx.script.builder.frame.ForFrame
- tilelang.language.loop.vectorized(start, stop=None, *, annotations=None)ΒΆ
The vectorized For statement.
- Parameters:
start (PrimExpr) β The minimum value of iteration.
stop (PrimExpr) β The maximum value of iteration.
annotations (Dict[str, Any]) β The optional annotations of the For statement.
- Returns:
res β The ForFrame.
- Return type:
frame.ForFrame
- tilelang.language.loop.Vectorized(start, stop=None, *, annotations=None)ΒΆ
Alias of T.vectorized.
- Parameters:
start (tvm.tirx.PrimExpr)
stop (tvm.tirx.PrimExpr | None)
annotations (dict[str, Any] | None)
- Return type:
tvm.tirx.script.builder.frame.ForFrame