TREMS
Instruction Diagram
Introduction
Element-wise remainder with a scalar: remainder(src, scalar).
Mathematical Semantics
For each element (i, j) in the valid region:
Assembly Syntax
Synchronous form:
%dst = trems %src, %scalar : !pto.tile<...>, f32AS Level 1 (SSA)
%dst = pto.trems %src, %scalar : (!pto.tile<...>, dtype) -> !pto.tile<...>AS Level 2 (DPS)
pto.trems ins(%src, %scalar : !pto.tile_buf<...>, dtype) 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 <auto PrecisionType = RemSAlgorithm::DEFAULT, typename TileDataDst, typename TileDataSrc, typename TileDataTmp,
typename... WaitEvents>
PTO_INST RecordEvent TREMS(TileDataDst &dst, TileDataSrc &src, typename TileDataSrc::DType scalar, TileDataTmp &tmp,
WaitEvents &...events);PrecisionType can specify the following values:
RemSAlgorithm::DEFAULT: normal algorithm that is fast but less accurate.RemSAlgorithm::HIGH_PRECISION: high-precision algorithm that is slower and supports only thefloattype.
Constraints
- Implementation check (Atlas A2/A3 training products/Atlas A2/A3 inference products):
dstandsrcmust use the same element type.- Supported element types:
floatandint32_t. dstandsrcmust be vector tiles.dstandsrcmust be row-major.- Runtime:
dst.GetValidRow() == src.GetValidRow() > 0anddst.GetValidCol() == src.GetValidCol() > 0. - tmp buffer requirements:
tmp.GetValidCol() >= dst.GetValidCol()(at least the same number of columns as dst)tmp.GetValidRow() >= 1(at least 1 row)- The data type must match
TileDataDst::DType.
- Implementation check (Ascend 950PR/Ascend 950DT):
dstandsrcmust use the same element type.- Supported element types:
float,int32_t,uint32_t,half,int16_t, anduint16_t. dstandsrcmust be vector tiles.- The static valid boundaries of both tiles must satisfy
ValidRow <= RowsandValidCol <= Cols. - Runtime:
dst.GetValidRow() == src.GetValidRow()anddst.GetValidCol() == src.GetValidCol(). - Note: The tmp parameter is accepted but not validated or used on Ascend 950PR/Ascend 950DT.
- Division by zero:
- The behavior is target-defined; the CPU simulator asserts in debug builds.
- Valid region:
- This operation uses
dst.GetValidRow()/dst.GetValidCol()as the iteration domain.
- This operation uses
- For
int32_tinputs (Atlas A2/A3 training products/Atlas A2/A3 inference products only): The elements ofsrcandscalarmust be within the range[-2^24, 2^24](that is,[-16777216, 16777216]) to ensure exact conversion to float32 during computation. - High-precision algorithm:
- Valid only on Ascend 950PR/Ascend 950DT; the
PrecisionTypeoption is ignored on Atlas A3 training products/Atlas A3 inference products.
- Valid only on Ascend 950PR/Ascend 950DT; the
Examples
#include <pto/pto-inst.hpp>
using namespace pto;
void example() {
using TileT = Tile<TileType::Vec, float, 16, 16>;
TileT x, out;
Tile<TileType::Vec, float, 16, 16> tmp;
TREMS(out, x, 3.0f, tmp);
}ASM Examples
Automatic Mode
# Automatic mode: the compiler/runtime is responsible for resource placement and scheduling.
%dst = pto.trems %src, %scalar : (!pto.tile<...>, dtype) -> !pto.tile<...>Manual Mode
# Manual mode: bind resources explicitly first, then issue the instruction.
# Optional (when the instruction contains tile operands):
# pto.tassign %arg0, @tile(0x1000)
# pto.tassign %arg1, @tile(0x2000)
%dst = pto.trems %src, %scalar : (!pto.tile<...>, dtype) -> !pto.tile<...>PTO Assembly Form
%dst = trems %src, %scalar : !pto.tile<...>, f32
# AS Level 2 (DPS)
pto.trems ins(%src, %scalar : !pto.tile_buf<...>, dtype) outs(%dst : !pto.tile_buf<...>)