Tile Primitives#
Note
This page documents the tile-primitive surface and dispatch as it exists in the source today; signatures and variants may change.
Tile primitives are the dispatchable, hardware-level operations a TIRx kernel
issues — data movement (copy, copy_async), matrix multiply (gemm,
gemm_async), reductions, elementwise math, and a few fused/compose forms.
A primitive call is recorded as an unresolved TilePrimitiveCall IR node;
the compiler later dispatches it — selecting a concrete lowering from the
primitive, the execution scope, the operand layouts, the target, and an optional
explicit hint — and replaces it with native IR (loops, address arithmetic,
synchronization, and backend intrinsics).
Calling convention#
The examples use one TIRx dialect alias and reach tile primitives through its
tile namespace:
from tvm.script import tirx as Tx
Tx is an ordinary Python module alias, not an injected language keyword.
Under Tx.tile, the next namespace prefix selects the cooperation
scope:
Tx.tile.<name>(...)— unqualified, runs at thread scope.Tx.tile.warp.<name>/Tx.tile.wg.<name>(aliasTx.tile.warpgroup) /Tx.tile.cta.<name>/Tx.tile.cluster.<name>/Tx.tile.thread.<name>— bind a wider scope.
Most primitive constructors also carry workspace: dict[str, Buffer] | None,
dispatch: str | None (force a named lowering variant), and **kwargs
collected into a config dict that tunes the chosen lowering. ScopedOp
fills the underlying scope argument from the namespace prefix; select a
scope with Tx.tile.warp / Tx.tile.wg / Tx.tile.cta rather than
passing it to the callable directly. Operands are Buffer / BufferRegion
values, each carrying a TileLayout that dispatch reads.
Primitive catalog#
The C++ registry currently defines 31 operation names. This programming guide
groups them by purpose; the API reference lists their current
Python callables and explains the internal scope parameter exposed by
introspection.
Group |
Operations |
Purpose |
|---|---|---|
Data movement |
|
synchronous and asynchronous transfer, or rearrangement between layouts |
Matrix multiply |
|
synchronous register MMA or asynchronous/backend-specific MMA, including block scaling where supported |
Initialization |
|
initialize a tile or region |
Unary and cast |
|
per-element conversion or unary math |
Binary and ternary |
|
per-element arithmetic and selection |
Reductions |
|
reduce selected axes, optionally accumulating into the destination |
Fused and composed |
|
combine several primitive operations for backends that dispatch them as one unit |
Dispatch config#
A call is materialized as a TilePrimitiveCall node whose fields carry
everything dispatch needs (python/tvm/tirx/tile_primitive.py):
Field |
Type |
Meaning |
|---|---|---|
|
|
primitive identity, e.g. |
|
|
operands (regions / scalars), in the order shown above |
|
|
pre-allocated scratch buffers |
|
|
open-ended tuning bag (table below) |
|
|
forced variant name; |
|
|
cooperation scope (default |
config has no central schema. Each dispatch implementation defines and
interprets the keys it consumes. Some implementations ignore unrelated keys,
while others (notably the TMA variants) reject unknown keys. Only dispatch
is interpreted generically by the dispatcher. The current target
implementations consume the following keys:
Primitive / variant |
Keys consumed |
Notes |
|---|---|---|
|
|
Explicit, thread-scope fixed-width copies. Cache controls require a global-memory source. |
|
|
|
|
|
|
|
|
Both are required: the destination CTA id and its completion barrier. |
|
|
|
|
|
|
|
|
Enables the per-thread shuffle-reduction mode where supported. |
binary elementwise: |
|
Passed to packed floating-point forms that expose a rounding mode. |
Trainium tile implementations |
|
Instruction-size limit used by copy, elementwise, select, reduction, and composed-op implementations. |
Vector widths selected by vec_auto and ldgsts are derived internally
from dtype, alignment, layout, and execution scope; vec_len is not a user
configuration key.
Three dispatch inputs are implicit, not config keys: the execution scope
(set by the namespace, then refined against the active thread set tracked through
control flow into inter/intra maps and a scope_kind), the operand
layouts (each Buffer.layout), and the target (the dispatch table is
keyed by its kind, e.g. "cuda").
See also#
Tensor Layout — the
TileLayoutmodel dispatch reads from operands.Tile Primitive Authoring API — current
Tx.tile.*callables and introspected signatures.Tile Primitive Dispatch — dispatch selection, extension points, and the target-specific variants for each primitive.
Overview — execution scope, tensor layout, and tile primitive dispatch as the three core constructs.