TCOLSUM¶
Tile Operation Diagram¶
Introduction¶
Reduce each column by summing across rows.
Math Interpretation¶
Let R = src.GetValidRow() and C = src.GetValidCol(). For 0 <= j < C:
\[ \mathrm{dst}_{0,j} = \sum_{i=0}^{R-1} \mathrm{src}_{i,j} \]
isBinary selects the implementation path (binary-tree accumulation vs. sequential accumulation).
Assembly Syntax¶
Synchronous form:
%dst = tcolsum %src {isBinary = false} : !pto.tile<...> -> !pto.tile<...>
Lowering may introduce internal scratch tiles; the C++ intrinsic requires an explicit tmp operand.
AS Level 1 (SSA)¶
%dst = pto.tcolsum %src : !pto.tile<...> -> !pto.tile<...>
%dst = pto.tcolsum %src, %tmp {isBinary = false} : (!pto.tile<...>, !pto.tile<...>) -> !pto.tile<...>
AS Level 2 (DPS)¶
pto.tcolsum ins(%src : !pto.tile_buf<...>) outs(%dst : !pto.tile_buf<...>)
pto.tcolsum ins(%src, %tmp {isBinary = false} : !pto.tile_buf<...>, !pto.tile_buf<...>) outs(%dst : !pto.tile_buf<...>)
C++ Intrinsic¶
Declared in include/pto/common/pto_instr.hpp:
template <typename TileDataOut, typename TileDataIn, typename... WaitEvents>
PTO_INST RecordEvent TCOLSUM(TileDataOut &dst, TileDataIn &src, WaitEvents &... events);
template <typename TileDataOut, typename TileDataIn, typename TileDataTmp, typename... WaitEvents>
PTO_INST RecordEvent TCOLSUM(TileDataOut &dst, TileDataIn &src, TileDataTmp &tmp, bool isBinary, WaitEvents &... events);
Constraints¶
General constraints / checks¶
dstandsrcmust beTileType::Vec.dstandsrcmust use standard ND layout: row-major and non-fractal (BLayout::RowMajor,SLayout::NoneBox).dstandsrcmust use the same element type.- Runtime checks:
src.GetValidCol() == dst.GetValidCol()src.GetValidRow() != 0(implementation silently returns early when zero, no computation performed)src.GetValidCol() != 0(implementation silently returns early when zero, no computation performed)src.GetValidCol() <= tmprow stride measured insrcelements
isBinaryselects the checked backend path:true: binary-tree accumulation usingtmpfalse: sequential accumulation intodst
A2A3 implementation checks¶
- Supported element types:
half,float,int16_t,int32_t. tmpmust beTileType::Vecand use standard ND layout: row-major and non-fractal (BLayout::RowMajor,SLayout::NoneBox).tmpmust use the same element type assrcanddst.- If
src.GetValidRow() == 0orsrc.GetValidCol() == 0, the implementation returns early.
A5 implementation checks¶
- Shared A5 column-reduce checks allow
half,float,int8_t,uint8_t,int16_t,uint16_t,int32_t,uint32_t,bfloat16_t. - The checked A5
TCOLSUMpath still takestmponly for the binary accumulation path; no extra compile-timetmptype/layout assertions are explicitly enforced inTCOLSUM_IMPL.
Temporary Space¶
Without tmp (2-argument overload: TCOLSUM(dst, src))¶
No tmp is required. Both A2A3 and A5 use sequential accumulation directly into dst.
With tmp and isBinary (4-argument overload: TCOLSUM(dst, src, tmp, isBinary))¶
A2A3¶
- When
isBinary = true:tmpis used for binary-tree accumulation. Adjacent row pairs fromsrcare summed intotmp, thentmpis recursively halved until a single row remains. tmpmust have the same element type assrc/dst.tmpmust beTileType::Vec, row-major, non-fractal.tmp.GetValidCol() >= src.GetValidCol()(in element count, accounting fortmpstride).tmpneeds at leastceil(src.GetValidRow() / 2)rows.- When
isBinary = false:tmpis accepted but the implementation uses sequential accumulation intodst;tmpis not actively used.
A5¶
- When
isBinary = true:tmpis used for binary-tree accumulation in vector registers with UB storage. tmpmust have the same element type assrc/dst.tmp.GetValidCol() >= src.GetValidCol()(in element count, accounting fortmpstride).tmpneeds at leastceil(src.GetValidRow() / 2)rows.- When
isBinary = false:tmpis not actively used; the implementation uses sequential reduction viaTColReduceInstr.
Examples¶
Auto¶
#include <pto/pto-inst.hpp>
using namespace pto;
void example_auto() {
using SrcT = Tile<TileType::Vec, float, 16, 16>;
using DstT = Tile<TileType::Vec, float, 1, 16>;
using TmpT = Tile<TileType::Vec, float, 16, 16>;
SrcT src;
DstT dst;
TmpT tmp;
TCOLSUM(dst, src, tmp, /*isBinary=*/false);
}
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>;
using TmpT = Tile<TileType::Vec, float, 16, 16>;
SrcT src;
DstT dst;
TmpT tmp;
TASSIGN(src, 0x1000);
TASSIGN(dst, 0x2000);
TASSIGN(tmp, 0x3000);
TCOLSUM(dst, src, tmp, /*isBinary=*/false);
}
ASM Form Examples¶
Auto Mode¶
# Auto mode: compiler/runtime-managed placement and scheduling.
%dst = pto.tcolsum %src : !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.tcolsum %src : !pto.tile<...> -> !pto.tile<...>
PTO Assembly Form¶
%dst = tcolsum %src {isBinary = false} : !pto.tile<...> -> !pto.tile<...>
# AS Level 2 (DPS)
pto.tcolsum ins(%src : !pto.tile_buf<...>) outs(%dst : !pto.tile_buf<...>)