Skip to content

Commit a8d7eeb

Browse files
committed
Add predefined datatypes for bfloat16 data
Adds predefined datatypes for little- and big-endian bfloat16 data Does not add support for any native bfloat16 types; datatype conversions are performed in software
1 parent af34892 commit a8d7eeb

Some content is hidden

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

46 files changed

+2765
-804
lines changed

c++/src/H5PredType.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ PredType *PredType::IEEE_F32LE_;
152152
PredType *PredType::IEEE_F64BE_;
153153
PredType *PredType::IEEE_F64LE_;
154154

155+
PredType *PredType::FLT_BF16BE_;
156+
PredType *PredType::FLT_BF16LE_;
157+
155158
PredType *PredType::UNIX_D32BE_;
156159
PredType *PredType::UNIX_D32LE_;
157160
PredType *PredType::UNIX_D64BE_;
@@ -339,6 +342,9 @@ PredType::makePredTypes()
339342
IEEE_F64BE_ = new PredType(H5T_IEEE_F64BE);
340343
IEEE_F64LE_ = new PredType(H5T_IEEE_F64LE);
341344

345+
FLT_BF16BE_ = new PredType(H5T_FLT_BF16BE);
346+
FLT_BF16LE_ = new PredType(H5T_FLT_BF16LE);
347+
342348
UNIX_D32BE_ = new PredType(H5T_UNIX_D32BE);
343349
UNIX_D32LE_ = new PredType(H5T_UNIX_D32LE);
344350
UNIX_D64BE_ = new PredType(H5T_UNIX_D64BE);
@@ -492,6 +498,9 @@ PredType::deleteConstants()
492498
delete IEEE_F64BE_;
493499
delete IEEE_F64LE_;
494500

501+
delete FLT_BF16BE_;
502+
delete FLT_BF16LE_;
503+
495504
delete UNIX_D32BE_;
496505
delete UNIX_D32LE_;
497506
delete UNIX_D64BE_;
@@ -649,6 +658,9 @@ const PredType &PredType::IEEE_F32LE = *IEEE_F32LE_;
649658
const PredType &PredType::IEEE_F64BE = *IEEE_F64BE_;
650659
const PredType &PredType::IEEE_F64LE = *IEEE_F64LE_;
651660

661+
const PredType &PredType::FLT_BF16BE = *FLT_BF16BE_;
662+
const PredType &PredType::FLT_BF16LE = *FLT_BF16LE_;
663+
652664
const PredType &PredType::UNIX_D32BE = *UNIX_D32BE_;
653665
const PredType &PredType::UNIX_D32LE = *UNIX_D32LE_;
654666
const PredType &PredType::UNIX_D64BE = *UNIX_D64BE_;

c++/src/H5PredType.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ class H5_DLLCPP PredType : public AtomType {
9292
static const PredType &IEEE_F64BE;
9393
static const PredType &IEEE_F64LE;
9494

95+
static const PredType &FLT_BF16BE;
96+
static const PredType &FLT_BF16LE;
97+
9598
static const PredType &UNIX_D32BE;
9699
static const PredType &UNIX_D32LE;
97100
static const PredType &UNIX_D64BE;
@@ -262,6 +265,9 @@ class H5_DLLCPP PredType : public AtomType {
262265
static PredType *IEEE_F64BE_;
263266
static PredType *IEEE_F64LE_;
264267

268+
static PredType *FLT_BF16BE_;
269+
static PredType *FLT_BF16LE_;
270+
265271
static PredType *UNIX_D32BE_;
266272
static PredType *UNIX_D32LE_;
267273
static PredType *UNIX_D64BE_;

doxygen/dox/DDLBNF200.dox

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,11 @@ This section contains a brief explanation of the symbols used in the DDL.
9393
H5T_NATIVE_LONG | H5T_NATIVE_ULONG |
9494
H5T_NATIVE_LLONG | H5T_NATIVE_ULLONG
9595

96-
<float> ::= H5T_IEEE_F16BE | H5T_IEEE_F16LE |
96+
<float> ::= H5T_IEEE_F16BE | H5T_IEEE_F16LE |
9797
H5T_IEEE_F32BE | H5T_IEEE_F32LE |
9898
H5T_IEEE_F64BE | H5T_IEEE_F64LE |
99-
H5T_NATIVE_FLOAT16 | H5T_NATIVE_FLOAT |
99+
H5T_FLT_BF16BE | H5T_FLT_BF16LE |
100+
H5T_NATIVE_FLOAT16 | H5T_NATIVE_FLOAT |
100101
H5T_NATIVE_DOUBLE | H5T_NATIVE_LDOUBLE
101102

102103
<time> ::= H5T_TIME: not yet implemented

doxygen/dox/PredefinedDatatypeTables.dox

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
* </div>
99
*
1010
* <div>
11+
* \snippet{doc} tables/predefinedDatatypes.dox predefined_alt_float_datatypes_table
12+
* </div>
13+
*
14+
* <div>
1115
* \snippet{doc} tables/predefinedDatatypes.dox predefined_complex_datatypes_table
1216
* </div>
1317
*

doxygen/examples/tables/predefinedDatatypes.dox

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,25 @@
3535
//! [predefined_ieee_datatypes_table]
3636
*
3737
*
38+
//! [predefined_alt_float_datatypes_table]
39+
<table>
40+
<caption>Predefined Alternative Floating Point Datatypes</caption>
41+
<tr>
42+
<th>Datatype</th>
43+
<th>Description</th>
44+
</tr>
45+
<tr>
46+
<td>#H5T_FLT_BF16BE</td>
47+
<td>16-bit big-endian bfloat16 floating point</td>
48+
</tr>
49+
<tr>
50+
<td>#H5T_FLT_BF16LE</td>
51+
<td>16-bit little-endian bfloat16 floating point</td>
52+
</tr>
53+
</table>
54+
//! [predefined_alt_float_datatypes_table]
55+
*
56+
*
3857
//! [predefined_complex_datatypes_table]
3958
<table>
4059
<caption>Predefined Complex Number Datatypes</caption>

fortran/src/H5_f.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,14 @@ h5init_types_c(hid_t_f *types, hid_t_f *floatingtypes, hid_t_f *integertypes)
245245
return ret_value;
246246
if ((floatingtypes[3] = (hid_t_f)H5Tcopy(H5T_IEEE_F64LE)) < 0)
247247
return ret_value;
248+
if ((floatingtypes[4] = (hid_t_f)H5Tcopy(H5T_IEEE_F16BE)) < 0)
249+
return ret_value;
250+
if ((floatingtypes[5] = (hid_t_f)H5Tcopy(H5T_IEEE_F16LE)) < 0)
251+
return ret_value;
252+
if ((floatingtypes[6] = (hid_t_f)H5Tcopy(H5T_FLT_BF16BE)) < 0)
253+
return ret_value;
254+
if ((floatingtypes[7] = (hid_t_f)H5Tcopy(H5T_FLT_BF16LE)) < 0)
255+
return ret_value;
248256

249257
if ((integertypes[0] = (hid_t_f)H5Tcopy(H5T_STD_I8BE)) < 0)
250258
return ret_value;

fortran/src/H5_ff.F90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ END FUNCTION h5init1_flags_c
291291
H5T_IEEE_F32LE = floating_types(2)
292292
H5T_IEEE_F64BE = floating_types(3)
293293
H5T_IEEE_F64LE = floating_types(4)
294+
H5T_IEEE_F16BE = floating_types(5)
295+
H5T_IEEE_F16LE = floating_types(6)
296+
H5T_FLT_BF16BE = floating_types(7)
297+
H5T_FLT_BF16LE = floating_types(8)
294298

295299
H5T_STD_I8BE = integer_types(1)
296300
H5T_STD_I8LE = integer_types(2)

fortran/src/H5f90global.F90

Lines changed: 9 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 = 4
66+
INTEGER, PARAMETER :: FLOATING_TYPES_LEN = 8
6767
INTEGER, PARAMETER :: INTEGER_TYPES_LEN = 28
6868

6969
! These arrays need to be global because they are used in
@@ -87,6 +87,10 @@ MODULE H5GLOBAL
8787
!DEC$ATTRIBUTES DLLEXPORT :: H5T_IEEE_F32LE
8888
!DEC$ATTRIBUTES DLLEXPORT :: H5T_IEEE_F64BE
8989
!DEC$ATTRIBUTES DLLEXPORT :: H5T_IEEE_F64LE
90+
!DEC$ATTRIBUTES DLLEXPORT :: H5T_IEEE_F16BE
91+
!DEC$ATTRIBUTES DLLEXPORT :: H5T_IEEE_F16LE
92+
!DEC$ATTRIBUTES DLLEXPORT :: H5T_FLT_BF16BE
93+
!DEC$ATTRIBUTES DLLEXPORT :: H5T_FLT_BF16LE
9094
!DEC$ATTRIBUTES DLLEXPORT :: H5T_STD_I8BE
9195
!DEC$ATTRIBUTES DLLEXPORT :: H5T_STD_I8LE
9296
!DEC$ATTRIBUTES DLLEXPORT :: H5T_STD_I16BE
@@ -137,6 +141,10 @@ MODULE H5GLOBAL
137141
INTEGER(HID_T) :: H5T_IEEE_F32LE !< H5T_IEEE_F32LE
138142
INTEGER(HID_T) :: H5T_IEEE_F64BE !< H5T_IEEE_F64BE
139143
INTEGER(HID_T) :: H5T_IEEE_F64LE !< H5T_IEEE_F64LE
144+
INTEGER(HID_T) :: H5T_IEEE_F16BE !< H5T_IEEE_F16BE
145+
INTEGER(HID_T) :: H5T_IEEE_F16LE !< H5T_IEEE_F16LE
146+
INTEGER(HID_T) :: H5T_FLT_BF16BE !< H5T_FLT_BF16BE
147+
INTEGER(HID_T) :: H5T_FLT_BF16LE !< H5T_FLT_BF16LE
140148
INTEGER(HID_T) :: H5T_STD_I8BE !< H5T_STD_I8BE
141149
INTEGER(HID_T) :: H5T_STD_I8LE !< H5T_STD_I8LE
142150
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
@@ -2305,6 +2305,12 @@ H5LT_dtype_to_text(hid_t dtype, char *dt_str, H5LT_lang_t lang, size_t *slen, bo
23052305
else if (H5Tequal(dtype, H5T_IEEE_F64LE)) {
23062306
snprintf(dt_str, *slen, "H5T_IEEE_F64LE");
23072307
}
2308+
else if (H5Tequal(dtype, H5T_FLT_BF16BE)) {
2309+
snprintf(dt_str, *slen, "H5T_FLT_BF16BE");
2310+
}
2311+
else if (H5Tequal(dtype, H5T_FLT_BF16LE)) {
2312+
snprintf(dt_str, *slen, "H5T_FLT_BF16LE");
2313+
}
23082314
#ifdef H5_HAVE__FLOAT16
23092315
else if (H5Tequal(dtype, H5T_NATIVE_FLOAT16)) {
23102316
snprintf(dt_str, *slen, "H5T_NATIVE_FLOAT16");

0 commit comments

Comments
 (0)