pl.tile¶
Tile 级算子 —— 在 InCore 函数内接受并返回 pl.Tile 值的那一族。什么时候该用它们而不是 pl.* 或 pl.tensor.* 的对应物,见选择命名空间。
Tile operations for PyPTO Language DSL.
This module provides type-safe wrappers around pypto.ir.op.tile operations that accept and return Tile types instead of raw Expr/Call objects.
Accessed as pl.tile.*
MemRefType
¶
Opaque sentinel type for MemRef-typed variables in printed IR.
The C++ printer emits pl.MemRefType as the annotation for a bare
MemRef variable (the SSA-edge type of a MemRef expression). This
class exists solely so that the printed Python source is valid Python that
the text-parser can exec().
Note: this is not the type of a tile.alloc / tensor.alloc result —
those produce a base Ptr (PtrType); see alloc.
alloc(memory_space, size, *, pinned=False)
¶
Stub for the internal tile.alloc IR operation.
This function is never called in user-written DSL code. It is emitted
by the C++ python-printer after the InitMemRef / AllocateMemoryAddr
passes and must be importable so that the printed source is valid Python
that the text-parser can exec().
The result is a base Ptr (allocation identity token): the printer
annotates the assignment target as pl.Ptr, matching the IR design
where tile.alloc / tensor.alloc Calls carry PtrType.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
memory_space
|
MemorySpace
|
Target memory space (e.g. |
required |
size
|
int
|
Allocation size in bytes |
required |
pinned
|
bool
|
True when the author declared this allocation via a
one-argument |
False
|
Returns:
| Type | Description |
|---|---|
Ptr
|
Opaque |
Ptr
|
call in the AST and never invokes this stub) |
create_tile = create
module-attribute
¶
create(shape, dtype, target_memory=None, transpose=None, *, flat_layout=None, compact=None)
¶
Create a tile from a shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
Sequence[IntLike]
|
Shape of the tile |
required |
dtype
|
DataType
|
Data type of the tile |
required |
target_memory
|
MemorySpace | None
|
Target memory space (MemorySpace.Vec, .Mat, .Left, .Right).
|
None
|
transpose
|
bool | None
|
When True, allocate the transposed Mat (ZN) fractal layout for a
matmul |
None
|
flat_layout
|
bool | None
|
Keyword-only. When True, allocate a flat (non-fractal,
slayout=none_box) L1/cbuf tile — a contiguous staging buffer rather
than the boxed NZ layout Mat tiles normally carry. Requires
|
None
|
compact
|
bool | None
|
Keyword-only. Compiler-internal. Declares that this L0C buffer
holds a valid-region-packed product -- N-fractal pitch
|
None
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the create operation |
read(tile, indices)
¶
Read a scalar value from a tile at given indices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile |
required |
indices
|
IntLike | Sequence[IntLike]
|
A single index expression (for 1-D flat access) or a list of index expressions (one per tile dimension) |
required |
Returns:
| Type | Description |
|---|---|
Scalar
|
Scalar wrapping the read operation |
write(tile, indices, value)
¶
Write a scalar value into a tile at given indices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Destination tile |
required |
indices
|
IntLike | Sequence[IntLike]
|
A single index expression (for 1-D flat access) or a list of index expressions (one per tile dimension) |
required |
value
|
Scalar | Expr
|
Scalar value to write (DSL Scalar or raw Expr) |
required |
Returns:
| Type | Description |
|---|---|
Expr
|
The underlying |
Expr
|
typically ignore it; the DSL parser surfaces it as an |
load(tensor, offsets, shapes, valid_shape=None, target_memory=None, clamp=False, cache=None)
¶
Copy data from tensor to unified buffer (tile).
Only the valid extent is read, so the tile may be larger than the region that
exists in the source. The tile's valid region is the source's valid region,
shifted by offsets and cut to the tile — a load never reports source bytes
that do not exist as real data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tensor
|
Tensor
|
Source tensor |
required |
offsets
|
Sequence[IntLike]
|
Offsets in each dimension. Always in the source tensor's
coordinate system. Each element must be an integer scalar — a float
( |
required |
shapes
|
Sequence[IntLike]
|
Shape of the region to load in each dimension. Always in the
source tensor's coordinate system. Each element must be an integer
scalar, on the same terms as |
required |
valid_shape
|
Sequence[IntLike] | None
|
Valid shape of the tile in each dimension. When provided, sets
TileView.valid_shape in the output TileType. When omitted, shapes is used
as valid_shape. Uses the same coordinate convention as shapes. Narrows
the tile; cannot widen it past what the source has. Each element must
be an integer scalar — one extent per dimension, not a nested
|
None
|
target_memory
|
MemorySpace | None
|
Target memory space (MemorySpace.Vec or MemorySpace.Mat).
|
None
|
clamp
|
bool
|
Sanction a read that runs off the end of the source. By default a
load asserts |
False
|
cache
|
CachePolicy | None
|
GM cache-access policy for this read. |
None
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the load operation |
store(tile, offsets, output_tensor, shapes=None, *, atomic=AtomicType.None_, st_phase=STPhase.Unspecified)
¶
Copy data from tile back to tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Source tile |
required |
offsets
|
Sequence[IntLike]
|
Offsets in each dimension. Each element must be an integer scalar — a float or a nested sequence is rejected. |
required |
output_tensor
|
_TensorT
|
Output tensor |
required |
shapes
|
Sequence[IntLike] | None
|
Optional ND partition shape. Injected by FlattenTileNdTo2D for ND tensors.
Each element must be an integer scalar, on the same terms as |
None
|
atomic
|
AtomicType
|
Combine mode for the global-memory write. NOTE: atomic-add accumulation order across cores is not fixed, so floating-point results are non-deterministic. The destination must be zero-initialised before the kernel runs. Supported tile dtypes: fp32 / bf16 / fp16 / int32 / int16 / int8. bf16 atomic-add is available on the Ascend910B (A2/A3) profile; it is not supported on A5, where an fp32 accumulator + cast is required instead. |
None_
|
st_phase
|
STPhase
|
Consumer-side unit-flag phase. A producer that finishes with
|
Unspecified
|
Returns:
| Type | Description |
|---|---|
_TensorT
|
Tensor wrapping the store operation |
Example
2D store¶
result = store(tile, [0, 0], tensor)
3D store¶
result = store(tile, [0, 0, 0], tensor)
atomic-add store (split-K)¶
result = store(partial, [0, 0], out, atomic=pl.AtomicType.Add)
clear the unit flag after a final phased accumulation¶
result = store(acc, [0, 0], out, st_phase=pl.STPhase.Final)
assemble(target, source, offset)
¶
Write source tile data into target tile at specified offset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Tile
|
Target tile to update |
required |
source
|
Tile
|
Source tile to write |
required |
offset
|
Sequence[IntLike]
|
Offset dimensions for where to write |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the assemble operation |
gather_row(dst, src, dst_offset, src_offset, shapes, transpose=False, *, valid_shape=None)
¶
Load one GM row directly into a sub-region of an on-chip tile (DPS).
Per-row primitive of the paged-gather lowering: DMAs one GM row window
straight into dst at dst_offset (pto.subview of dst +
pto.tload, GM -> on-chip, no pto.tmov). The caller computes the
physical src_offset (block-table lookup + bias) and the dst_offset
slot itself, so arbitrary gather logic stays in the kernel. Writes dst
in place, so a loop-carried accumulator is filled row by row and feeds
pl.matmul directly — the tile-level counterpart of
pypto.language.op.tensor_ops.gather_row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dst
|
Tile
|
Destination on-chip accumulator tile (Mat/L1 or Vec/UB). |
required |
src
|
Tensor
|
Source pool in GM (a |
required |
dst_offset
|
Sequence[IntLike]
|
|
required |
src_offset
|
Sequence[IntLike]
|
|
required |
shapes
|
Sequence[IntLike]
|
GM row window shape |
required |
valid_shape
|
Sequence[IntLike] | None
|
How much of that window to actually transfer, defaulting to
all of it. May hold runtime |
None
|
transpose
|
bool
|
Place the GM row |
False
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile aliasing |
extract(src, index_row, index_col, shape, *, target_memory)
¶
Extract a sub-tile from src at (index_row, index_col) — ISA TEXTRACT.
Maps to ISA TEXTRACT Variant 1 (Standard Extract). The result tile has the
given static shape and lives in target_memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
Tile
|
Source tile (typically in Mat or Acc memory) |
required |
index_row
|
IntLike
|
Starting row offset |
required |
index_col
|
IntLike
|
Starting col offset |
required |
shape
|
Sequence[IntLike]
|
Static 2D shape of the extracted sub-tile |
required |
target_memory
|
MemorySpace
|
Destination memory space —
|
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile of the requested shape in |
scatter_update(input, *args, **kwargs)
¶
Update tile rows at positions specified by 2D index tile with values from src.
Supports two rank variants:
- 2D:
input [rows, d],src [b*s, d],index [b, s] - 4D:
input [blockNum, blockSize, 1, d],src [b, s, 1, d],index [b, s]
Accepts the same flexible call shapes as the IR builder
pypto.ir.op.tile.scatter_update:
scatter_update(input, dim, index, src)scatter_update(input, index, src, dim=-2)scatter_update(input, dim, index=..., src=...)
Tile / Scalar wrappers are unwrapped before forwarding so the IR builder
receives raw Expr operands.
concat(src0, src1)
¶
move(tile, target_memory, blayout=None, slayout=None)
¶
Move tile between memory levels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile |
required |
target_memory
|
MemorySpace
|
Target memory space (MemorySpace.Vec, .Mat, .Left, .Right, .LeftScale, .RightScale) |
required |
blayout
|
TileLayout | None
|
Optional block layout for the destination tile |
None
|
slayout
|
TileLayout | None
|
Optional scatter layout for the destination tile |
None
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the move operation |
aiv_shard(x, span=None)
¶
Bring a cube-produced operand onto the AIV lane (AIC -> AIV crossing).
In a data-parallel region (UP_DOWN / LEFT_RIGHT) the crossing also
halves the operand along the split axis, so each lane gets one half; in a
task-parallel mode=NONE region there is no split axis, so it crosses and
preserves the shape. Either way, writing it is how a C->V crossing into a
region is named — the AivSplitValid verifier rejects an unnamed one.
The split mode is inherited from the enclosing
for aiv_id in pl.split_aiv(mode=...) scope — it is not passed here.
This wrapper therefore only resolves inside a parsed kernel, where the
parser intercepts the call and fills the inherited mode. Calling it eagerly
(outside a parsed program) raises, since there is no scope to read the mode
from.
The operand may be a Tile (legacy @pl.program form -> tile.aiv_shard)
or a high-level Tensor (@pl.jit / pl.spmd form -> tensor.aiv_shard,
lowered 1:1 to tile.aiv_shard at ConvertTensorToTileOps). The Tensor form
is region-only. Distributed tensors are not supported.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
_SplitOperandT
|
Input operand (2D Tile or Tensor) |
required |
span
|
Span | None
|
Optional source span |
None
|
Returns:
| Type | Description |
|---|---|
_SplitOperandT
|
Operand of the same kind: the split axis halved in a data-parallel region, |
_SplitOperandT
|
the shape unchanged in a |
aic_gather(x, span=None)
¶
Hand a vector-produced operand to the cube (AIV -> AIC crossing).
Inverse of aiv_shard: in a data-parallel region it rejoins the two
lanes' halves along the split axis, and in a task-parallel mode=NONE region
it crosses and preserves the shape. It is how a V->C crossing out of a
region is named; an unnamed one is rejected by the AivSplitValid verifier.
Out of a mode=NONE region the two lanes share one destination slot with no
per-lane offset and nothing arbitrates between them: both push, so when they
hold different values the cube receives an unspecified one of the two.
Guarding the production of the value does not help — lane 1 still reaches
the push and still sends its own tile. Gather only a value both lanes agree
on; if they must contribute different data, use a data-parallel region.
Like aiv_shard, the split mode is
inherited from the enclosing for aiv_id in pl.split_aiv(mode=...)
scope and must not be passed here. Calling it eagerly (outside a parsed
program) raises, since there is no scope to read the mode from.
The operand may be a Tile (legacy @pl.program form -> tile.aic_gather)
or a high-level Tensor (@pl.jit / pl.spmd form -> tensor.aic_gather,
lowered 1:1 to tile.aic_gather at ConvertTensorToTileOps). The Tensor form
is region-only. Distributed tensors are not supported.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
_SplitOperandT
|
Input operand (2D Tile or Tensor) |
required |
span
|
Span | None
|
Optional source span |
None
|
Returns:
| Type | Description |
|---|---|
_SplitOperandT
|
Operand of the same kind: the split axis doubled in a data-parallel region, |
_SplitOperandT
|
the shape unchanged in a |
full(shape, dtype, value)
¶
Create a tile from a shape and fill with value in Vec.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
list[int]
|
Shape of the tile |
required |
dtype
|
DataType
|
Data type of the tile |
required |
value
|
int | float
|
filling scalar |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the full operation |
ci(start, shape, dtype=DataType.INT32, descending=False, *, tmp=None)
¶
Generate a contiguous integer sequence into a tile.
Equivalent to numpy.arange-style index generation. Maps to pto.tci.
For a column index k in the first row of the destination, ascending gives
dst[0, k] = start + k and descending gives dst[0, k] = start - k.
Note
pto.tci uses the destination's valid-column count as the sequence
length and does NOT populate additional rows. Leading dimensions must
be 1 — prefer shapes of the form [1, N].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
int | Scalar
|
Starting integer (plain int or a Scalar). Must match |
required |
shape
|
Sequence[int]
|
Shape of the destination tile (static, innermost dim != 1). |
required |
dtype
|
DataType
|
Destination dtype. One of {INT16, INT32}. Defaults to INT32. |
INT32
|
descending
|
bool
|
If True, generate a descending sequence. |
False
|
tmp
|
Tile | None
|
Optional A2/A3 PTOAS scratch tile. Normally compiler-generated. |
None
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the ci operation. |
arange = ci
module-attribute
¶
tri(diagonal, shape, valid_shape=None, dtype=DataType.INT32, upper=False)
¶
Generate a lower- or upper-triangular mask tile.
upper=False writes one where j <= i + diagonal; upper=True
writes one where j >= i + diagonal. Only the optional valid region is
written.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diagonal
|
int | Scalar
|
Offset of the boundary from the main diagonal, in columns.
0 includes the diagonal; positive shifts it right, negative left.
May be a runtime |
required |
shape
|
Sequence[int]
|
Shape of the destination tile (static). |
required |
valid_shape
|
Sequence[int] | None
|
Optional written region (each dim |
None
|
dtype
|
DataType
|
Destination dtype. Defaults to |
INT32
|
upper
|
bool
|
Select the upper triangle instead of the lower. |
False
|
Returns:
| Type | Description |
|---|---|
Tile
|
A tile holding 1 inside the selected triangle and 0 outside it. |
random(key0, key1, counter0, counter1, counter2, counter3, shape, valid_shape=None, dtype=DataType.UINT32, rounds=10)
¶
Generate counter-based pseudo-random values into a tile.
Implements a counter-based (Philox/ChaCha-style) RNG. Each element is derived
deterministically from the 64-bit key (key0, key1) and 128-bit counter
(counter0..counter3) plus the element position, so the same seeds always
reproduce the same tile. Maps to pto.trandom.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key0
|
int | Scalar
|
Low INT32 key word (plain int or Scalar). |
required |
key1
|
int | Scalar
|
High INT32 key word (plain int or Scalar). |
required |
counter0
|
int | Scalar
|
First INT32 counter word. |
required |
counter1
|
int | Scalar
|
Second INT32 counter word. |
required |
counter2
|
int | Scalar
|
Third INT32 counter word. |
required |
counter3
|
int | Scalar
|
Fourth INT32 counter word. |
required |
shape
|
Sequence[int]
|
Shape of the destination tile (static). |
required |
valid_shape
|
Sequence[int] | None
|
Optional written region (each dim |
None
|
dtype
|
DataType
|
Destination dtype. One of {INT32, UINT32}. Defaults to UINT32. |
UINT32
|
rounds
|
int
|
Cipher round count, 7 or 10. Defaults to 10. |
10
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the random operation. |
fillpad(tile, pad_value=PadValue.zero)
¶
Fill remaining tile elements with specified padding value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile |
required |
pad_value
|
PadValue | int | float
|
|
zero
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the fillpad operation |
fillpad_inplace(tile, pad_value=PadValue.zero)
¶
Fill padding elements of input tile in place.
Unlike fillpad which allocates a new output tile, this operation reuses the input tile's UB buffer. The result shares the same memory address, making it equivalent to TFILLPAD_INPLACE on the hardware.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile |
required |
pad_value
|
PadValue | int | float
|
|
zero
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile with padding filled (shares memory with the input tile). |
fillpad_expand(tile, shape, pad_value=PadValue.zero)
¶
Copy a smaller source tile into a larger destination tile, padding the rest.
Unlike fillpad (which keeps the same physical shape and only fills the
valid-region expansion), this op produces a larger output tile: the source's
valid region is copied to the top-left and every other element is filled with
pad_value. Equivalent to TFILLPAD_EXPAND on the hardware.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Source tile |
required |
shape
|
Sequence[IntLike]
|
Destination shape; each dimension must be >= the source dimension |
required |
pad_value
|
PadValue | int | float
|
|
zero
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the fillpad_expand operation (a new, larger tile). |
get_block_idx()
¶
Get the current block index.
This operation returns the index of the current compute tile. It is typically used in tile-level programming to identify which block of data is being processed.
Returns:
| Type | Description |
|---|---|
Scalar
|
Scalar wrapping the get_block_idx operation (INDEX type) |
Example
block_idx = pl.tile.get_block_idx() if block_idx < 10: # Process first 10 blocks differently ...
get_subblock_idx()
¶
Get the current sub-block (vector core) index.
Returns the index of the current vector core within a split execution. Core 0 returns 0, core 1 returns 1.
Returns:
| Type | Description |
|---|---|
Scalar
|
Scalar wrapping the get_subblock_idx operation (INDEX type) |
get_block_num()
¶
Get the total number of blocks in the current SPMD task.
This operation returns the total count of blocks dispatched for the current task. Used with get_block_idx() for SPMD work partitioning.
Returns:
| Type | Description |
|---|---|
Scalar
|
Scalar wrapping the get_block_num operation (INDEX type) |
Example
block_idx = pl.tile.get_block_idx() block_num = pl.tile.get_block_num()
add(lhs, rhs)
¶
Element-wise addition of tile and tile or scalar.
Supports broadcasting when both operands are tiles. A scalar rhs
canonicalizes to tile.adds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
Left-hand side tile |
required |
rhs
|
Tile | int | float | Scalar | Expr
|
Right-hand side tile or scalar |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the add operation |
sub(lhs, rhs)
¶
Element-wise subtraction of tile and tile or scalar.
Supports broadcasting when both operands are tiles. A scalar rhs
canonicalizes to tile.subs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
Left-hand side tile |
required |
rhs
|
Tile | int | float | Scalar | Expr
|
Right-hand side tile or scalar |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the sub operation |
mul(lhs, rhs)
¶
Element-wise multiplication of tile and tile or scalar.
Supports broadcasting when both operands are tiles. A scalar rhs
canonicalizes to tile.muls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
Left-hand side tile |
required |
rhs
|
Tile | int | float | Scalar | Expr
|
Right-hand side tile or scalar |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the mul operation |
div(lhs, rhs, high_precision=False)
¶
Element-wise division of tile and tile or scalar.
Tile-tile division requires identical physical and valid shapes. A scalar
rhs canonicalizes to tile.divs, which does not expose the tdiv
precision mode — hence high_precision applies only to the tile-tile form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
Left-hand side tile |
required |
rhs
|
Tile | int | float | Scalar | Expr
|
Right-hand side tile or scalar |
required |
high_precision
|
bool
|
Whether to select PTOAS's high-precision division mode.
Only available when |
False
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the div operation |
adds(lhs, rhs)
¶
subs(lhs, rhs)
¶
muls(lhs, rhs)
¶
divs(lhs, rhs)
¶
neg(tile)
¶
exp(tile)
¶
sin(tile)
¶
cos(tile)
¶
sqrt(tile)
¶
rsqrt(tile, tmp=None)
¶
recip(tile, high_precision=False)
¶
log(tile, high_precision=False)
¶
abs(tile)
¶
relu(tile)
¶
cast(tile, target_type, mode='round', *, tmp=None, saturation_mode=None)
¶
Cast tile to target data type (element-wise).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile (TileType) |
required |
target_type
|
int | DataType
|
Target data type (DataType) |
required |
mode
|
str | int
|
Rounding mode — string name ("none", "rint", "round", "floor", "ceil", "trunc", "odd") or int (0–6) |
'round'
|
tmp
|
Tile | None
|
Optional A2/A3 PTOAS scratch tile. Normally compiler-generated, and only for a cast that opted out of saturation — the saturating form is native and reads none. |
None
|
saturation_mode
|
str | int | None
|
Destination saturation — |
None
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the cast operation |
Example
tile_fp32 = pl.tile.cast(tile_bf16, pl.FP32)
quant_mx(src, *, group_axis, dtype=DataType.FP8E4M3FN)
¶
MXFP8 block-32 dynamic quantization with PTOAS grpAxis selection.
group_axis is required and must be 0 or 1 (same meaning as
PTOAS #pto<mx_group_axis axis*>). Axis 1 is the A-side [M, K] path;
axis 0 is the B-side [N, K] path (LowerCompositeOps transposes to
[K, N] before quantization). GM TensorLayout.MX_* is only for
tensor / tensor.view annotations, not this tile op.
This release supports MXFP8 only (dtype=FP8E4M3FN). MXFP4 is out of
scope for this PR.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
Tile
|
Source tile (FP16/FP32/BF16, 2D).
|
required |
group_axis
|
int
|
PTOAS grouping axis — |
required |
dtype
|
DataType
|
Must be |
FP8E4M3FN
|
Returns:
| Type | Description |
|---|---|
Tile
|
|
Tile
|
|
tuple[Tile, Tile]
|
Cube RHS layout; scale col/col NN. |
Note
On Ascend950, quant_mx and matmul_mx may share one InCore mixed
task. The compiler carries both generated results over V2C; the
FP8E8M0 scale keeps its logical MX scale layout.
tmov_x2zz(src, tmp, *, group_axis=1, dst_rows=None, dst_cols=None)
¶
Exponent X-to-ZZ layout conversion (A5-only).
tmp is a write-only workspace. Axis1 requires capacity
64 + ceil(rows/16) * cols bytes (typically 32-byte-aligned by the
caller) and dst_rows/dst_cols for the ZZ [M, G] shape. Axis0
(TMovDnTo2Zz) still requires a Vec tmp operand; use a minimal 32-byte-aligned
pad.
matmul(lhs, rhs)
¶
batch_matmul(lhs, rhs)
¶
Batch matrix multiplication of two tiles.
Broadcasts the batch dims: for inputs shaped [...batch_dims, M, K] and
[...batch_dims, K, N], the output is [...broadcast_batch_dims, M, N].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
Left-hand side tile |
required |
rhs
|
Tile
|
Right-hand side tile |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the batch_matmul operation |
matmul_acc(acc, lhs, rhs, init_cond=None)
¶
Matrix multiplication with accumulation: acc += lhs @ rhs.
init_cond makes the accumulator's initial value conditional: on the steps
where it holds, acc is overwritten with lhs @ rhs rather than
accumulated into. This is the split-K idiom, and it removes the need to zero
the accumulator or to peel the first K step::
for n0 in pl.range(N // N_TILE):
for k0 in pl.pipeline(0, K, K_TILE, stage=2):
acc_n = pl.tile.slice(acc, [M, N_TILE], [0, n0 * N_TILE])
pl.tile.matmul_acc(acc_n, a, b, init_cond=(k0 == 0))
A literal True / False selects one form at compile time; a runtime
predicate lowers to a branch over the two, with no phi on the accumulator.
Note
When acc is a window of a larger Mem.Acc (L0C) tile, slice it
along columns, as above -- the window must span every row of its
parent, or be at most 16 columns wide inside a single 16-column block.
L0C stores 16x16 blocks column-major, so a row window of a parent with
more than one block column is strided, and the MAD writes its result
compactly from a bare pointer with no destination stride. Slicing
[ROW_TILE, N] at [t0, 0] out of an [M, N] accumulator is
therefore rejected by CanonicalizeTileSlice rather than silently
miscomputed. Column windows address the same L0C memory in the order the
hardware writes it, so nothing is lost by preferring them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
acc
|
Tile
|
Accumulator tile |
required |
lhs
|
Tile
|
Left-hand side tile |
required |
rhs
|
Tile
|
Right-hand side tile |
required |
init_cond
|
BoolLike | None
|
Optional predicate selecting overwrite over accumulate |
None
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the matmul_acc operation |
batch_matmul_acc(acc, lhs, rhs, init_cond=None)
¶
Batch matrix multiplication with accumulation: acc += lhs @ rhs.
Performs the in-place acc += lhs @ rhs with batch-dim broadcasting between
lhs and rhs. The broadcast batch shape must equal the batch shape of
acc (acc is the in-place accumulation target and is not broadcast).
init_cond behaves exactly as on
matmul_acc: where it holds, acc
is overwritten with lhs @ rhs rather than accumulated into.
FlattenTileNdTo2D forwards the predicate to every 2D tile.matmul_acc
it unrolls this op into.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
acc
|
Tile
|
Accumulator tile (at least 2D) |
required |
lhs
|
Tile
|
Left-hand side tile (at least 2D) |
required |
rhs
|
Tile
|
Right-hand side tile (at least 2D) |
required |
init_cond
|
BoolLike | None
|
Optional predicate selecting overwrite over accumulate |
None
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the batch_matmul_acc operation |
matmul_bias(lhs, rhs, bias)
¶
Matrix multiplication with bias add: C = lhs @ rhs + bias.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
Left-hand side tile [M, K] |
required |
rhs
|
Tile
|
Right-hand side tile [K, N] |
required |
bias
|
Tile
|
Bias tile [1, N] with the accumulator dtype (FP32 for floating-point matrix operands, INT32 for integer matrix operands) |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the matmul_bias operation |
matmul_mx(lhs, lhs_scale, rhs, rhs_scale)
¶
MX block-scale matrix multiplication.
Scales use logical [M, K/32] / [K/32, N] shapes. Both data tiles
passed to this operation must be FP8E4M3FN. For the supported FP4 x FP8
input form, explicitly cast the FP4 lhs to FP8E4M3FN before calling this
operation; native FP4 x FP4 is not supported.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
Left-hand side data tile (FP8E4M3FN) |
required |
lhs_scale
|
Tile
|
Left-hand side scale tile (FP8E8M0) |
required |
rhs
|
Tile
|
Right-hand side data tile (FP8E4M3FN) |
required |
rhs_scale
|
Tile
|
Right-hand side scale tile (FP8E8M0) |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the matmul_mx operation |
matmul_mx_acc(acc, lhs, lhs_scale, rhs, rhs_scale)
¶
MX block-scale matmul with accumulation.
Data operands follow matmul_mx: an FP4 lhs must first be cast to
FP8E4M3FN, and the operation itself receives two FP8E4M3FN tiles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
acc
|
Tile
|
Accumulator tile |
required |
lhs
|
Tile
|
Left-hand side data tile (FP8E4M3FN) |
required |
lhs_scale
|
Tile
|
Left-hand side scale tile (FP8E8M0) |
required |
rhs
|
Tile
|
Right-hand side data tile (FP8E4M3FN) |
required |
rhs_scale
|
Tile
|
Right-hand side scale tile (FP8E8M0) |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the matmul_mx_acc operation |
matmul_mx_bias(lhs, lhs_scale, rhs, rhs_scale, bias)
¶
MX block-scale matmul with bias.
Data operands follow matmul_mx: an FP4 lhs must first be cast to
FP8E4M3FN, and the operation itself receives two FP8E4M3FN tiles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
Left-hand side data tile (FP8E4M3FN) |
required |
lhs_scale
|
Tile
|
Left-hand side scale tile (FP8E8M0) |
required |
rhs
|
Tile
|
Right-hand side data tile (FP8E4M3FN) |
required |
rhs_scale
|
Tile
|
Right-hand side scale tile (FP8E8M0) |
required |
bias
|
Tile
|
Bias tile |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the matmul_mx_bias operation |
gemv(lhs, rhs, acc_phase=AccPhase.Unspecified)
¶
General Matrix-Vector multiplication: C[1,N] = A[1,K] @ B[K,N].
lhs must have exactly one physical and logical row. The rhs logical K
must cover the lhs logical K. Inputs must use the same INT8, FP16, BF16, or FP32
dtype; the output is INT32 for INT8 inputs and FP32 otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
Row vector tile [1, K] |
required |
rhs
|
Tile
|
Right-hand side tile [K, N] |
required |
acc_phase
|
AccPhase
|
Producer-side unit-flag phase. Use |
Unspecified
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the gemv operation |
gemv_acc(acc, lhs, rhs, acc_phase=AccPhase.Unspecified, *, init_cond=None)
¶
GEMV with accumulation: C[1,N] += A[1,K] @ B[K,N].
acc must use the GEMV output dtype. The logical K extents and lhs/rhs
dtype requirements are identical to gemv.
init_cond makes the accumulator's initial value conditional, exactly as in
matmul_acc — GEMV is a matmul whose M is
1, run on the same cube MAD, so it carries the same predicate bit. On the
steps where it holds, acc is overwritten with lhs @ rhs rather than
accumulated into, which removes the peeled first step from split-K::
for k0 in pl.pipeline(0, K, K_TILE):
a = pl.load(vec, [0, k0], [1, K_TILE], target_memory=pl.MemorySpace.Mat)
b = pl.load(mat, [k0, 0], [K_TILE, N], target_memory=pl.MemorySpace.Mat)
acc = pl.tile.gemv_acc(acc, a, b, init_cond=(k0 == 0))
A literal True / False selects one form at compile time; a runtime
predicate lowers to a branch over the two, with no phi on the accumulator.
init_cond is keyword-only because acc_phase already owns the fourth
positional slot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
acc
|
Tile
|
Accumulator tile [1, N] |
required |
lhs
|
Tile
|
Row vector tile [1, K] |
required |
rhs
|
Tile
|
Right-hand side tile [K, N] |
required |
acc_phase
|
AccPhase
|
Producer-side unit-flag phase. Use |
Unspecified
|
init_cond
|
BoolLike | None
|
Optional predicate selecting overwrite over accumulate |
None
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the gemv_acc operation |
gemv_bias(lhs, rhs, bias, acc_phase=AccPhase.Unspecified)
¶
GEMV with bias add: C[1,N] = A[1,K] @ B[K,N] + bias[1,N].
bias must use the GEMV output dtype and its valid shape must cover the
logical output shape [1, N]. The logical K extents and lhs/rhs dtype
requirements are identical to gemv.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
Row vector tile [1, K] |
required |
rhs
|
Tile
|
Right-hand side tile [K, N] |
required |
bias
|
Tile
|
Bias tile [1, N] with the accumulator dtype (FP32 for floating-point matrix operands, INT32 for integer matrix operands) |
required |
acc_phase
|
AccPhase
|
Producer-side unit-flag phase. Use |
Unspecified
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the gemv_bias operation |
row_max(tile, tmp_tile)
¶
Row-wise max reduction.
Reduces the last axis with keepdim, producing output shape
input_shape[:-1] + [1] (e.g. [rows, 1] for a 2D [rows, cols] input).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile |
required |
tmp_tile
|
Tile
|
Scratch tile with the same dtype and rank as |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the row_max operation |
row_sum(tile, tmp_tile)
¶
Row-wise sum reduction.
Reduces the last axis with keepdim, producing output shape
input_shape[:-1] + [1] (e.g. [rows, 1] for a 2D [rows, cols] input).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile |
required |
tmp_tile
|
Tile
|
Scratch tile with the same dtype and rank as |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the row_sum operation |
row_min(tile, tmp_tile)
¶
Row-wise min reduction.
Reduces the last axis with keepdim, producing output shape
input_shape[:-1] + [1] (e.g. [rows, 1] for a 2D [rows, cols] input).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile |
required |
tmp_tile
|
Tile
|
Scratch tile with the same dtype and rank as |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the row_min operation |
row_prod(tile, tmp_tile)
¶
Row-wise product reduction.
Reduces the last axis with keepdim, producing output shape
input_shape[:-1] + [1] (e.g. [rows, 1] for a 2D [rows, cols] input).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile |
required |
tmp_tile
|
Tile
|
Scratch tile with the same dtype and rank as |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the row_prod operation |
col_sum(tile, tmp_tile=None)
¶
Column-wise sum reduction.
Output shape is [1, N] for an [M, N] input.
Passing tmp_tile activates the binary-tree reduction path (O(log M) depth,
better precision); omitting it uses the sequential path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile |
required |
tmp_tile
|
Tile | None
|
Optional scratch tile (same shape/dtype as input) that selects the binary-tree reduction path. Unlike the arg reductions, this is not enforced by type deduction -- pass the input's shape and dtype. |
None
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the col_sum operation |
col_max(tile)
¶
col_min(tile)
¶
col_prod(tile)
¶
row_argmax(tile, tmp_tile)
¶
Row-wise argmax (column index of the per-row maximum, int32 output).
Output shape is [rows, 1] with INT32 index dtype.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile |
required |
tmp_tile
|
Tile
|
Scratch tile with exactly the same shape and dtype as |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the row_argmax operation |
row_argmin(tile, tmp_tile)
¶
Row-wise argmin (column index of the per-row minimum, int32 output).
Output shape is [rows, 1] with INT32 index dtype.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile |
required |
tmp_tile
|
Tile
|
Scratch tile with exactly the same shape and dtype as |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the row_argmin operation |
col_argmax(tile, tmp_tile)
¶
Column-wise argmax (row index of the per-column maximum, int32 output).
Output shape is [1, N] with INT32 index dtype. Unlike col_max, the
column argmax requires a tmp_tile scratch buffer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile |
required |
tmp_tile
|
Tile
|
Scratch tile with exactly the same shape and dtype as |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the col_argmax operation |
col_argmin(tile, tmp_tile)
¶
Column-wise argmin (row index of the per-column minimum, int32 output).
Output shape is [1, N] with INT32 index dtype. Unlike col_min, the
column argmin requires a tmp_tile scratch buffer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile |
required |
tmp_tile
|
Tile
|
Scratch tile with exactly the same shape and dtype as |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the col_argmin operation |
maximum(lhs, rhs)
¶
row_expand(target, row_vec)
¶
row_expand_sub(tile, row_vec)
¶
Row-wise broadcast subtraction.
Subtracts a row vector from each row of the tile:
tile[i, :] - row_vec[i, 0] for all i.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile [M, N] |
required |
row_vec
|
Tile
|
Row vector [M, 1] |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the row_expand_sub operation |
row_expand_div(tile, row_vec)
¶
Row-wise broadcast division.
Divides each row of the tile by the corresponding row vector value:
tile[i, :] / row_vec[i, 0] for all i.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile [M, N] |
required |
row_vec
|
Tile
|
Row vector [M, 1] |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the row_expand_div operation |
row_expand_mul(tile, row_vec)
¶
Row-wise broadcast multiplication.
Multiplies each row of the tile by the corresponding row vector value:
tile[i, :] * row_vec[i, 0] for all i.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile [M, N] |
required |
row_vec
|
Tile
|
Row vector [M, 1] |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the row_expand_mul operation |
row_expand_add(tile, row_vec, tmp=None)
¶
Row-wise scalar or packed-block expansion addition.
A non-row-major [M, 1] carrier broadcasts one scalar per row:
tile[i, :] + row_vec[i, 0] for all i. A row-major carrier instead holds
one 32-byte lane block per row and repeats that block across the destination
columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile [M, N] |
required |
row_vec
|
Tile
|
DN |
required |
tmp
|
Tile | None
|
Optional PTOAS scratch tile |
None
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the row_expand_add operation |
row_expand_max(tile, row_vec)
¶
Row-wise broadcast maximum: max(tile, row_vec broadcasted).
Takes the element-wise maximum of each row and the row vector value:
max(tile[i, :], row_vec[i, 0]) for all i.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile [M, N] |
required |
row_vec
|
Tile
|
Row vector [M, 1] |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the row_expand_max operation |
row_expand_min(tile, row_vec)
¶
Row-wise broadcast minimum: min(tile, row_vec broadcasted).
Takes the element-wise minimum of each row and the row vector value:
min(tile[i, :], row_vec[i, 0]) for all i.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile [M, N] |
required |
row_vec
|
Tile
|
Row vector [M, 1] |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the row_expand_min operation |
row_expand_expdif(tile, row_vec)
¶
Row-wise exp-diff: exp(tile - row_vec) with per-row scalar.
Computes exp(tile[i, :] - row_vec[i, 0]) for all i.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile [M, N] |
required |
row_vec
|
Tile
|
Row vector providing per-row scalar [M, 1] |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the row_expand_expdif operation |
col_expand(target, col_vec)
¶
col_expand_mul(tile, col_vec)
¶
Expand column vector and multiply with tile.
Multiplies each column of the tile by the corresponding column vector value:
tile[:, j] * col_vec[0, j] for all j.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile [M, N] |
required |
col_vec
|
Tile
|
Column vector [1, N] |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the col_expand_mul operation |
col_expand_div(tile, col_vec)
¶
Expand column vector and divide tile by it.
Divides each column of the tile by the corresponding column vector value:
tile[:, j] / col_vec[0, j] for all j.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile [M, N] |
required |
col_vec
|
Tile
|
Column vector [1, N] |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the col_expand_div operation |
col_expand_sub(tile, col_vec)
¶
Expand column vector and subtract from tile.
Subtracts a column vector from each column of the tile:
tile[:, j] - col_vec[0, j] for all j.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile [M, N] |
required |
col_vec
|
Tile
|
Column vector [1, N] |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the col_expand_sub operation |
col_expand_add(tile, col_vec)
¶
Expand column vector and add to tile.
Adds a column vector to each column of the tile:
tile[:, j] + col_vec[0, j] for all j.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile [M, N] |
required |
col_vec
|
Tile
|
Column vector [1, N] |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the col_expand_add operation |
col_expand_max(tile, col_vec)
¶
Expand column vector and take element-wise maximum with tile.
Computes max(tile[:, j], col_vec[0, j]) for all j.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile [M, N] |
required |
col_vec
|
Tile
|
Column vector [1, N] |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the col_expand_max operation |
col_expand_min(tile, col_vec)
¶
Expand column vector and take element-wise minimum with tile.
Computes min(tile[:, j], col_vec[0, j]) for all j.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile [M, N] |
required |
col_vec
|
Tile
|
Column vector [1, N] |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the col_expand_min operation |
col_expand_expdif(tile, col_vec)
¶
Expand column vector and compute exp-diff with per-column scalar.
Computes exp(tile[:, j] - col_vec[0, j]) for all j.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile [M, N] |
required |
col_vec
|
Tile
|
Column vector providing per-column scalar [1, N] |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the col_expand_expdif operation |
expands(target, scalar)
¶
Expand scalar to target tile shape.
Broadcasts a scalar value to match the shape of the target tile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Tile
|
Target tile defining output shape |
required |
scalar
|
int | float | Expr | Scalar
|
Scalar value to expand |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the expands operation |
minimum(lhs, rhs)
¶
cmp(lhs, rhs, cmp_type=0)
¶
Element-wise comparison of two tiles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
Left-hand side tile |
required |
rhs
|
Tile
|
Right-hand side tile |
required |
cmp_type
|
int
|
Comparison type (EQ=0, NE=1, LT=2, LE=3, GT=4, GE=5) |
0
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping a packed predicate mask. Use tile.sel with an explicit tmp tile to materialize values. |
cmps(lhs, rhs, cmp_type=0)
¶
Element-wise comparison of tile and scalar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
Tile |
required |
rhs
|
int | float | Expr | Scalar
|
Scalar value |
required |
cmp_type
|
int
|
Comparison type (EQ=0, NE=1, LT=2, LE=3, GT=4, GE=5) |
0
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping a packed predicate mask. Use tile.sel with an explicit tmp tile to materialize values. |
max(lhs, rhs)
¶
Scalar max of two values.
Tile reductions are direction-specific — use row_max (collapses the
last axis) or col_max (collapses axis 0).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Scalar | int | Expr
|
First scalar operand |
required |
rhs
|
Scalar | int | Expr
|
Second scalar operand |
required |
Returns:
| Type | Description |
|---|---|
Scalar
|
Scalar wrapping the max operation |
min(lhs, rhs)
¶
Scalar min of two values.
Tile reductions are direction-specific — use row_min (collapses the
last axis) or col_min (collapses axis 0).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Scalar | int | Expr
|
First scalar operand |
required |
rhs
|
Scalar | int | Expr
|
Second scalar operand |
required |
Returns:
| Type | Description |
|---|---|
Scalar
|
Scalar wrapping the min operation |
slice(tile, shape, offset, valid_shape=None, drop_dims=None, pad_value=None)
¶
Create a slice of a tile with static shape and optional valid shape.
The slice is never valid where the source tile is not: the source's valid
region, shifted by offset and cut to the window, bounds the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile |
required |
shape
|
Sequence[IntLike]
|
Static shape dimensions. Always full-rank — a scalar-indexed axis
contributes a unit dim here and is listed in |
required |
offset
|
Sequence[IntLike]
|
Offset dimensions for the slice |
required |
valid_shape
|
Sequence[IntLike] | None
|
Valid shape dimensions. When omitted, the source's validity under the window is used. Narrows the result; cannot widen it. |
None
|
drop_dims
|
Sequence[int | Expr] | None
|
Optional axes to erase from the result type (numpy-style rank
reduction). Each listed axis must be a static unit dim of |
None
|
pad_value
|
PadValue | int | float | None
|
Optional padding mode for out-of-valid-shape elements.
|
None
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the slice operation |
Note
Unlike tensor.slice, there is no clamp
option: an on-chip window has nothing that could clamp it, so
offset + shape must stay inside the source tile.
reshape(tile, shape)
¶
Reshape tile to new shape.
The valid region is carried through, never widened: the result holds real
data in exactly the cells the input did. See pl.reshape for the cases
that always map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile |
required |
shape
|
Sequence[IntLike]
|
New shape dimensions. A tile is physically 2D, so a higher-rank
result is an intermediate that |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the reshape operation |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the element count changes, or if the input holds real
data in only part of its buffer and no origin-anchored region of
|
reinterpret_view(data, dtype, *, shape=None)
¶
Reinterpret a tile over the same bytes with a different dtype.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Tile
|
Input tile. |
required |
dtype
|
DataType
|
Target element dtype, which must differ from the source dtype. |
required |
shape
|
Sequence[IntLike] | None
|
Optional byte-equivalent target shape. When omitted, the physically contiguous dimension is scaled according to the source/target dtype byte ratio. |
None
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the zero-copy reinterpret-view operation. |
transpose(tile, axis1, axis2, tmp_tile=None)
¶
Transpose tile by swapping two axes.
The pto.ttrans scratch buffer is a codegen detail allocated later by
FlattenTileNdTo2D, so user code never supplies tmp_tile. The optional
parameter exists only so the lowered 4-arg form round-trips through the parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile. |
required |
axis1
|
int
|
First axis to swap (supports negative indexing). |
required |
axis2
|
int
|
Second axis to swap (supports negative indexing). |
required |
tmp_tile
|
Tile | None
|
Optional scratch tile — compiler-generated lowered IR only. |
None
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the transpose operation. |
transpose_view(tile)
¶
Zero-copy fractal-layout reinterpretation (NZ<->ZN) of a tile.
Swaps the trailing two dims together with the block/scatter layouts, aliasing
the source buffer byte-for-byte: an NZ [..., N, K] tile and a ZN
[..., K, N] tile over the same L1 bytes are mutual transposes. Emits no
data movement, so one GM->L1 load can feed both a b_trans=True and a
b_trans=False matmul on a shared operand.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile (TileType, >=2D; typically Mat-resident). |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the transposed-layout view. |
set_validshape(tile, valid_rows, valid_cols)
¶
Update valid-shape metadata of a tile without data movement.
.. note::
The operand must not be a view (a pl.tile.slice or reshape result): a
view carries its valid extent in its type, so there is nothing to update.
Narrow at the slice with valid_shape= instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile (must be 2D) |
required |
valid_rows
|
IntLike
|
Number of valid rows (int or Scalar[INDEX]) |
required |
valid_cols
|
IntLike
|
Number of valid columns (int or Scalar[INDEX]) |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile with updated valid_shape metadata |
rem(lhs, rhs, tmp, high_precision=False)
¶
Element-wise remainder (modulo) of two tiles.
Computes lhs % rhs element-wise. Maps to the TREM hardware intrinsic.
On A2/A3, every INT32 input element must be in [-2**24, 2**24].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
Left-hand side tile |
required |
rhs
|
Tile
|
Right-hand side tile |
required |
tmp
|
Tile
|
Same-dtype scratch tile whose physical and valid capacity provably provides two rows and covers the dividend columns on A2/A3. It must not overlap either source there. |
required |
high_precision
|
bool
|
Whether to select PTOAS's high-precision TREM mode. This mode is defined only for FP32 and is ignored by A2/A3 hardware. |
False
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the rem operation |
rems(lhs, rhs, tmp)
¶
Element-wise remainder (modulo) of tile and scalar.
Computes lhs % rhs element-wise. Maps to the TREMS hardware intrinsic.
On A2/A3, source valid extents must be provably positive and every INT32
source element and scalar must be in [-2**24, 2**24].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
Tile |
required |
rhs
|
int | float | Expr | Scalar
|
Scalar value |
required |
tmp
|
Tile
|
Same-dtype scratch tile whose physical and valid capacity provably provides one row and covers the dividend columns on A2/A3. It must not overlap the dividend there. |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the rems operation |
part_add(src0, src1)
¶
Partial element-wise add of two tiles.
Adds over the destination valid region; where only one source is valid the result copies that source. Maps to the TPARTADD hardware intrinsic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src0
|
Tile
|
First source tile |
required |
src1
|
Tile
|
Second source tile |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the part_add operation |
part_mul(src0, src1)
¶
Partial element-wise multiply of two tiles.
Multiplies over the destination valid region; where only one source is valid the result copies that source. Maps to the TPARTMUL hardware intrinsic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src0
|
Tile
|
First source tile |
required |
src1
|
Tile
|
Second source tile |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the part_mul operation |
part_max(src0, src1)
¶
Partial element-wise max of two tiles.
Takes the max over the destination valid region; where only one source is valid the result copies that source. Maps to the TPARTMAX hardware intrinsic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src0
|
Tile
|
First source tile |
required |
src1
|
Tile
|
Second source tile |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the part_max operation |
part_min(src0, src1)
¶
Partial element-wise min of two tiles.
Takes the min over the destination valid region; where only one source is valid the result copies that source. Maps to the TPARTMIN hardware intrinsic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src0
|
Tile
|
First source tile |
required |
src1
|
Tile
|
Second source tile |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the part_min operation |
fmod(lhs, rhs, high_precision=False)
¶
Element-wise truncating remainder of two tiles.
Computes the truncating remainder of lhs / rhs element-wise, matching
torch.fmod with the result taking the dividend sign. Maps to TFMOD.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
Left-hand side tile |
required |
rhs
|
Tile
|
Right-hand side tile |
required |
high_precision
|
bool
|
Whether to select PTOAS's high-precision TFMOD mode. This mode is defined only for FP32. |
False
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the fmod operation |
fmods(lhs, rhs)
¶
Element-wise truncating remainder of tile and scalar.
Computes the truncating remainder of lhs / rhs element-wise, matching
torch.fmod with the result taking the dividend sign. Maps to TFMODS.
A2/A3 requires every source valid extent to be provably positive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
Tile |
required |
rhs
|
int | float | Expr | Scalar
|
Scalar value |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the fmods operation |
and_(lhs, rhs)
¶
ands(lhs, rhs)
¶
or_(lhs, rhs)
¶
ors(lhs, rhs)
¶
xor(lhs, rhs, tmp)
¶
Element-wise bitwise XOR of two tiles.
Computes lhs ^ rhs element-wise. Maps to the TXOR hardware intrinsic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
Left-hand side tile |
required |
rhs
|
Tile
|
Right-hand side tile |
required |
tmp
|
Tile
|
Temporary tile required by the hardware |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the xor operation |
xors(lhs, rhs, tmp)
¶
Element-wise bitwise XOR of tile and scalar.
Computes lhs ^ rhs element-wise. Maps to the TXORS hardware intrinsic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
Tile |
required |
rhs
|
int | Expr | Scalar
|
Scalar value |
required |
tmp
|
Tile
|
Temporary tile required by the hardware |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the xors operation |
shl(lhs, rhs)
¶
shls(lhs, rhs)
¶
Element-wise bitwise left shift of tile and scalar.
Computes lhs << rhs element-wise. Maps to the TSHLS hardware intrinsic.
Note
The scalar shift amount must be zero or positive; negative values are not supported by the hardware and will be rejected by codegen.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
Tile |
required |
rhs
|
int | Expr | Scalar
|
Scalar shift amount; must be >= 0 |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the shls operation |
shr(lhs, rhs)
¶
shrs(lhs, rhs)
¶
Element-wise bitwise right shift of tile and scalar.
Computes lhs >> rhs element-wise. Maps to the TSHRS hardware intrinsic.
Note
The scalar shift amount must be zero or positive; negative values are not supported by the hardware and will be rejected by codegen.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
Tile |
required |
rhs
|
int | Expr | Scalar
|
Scalar shift amount; must be >= 0 |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the shrs operation |
maximums(lhs, rhs)
¶
Element-wise maximum of tile and scalar.
Computes max(lhs, rhs) element-wise. Maps to the TMAXS hardware intrinsic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
Tile |
required |
rhs
|
int | float | Expr | Scalar
|
Scalar value |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the maximums operation |
minimums(lhs, rhs)
¶
Element-wise minimum of tile and scalar.
Computes min(lhs, rhs) element-wise. Maps to the TMINS hardware intrinsic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
Tile |
required |
rhs
|
int | float | Expr | Scalar
|
Scalar value |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the minimums operation |
prelu(tile, slope, tmp)
¶
Element-wise parametric ReLU of a tile.
Computes prelu(tile, slope) element-wise. Maps to the TPRELU hardware intrinsic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile |
required |
slope
|
Tile
|
Slope tile used for negative values |
required |
tmp
|
Tile
|
Temporary tile required by the hardware |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the prelu operation |
not_(tile)
¶
addc(lhs, rhs, rhs2)
¶
Element-wise carry addition of three tiles.
Computes src0 + src1 + carry element-wise. Maps to TADDC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
First source tile |
required |
rhs
|
Tile
|
Second source tile |
required |
rhs2
|
Tile
|
Per-element carry-in tile, normally containing 0 or 1 |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the addc operation |
subc(lhs, rhs, rhs2)
¶
Element-wise carry subtraction of three tiles.
Computes src0 - src1 + carry element-wise. Maps to TSUBC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
Minuend tile |
required |
rhs
|
Tile
|
Subtrahend tile |
required |
rhs2
|
Tile
|
Per-element carry-in tile, normally containing 0 or 1 |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the subc operation |
addsc(lhs, rhs, rhs2)
¶
Element-wise scalar carry addition.
Computes src0 + scalar + carry element-wise. Maps to TADDSC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
Source tile |
required |
rhs
|
int | float | Expr | Scalar
|
Scalar addend with the same dtype as |
required |
rhs2
|
Tile
|
Per-element carry-in tile, normally containing 0 or 1 |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the addsc operation |
subsc(lhs, rhs, rhs2)
¶
Element-wise scalar carry subtraction.
Computes src0 - scalar + carry element-wise. Maps to TSUBSC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lhs
|
Tile
|
Minuend tile |
required |
rhs
|
int | float | Expr | Scalar
|
Scalar subtrahend with the same dtype as |
required |
rhs2
|
Tile
|
Per-element carry-in tile, normally containing 0 or 1 |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the subsc operation |
lrelu(tile, slope)
¶
Element-wise leaky ReLU with scalar slope.
Computes max(tile, slope * tile) element-wise. Maps to the TLRELU hardware intrinsic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Input tile |
required |
slope
|
int | float | Expr | Scalar
|
Scalar slope for negative values |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the lrelu operation |
sel(mask, lhs, rhs, tmp)
¶
Per-element selection between two tiles using a predicate mask tile.
For each element (i, j): dst[i,j] = lhs[i,j] if mask[i,j] is true, else rhs[i,j]. Maps to the TSEL hardware intrinsic. The mask encoding is target-defined.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
Tile
|
Predicate mask tile; encoding is target-defined |
required |
lhs
|
Tile
|
Source tile 0, selected where mask is true |
required |
rhs
|
Tile
|
Source tile 1, selected where mask is false |
required |
tmp
|
Tile
|
Scratch tile required by TSEL (UINT32 [1, 16] on A2/A3; unread ABI placeholder on A5) |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the sel operation |
sels(mask, src, tmp, scalar)
¶
Per-element selection between a source tile and a scalar.
For each element (i, j): dst[i,j] = src[i,j] if mask[i,j] is true, else scalar. Maps to the TSELS hardware intrinsic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
Tile
|
Predicate mask tile; encoding is target-defined |
required |
src
|
Tile
|
Source tile, selected where mask is true |
required |
tmp
|
Tile
|
Scratch tile required by TSELS |
required |
scalar
|
int | float | Expr | Scalar
|
Scalar value, selected where mask is false |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the sels operation |
tpush_to_aiv(tile, *, split, lane_stride=None, id=None, span=None)
¶
Push tile data from AIC to AIV via cross-core pipe.
The Vector side receives it with tpop_from_aic and releases the
slot with tfree_to_aic; split and id must match across all
three.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Tile to send. Its Cube-side buffer stays live until the consumer frees the slot. |
required |
split
|
int
|
pto-isa split code (0=none, 1/2=up-down/left-right, 3/4=the same axes over an odd extent). Selects the axis along which the two AIV lanes divide the tile, and how their extents relate; 0 sends it whole. |
required |
lane_stride
|
int | None
|
Partition stride carried when a ragged boundary was balanced across the two AIV lanes; omit for the default box partition. |
None
|
id
|
int | None
|
Optional frontend pipe id. Omit to use PTOAS default id 0. |
None
|
span
|
Span | None
|
Optional source span |
None
|
tpush_to_aic(tile, *, split, id=None, span=None)
¶
Push tile data from AIV to AIC via cross-core pipe.
The Cube side receives it with tpop_from_aiv and releases the
slot with tfree_to_aiv; split and id must match across all
three.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
Tile
|
Tile to send. Its Vector-side buffer stays live until the consumer frees the slot. |
required |
split
|
int
|
Split mode (0=none, 1=up-down, 2=left-right). Selects the axis along which the two AIV lanes divide the tile; 0 sends it whole. |
required |
id
|
int | None
|
Optional frontend pipe id. Omit to use PTOAS default id 0. |
None
|
span
|
Span | None
|
Optional source span |
None
|
tpop_from_aic(*, shape=None, dtype=None, split=0, lane_stride=None, id=None, span=None)
¶
Pop tile data from AIC cross-core pipe into AIV.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
list[int] | None
|
Shape of the tile to receive |
None
|
dtype
|
DataType | None
|
Data type of the tile to receive |
None
|
split
|
int
|
pto-isa split code (0=none, 1/2=up-down/left-right, 3/4=the same axes over an odd extent) |
0
|
lane_stride
|
int | None
|
Partition stride carried when a ragged boundary was balanced across the two AIV lanes; omit for the box partition |
None
|
id
|
int | None
|
Optional frontend pipe id. Omit to use PTOAS default id 0. |
None
|
span
|
Span | None
|
Optional source span |
None
|
tpop_from_aiv(*, shape=None, dtype=None, split=0, id=None, span=None)
¶
Pop tile data from AIV cross-core pipe into AIC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
list[int] | None
|
Shape of the tile to receive |
None
|
dtype
|
DataType | None
|
Data type of the tile to receive |
None
|
split
|
int
|
Split mode (0=none, 1=up-down, 2=left-right) |
0
|
id
|
int | None
|
Optional frontend pipe id. Omit to use PTOAS default id 0. |
None
|
span
|
Span | None
|
Optional source span |
None
|
sort32(src, idx, *, tmp=None)
¶
Sort fixed 32-element blocks with explicit index tile.
Sorts 32-element blocks in src, permuting idx alongside. Returns an 8-byte value-index-pair tile. Its last dimension is 2x the input width for FP32 and 4x the input width for FP16.
For FP16 src: initialize idx with [0, 1, 2, ..., 31] per block. For FP32 src: initialize idx with [0, 2, 4, ..., 62] per block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
Tile
|
Input value tile (FP16 or FP32) |
required |
idx
|
Tile
|
Input index tile with sequential offsets |
required |
tmp
|
Tile | None
|
Optional A2/A3 PTOAS scratch tile. Normally compiler-generated. |
None
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the dtype-dependent expanded sort32 output |
gather(src, indices, tmp)
¶
Gather elements from src tile by per-element indices (index form).
Computes dst[i, j] = src[indices[i, j]]. Maps to PTOAS pto.tgather
index form. For the hardware mask-pattern variant, use gather_mask.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
Tile
|
Source tile (FP16, FP32, INT16, or INT32) |
required |
indices
|
Tile
|
Index tile (INT32 with any src, or INT16 with a 16-bit src — FP16/INT16);
selects which elements of |
required |
tmp
|
Tile
|
Temporary workspace tile (any Vec dtype; required as an operand but not constrained by the A5 index form — A2/A3 narrows this at PTOAS) |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile with gathered elements (same dtype as |
gatherb(src, offset, *, output_dtype=None)
¶
Gather 32-byte blocks from src by UINT32 byte offsets.
Each offset selects one 32-byte source block. One offset column expands to
32 / sizeof(output_dtype) output elements. output_dtype defaults to
src.dtype and may select another supported byte interpretation.
A sliced source must have a byte address that PyPTO can prove is 32-byte
aligned; dynamic column offsets are rejected conservatively.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
Tile
|
Source tile to gather blocks from. |
required |
offset
|
Tile
|
UINT32 tile of byte offsets into |
required |
output_dtype
|
int | DataType | None
|
Byte interpretation of the result. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile wrapping the gatherb operation. |
gather_mask(src, mask_pattern, *, output_dtype=None)
¶
Gather elements from src tile by a fixed hardware mask pattern (mask form).
Selects elements according to a stride/mask pattern baked into the hardware.
For the per-element indices variant, use gather.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
Tile
|
Source tile (FP16, FP32, INT16, or INT32) |
required |
mask_pattern
|
int
|
Mask pattern selector (1-7), see |
required |
output_dtype
|
int | DataType | None
|
Optional output dtype. When provided, the result tile has
this dtype instead of |
None
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile with mask-selected elements |
Examples:
Same dtype¶
out = gather_mask(src, mask_pattern=pl.tile.MaskPattern.P0101)
Cross-type output (FP32 bits → UINT32)¶
out = gather_mask(src, pl.tile.MaskPattern.P1010, output_dtype=pl.UINT32)
gather_compare(src, kvalue, tmp, *, cmp_mode='eq', offset=0, out_cols, count_dtype=None)
¶
Compare-form gather (tile-level): produce (dst, cdst) — gathered indices and per-row match counts.
Maps to PTOAS pto.tgather compare-form. Hardware DPS allocation of
dst/cdst is handled downstream — only the three inputs (src, kvalue, tmp)
appear at this surface.
DSL form (inside @pl.function)::
dst, cdst = pl.tile.gather_compare(src, kvalue, tmp,
cmp_mode="eq", offset=0,
out_cols=K)
The a, b = call(...) Python tuple unpack is desugared by the parser
into _tuple = call; a = _tuple[0]; b = _tuple[1]. The parser
consumes the underlying tuple-typed ir.Call returned by
pypto.ir.op.tile_ops.gather_compare; the (Tile, Tile) split
below only runs in interactive Python contexts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
Tile
|
Source tile (FP16/FP32/INT16/INT32, 2D). |
required |
kvalue
|
int | Scalar | Expr
|
Scalar threshold (dtype must match |
required |
tmp
|
Tile
|
Workspace tile (UINT8) sized for the codegen kernel. |
required |
cmp_mode
|
str | int
|
|
'eq'
|
offset
|
int
|
Starting index offset (default 0). |
0
|
out_cols
|
int
|
Output column count per row for |
required |
count_dtype
|
int | DataType | None
|
Per-row count dtype, INT32 or UINT32; defaults to INT32. |
None
|
Returns:
| Type | Description |
|---|---|
Tile
|
|
Tile
|
gathered indices and |
tuple[Tile, Tile]
|
per-row match counts. |
scatter(dst, src, indexes)
¶
Scatter elements of src into dst at per-element flattened indices.
Computes dst.flat[indexes[i, j]] = src[i, j], i.e. indexes carries the
flattened destination offset for each src element and therefore has the
same [rows, cols] shape as src. Maps to PTOAS pto.tscatter index
form. The op is DPS — dst is the first (in/out) argument, rewritten in
place, and the returned Tile aliases the same buffer. For the hardware
mask-pattern variant, use scatter_mask.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dst
|
Tile
|
Destination tile (same dtype as |
required |
src
|
Tile
|
Source tile (FP16/FP32/BF16/INT8/INT16/INT32, 2D) |
required |
indexes
|
Tile
|
Per-element flattened destination index tile (INT16 or INT32;
same shape as |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile aliasing the post-scatter |
scatter_mask(dst, src, mask_pattern)
¶
Scatter src rows into mask-marked columns of dst (mask form).
For each row, the elements of src are written into the columns of
dst selected by mask_pattern (the inverse of gather_mask).
Unlike gather_mask (a real pto.tgather ISA op on A2/A3 and A5),
mask-pattern scatter is not a distinct pto-isa instruction — PyPTO emits it
as a pto.tscatter mask-form construct for A2/A3 / CPU-sim style lowering
paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dst
|
Tile
|
Destination tile (rewritten on positions selected by |
required |
src
|
Tile
|
Source tile (compact rows; same dtype as |
required |
mask_pattern
|
int
|
Mask pattern selector (1-7), see |
required |
Returns:
| Type | Description |
|---|---|
Tile
|
Tile aliasing the post-scatter |
Examples:
out = scatter_mask(dst, src, mask_pattern=pl.tile.MaskPattern.P0101)
mscatter(src, idx, output_tensor)
¶
Scatter-store tile elements into a tensor at per-element indices.
Semantics: output_tensor[idx[i, j]] = src[i, j]
Maps to the PTOAS pto.mscatter instruction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
Tile
|
Source tile (FP16, FP32, INT16, or INT32) |
required |
idx
|
Tile
|
Index tile (INT32, same rank as src) |
required |
output_tensor
|
_TensorT
|
Output tensor to scatter into (same dtype as src) |
required |
Returns:
| Type | Description |
|---|---|
_TensorT
|
Tensor wrapping the mscatter operation |
Example
result = pl.tile.mscatter(src_tile, idx_tile, out_tensor)
mgather(mem, idx, coalesce='row', *, gather_oob='undefined', target_memory=MemorySpace.Vec, scratch=None, valid_shape=None)
¶
mgather(mem: Tensor, idx: Tile, coalesce: str | int = ..., *, gather_oob: str | int = ..., target_memory: Literal[MemorySpace.Vec] = ..., scratch: None = ..., valid_shape: None = ...) -> Tile
Gather-load rows or elements from a GM tensor into a fresh Vec or Mat tile.
Vec output uses a 2D INT32 index tile. Mat output uses a GM INT32 index tensor and produces canonical NZ layout; its element mode additionally requires a same-dtype GM scratch tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mem
|
Tensor
|
Source tensor in GM. |
required |
idx
|
Tile | Tensor
|
Two-dimensional INT32 index tile for Vec output, or GM tensor for Mat output. |
required |
coalesce
|
str | int
|
|
'row'
|
gather_oob
|
str | int
|
Out-of-bounds handling: |
'undefined'
|
target_memory
|
MemorySpace
|
|
Vec
|
scratch
|
Tensor | None
|
Same-dtype GM workspace required by Mat element gather and forbidden by the other forms. |
None
|
valid_shape
|
Sequence[int] | None
|
Optional two-dimensional written region for Mat output. Vec output derives its valid region from the index tile. |
None
|
MaskPattern
¶
Hardware mask pattern selectors for tile.gather_mask.
Bit patterns are read right-to-left; lower bits correspond to lower indices.
P0101 = 1
class-attribute
instance-attribute
¶
P1010 = 2
class-attribute
instance-attribute
¶
P0001 = 3
class-attribute
instance-attribute
¶
P0010 = 4
class-attribute
instance-attribute
¶
P0100 = 5
class-attribute
instance-attribute
¶
P1000 = 6
class-attribute
instance-attribute
¶
P1111 = 7
class-attribute
instance-attribute
¶
mrgsort(src0, src1=None, src2=None, src3=None, tmp=None, exhausted=False, *, block_len=None)
¶
Merge sort — format1 (single-list) or format2 (2-4 way merge).
Format1: sorts a tile containing multiple pre-sorted runs of length block_len. Format2: merges 2, 3, or 4 pre-sorted input tiles into one sorted output.
Format1 usage (keyword block_len): out = mrgsort(src, block_len=64)
Format2 2-way usage (keyword tmp): out = mrgsort(src0, src1, tmp=tmp_tile) out = mrgsort(src0, src1, tmp=tmp_tile, exhausted=True)
Format2 3-way usage
out = mrgsort(src0, src1, src2, tmp=tmp_tile)
Format2 4-way usage (5 positional args): out = mrgsort(src0, src1, src2, src3, tmp) out = mrgsort(src0, src1, src2, src3, tmp, exhausted=True)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src0
|
Tile
|
For format1: input tile with pre-sorted runs (FP16 or FP32). For format2: first sorted input tile. |
required |
src1
|
Tile | None
|
(format2) Second sorted input tile. |
None
|
src2
|
Tile | None
|
(format2, optional) Third sorted input tile (3-way or 4-way). |
None
|
src3
|
Tile | None
|
(format2, optional) Fourth sorted input tile (4-way only). |
None
|
tmp
|
Tile | None
|
(format2) Temporary workspace tile (same shape as output). Pass as keyword arg for 2-way and 3-way. |
None
|
exhausted
|
bool
|
(format2) If True, marks inputs as exhausted (default: False). |
False
|
block_len
|
int | Scalar | None
|
(format1, keyword-only) Run length, must be multiple of 64. |
None
|
Returns:
| Type | Description |
|---|---|
Tile
|
Tile with merged sorted elements |