Truncate(ISASI)

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product/Atlas A3 inference product

x

Atlas A2 training product/Atlas A2 inference product

x

Atlas 200I/500 A2 inference product

x

Atlas inference product AI Core

x

Atlas inference product Vector Core

x

Atlas training product

x

Function Usage

Truncates floating-point elements of the source operand to their integer part, while retaining the data type of the source operand.

Prototype

1
2
template <typename T, RoundMode roundMode>
__aicore__ inline void Truncate(const LocalTensor<T> &dst, const LocalTensor<T> &src, const uint32_t count)

Parameters

Table 1 Template parameters

Parameter

Description

T

Operand data type.

For the Atlas 350 Accelerator Card, the supported data types are half, float, and bfloat16_t.

roundMode

Rounding mode. The values are as follows:

  • RoundMode::CAST_RINT: Returns the nearest integer. If two integers are equally close, the even integer is returned.
  • RoundMode::CAST_ROUND: Rounds to the nearest integer.
  • RoundMode::CAST_FLOOR: Rounds down.
  • RoundMode::CAST_CEIL: Rounds up.
  • RoundMode::CAST_TRUNC: Truncates by discarding the fractional part.
Table 2 Parameters

Parameter

Input/Output

Description

dst

Output

Destination operand.

The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT.

The start address of LocalTensor must be 32-byte aligned.

src

Input

Source operand.

The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT.

The start address of LocalTensor must be 32-byte aligned.

The source operand must have the same data type as the destination operand.

count

Input

Number of elements involved in the computation.

Returns

None

Restrictions

Examples

1
AscendC::Truncate<T, RoundMode::CAST_FLOOR>(dstLocal, srcLocal, 512);
Result example:
Input (srcLocal): [-37.063736    64.17277    -33.448692 ... ]
Output (dstLocal): [-38 64 -34 ... ]