TSEL¶
Tile Operation Diagram¶
Introduction¶
Select between two tiles using a mask tile (per-element selection).
Math Interpretation¶
For each element (i, j) in the valid region:
\[
\mathrm{dst}_{i,j} =
\begin{cases}
\mathrm{src0}_{i,j} & \text{if } \mathrm{mask}_{i,j}\ \text{is true} \\
\mathrm{src1}_{i,j} & \text{otherwise}
\end{cases}
\]
Assembly Syntax¶
PTO-AS form: see PTO-AS Specification.
Synchronous form:
%dst = tsel %mask, %src0, %src1 : !pto.tile<...>
AS Level 1 (SSA)¶
%dst = pto.tsel %mask, %src0, %src1 : (!pto.tile<...>, !pto.tile<...>, !pto.tile<...>) -> !pto.tile<...>
AS Level 2 (DPS)¶
pto.tsel ins(%mask, %src0, %src1 : !pto.tile_buf<...>, !pto.tile_buf<...>, !pto.tile_buf<...>) outs(%dst : !pto.tile_buf<...>)
C++ Intrinsic¶
Declared in include/pto/common/pto_instr.hpp:
template <typename TileData, typename MaskTile, typename TmpTile, typename... WaitEvents>
PTO_INST RecordEvent TSEL(TileData &dst, MaskTile &selMask, TileData &src0, TileData &src1, TmpTile &tmp, WaitEvents &... events);
Constraints¶
- Implementation checks (A2A3):
sizeof(TileData::DType)must be2or4bytes.TileData::DTypemust beint16_toruint16_torint32_toruint32_torhalforbfloat16_torfloat.dst,src0, andsrc1must use the same element type.dst,src0, andsrc1must be row-major.- The selection domain is
dst.GetValidRow()/dst.GetValidCol().
- Implementation checks (A5):
sizeof(TileData::DType)must be2or4bytes.TileData::DTypemust beint16_toruint16_torint32_toruint32_torhalforbfloat16_torfloat.dst,src0, andsrc1must use the same element type.dst,src0, andsrc1must be row-major.- The selection domain is
dst.GetValidRow()/dst.GetValidCol().
- Mask encoding:
- The mask tile is interpreted as packed predicate bits in a target-defined layout.
Examples¶
Auto¶
#include <pto/pto-inst.hpp>
using namespace pto;
void example_auto() {
using TileT = Tile<TileType::Vec, float, 16, 16>;
using MaskT = Tile<TileType::Vec, uint8_t, 16, 32, BLayout::RowMajor, -1, -1>;
using TmpT = Tile<TileType::Vec, uint32_t, 1, 16>;
TileT src0, src1, dst;
MaskT mask(16, 2);
TmpT tmp;
TSEL(dst, mask, src0, src1, tmp);
}
Manual¶
#include <pto/pto-inst.hpp>
using namespace pto;
void example_manual() {
using TileT = Tile<TileType::Vec, float, 16, 16>;
using MaskT = Tile<TileType::Vec, uint8_t, 16, 32, BLayout::RowMajor, -1, -1>;
using TmpT = Tile<TileType::Vec, uint32_t, 1, 16>;
TileT src0, src1, dst;
MaskT mask(16, 2);
TmpT tmp;
TASSIGN(src0, 0x1000);
TASSIGN(src1, 0x2000);
TASSIGN(dst, 0x3000);
TASSIGN(mask, 0x4000);
TASSIGN(tmp, 0x5000);
TSEL(dst, mask, src0, src1, tmp);
}
ASM Form Examples¶
Auto Mode¶
# Auto mode: compiler/runtime-managed placement and scheduling.
%dst = pto.tsel %mask, %src0, %src1 : (!pto.tile<...>, !pto.tile<...>, !pto.tile<...>) -> !pto.tile<...>
Manual Mode¶
# Manual mode: bind resources explicitly before issuing the instruction.
# Optional for tile operands:
# pto.tassign %arg0, @tile(0x1000)
# pto.tassign %arg1, @tile(0x2000)
%dst = pto.tsel %mask, %src0, %src1 : (!pto.tile<...>, !pto.tile<...>, !pto.tile<...>) -> !pto.tile<...>
PTO Assembly Form¶
%dst = tsel %mask, %src0, %src1 : !pto.tile<...>
# AS Level 2 (DPS)
pto.tsel ins(%mask, %src0, %src1 : !pto.tile_buf<...>, !pto.tile_buf<...>, !pto.tile_buf<...>) outs(%dst : !pto.tile_buf<...>)