TCOLARGMIN
Instruction Diagram
Introduction
Obtains the row index corresponding to the minimum value of each column. It also provides a value+index mode, which returns both the minimum value of each column and its row index.
Mathematical Semantics
Index-Only Mode
Assume R = src.GetValidRow() and C = src.GetValidCol(). For 0 <= j < C:
Value + Index Mode
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.
Index-Only Mode (3 Parameters)
template <typename TileDataOut, typename TileDataIn, typename TileDataTmp, typename... WaitEvents>
PTO_INST RecordEvent TCOLARGMIN(TileDataOut &dst, TileDataIn &src, TileDataTmp &tmp, WaitEvents &...events)Value + Index Mode (4 Parameters)
template <typename TileDataOutVal, typename TileDataOutIdx, typename TileDataIn, typename TileDataTmp,
typename... WaitEvents>
PTO_INST RecordEvent TCOLARGMIN(TileDataOutVal& dstVal, TileDataOutIdx& dstIdx, TileDataIn& src, TileDataTmp& tmp,
WaitEvents&... events);Constraints
General Constraints or Checks
dstIdxandsrcmust beTileType::Vec.srccan use ND or DN non-fractal layout (SLayout::NoneBox).dstIdxmust use a standard ND layout: row-major and non-fractal (BLayout::RowMajor,SLayout::NoneBox).- Supported index destination element types:
uint32_t,int32_t,uint16_t,int16_t. - Runtime checks:
src.GetValidRow() != 0src.GetValidCol() != 0dstIdx.GetValidRow() == 1src.GetValidCol() == dstIdx.GetValidCol()
CPU_SIM Implementation Check
- The supported source element types are integer types,
half,bfloat16_t, andfloat. - The index destination element type must be
int32_toruint32_t. - In value + index mode, the value destination element type must be consistent with the source element type.
- The API retains
tmpfor compatibility, and the CPU implementation does not use this temporary Tile.
Index-Only Mode (3 Parameters)
Implementation Check for Atlas A2/A3 Training Products/Atlas A2/A3 Inference Products
- Supported source element types:
half,float,uint16_t,uint32_t. - The element type of
tmpmust match that ofsrc. tmpis used as temporary storage for index tracking and the current comparison value.
Ascend 950PR/Ascend 950DT Implementation Check
- The supported source element width is 8-bit, 16-bit, or 32-bit, covering
int8_t,uint8_t,int16_t,uint16_t,int32_t,uint32_t,half, andfloat. - The API receives
tmp, but the implementation does not actually use it.
Value + Index Mode (4 Parameters)
In addition to the general constraints:
dstValmust beTileType::Vec, using the standard ND layout (row-major, non-fractal).- The
dstValelement type must match the source element typeTileDataIn::DType. - 8-bit source types are not supported.
- Runtime checks:
dstVal.GetValidRow() == 1dstVal.GetValidCol() != 0src.GetValidCol() == dstVal.GetValidCol()dstVal.GetValidRow() == dstIdx.GetValidRow()dstVal.GetValidCol() == dstIdx.GetValidCol()
Implementation Check for Atlas A2/A3 Training Products/Atlas A2/A3 Inference Products
- Supported source element types:
half,float,uint16_t,uint32_t. - When the source element size is 2 bytes (
half,uint16_t): thedstIdxelement type must beuint16_torint16_t. - When the source element size is 4 bytes (
float,uint32_t): thedstIdxelement type must beuint32_torint32_t. - The element type of
tmpmust match that ofsrc. tmpis used as temporary storage; for the half input type, the s16->f16->s32 conversion path is performed internally.
Ascend 950PR/Ascend 950DT Implementation Check
- The source element size must be 16-bit or 32-bit (
sizeof(T) != 1). - When the source element size is 2 bytes (
half,int16_t,uint16_t): thedstIdxelement type must beuint16_torint16_t. - When the source element size is 4 bytes (
float,int32_t,uint32_t): thedstIdxelement type must beuint32_torint32_t. - The API receives
tmp, but the implementation does not actually use it.
tmp Tile Description for Atlas A2/A3 Training Products/Atlas A2/A3 Inference Products
tmp Tile Description for Atlas A2/A3 Training Products/Atlas A2/A3 Inference ProductsIn the implementation of Atlas A2/A3 training products/Atlas A2/A3 inference products,
tmpis always used, but the extent of usage depends on the source element type and mode:Source Type Mode Region 0 (Row Index) Region 1 (Comparison Value) Region 2 (argmin Index) halfPure Index tmptmptmphalfValue + Index tmptmpdstIdxfloatPure Index tmpdstIdxdstIdxfloatValue + Index tmpdstIdxdstIdxThe data type of the
tmptile must be consistent with that ofsrc.The
tmptile is divided into up to three regions within a single row:- Region 0 (
[0, tmpGapEles)): current row index counter (incremented per row). It is always stored intmp. - Region 1 (
[tmpGapEles, 2 * tmpGapEles)): current minimum element, used for comparison. For thehalftype, it is stored intmp; for thefloattype, it is stored indstIdx. - Region 2 (
[2 * tmpGapEles, 3 * tmpGapEles)): argmin index result. It is stored intmponly in thehalf+ index-only mode; in other cases, it is stored indstIdx.
- Region 0 (
Determination of
tmpGapEles:- When
srcValidCol >= elemPerRpt:tmpGapEles = elemPerRpt. - When
srcValidCol < elemPerRpt:tmpGapEles = ceil(srcValidCol / elemPerBlock) * elemPerBlock.
- When
For
half+ index-only mode (the case with the largesttmpusage), whensrcis small, you can directly set thetmptile size to be the same assrc; you can also calculate the required stride of thetmptile using the following formula:repeats = ceil(validCol / elementPerRepeat) stride = ceil(repeats * 2 / elementPerBlock) * elementPerBlock + ceil(repeats / elementPerBlock) * elementPerBlockFor other type/mode combinations, only region 0 is required in
tmp, so thetmpstride only needs to betmpGapEles.In index-only mode, if the input is of the
halftype, the data in region 2 oftmpundergoes s16->f16->s32 conversion before being written todstIdx.
Ascend 950PR/Ascend 950DT tmp Tile Description
tmp Tile Description- In the Ascend 950PR/Ascend 950DT implementation, the
tmptile is not used in either mode. Ascend 950PR/Ascend 950DT uses a vector-register-based computation approach (__VEC_SCOPE__) and does not require temporary tile storage. tmpis retained in the C++ built-in API signature only for API compatibility with Atlas A2/A3 training products/Atlas A2/A3 inference products.
Examples
Index-Only Mode
Automatic
#include <pto/pto-inst.hpp>
using namespace pto;
void example_auto() {
using SrcT = Tile<TileType::Vec, float, 16, 256, BLayout::RowMajor, -1, -1>;
using DstT = Tile<TileType::Vec, uint32_t, 1, 256, BLayout::RowMajor, -1, -1>;
using TmpT = Tile<TileType::Vec, float, 1, 32, BLayout::RowMajor, -1, -1>;
SrcT src(16, 255);
DstT dst(1, 255);
TmpT tmp(1, 32);
TCOLARGMIN(dst, src, tmp);
}Manual
#include <pto/pto-inst.hpp>
using namespace pto;
void example_manual() {
using SrcT = Tile<TileType::Vec, float, 16, 256, BLayout::RowMajor, -1, -1>;
using DstT = Tile<TileType::Vec, uint32_t, 1, 256, BLayout::RowMajor, -1, -1>;
using TmpT = Tile<TileType::Vec, float, 1, 32, BLayout::RowMajor, -1, -1>;
SrcT src(16, 255);
DstT dst(1, 255);
TmpT tmp(1, 32);
TASSIGN(src, 0x0);
TASSIGN(dst, 0x1000);
TASSIGN(tmp, 0x2000);
TCOLARGMIN(dst, src, tmp);
}Value + Index Mode
Automatic
#include <pto/pto-inst.hpp>
using namespace pto;
void example_auto_val_idx() {
using SrcT = Tile<TileType::Vec, float, 16, 256, BLayout::RowMajor, -1, -1>;
using DstValT = Tile<TileType::Vec, float, 1, 256, BLayout::RowMajor, -1, -1>;
using DstIdxT = Tile<TileType::Vec, int32_t, 1, 256, BLayout::RowMajor, -1, -1>;
using TmpT = Tile<TileType::Vec, float, 1, 32, BLayout::RowMajor, -1, -1>;
SrcT src(16, 255);
DstValT dstVal(1, 255);
DstIdxT dstIdx(1, 255);
TmpT tmp(1, 32);
TCOLARGMIN(dstVal, dstIdx, src, tmp);
}Manual
#include <pto/pto-inst.hpp>
using namespace pto;
void example_manual_val_idx() {
using SrcT = Tile<TileType::Vec, float, 16, 256, BLayout::RowMajor, -1, -1>;
using DstValT = Tile<TileType::Vec, float, 1, 256, BLayout::RowMajor, -1, -1>;
using DstIdxT = Tile<TileType::Vec, int32_t, 1, 256, BLayout::RowMajor, -1, -1>;
using TmpT = Tile<TileType::Vec, float, 1, 32, BLayout::RowMajor, -1, -1>;
SrcT src(16, 255);
DstValT dstVal(1, 255);
DstIdxT dstIdx(1, 255);
TmpT tmp(1, 32);
TASSIGN(src, 0x0);
TASSIGN(dstVal, 0x1000);
TASSIGN(dstIdx, 0x2000);
TASSIGN(tmp, 0x3000);
TCOLARGMIN(dstVal, dstIdx, src, tmp);
}