TGATHER
Tile Operation Diagram
Introduction
Gather/select elements using either an index tile or a compile-time mask pattern.
Math Interpretation
Index-based gather (conceptual):
Let R = dst.GetValidRow() and C = dst.GetValidCol(). For 0 <= i < R and 0 <= j < C:
dsti,j=src0 [indicesi,j]\mathrm{dst}_{i,j} = \mathrm{src0}\!\left[\mathrm{indices}_{i,j}\right]
Exact index interpretation and bounds behavior are implementation-defined.
Mask-pattern gather is an implementation-defined selection/reduction controlled by pto::MaskPattern.
Assembly Syntax
PTO-AS form: see PTO-AS Specification.
Index-based gather:
%dst = tgather %src0, %indices : !pto.tile<...> -> !pto.tile<...>
Mask-pattern gather:
%dst = tgather %src {maskPattern = #pto.mask_pattern<P0101>} : !pto.tile<...> -> !pto.tile<...>
AS Level 1 (SSA)
%dst = pto.tgather %src, %indices : (!pto.tile<...>, !pto.tile<...>) -> !pto.tile<...>
%dst = pto.tgather %src {maskPattern = #pto.mask_pattern<P0101>}: !pto.tile<...> -> !pto.tile<...>
AS Level 2 (DPS)
pto.tgather ins(%src, %indices : !pto.tile_buf<...>, !pto.tile_buf<...>) outs(%dst : !pto.tile_buf<...>)
pto.tgather ins(%src, {maskPattern = #pto.mask_pattern<P0101>} : !pto.tile_buf<...>) outs(%dst : !pto.tile_buf<...>)
C++ Intrinsic
Declared in include/pto/common/pto_instr.hpp:
template <typename TileDataD, typename TileDataS0, typename TileDataS1, typename TileDataTmp, typename... WaitEvents>
PTO_INST RecordEvent TGATHER(TileDataD &dst, TileDataS0 &src0, TileDataS1 &src1, TileDataTmp &tmp, WaitEvents &... events);
template <typename DstTileData, typename SrcTileData, MaskPattern maskPattern, typename... WaitEvents>
PTO_INST RecordEvent TGATHER(DstTileData &dst, SrcTileData &src, WaitEvents &... events);
Constraints
- Index-based gather: implementation checks (A2A3):
sizeof(DstTileData::DType)must be must beint16_t,uint16_t,int32_t,uint32_t,half,float.sizeof(Src1TileData::DType)must be must beint32_t,uint32_t.DstTileData::DTypemust be the same type asSrc0TileData::DType.src1.GetValidCol() == Src1TileData::Colsanddst.GetValidCol() == DstTileData::Cols.
- Index-based gather: implementation checks (A5):
sizeof(DstTileData::DType)must be must beint16_t,uint16_t,int32_t,uint32_t,half,float.sizeof(Src1TileData::DType)must be must beint16_t,uint16_t,int32_t,uint32_t.DstTileData::DTypemust be the same type asSrc0TileData::DType.src1.GetValidCol() == Src1TileData::Colsanddst.GetValidCol() == DstTileData::Cols.
- Mask-pattern gather: implementation checks (A2A3):
- Source element size must be
2or4bytes. SrcTileData::DType/DstTileData::DTypemust beint16_toruint16_torint32_toruint32_torhalforbfloat16_torfloat.dstandsrcmust both beTileType::Vecand row-major.sizeof(dst element) == sizeof(src element)anddst.GetValidCol() == DstTileData::Cols(continuous dst storage).
- Source element size must be
- Mask-pattern gather: implementation checks (A5):
- Source element size must be
1or2or4bytes. dstandsrcmust both beTileType::Vecand row-major.SrcTileData::DType/DstTileData::DTypemust beint8_toruint8_torint16_toruint16_torint32_toruint32_torhalforbfloat16_torfloatorfloat8_e4m3_torfloat8_e5m2_torhifloat8_t.- Supported dtypes are restricted to a target-defined set (checked via
static_assertin the implementation), andsizeof(dst element) == sizeof(src element),dst.GetValidCol() == DstTileData::Cols(continuous dst storage).
- Source element size must be
- Bounds / validity:
- Index bounds are not validated by explicit runtime assertions; out-of-range indices are target-defined.
Examples
Auto
#include <pto/pto-inst.hpp>
using namespace pto;
void example_auto() {
using SrcT = Tile<TileType::Vec, float, 16, 16>;
using IdxT = Tile<TileType::Vec, int32_t, 16, 16>;
using DstT = Tile<TileType::Vec, float, 16, 16>;
SrcT src0;
IdxT idx;
DstT dst;
TGATHER(dst, src0, idx);
}
Manual
#include <pto/pto-inst.hpp>
using namespace pto;
void example_manual() {
using SrcT = Tile<TileType::Vec, float, 16, 16>;
using DstT = Tile<TileType::Vec, float, 1, 16>;
SrcT src;
DstT dst;
TASSIGN(src, 0x1000);
TASSIGN(dst, 0x2000);
TGATHER<DstT, SrcT, MaskPattern::P0101>(dst, src);
}
ASM Form Examples
Auto Mode
# Auto mode: compiler/runtime-managed placement and scheduling.
%dst = pto.tgather %src, %indices : (!pto.tile<...>, !pto.tile<...>) -> !pto.tile<...>
Manual Mode
# Manual mode: resources must be bound explicitly before issuing the instruction.
# Optional for tile operands:
# pto.tassign %arg0, @tile(0x1000)
# pto.tassign %arg1, @tile(0x2000)
%dst = pto.tgather %src, %indices : (!pto.tile<...>, !pto.tile<...>) -> !pto.tile<...>
PTO Assembly Form
%dst = pto.tgather %src, %indices : (!pto.tile<...>, !pto.tile<...>) -> !pto.tile<...>
# AS Level 2 (DPS)
pto.tgather ins(%src, %indices : !pto.tile_buf<...>, !pto.tile_buf<...>) outs(%dst : !pto.tile_buf<...>)