TSCATTER¶
指令示意图¶
简介¶
使用逐元素行索引将源 Tile 的行散播到目标 Tile 中。
数学语义¶
对每个源元素 (i, j), let k = idx[i,j] and write:
\[ \mathrm{dst\_flat}_{k} = \mathrm{src}_{i,j} \]
Here dst_flat denotes the destination tile viewed as a single linear storage sequence. TSCATTER does not interpret idx[i,j] as a destination row selector. On the standard row-major tile layout, this is equivalent to writing the k-th flattened destination element.
If multiple elements map to the same destination location, the final value is implementation-defined (last writer wins in the current implementation).
汇编语法¶
PTO-AS 形式:参见 PTO-AS Specification.
同步形式:
%dst = tscatter %src, %idx : !pto.tile<...>, !pto.tile<...> -> !pto.tile<...>
AS Level 1(SSA)¶
%dst = pto.tscatter %src, %idx : (!pto.tile<...>, !pto.tile<...>) -> !pto.tile<...>
AS Level 2(DPS)¶
pto.tscatter ins(%src, %idx : !pto.tile_buf<...>, !pto.tile_buf<...>) outs(%dst : !pto.tile_buf<...>)
C++ 内建接口¶
声明于 include/pto/common/pto_instr.hpp:
template <typename TileDataD, typename TileDataS, typename TileDataI, typename... WaitEvents>
PTO_INST RecordEvent TSCATTER(TileDataD &dst, TileDataS &src, TileDataI &indexes, WaitEvents &... events);
约束¶
- 实现检查 (A2A3):
TileDataD::Loc,TileDataS::Loc,TileDataI::Locmust beTileType::Vec.TileDataD::DType,TileDataS::DTypemust be one of:int32_t,int16_t,int8_t,half,float32_t,uint32_t,uint16_t,uint8_t,bfloat16_t.TileDataI::DTypemust be one of:int16_t,int32_t,uint16_toruint32_t.indexesvalues are interpreted as flattened destination element offsets in destination tile storage order.- No bounds checks are enforced on
indexesvalues. - Static valid bounds:
TileDataD::ValidRow <= TileDataD::Rows,TileDataD::ValidCol <= TileDataD::Cols,TileDataS::ValidRow <= TileDataS::Rows,TileDataS::ValidCol <= TileDataS::Cols,TileDataI::ValidRow <= TileDataI::Rows,TileDataI::ValidCol <= TileDataI::Cols. TileDataD::DTypeandTileDataS::DTypemust be the same.- When size of
TileDataD::DTypeis 4 bytes, the size ofTileDataI::DTypemust be 4 bytes. - When size of
TileDataD::DTypeis 2 bytes, the size ofTileDataI::DTypemust be 2 bytes. - When size of
TileDataD::DTypeis 1 bytes, the size ofTileDataI::DTypemust be 2 bytes. - 实现检查 (A5):
TileDataD::Loc,TileDataS::Loc,TileDataI::Locmust beTileType::Vec.TileDataD::DType,TileDataS::DTypemust be one of:int32_t,int16_t,int8_t,half,float32_t,uint32_t,uint16_t,uint8_t,bfloat16_t.TileDataI::DTypemust be one of:int16_t,int32_t,uint16_toruint32_t.indexesvalues are interpreted as flattened destination element offsets in destination tile storage order.- No bounds checks are enforced on
indexesvalues. - Static valid bounds:
TileDataD::ValidRow <= TileDataD::Rows,TileDataD::ValidCol <= TileDataD::Cols,TileDataS::ValidRow <= TileDataS::Rows,TileDataS::ValidCol <= TileDataS::Cols,TileDataI::ValidRow <= TileDataI::Rows,TileDataI::ValidCol <= TileDataI::Cols. TileDataD::DTypeandTileDataS::DTypemust be the same.- When size of
TileDataD::DTypeis 4 bytes, the size ofTileDataI::DTypemust be 4 bytes. - When size of
TileDataD::DTypeis 2 bytes, the size ofTileDataI::DTypemust be 2 bytes. - When size of
TileDataD::DTypeis 1 bytes, the size ofTileDataI::DTypemust be 2 bytes.
示例¶
自动(Auto)¶
#include <pto/pto-inst.hpp>
using namespace pto;
void example_auto() {
using TileT = Tile<TileType::Vec, float, 16, 16>;
using IdxT = Tile<TileType::Vec, uint16_t, 16, 16>;
TileT src, dst;
IdxT idx;
TSCATTER(dst, src, idx);
}
手动(Manual)¶
#include <pto/pto-inst.hpp>
using namespace pto;
void example_manual() {
using TileT = Tile<TileType::Vec, float, 16, 16>;
using IdxT = Tile<TileType::Vec, uint16_t, 16, 16>;
TileT src, dst;
IdxT idx;
TASSIGN(src, 0x1000);
TASSIGN(dst, 0x2000);
TASSIGN(idx, 0x3000);
TSCATTER(dst, src, idx);
}