SetHF32

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

Sets whether to enable the HF32 mode (data type that can be used for matrix multiplication) in CUBE_ONLY mode (only matrix computation). After the mode is enabled, the float32 data type is converted to the hf32 data type during matrix multiplication, which improves the computing performance but causes precision loss.

Prototype

1
__aicore__ inline void SetHF32(bool enableHF32 = false, int32_t transMode = 0)

Parameters

Parameter

Input/Output

Description

enableHF32

Input

Whether to enable the HF32 mode. The default value is false, indicating that the HF32 mode is disabled.

transMode

Input

ROUND mode used for converting float to hf32 when the HF32 mode is enabled. The default value is 0.

0: rounding to the nearest even number when the distance is equal.

1: rounding to the nearest number away from zero when the distance is equal.

Returns

None

Restrictions

This API can be called only in CUBE_ONLY mode.

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
// CUBE_ONLY mode
#define ASCENDC_CUBE_ONLY
REGIST_MATMUL_OBJ(&pipe, GetSysWorkSpacePtr(), mm, &tiling);    // A/B/C/Bias is of the float type.
mm.SetTensorA(gm_a);
mm.SetTensorB(gm_b);
if (tiling.isBias) {
    mm.SetBias(gmBias);
}
mm.SetHF32(true);
mm.IterateAll(gm_c);
mm.SetHF32(false);
mm.End();