TREMS
Instruction Diagram
Introduction
Takes the element-wise remainder with a scalar: remainder(src, scalar). When the scalar divisor is non-zero, the sign of a non-zero result is the same as that of the divisor.
Mathematical Semantics
For each element (i, j) in the valid region whose divisor is non-zero:
When scalar is non-zero, the sign of a non-zero result is the same as that of scalar; when the division is exact, the result is zero.
For example, remainder(-7, 3) = 2, remainder(7, -3) = -2, and remainder(-6, 3) = 0.
On Ascend 950PR/Ascend 950DT, int64_t follows the floor-based definition above, and when the divisor is non-zero, its remainder semantics are consistent with those of int32_t.
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,int64_t,uint64_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:
- On Ascend 950PR/Ascend 950DT, when
scalaris zero,int64_tanduint64_treturn-1andUINT64_MAX(all 64 bits set to 1), respectively. - The behavior is target-defined; the CPU simulator asserts in debug builds.
- On Ascend 950PR/Ascend 950DT, when
- Valid region:
- The operation uses
dst.GetValidRow()/dst.GetValidCol()as the iteration domain.
- The 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);
}