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 binary tree or sequential accumulation; the 64-bit integer path on A5 ignores this parameter.
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).- The element types of
dstandsrcmust be consistent. - 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)- Only for the binary accumulation path that uses
tmp:src.GetValidCol()must not be greater than thetmprow stride in terms ofsrcelements (that is,tmp.RowStride * sizeof(TmpDType) / sizeof(DType) >= src.GetValidCol())
- For non-64-bit integer types,
isBinaryselects the 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,int64_t,uint64_t,bfloat16_t.In the checked Ascend 950PR/Ascend 950DT
TCOLSUMpath,tmpis used only for the binary accumulation path of non-64-bit integers;TCOLSUM_IMPLdoes not add any additional explicit compile-time type/layout assertion fortmp.For
int64_t/uint64_t: the output valid shape should be[1, src.GetValidCol()]; the physicalColsis a multiple of 4, and the valid column count does not need to be aligned. Only the valid result of row 0 is written, and the remaining physical padding is preserved.
Temporary Space
Without tmp (2-Parameter Overload: TCOLSUM(dst, src))
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))
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
For int64_t / uint64_t, both overloads use the same integer column reduction path; both tmp and isBinary are ignored, and no temporary Tile storage is used. The following temporary space requirements apply only to other supported types.
- 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 elements, 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);
}