Abs
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
x |
|
x |
|
x |
|
x |
|
x |
|
x |
Function Usage
Computes the absolute values of valid elements in srcReg one by one and writes them to the matching position in dstReg.
Prototype
template <typename T = DefaultType, MaskMergeMode mode = MaskMergeMode::ZEROING, typename U> __simd_callee__ inline void Abs(U& dstReg, U& srcReg, MaskReg& mask) template <typename T = DefaultType, typename U = DefaultType, MaskMergeMode mode = MaskMergeMode::ZEROING, typename S, typename V> __simd_callee__ inline void Abs(S& dstReg, V& srcReg, MaskReg& mask)
Parameters
Parameter |
Description |
|---|---|
T |
Operand data type. For the Atlas 350 Accelerator Card, the supported data types are int8_t, int16_t, int32_t, int64_t, half, and float. |
U |
Data type of the source operand. For the Atlas 350 Accelerator Card, the supported data types are complex32 and complex64. When U is of type complex32, T must be of type half. When U is of type complex64, T must be of type float. |
mode |
Set it to MERGING or ZEROING.
|
S |
RegTensor type of the destination operand, for example, RegTensor<half>. It is automatically inferred by the compiler and does not need to be specified. |
V |
RegTensor type of the source operand, for example, RegTensor<half>. It is automatically inferred by the compiler and does not need to be specified. |
Returns
None
Restrictions
If the computation result of an integer exceeds the representable range of its data type, non-saturating truncation is applied. For example, for an int8 type, if srcReg is -128, its absolute value, 128, will be truncated to -128.
Examples
template<typename T>
__simd_vf__ inline void AbsVF(__ubuf__ T* dstAddr, __ubuf__ T* srcAddr, uint32_t count,
uint32_t oneRepeatSize, uint16_t repeatTimes)
{
AscendC::Reg::RegTensor<T> srcReg;
AscendC::Reg::RegTensor<T> dstReg;
AscendC::Reg::MaskReg mask;
for (uint16_t i = 0; i < repeatTimes; i++) {
mask = AscendC::Reg::UpdateMask<T>(count);
AscendC::Reg::LoadAlign(srcReg, srcAddr + i * oneRepeatSize);
AscendC::Reg::Abs(dstReg, srcReg, mask);
AscendC::Reg::StoreAlign(dstAddr + i * oneRepeatSize, dstReg, mask);
}
}
template<typename T, typename U>
__simd_vf__ inline void AbsVF(__ubuf__ U* dstAddr, __ubuf__ T* srcAddr, uint32_t count,
uint32_t oneRepeatSize, uint16_t repeatTimes)
{
AscendC::Reg::RegTensor<T> srcReg;
AscendC::Reg::RegTensor<U> dstReg;
AscendC::Reg::MaskReg mask;
for (uint16_t i = 0; i < repeatTimes; i++) {
mask = AscendC::Reg::UpdateMask<T>(count);
AscendC::Reg::LoadAlign(srcReg, srcAddr + i * oneRepeatSize);
AscendC::Reg::Abs(dstReg, srcReg, mask);
AscendC::Reg::StoreAlign(dstAddr + i * oneRepeatSize, dstReg, mask);
}
}