0%
Technical specification of HiFloat8 data format
Technical specification of HiFloat8 data format

Technical specification of HiFloat8 data format ​

Introduction ​

This document has been drafted in accordance with 《GB/T 1.1—2020, Directives for standardization—Part 1: Rules for the structure and drafting of standardizing documents》.

This document was proposed by, and is under the jurisdiction of the Global Computing Consortium.

The drafting organizations of this document are: Advanced Manufacturing EDA Co.,Ltd; Beihang University; China Telecom Research Institute; China Electronics Standardization Institute; Digital China Group Co.,Ltd.; GRG Wuzhou Technology Co., Ltd.; Hangzhou Tiankuan Technology Co., Ltd.; Huawei Technologies Co., Ltd.; Henan KunLun Technology Co., Ltd.; iFLYTEK Co., Ltd.; Peking University; Pengcheng Laboratory; Phytium Technology Co., Ltd.; South China University of Technology; Shanghai Artificial Intelligence Innovation Center; Shanghai SenseTime Technology Development Co., Ltd.; STATE CLOUD; Shenzhen Research Institute of Big Data; Shenzhen Longsailing Semiconductor Co. Ltd.; Shenzhen Open Source Co-Creation Technology Co., Ltd.; Tsinghua University; Theo End (Nanjing)Computing Technology Co.Ltd; XCORE SIGMA CORPORATION; Y-semi Computing Co.,Ltd; Zhejiang Lab

Principal Drafters of This Document:Anfa Zhang, Chunyu Shi, Dandan Huang, Fan Zhang, Fangxin Xu, Guipeng Hu, Guangxu Zhu, Haonan Zhang, Hejun Wang, Haijun Zhang, Hongfu Gao, Hua Xiong, Jie Hou, Jinxiang Wang, Jinyang Du, Jianguo Xu., Jinlong Tang, Jun Xiao, Lu Lu, Li Yuan, Liang Li, Mi Liu, Mingyao Zhou, Pu Zhong, Qi Zhang, Qian Wang, Ruihao Gong, Shan Yu, Shiqiao Gu, Shixun Zhang, Xianglong Liu, Xin Wang, Xiaodong Meng, Xinda Ma, Xuecong Wang, Yunyang Ge, Yang Yong, Yansong Tang, Yizhe Wei, Yuanyong Luo, Yaling Li, Yang Li, Yun Zhao, Ziwei Yu, Zhengsheng Chen

1. Scope ​

This document specifies the technical requirements for the binary HiFloat8 data format, including the format specifications, encoding rules and format conversion requirements.

This document is applicable to scenarios where binary data formats are used, and there are comprehensive requirements on the dynamic range and numerical precision, and calculations need to be performed based on the fixed 8-bit width data format. Such scenarios include AI model training and inference, software development and evaluation, and performance assessment.

2. Normative references ​

The content of the following documents, through normative references in the text, constitutes an integral part of this document. For referenced documents with specified dates, only the version corresponding to that date applies to this document. For referenced documents without specified dates, the latest version (including all amendments) applies to this document.

GB/T 17966—2024 Information technology—Microprocessor systems—Floating-point arithmetic

3. Terms and Definitions ​

The content specified in chapter 3 of GB/T 17966—2024, the following terms and definitions apply to this document.

3.1 Data format

The encoding rules in a computer system that define various fields used to represent real values and special values, along with their combination methods.

3.2 Non-redundant coding

Under fixed bit-width conditions, an encoding characteristic that ensures the numerical values represented by different binary bit patterns do not overlap through encoding rules.

3.3 Exponent

A field in the floating-point number representation that is used to represent an integer exponent, where a corresponding power of the radix is used to determine the magnitude and representable range of the value.

3.4 Mantissa

The fractional part used to represent the significant digits in a floating-point number.

3.5 Dot field

The indicator of storage bit width and encoding mode of the exponent, along with the immediately decodable variable-length prefix code field.

3.6 Tapered accuracy

The characteristic of a data format that the number of digits in the mantissa gradually decreases as the absolute value of the exponent increases.

3.7 Not a number

Special encoding of floating-point data that represents an invalid or undefined operation result.

3.8 Infinity

A special floating-point value representing a result that exceeds the range of finite values. Depending on the value of the sign bit, it can be divided into positive infinity and negative infinity.

4. Abbreviations ​

The following abbreviations apply to this document.

NML:Normal

DML:Denormal

HiF8:HiFloat8 Floating-point Data Format

Inf:Infinity

NaN:Not a Number

RHA:Round Half Away from Zero

RTN:Round to Nearest

SE:Sign of Exponent

5. Binary Format ​

5.1 Overview

HiF8 is an 8-bit floating-point data format. It should utilize a dot field to indicate the bit width of the exponent storage and the DML flag, enabling dynamic allocation of the exponent and mantissa bit widths. It should be capable of supporting tapered precision and non-redundant encoding within a fixed 8-bit width.

5.2 Bit field definition

  1. Table 1 lists the binary field segments of HiF8, including the sign field, dot field, exponent field and mantissa field:

    a) Sign field: 1 bit, where 0 indicates that the numerical sign is positive, 1 indicates that the numerical sign is negative.

    b) Dot field: A variable-length field (2-4 bits), encoded with a prefix code, explicitly indicating the storage bit width (0-4) of the exponent field for the current value, or the DML encoding mode flag.

    c) Exponent field: A variable-length field (0-4 bits). When it is 0 bits, it indicates that the exponent value is 0. When it is more than 0 bits, it includes an exponent sign bit, where 0 indicates that the numerical sign of the exponent is positive, 1 indicates that the numerical sign of the exponent is negative, and the highest significant bit of the magnitude is fixed at 1 which is hidden and not stored.

    d) Mantissa field: A variable-length field (1-3 bits). In NML mode, it contains a fixed 1-bit integer hidden bit which indicates 1, with an effective precision of 2-4 bits, storing the fractional part of significant digits. The actual storage bit width is dynamically determined by subtracting the bit widths of sign, dot and exponent fields from the total 8-bit width. In DML mode, the mantissa field is used to extend the range of supported binary decimal values, as well as to represent the special values zero and NaN.

Table 1 HiF8 Binary Field Segments

FieldSign FieldDot FieldExponent FieldMantissa Field
Width1bit2-4bits0-4bits1-3bits

5.3 Encoding Mode and Bit Width Allocation

The encoding modes of HiF8 are determined by the value of the dot field. Table 2 lists the encoding rules and bit width allocations for all modes.

Table 2 HiF8 Encoding Modes, Bit Width Allocations and Exponent Ranges

Dot Value​Dot Field CodeMode​Exponent WidthMantissa WidthExponent Range
00001NML0 bits3 bits0
1001NML1 bit (SE)3 bits±1
201NML2 bit (SE+E)3 bits±[2, 3]
310NML3 bit (SE+E+E)2 bits±[4, 7]
411NML4 bit (SE+E+E+E)1 bits±[8, 15]
DML0000DML0 bit3 bits[-22, -16]

When the dot value of dot field is 0-4, it indicates the NML mode, otherwise it indicates the DML mode.

a) NML mode:

​  1) If the exponent field indicates that the exponent bit width is 0, then the exponent value is 0.

​  2) If the exponent bit width indicated by the dot field ranges from 1 to 4, it includes the exponent sign bit SE and 0-3 bits of exponent value. Taking Dot=4 as an example, the 4 bits of the exponent field are {SE, E, E, E}, and the decoded unsigned binary representation is {SE, 1, E, E, E}, corresponding to a decimal exponent range of ± [8, 15].

​  3) In NML mode, the decimal exponent range is [-15, 15].

b) DML mode:

​  1) The exponent field is empty.

​  2) Three bits of the mantissa field are used to extend the exponent range of seven fraction values. It contains one integer hidden bit with a fixed value of 1. Special values zero and NaN can be represented at this mode.

​  3) In DML mode, the decimal exponent range is [-22, -16].

1

▼ represents DML mode, ★ represents NML mode. The horizontal axis indicates the exponent range. The vertical axis indicates the precision, i.e. the bit width used by the fraction value.

Figure 1 HiF8 Tapered Precision

The relationship between the effective mantissa bit width and the exponent range of HiF8 is illustrated in Figure 1. Unlike data formats with a fixed field segment of bit width, the number of mantissa bits in HiF8 gradually decreases as the absolute value of the exponent increases, exhibiting a tapered precision characteristic. When the exponent value moves away from 0, the number of effective mantissa bits progressively decreases.

6. Encoding Rule ​

6.1 Overview

The encoding of HiF8 should include two modes: NML encoding and DML encoding, as well as three special value encoding modes.

6.2 NML Encoding(Dot=0-4)

When the dot field takes values from 0 to 4, HiF8 adopts the NML encoding mode. Its numerical calculation follows binary scientific notation:

(1)XNML=(−1)S×2E×1.M

Where:

XNML ——Encoding value in NML encoding mode;

𝑆 —— Value represented by the sign bit;

𝐸 —— Integer value represented by the exponent field;

1.𝑀 —— The value represented by one hidden bit with a fixed value of 1 and the mantissa bits.

The exponent field of HiF8 uses sign-magnitude encoding, with the highest bit of the exponent magnitude fixed as the hidden bit. When the dot field takes value of 0, the hidden bit is 0, corresponding to an exponent value of 0. When the dot field takes values from 1 to 4, the hidden bit is 1, and the exponent ranges corresponding to different dot field values should be continuous and non-overlapping.

6.3 DML Encoding(Dot=DML)

When the dot field is encoded as DML, HiF8 adopts the DML encoding mode. In DML encoding mode, there is no exponent field, the mantissa field is directly used to extend the exponent range. The numerical calculation formula is as follows:

(2)XDML=(−1)S×2M−23×1.0

Where:

XDML —— Encoding value in DML encoding mode;

𝑆 —— Value represented by the sign bit;

M —— Three-bit unsigned fixed-point mantissa values (ranging from 1 to 7);

0 —— Definition of special values in this mode。

6.4 Encoding Scope

The exponent range of HiF8 in NML and DML modes is [–22, 15], where 38 binary exponent values are encoded. Table 3 shows the HiF8 encoding diagram, where the encoding representation is S_D_E_M,in which S, D, E and M are the sign, dot, exponent and mantissa fields, respectively. The SE bits are used to indicate the exponent sign (0 for positive, 1 for negative). The numbers in parentheses represent the hidden bits of the fixed amplitude in the exponent field and do not occupy the storage bit width.

Table 3 HiF8 Encoding Diagram

Dot ValueHiF8 CodeExponent Range
0S_0001_(0)_MMM0
1S_001_SE(1)_MMM±1
2S_01_SE(1)E_MMM±[2,3]
3S_10_SE(1)EE_MM±[4,7]
4S_11_SE(1)EEE_M±[8,15]
DMLS_0000_MMM[-22,-16]

6.5 Special Value Encoding

HiF8 defines three types of special values to ensure the completeness of the data format.

a) Zero:S=0, Dot =00002 (DML),M=0002。HiF8 should not distinguish positive zero from negative zero and use the same code to represent ± 0.

b) NaN:S=1, Dot =00002 (DML),M=0002。

c) ±Inf:S=X,Dot =112 ,E=01112 , M=12。

6.6 Key HiF8 Encoding Value

Key HiF8 encoding values and features are shown in Table 4.

Table 4 Key HiF8 Encoding Values and Features

FeatureHiF8 codeValue
InfinitiesS_11_0111_12±Inf
NaN1_0000_0002NaN
Zero0_0000_00020
Maximum NMLS_11_0111_02±215
Minimum NMLS_11_1111_02±2−15
Maximum DMLS_0000_1112±2−16
Minimum DMLS_0000_0012±2−22
Dynamic Range/38 Binary Exponent Values

7. Format Conversion Requirements ​

7.1 Overview

The HiF8 data format should support conversion from a wider floating-point data format. The wider floating-point data formats include:

a) 32-bit floating point number defined in GB/T 17966-2024.

b) 16-bit floating point number defined in GB/T 17966-2024.

c) BF16 data format.

The conversion process should support two conversion modes: saturation mode and non-saturation mode. Table 5 shows the conversion rules.

Format conversion can be achieved through software, hardware, or a combination of both. An example of an algorithm for converting from a wider floating-point type to the HiF8 data format is provided in Appendix A.

Table 5 Conversion Rules for Wider Floating-point Numbers to HiF8

Wider Floating-point NumbersSaturation HiF8 modeNon-saturation HiF8 mode
NANNANNaN
±INF±215±inf
The amplitude is not less than the rounding upper boundary of HiF8: 215×1.25±215±inf
The amplitude is no greater than the rounding lower boundary of HiF8:2−23(Including ±0)00
The amplitude is within the rounding boundary range of HiF8Rounded ValueRounded Value

7.2 Special Value Conversion Rules

  1. During the format conversion process, the handling of special values should obey the following rules:

    a) NaN values are mapped to the NaN representation defined in the HiF8 data format.

    b) Infinity (±Inf) is handled according to the conversion mode.

    ​  1) In saturation mode, it is mapped to the maximum NML of HiF8 (i.e., ±215), and the sign bit is retained.

    ​  2) In non-saturation mode, it is mapped to the infinity defined by HiF8, and the sign bit is retained.

7.3 Rules for Converting the Amplitude of Values

During the format conversion process, numerical processing should obey the following rules:

a) If the data amplitude is no less than 215×1.25 (HiF8 rounding upper boundary value in RHA rounding mode. If it is in RTN rounding mode, only the data amplitude more than 215×1.25 needs to be satisfied).

​  1) In saturation mode, the value is mapped to the maximum NML of HiF8 (i.e., ±215), and the sign bit is reserved.

​  2) In non-saturation mode, it is mapped to ± Inf as defined by HiF8, and the sign bit is reserved.

b) If the data amplitude is no greater than 2-23 (Lower bound of the HiF8 rounding, including ±0), it is mapped to the Zero of HiF8.

c) If the data amplitude falls within the HiF8 rounding boundary range, generate the corresponding HiF8 data representation according to the rounding rules defined in section 7.4. During the rounding process, the impact of carry on the exponent and the mantissa field should be considered to ensure the correct binary encoding is generated. The conversion logic refers to the algorithm example shown in Appendix A.

7.4 Rounding Rules

The rounding strategy should implement both RHA and RTN rounding modes and obey the following rules:

a) In RHA rounding mode, check the highest bit of the discarded bits:

​  1) If this bit is 1, the carry operation is performed on the reserved bit.

​  2) If this bit is 0, the reserved bits remain unchanged.

b) In RTN rounding mode, the discarded bits are treated as the binary fractional part as a whole:

​  1) If the value of the discarded bits is greater than 0.5, perform a carry operation.

​  2) If the value of the discarded bits is less than 0.5, no carry is performed.

​  3) If the value of the discarded bits is equal to 0.5, check the lowest significant bit of the retained bits. If this bit is 1, perform a carry operation. If this bit is 0, no carry is performed.

7.5 High-Precision Format and HiF8 Quantization/Dequantization

The quantization and dequantization processes between the high-precision floating-point format and the HiF8 data format must comply with the numerical range, saturation behavior, rounding mode and special value handling rules specified in Chapter 7.

Appendix A ​

Algorithm Example for Converting Wider Floating-Point Formats to HiF8 Format

The following example demonstrates the basic logic of converting wider floating-point format data to HiF8 data format when the input data amplitude falls within the HiF8 rounding boundary range.

【Example:

  1. Ex=foor(log2(abs(Xfloat)) //Ex∈[−23, 15]
  2. Ex= −22 if Ex< −22 //Ex∈[−22, 15]
  3. Mx=abs(x)×2−Ex //Mx=(0.5, 2)
  4. Dx,Mwidth=HiF8_Encode_Exp(Ex) //Dot field encoding and mantissa width
  5. Mrounded=Round(Mx, Mwidth, mode=RHA/RTN) //Rounding operation,Mrounded=[1, 2]
  6. IF (Mrounded==2): //Updating the HiF8 fields after rounding
  7. Mrounded=1
  8. Ex=Ex+1
  9. Dx=HiF8_Encode_Exp(Ex)
  10. ENDIF
  11. XHiF8=HiF8_Encode(Sign(Xfloat), Dx, Ex, Mrounded) //Encoding the rounded value into HiF8

Algorithm Description:

a) Lines 1 to 3 are used to extract and preprocess the exponent value and mantissa value of wider floating-point format data:

​  1) Line 1 obtains the exponent value Ex by taking the base-2 logarithm of the absolute value of the input data and then taking the floor, with the range of [-23, 15].

​  2) Line 2 restricts the lower bound of the exponent. When Ex<−22, it is truncated to -22. This processing ensures that data with an amplitude smaller than the minimum non-zero NML encoded value of HiF8 can still be represented by HiF8 after rounding and carry, thereby extending the representable range of HiF8.

​  3) In line 3, the mantissa value Mx is calculated based on the processed exponent value, and the value range of Mxis (0.5,2).

b) Lines 4-5 implement the calculation of parameters before rounding and the rounding operation:

​  4) In line 4, the HiF8 dot field code Dx and the mantissa width Mwidth are calculated based on the exponent of the wider floating point. For the mapping relationship, refer to the rules defined in Table 2 for the correspondence among the HiF8 exponent, dot field and mantissa width.

Note: In NML mode, the effective bit width equals the sum of the mantissa bit width and the hidden bit width. In DML mode, the effective bit width is 1.

​  5) In Line 5, based on the configured rounding mode (RHA or RTN), calculate the rounded HiF8 value of mantissa.

c) Lines 6-10 are used to handle special cases where rounding results have a carry (i.e., the mantissa value is 2). In this case, the mantissa value is divided by 2 to become 1, and the exponent is incremented by 1. Since the exponent has changed, it may cause the exponent value to cross the boundary indicated by the HiF8 dot field. Therefore, it is necessary to refer to Table 2 to confirm the updated dot field.

d) Line 11 encodes the rounded, wider floating-point format data into binary HiF8 data based on the HiF8 encoding rules. This step requires the sign bit, dot field encoding, exponent value and mantissa value.】

Reference ​

[1] GB/T 17966—2024 Information technology—Microprocessor systems—Floating-point arithmetic

[2] IEEE Computer Society, “IEEE Standard for Floating-Point Arithmetic”, in IEEE Std 754-2019 (Revision of IEEE 754-2008), link, June 2019

[3] Google, “The Bfloat16 Numerical Format”, https://cloud.google.com/tpu/docs/bfloat16