Skip to content

Commit d0e8532

Browse files
committed
Add predefined datatypes for FP8 formats
Adds predefined datatypes for FP8 data in E4M3 and E5M2 formats Does not add support for any native FP8 types; datatype conversions are performed in software
1 parent 4202ae8 commit d0e8532

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2555
-728
lines changed

c++/src/H5PredType.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ PredType *PredType::IEEE_F64LE_;
154154

155155
PredType *PredType::FLOAT_BFLOAT16BE_;
156156
PredType *PredType::FLOAT_BFLOAT16LE_;
157+
PredType *PredType::FLOAT_F8E4M3_;
158+
PredType *PredType::FLOAT_F8E5M2_;
157159

158160
PredType *PredType::UNIX_D32BE_;
159161
PredType *PredType::UNIX_D32LE_;
@@ -344,6 +346,8 @@ PredType::makePredTypes()
344346

345347
FLOAT_BFLOAT16BE_ = new PredType(H5T_FLOAT_BFLOAT16BE);
346348
FLOAT_BFLOAT16LE_ = new PredType(H5T_FLOAT_BFLOAT16LE);
349+
FLOAT_F8E4M3_ = new PredType(H5T_FLOAT_F8E4M3);
350+
FLOAT_F8E5M2_ = new PredType(H5T_FLOAT_F8E5M2);
347351

348352
UNIX_D32BE_ = new PredType(H5T_UNIX_D32BE);
349353
UNIX_D32LE_ = new PredType(H5T_UNIX_D32LE);
@@ -500,6 +504,8 @@ PredType::deleteConstants()
500504

501505
delete FLOAT_BFLOAT16BE_;
502506
delete FLOAT_BFLOAT16LE_;
507+
delete FLOAT_F8E4M3_;
508+
delete FLOAT_F8E5M2_;
503509

504510
delete UNIX_D32BE_;
505511
delete UNIX_D32LE_;
@@ -660,6 +666,8 @@ const PredType &PredType::IEEE_F64LE = *IEEE_F64LE_;
660666

661667
const PredType &PredType::FLOAT_BFLOAT16BE = *FLOAT_BFLOAT16BE_;
662668
const PredType &PredType::FLOAT_BFLOAT16LE = *FLOAT_BFLOAT16LE_;
669+
const PredType &PredType::FLOAT_F8E4M3 = *FLOAT_F8E4M3_;
670+
const PredType &PredType::FLOAT_F8E5M2 = *FLOAT_F8E5M2_;
663671

664672
const PredType &PredType::UNIX_D32BE = *UNIX_D32BE_;
665673
const PredType &PredType::UNIX_D32LE = *UNIX_D32LE_;

c++/src/H5PredType.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class H5CPP_DLL PredType : public AtomType {
9494

9595
static const PredType &FLOAT_BFLOAT16BE;
9696
static const PredType &FLOAT_BFLOAT16LE;
97+
static const PredType &FLOAT_F8E4M3;
98+
static const PredType &FLOAT_F8E5M2;
9799

98100
static const PredType &UNIX_D32BE;
99101
static const PredType &UNIX_D32LE;
@@ -267,6 +269,8 @@ class H5CPP_DLL PredType : public AtomType {
267269

268270
static PredType *FLOAT_BFLOAT16BE_;
269271
static PredType *FLOAT_BFLOAT16LE_;
272+
static PredType *FLOAT_F8E4M3_;
273+
static PredType *FLOAT_F8E5M2_;
270274

271275
static PredType *UNIX_D32BE_;
272276
static PredType *UNIX_D32LE_;

doxygen/dox/DDLBNF200.dox

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ This section contains a brief explanation of the symbols used in the DDL.
100100
H5T_IEEE_F32BE | H5T_IEEE_F32LE |
101101
H5T_IEEE_F64BE | H5T_IEEE_F64LE |
102102
H5T_FLOAT_BFLOAT16BE | H5T_FLOAT_BFLOAT16LE |
103+
H5T_FLOAT_F8E4M3 | H5T_FLOAT_F8E5M2 |
103104
H5T_NATIVE_FLOAT16 | H5T_NATIVE_FLOAT |
104105
H5T_NATIVE_DOUBLE | H5T_NATIVE_LDOUBLE
105106

doxygen/examples/tables/predefinedDatatypes.dox

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@
5050
<td>#H5T_FLOAT_BFLOAT16LE</td>
5151
<td>16-bit little-endian bfloat16 floating point</td>
5252
</tr>
53+
<tr>
54+
<td>#H5T_FLOAT_F8E4M3</td>
55+
<td>8-bit FP8 E4M3 (4 exponent bits, 3 mantissa bits) floating point</td>
56+
</tr>
57+
<tr>
58+
<td>#H5T_FLOAT_F8E5M2</td>
59+
<td>8-bit FP8 E5M2 (5 exponent bits, 2 mantissa bits) floating point</td>
60+
</tr>
5361
</table>
5462
//! [predefined_alt_float_datatypes_table]
5563
*

fortran/src/H5_f.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ h5init_types_c(hid_t_f *types, hid_t_f *floatingtypes, hid_t_f *integertypes)
253253
return ret_value;
254254
if ((floatingtypes[7] = (hid_t_f)H5Tcopy(H5T_FLOAT_BFLOAT16LE)) < 0)
255255
return ret_value;
256+
if ((floatingtypes[8] = (hid_t_f)H5Tcopy(H5T_FLOAT_F8E4M3)) < 0)
257+
return ret_value;
258+
if ((floatingtypes[9] = (hid_t_f)H5Tcopy(H5T_FLOAT_F8E5M2)) < 0)
259+
return ret_value;
256260

257261
if ((integertypes[0] = (hid_t_f)H5Tcopy(H5T_STD_I8BE)) < 0)
258262
return ret_value;

fortran/src/H5_ff.F90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ END FUNCTION h5init1_flags_c
295295
H5T_IEEE_F16LE = floating_types(6)
296296
H5T_FLOAT_BFLOAT16BE = floating_types(7)
297297
H5T_FLOAT_BFLOAT16LE = floating_types(8)
298+
H5T_FLOAT_F8E4M3 = floating_types(9)
299+
H5T_FLOAT_F8E5M2 = floating_types(10)
298300

299301
H5T_STD_I8BE = integer_types(1)
300302
H5T_STD_I8LE = integer_types(2)

fortran/src/H5f90global.F90

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ MODULE H5GLOBAL
6363
! Do not forget to change these values when new predefined
6464
! datatypes are added
6565
INTEGER, PARAMETER :: PREDEF_TYPES_LEN = 19
66-
INTEGER, PARAMETER :: FLOATING_TYPES_LEN = 8
66+
INTEGER, PARAMETER :: FLOATING_TYPES_LEN = 10
6767
INTEGER, PARAMETER :: INTEGER_TYPES_LEN = 28
6868

6969
! These arrays need to be global because they are used in
@@ -91,6 +91,8 @@ MODULE H5GLOBAL
9191
!DEC$ATTRIBUTES DLLEXPORT :: H5T_IEEE_F16LE
9292
!DEC$ATTRIBUTES DLLEXPORT :: H5T_FLOAT_BFLOAT16BE
9393
!DEC$ATTRIBUTES DLLEXPORT :: H5T_FLOAT_BFLOAT16LE
94+
!DEC$ATTRIBUTES DLLEXPORT :: H5T_FLOAT_F8E4M3
95+
!DEC$ATTRIBUTES DLLEXPORT :: H5T_FLOAT_F8E5M2
9496
!DEC$ATTRIBUTES DLLEXPORT :: H5T_STD_I8BE
9597
!DEC$ATTRIBUTES DLLEXPORT :: H5T_STD_I8LE
9698
!DEC$ATTRIBUTES DLLEXPORT :: H5T_STD_I16BE
@@ -145,6 +147,8 @@ MODULE H5GLOBAL
145147
INTEGER(HID_T) :: H5T_IEEE_F16LE !< H5T_IEEE_F16LE
146148
INTEGER(HID_T) :: H5T_FLOAT_BFLOAT16BE !< H5T_FLOAT_BFLOAT16BE
147149
INTEGER(HID_T) :: H5T_FLOAT_BFLOAT16LE !< H5T_FLOAT_BFLOAT16LE
150+
INTEGER(HID_T) :: H5T_FLOAT_F8E4M3 !< H5T_FLOAT_F8E4M3
151+
INTEGER(HID_T) :: H5T_FLOAT_F8E5M2 !< H5T_FLOAT_F8E5M2
148152
INTEGER(HID_T) :: H5T_STD_I8BE !< H5T_STD_I8BE
149153
INTEGER(HID_T) :: H5T_STD_I8LE !< H5T_STD_I8LE
150154
INTEGER(HID_T) :: H5T_STD_I16BE !< H5T_STD_I16BE

hl/src/H5LT.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2311,6 +2311,12 @@ H5LT_dtype_to_text(hid_t dtype, char *dt_str, H5LT_lang_t lang, size_t *slen, bo
23112311
else if (H5Tequal(dtype, H5T_FLOAT_BFLOAT16LE)) {
23122312
snprintf(dt_str, *slen, "H5T_FLOAT_BFLOAT16LE");
23132313
}
2314+
else if (H5Tequal(dtype, H5T_FLOAT_F8E4M3)) {
2315+
snprintf(dt_str, *slen, "H5T_FLOAT_F8E4M3");
2316+
}
2317+
else if (H5Tequal(dtype, H5T_FLOAT_F8E5M2)) {
2318+
snprintf(dt_str, *slen, "H5T_FLOAT_F8E5M2");
2319+
}
23142320
#ifdef H5_HAVE__FLOAT16
23152321
else if (H5Tequal(dtype, H5T_NATIVE_FLOAT16)) {
23162322
snprintf(dt_str, *slen, "H5T_NATIVE_FLOAT16");

0 commit comments

Comments
 (0)