TREM
Instruction Diagram
Introduction
Performs element-wise remainder operation on two tiles. When the divisor is non-zero, the sign of a nonzero result is the same as that of the divisor.
Mathematical Semantics
For each element (i, j) in the valid region where the divisor is nonzero:
When the divisor (src1) is nonzero, the sign of a nonzero result is the same as that of the divisor; when the division is exact, the result is zero.
For example, remainder(-7, 3) = 2, remainder(7, -3) = -2, remainder(-6, 3) = 0.
On Ascend 950PR/Ascend 950DT, int64_t follows the floor definition above, and when the divisor is nonzero, the remainder semantics are consistent with int32_t.
Note: This differs from TFMOD, and the result sign of TFMOD is the same as that of the dividend (src0).
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 = RemAlgorithm::DEFAULT, typename TileDataDst, typename TileDataSrc0,
typename TileDataSrc1, typename TileDataTmp, typename... WaitEvents>
PTO_INST RecordEvent TREM(TileDataDst &dst, TileDataSrc0 &src0, TileDataSrc1 &src1, TileDataTmp &tmp, WaitEvents &... events);Constraints
- Implementation check (Atlas A2/A3 training products/Atlas A2/A3 inference products):
TileData::DTypemust be one of the following:float,float32_t,int32_t.- The tile layout must be row-major (
TileData::isRowMajor). - The tile position must be a vector (
TileData::Loc == TileType::Vec). - Runtime: the
src0,src1, anddsttiles should have the samevalidRow/validCol. tmpmust have at least 1 valid row andTileDataDst::RowStride + 8 * ceil(TileDataDst::RowStride / 256) + 8valid columns, used in sequence for the intermediate result, the 32-byte-aligned compressed comparison mask, and the 32-byte address buffer.
- Implementation check (Ascend 950PR/Ascend 950DT):
TileData::DTypemust be one of the following:half,float,int16_t,uint16_t,int32_t,uint32_t,int64_t,uint64_t.- The tile layout must be row-major (
TileData::isRowMajor). - The tile position must be a vector (
TileData::Loc == TileType::Vec). - Runtime: the
src0,src1, anddsttiles should have the samevalidRow/validCol. - Note: The
tmpparameter is accepted but not used on Ascend 950PR/Ascend 950DT.
- Valid region:
- The operation uses
dst.GetValidRow()/dst.GetValidCol()as the iteration domain.
- The operation uses
- Division by zero:
- On Ascend 950PR/Ascend 950DT,
int64_tanduint64_treturn-1andUINT64_MAX(all 64 bits set to 1), respectively, when the divisor is zero. - The behavior is target-defined; the CPU emulation asserts in debug builds.
- On Ascend 950PR/Ascend 950DT,
- High-precision arithmetic:
- It is valid only for the
floattype on Ascend 950PR/Ascend 950DT; thePrecisionTypeoption is ignored on Atlas A2/A3 training products/Atlas A2/A3 inference products.
- It is valid only for the
Examples
#include <pto/pto-inst.hpp>
using namespace pto;
void example() {
using TileT = Tile<TileType::Vec, float, 16, 16>;
using TmpT = Tile<TileType::Vec, float, 1, 32>;
TileT dst, src0, src1;
TmpT tmp;
TREM(dst, src0, src1, tmp);
}