TCOLSUM
Instruction Diagram
Introduction
Reduces each column by summing its rows.
Mathematical Semantics
Assume R = src.GetValidRow() and C = src.GetValidCol(). For 0 <= j < C:
isBinary selects the implementation path (binary tree accumulation vs. sequential accumulation).
Assembly Syntax
Synchronous form:
%dst = tcolsum %src {isBinary = false} : !pto.tile<...> -> !pto.tile<...>Rank reduction may introduce an internal temporary tile; the C++ built-in APIs require 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++ Built-in APIs
Declared in include/pto/common/pto_instr.hpp:
The public include header is
<pto/pto-inst.hpp>, and the internal declaration is located inpto/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 or Checks
dstandsrcmust beTileType::Vec.dstandsrcmust use the standard ND layout: row-major and non-fractal (BLayout::RowMajor,SLayout::NoneBox).dstandsrcmust have the same element type.- Runtime checks:
src.GetValidCol() == dst.GetValidCol()src.GetValidRow() != 0(when it is zero, the implementation returns silently without performing computation)src.GetValidCol() != 0(when it is zero, the implementation returns silently without performing computation)src.GetValidCol()must not be greater than thetmprow stride in terms ofsrcelements (that is,tmp.RowStride * sizeof(TmpDType) / sizeof(DType) >= src.GetValidCol())
isBinaryselects the checked backend path:true: usestmpfor binary tree accumulationfalse: performs sequential accumulation directly ondst
Implementation Check for Atlas A2/A3 Training Products/Atlas A2/A3 Inference Products
- Supported element types:
half,float,int16_t,int32_t. tmpmust beTileType::Vecand use the standard ND layout: row-major and non-fractal (BLayout::RowMajor,SLayout::NoneBox).- The element type of
tmpmust be consistent with that ofsrcanddst. - If
src.GetValidRow() == 0orsrc.GetValidCol() == 0, the implementation returns directly.
Ascend 950PR/Ascend 950DT Implementation Check
- The element types allowed by the Ascend 950PR/Ascend 950DT shared column reduction check are:
half,float,int8_t,uint8_t,int16_t,uint16_t,int32_t,uint32_t,bfloat16_t. - In the checked Ascend 950PR/Ascend 950DT
TCOLSUMpath,tmpis still used only for the binary accumulation path;TCOLSUM_IMPLdoes not add any additional explicit compile-time type/layout assertion fortmp.
Temporary Space
Without tmp (2-Parameter Overload: TCOLSUM(dst, src))
No tmp is required. Atlas A2/A3 training products/Atlas A2/A3 inference products and Ascend 950PR/Ascend 950DT all use sequential accumulation directly on dst.
With tmp and isBinary (4-Parameter Overload: TCOLSUM(dst, src, tmp, isBinary))
Atlas A2/A3 Training Products/Atlas A2/A3 Inference Products
- When
isBinary = true:tmpis used for binary tree accumulation. Adjacent row pairs insrcare summed intotmp, and thentmpis recursively halved until only a single row remains.tmpmust have the same element type assrc/dst.tmpmust beTileType::Vec, row-major, and non-fractal.tmp.GetValidCol() >= src.GetValidCol()(in elements, considering thetmpstride).tmprequires at leastceil(src.GetValidRow() / 2)rows.
- When
isBinary = false:tmpis accepted but the implementation uses sequential accumulation directly ondst;tmpis not actively used.
Ascend 950PR/Ascend 950DT
- When
isBinary = true:tmpis used for binary tree accumulation based on vector registers (using UB storage).tmpmust have the same element type assrc/dst.tmp.GetValidCol() >= src.GetValidCol()(in terms of element count, considering thetmpstride).tmprequires at leastceil(src.GetValidRow() / 2)rows.
- When
isBinary = false:tmpis not actively used; the implementation uses sequential reduction throughTColReduceInstr.
Examples
Automatic
#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 Examples
Automatic Mode
# Automatic mode: the compiler/runtime handles resource placement and scheduling.
%dst = pto.tcolsum %src : !pto.tile<...> -> !pto.tile<...>Manual Mode
# Manual mode: explicitly bind resources first, then issue the instruction.
# Optional (when the instruction contains 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<...>)