Cast (float to bfloat16_t)

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product/Atlas A3 inference product

Atlas A2 training product/Atlas A2 inference product

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

Converts scalar data of the float type to scalar data of the bfloat16_t type.

Prototype

1
__aicore__ inline bfloat16_t Cast(const float& fVal)

Parameters

Table 1 API parameters

Parameter

Input/Output

Meaning

fVal

Input

Scalar data of the float type.

Returns

Converted scalar data of the bfloat16_t type.

Constraints

None

Example

1
2
float m = 3.0f;
bfloat16_t n = AscendC::Cast(m); // n = 3.0. The exponent and mantissa expressions of bfloat16_t and float are different. Truncation can be used for conversion.