Truncate
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
x |
|
x |
|
x |
|
x |
|
x |
|
x |
Function Usage
Truncates the float elements of the source operand to their integer parts, while retaining the data type of the source operand.
Prototype
template <typename T = DefaultType, RoundMode roundMode = RoundMode::CAST_NONE, MaskMergeMode mode = MaskMergeMode::ZEROING, typename S> __simd_callee__ inline void Truncate(S& dstReg, S& srcReg, MaskReg& mask)
Parameters
Parameter |
Description |
|---|---|
T |
Operand data type. For the Atlas 350 Accelerator Card, the supported data types of dstReg/srcReg are half, float, and bfloat16_t. |
roundMode |
Rounding mode. The options are as follows:
|
mode |
Set it to MERGING or ZEROING.
|
S |
srcReg or dstReg type, for example, RegTensor<float>. It is automatically inferred by the compiler and does not need to be specified. |
Parameter |
Input/Output |
Description |
|---|---|---|
dstReg |
Output |
Destination operand. The type is RegTensor. |
srcReg |
Input |
Source operand. The type is RegTensor. The source operand must have the same data type as the destination operand. |
mask |
Input |
Valid indication of the source operand element operation. For details, see MaskReg. |
Returns
None
Constraints
- In non-saturation mode, if the input is NaN, the output is NaN. If the input value exceeds the value range of the input type, the output is +/-inf.
- In saturation mode, if the input is NaN, the output is 0. If the input value exceeds the value range of the input type, the output is saturated to the maximum or minimum value.
- The float type supports only the non-saturation mode.
Example
template<typename T>
__simd_vf__ inline void TruncVF(__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++) {
AscendC::Reg::LoadAlign(srcReg, srcAddr + i * oneRepeatSize);
mask = AscendC::Reg::UpdateMask<T>(count);
AscendC::Reg::Truncate<T, AscendC::RoundMode::CAST_FLOOR, AscendC::Reg::MaskMergeMode::ZEROING>(dstReg, srcReg, mask);
AscendC::Reg::StoreAlign(dstAddr + i * oneRepeatSize, dstReg, mask);
}
}