diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/lib/h5diff_array.c | 265 | ||||
-rw-r--r-- | tools/lib/h5diff_util.c | 10 | ||||
-rw-r--r-- | tools/lib/h5tools_dump.c | 10 | ||||
-rw-r--r-- | tools/lib/h5tools_str.c | 12 | ||||
-rw-r--r-- | tools/lib/h5tools_type.c | 8 | ||||
-rw-r--r-- | tools/src/h5import/h5import.c | 108 | ||||
-rw-r--r-- | tools/src/h5ls/h5ls.c | 13 | ||||
-rw-r--r-- | tools/test/h5dump/CMakeTests.cmake | 5 | ||||
-rw-r--r-- | tools/test/h5dump/expected/tfloat16.ddl | 46 | ||||
-rw-r--r-- | tools/test/h5dump/h5dumpgentest.c | 86 | ||||
-rw-r--r-- | tools/test/h5dump/testfiles/tfloat16.h5 | bin | 0 -> 2304 bytes | |||
-rw-r--r-- | tools/test/h5dump/testh5dump.sh.in | 5 | ||||
-rw-r--r-- | tools/test/h5ls/CMakeTests.cmake | 20 | ||||
-rw-r--r-- | tools/test/h5ls/expected/tfloat16.ls | 8 | ||||
-rw-r--r-- | tools/test/h5ls/expected/tfloat16_nosupport.ls | 8 | ||||
-rw-r--r-- | tools/test/h5ls/testh5ls.sh.in | 11 |
16 files changed, 583 insertions, 32 deletions
diff --git a/tools/lib/h5diff_array.c b/tools/lib/h5diff_array.c index d8c9ac6..86d873d 100644 --- a/tools/lib/h5diff_array.c +++ b/tools/lib/h5diff_array.c @@ -145,6 +145,10 @@ static hsize_t diff_double_element(unsigned char *mem1, unsigned char *mem2, hsi diff_opt_t *opts); static hsize_t diff_ldouble_element(unsigned char *mem1, unsigned char *mem2, hsize_t elem_idx, diff_opt_t *opts); +#ifdef H5_HAVE__FLOAT16 +static hsize_t diff_float16_element(unsigned char *mem1, unsigned char *mem2, hsize_t elem_idx, + diff_opt_t *opts); +#endif static hsize_t diff_schar_element(unsigned char *mem1, unsigned char *mem2, hsize_t elem_idx, diff_opt_t *opts); static hsize_t diff_uchar_element(unsigned char *mem1, unsigned char *mem2, hsize_t elem_idx, @@ -233,7 +237,20 @@ diff_array(void *_mem1, void *_mem2, diff_opt_t *opts, hid_t container1_id, hid_ */ case H5T_FLOAT: H5TOOLS_DEBUG("type_class:H5T_FLOAT"); - if (H5Tequal(opts->m_tid, H5T_NATIVE_FLOAT)) { +#ifdef H5_HAVE__FLOAT16 + if (H5Tequal(opts->m_tid, H5T_NATIVE_FLOAT16)) { + for (i = 0; i < opts->hs_nelmts; i++) { + nfound += diff_float16_element(mem1, mem2, i, opts); + + mem1 += sizeof(H5__Float16); + mem2 += sizeof(H5__Float16); + if (opts->count_bool && nfound >= opts->count) + return nfound; + } + } + else +#endif + if (H5Tequal(opts->m_tid, H5T_NATIVE_FLOAT)) { for (i = 0; i < opts->hs_nelmts; i++) { nfound += diff_float_element(mem1, mem2, i, opts); @@ -263,6 +280,7 @@ diff_array(void *_mem1, void *_mem2, diff_opt_t *opts, hid_t container1_id, hid_ return nfound; } /* nelmts */ } + break; case H5T_INTEGER: @@ -1221,38 +1239,50 @@ diff_datum(void *_mem1, void *_mem2, hsize_t elemtno, diff_opt_t *opts, hid_t co *------------------------------------------------------------------------- */ case H5T_FLOAT: - /*------------------------------------------------------------------------- - * H5T_NATIVE_FLOAT - *------------------------------------------------------------------------- - */ H5TOOLS_DEBUG("H5T_FLOAT"); - if (type_size == 4) { - if (type_size != sizeof(float)) - H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Type size is not float size"); - nfound += diff_float_element(mem1, mem2, elemtno, opts); - } +#ifdef H5_HAVE__FLOAT16 /*------------------------------------------------------------------------- - * H5T_NATIVE_DOUBLE + * H5T_NATIVE_FLOAT16 *------------------------------------------------------------------------- */ - else if (type_size == 8) { - if (type_size != sizeof(double)) - H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Type size is not double size"); - nfound += diff_double_element(mem1, mem2, elemtno, opts); + if (type_size == H5_SIZEOF__FLOAT16) { + if (type_size != sizeof(H5__Float16)) + H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Type size is not _Float16 size"); + nfound += diff_float16_element(mem1, mem2, elemtno, opts); } + else +#endif + /*------------------------------------------------------------------------- + * H5T_NATIVE_FLOAT + *------------------------------------------------------------------------- + */ + if (type_size == 4) { + if (type_size != sizeof(float)) + H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Type size is not float size"); + nfound += diff_float_element(mem1, mem2, elemtno, opts); + } + /*------------------------------------------------------------------------- + * H5T_NATIVE_DOUBLE + *------------------------------------------------------------------------- + */ + else if (type_size == 8) { + if (type_size != sizeof(double)) + H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Type size is not double size"); + nfound += diff_double_element(mem1, mem2, elemtno, opts); + } #if H5_SIZEOF_LONG_DOUBLE != H5_SIZEOF_DOUBLE - /*------------------------------------------------------------------------- - * H5T_NATIVE_LDOUBLE - *------------------------------------------------------------------------- - */ - else if (type_size == H5_SIZEOF_LONG_DOUBLE) { - if (type_size != sizeof(long double)) { - H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Type size is not long double size"); - } - nfound += diff_ldouble_element(mem1, mem2, elemtno, opts); - } /*H5T_NATIVE_LDOUBLE*/ -#endif /* H5_SIZEOF_LONG_DOUBLE */ + /*------------------------------------------------------------------------- + * H5T_NATIVE_LDOUBLE + *------------------------------------------------------------------------- + */ + else if (type_size == H5_SIZEOF_LONG_DOUBLE) { + if (type_size != sizeof(long double)) { + H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Type size is not long double size"); + } + nfound += diff_ldouble_element(mem1, mem2, elemtno, opts); + } /*H5T_NATIVE_LDOUBLE*/ +#endif /* H5_SIZEOF_LONG_DOUBLE */ break; /* H5T_FLOAT class */ @@ -2178,6 +2208,189 @@ diff_ldouble_element(unsigned char *mem1, unsigned char *mem2, hsize_t elem_idx, return nfound; } +#ifdef H5_HAVE__FLOAT16 +/*------------------------------------------------------------------------- + * Function: diff_float16_element + * + * Purpose: diff a single H5T_NATIVE_FLOAT16 type + * + * Return: number of differences found + * + *------------------------------------------------------------------------- + */ +static hsize_t +diff_float16_element(unsigned char *mem1, unsigned char *mem2, hsize_t elem_idx, diff_opt_t *opts) +{ + hsize_t nfound = 0; /* number of differences found */ + H5__Float16 temp1_float16; + H5__Float16 temp2_float16; + double per; + bool both_zero = false; + bool isnan1 = false; + bool isnan2 = false; + + H5TOOLS_START_DEBUG("delta_bool:%d - percent_bool:%d", opts->delta_bool, opts->percent_bool); + + memcpy(&temp1_float16, mem1, sizeof(H5__Float16)); + memcpy(&temp2_float16, mem2, sizeof(H5__Float16)); + + /* logic for detecting NaNs is different with opts -d, -p and no opts */ + + /*------------------------------------------------------------------------- + * -d and !-p + *------------------------------------------------------------------------- + */ + if (opts->delta_bool && !opts->percent_bool) { + /*------------------------------------------------------------------------- + * detect NaNs + *------------------------------------------------------------------------- + */ + if (opts->do_nans) { + isnan1 = isnan(temp1_float16); + isnan2 = isnan(temp2_float16); + } + + /* both not NaN, do the comparison */ + if (!isnan1 && !isnan2) { + if ((double)ABS(temp1_float16 - temp2_float16) > opts->delta) { + opts->print_percentage = 0; + print_pos(opts, elem_idx, 0); + if (print_data(opts)) { + parallel_print(F_FORMAT, (double)temp1_float16, (double)temp2_float16, + (double)ABS(temp1_float16 - temp2_float16)); + } + nfound++; + } + } + /* only one is NaN, assume difference */ + else if ((isnan1 && !isnan2) || (!isnan1 && isnan2)) { + opts->print_percentage = 0; + print_pos(opts, elem_idx, 0); + if (print_data(opts)) { + parallel_print(F_FORMAT, (double)temp1_float16, (double)temp2_float16, + (double)ABS(temp1_float16 - temp2_float16)); + } + nfound++; + } + } + /*------------------------------------------------------------------------- + * !-d and -p + *------------------------------------------------------------------------- + */ + else if (!opts->delta_bool && opts->percent_bool) { + /*------------------------------------------------------------------------- + * detect NaNs + *------------------------------------------------------------------------- + */ + if (opts->do_nans) { + isnan1 = isnan(temp1_float16); + isnan2 = isnan(temp2_float16); + } + /* both not NaN, do the comparison */ + if ((!isnan1 && !isnan2)) { + PER(temp1_float16, temp2_float16); + + if (not_comparable && !both_zero) { + opts->print_percentage = 1; + print_pos(opts, elem_idx, 0); + if (print_data(opts)) { + parallel_print(F_FORMAT_P_NOTCOMP, (double)temp1_float16, (double)temp2_float16, + (double)ABS(temp1_float16 - temp2_float16)); + } + nfound++; + } + else if (per > opts->percent) { + opts->print_percentage = 1; + print_pos(opts, elem_idx, 0); + if (print_data(opts)) { + parallel_print(F_FORMAT_P, (double)temp1_float16, (double)temp2_float16, + (double)ABS(temp1_float16 - temp2_float16), + (double)ABS(1 - temp2_float16 / temp1_float16)); + } + nfound++; + } + } + /* only one is NaN, assume difference */ + else if ((isnan1 && !isnan2) || (!isnan1 && isnan2)) { + opts->print_percentage = 0; + print_pos(opts, elem_idx, 0); + if (print_data(opts)) { + parallel_print(F_FORMAT, (double)temp1_float16, (double)temp2_float16, + (double)ABS(temp1_float16 - temp2_float16)); + } + nfound++; + } + } + /*------------------------------------------------------------------------- + * -d and -p + *------------------------------------------------------------------------- + */ + else if (opts->delta_bool && opts->percent_bool) { + /*------------------------------------------------------------------------- + * detect NaNs + *------------------------------------------------------------------------- + */ + if (opts->do_nans) { + isnan1 = isnan(temp1_float16); + isnan2 = isnan(temp2_float16); + } + + /* both not NaN, do the comparison */ + if (!isnan1 && !isnan2) { + PER(temp1_float16, temp2_float16); + + if (not_comparable && !both_zero) { + opts->print_percentage = 1; + print_pos(opts, elem_idx, 0); + if (print_data(opts)) { + parallel_print(F_FORMAT_P_NOTCOMP, (double)temp1_float16, (double)temp2_float16, + (double)ABS(temp1_float16 - temp2_float16)); + } + nfound++; + } + else if (per > opts->percent && (double)ABS(temp1_float16 - temp2_float16) > opts->delta) { + opts->print_percentage = 1; + print_pos(opts, elem_idx, 0); + if (print_data(opts)) { + parallel_print(F_FORMAT_P, (double)temp1_float16, (double)temp2_float16, + (double)ABS(temp1_float16 - temp2_float16), + (double)ABS(1 - temp2_float16 / temp1_float16)); + } + nfound++; + } + } + /* only one is NaN, assume difference */ + else if ((isnan1 && !isnan2) || (!isnan1 && isnan2)) { + opts->print_percentage = 0; + print_pos(opts, elem_idx, 0); + if (print_data(opts)) { + parallel_print(F_FORMAT, (double)temp1_float16, (double)temp2_float16, + (double)ABS(temp1_float16 - temp2_float16)); + } + nfound++; + } + } + /*------------------------------------------------------------------------- + * no -d and -p + *------------------------------------------------------------------------- + */ + else { + if (equal_float(temp1_float16, temp2_float16, opts) == false) { + opts->print_percentage = 0; + print_pos(opts, elem_idx, 0); + if (print_data(opts)) { + parallel_print(F_FORMAT, (double)temp1_float16, (double)temp2_float16, + (double)ABS(temp1_float16 - temp2_float16)); + } + nfound++; + } + } + + H5TOOLS_ENDDEBUG(": %" PRIuHSIZE " zero:%d", nfound, both_zero); + return nfound; +} +#endif + /*------------------------------------------------------------------------- * Function: diff_schar_element * diff --git a/tools/lib/h5diff_util.c b/tools/lib/h5diff_util.c index 4641c93..26cde1b 100644 --- a/tools/lib/h5diff_util.c +++ b/tools/lib/h5diff_util.c @@ -120,7 +120,11 @@ print_type(hid_t type) break; case H5T_FLOAT: - if (H5Tequal(type, H5T_IEEE_F32BE)) + if (H5Tequal(type, H5T_IEEE_F16BE)) + parallel_print("H5T_IEEE_F16BE"); + else if (H5Tequal(type, H5T_IEEE_F16LE)) + parallel_print("H5T_IEEE_F16LE"); + else if (H5Tequal(type, H5T_IEEE_F32BE)) parallel_print("H5T_IEEE_F32BE"); else if (H5Tequal(type, H5T_IEEE_F32LE)) parallel_print("H5T_IEEE_F32LE"); @@ -128,6 +132,10 @@ print_type(hid_t type) parallel_print("H5T_IEEE_F64BE"); else if (H5Tequal(type, H5T_IEEE_F64LE)) parallel_print("H5T_IEEE_F64LE"); +#ifdef H5_HAVE__FLOAT16 + else if (H5Tequal(type, H5T_NATIVE_FLOAT16)) + parallel_print("H5T_NATIVE_FLOAT16"); +#endif else if (H5Tequal(type, H5T_NATIVE_FLOAT)) parallel_print("H5T_NATIVE_FLOAT"); else if (H5Tequal(type, H5T_NATIVE_DOUBLE)) diff --git a/tools/lib/h5tools_dump.c b/tools/lib/h5tools_dump.c index efaddee..5a8c401 100644 --- a/tools/lib/h5tools_dump.c +++ b/tools/lib/h5tools_dump.c @@ -2190,7 +2190,11 @@ h5tools_print_datatype(FILE *stream, h5tools_str_t *buffer, const h5tool_format_ break; case H5T_FLOAT: - if (H5Tequal(type, H5T_IEEE_F32BE) == true) + if (H5Tequal(type, H5T_IEEE_F16BE) == true) + h5tools_str_append(buffer, "H5T_IEEE_F16BE"); + else if (H5Tequal(type, H5T_IEEE_F16LE) == true) + h5tools_str_append(buffer, "H5T_IEEE_F16LE"); + else if (H5Tequal(type, H5T_IEEE_F32BE) == true) h5tools_str_append(buffer, "H5T_IEEE_F32BE"); else if (H5Tequal(type, H5T_IEEE_F32LE) == true) h5tools_str_append(buffer, "H5T_IEEE_F32LE"); @@ -2202,6 +2206,10 @@ h5tools_print_datatype(FILE *stream, h5tools_str_t *buffer, const h5tool_format_ h5tools_str_append(buffer, "H5T_VAX_F32"); else if (H5Tequal(type, H5T_VAX_F64) == true) h5tools_str_append(buffer, "H5T_VAX_F64"); +#ifdef H5_HAVE__FLOAT16 + else if (H5Tequal(type, H5T_NATIVE_FLOAT16) == true) + h5tools_str_append(buffer, "H5T_NATIVE_FLOAT16"); +#endif else if (H5Tequal(type, H5T_NATIVE_FLOAT) == true) h5tools_str_append(buffer, "H5T_NATIVE_FLOAT"); else if (H5Tequal(type, H5T_NATIVE_DOUBLE) == true) diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c index 5ef86fb..47893ec 100644 --- a/tools/lib/h5tools_str.c +++ b/tools/lib/h5tools_str.c @@ -700,7 +700,17 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai switch (type_class) { case H5T_FLOAT: H5TOOLS_DEBUG("H5T_FLOAT"); - if (sizeof(float) == nsize) { +#ifdef H5_HAVE__FLOAT16 + if (sizeof(H5__Float16) == nsize) { + /* if (H5Tequal(type, H5T_NATIVE_FLOAT16)) */ + H5__Float16 tempfloat16; + + memcpy(&tempfloat16, vp, sizeof(H5__Float16)); + h5tools_str_append(str, OPT(info->fmt_float, "%g"), (double)tempfloat16); + } + else +#endif + if (sizeof(float) == nsize) { /* if (H5Tequal(type, H5T_NATIVE_FLOAT)) */ float tempfloat; diff --git a/tools/lib/h5tools_type.c b/tools/lib/h5tools_type.c index 7e9f6f7..c5e7472 100644 --- a/tools/lib/h5tools_type.c +++ b/tools/lib/h5tools_type.c @@ -55,7 +55,9 @@ h5tools_get_little_endian_type(hid_t tid) break; case H5T_FLOAT: - if (size == 4) + if (size == 2) + p_type = H5Tcopy(H5T_IEEE_F16LE); + else if (size == 4) p_type = H5Tcopy(H5T_IEEE_F32LE); else if (size == 8) p_type = H5Tcopy(H5T_IEEE_F64LE); @@ -134,7 +136,9 @@ h5tools_get_big_endian_type(hid_t tid) break; case H5T_FLOAT: - if (size == 4) + if (size == 2) + p_type = H5Tcopy(H5T_IEEE_F16BE); + else if (size == 4) p_type = H5Tcopy(H5T_IEEE_F32BE); else if (size == 8) p_type = H5Tcopy(H5T_IEEE_F64BE); diff --git a/tools/src/h5import/h5import.c b/tools/src/h5import/h5import.c index 663f68a..a375b57 100644 --- a/tools/src/h5import/h5import.c +++ b/tools/src/h5import/h5import.c @@ -3114,6 +3114,48 @@ getInputClassType(struct Input *in, char *buffer) kindex = 7; } + else if (!strcmp(buffer, "H5T_IEEE_F16BE")) { + in->inputSize = 16; + in->configOptionVector[INPUT_SIZE] = 1; + + if ((kindex = OutputArchStrToInt("IEEE")) == -1) { + (void)fprintf(stderr, "%s", err2); + return (-1); + } + in->outputArchitecture = kindex; + + if ((kindex = OutputByteOrderStrToInt("BE")) == -1) { + (void)fprintf(stderr, "%s", err3); + return (-1); + } + in->outputByteOrder = kindex; +#ifdef H5DEBUGIMPORT + printf("h5dump inputByteOrder %d\n", in->inputByteOrder); +#endif + + kindex = 3; + } + else if (!strcmp(buffer, "H5T_IEEE_F16LE")) { + in->inputSize = 16; + in->configOptionVector[INPUT_SIZE] = 1; + + if ((kindex = OutputArchStrToInt("IEEE")) == -1) { + (void)fprintf(stderr, "%s", err2); + return (-1); + } + in->outputArchitecture = kindex; + + if ((kindex = OutputByteOrderStrToInt("LE")) == -1) { + (void)fprintf(stderr, "%s", err3); + return (-1); + } + in->outputByteOrder = kindex; +#ifdef H5DEBUGIMPORT + printf("h5dump inputByteOrder %d\n", in->inputByteOrder); +#endif + + kindex = 3; + } else if (!strcmp(buffer, "H5T_IEEE_F32BE")) { in->inputSize = 32; in->configOptionVector[INPUT_SIZE] = 1; @@ -3210,6 +3252,20 @@ getInputClassType(struct Input *in, char *buffer) kindex = 3; } +#ifdef H5_HAVE__FLOAT16 + else if (!strcmp(buffer, "H5T_NATIVE_FLOAT16")) { + in->inputSize = 16; + in->configOptionVector[INPUT_SIZE] = 1; + + if ((kindex = OutputArchStrToInt("NATIVE")) == -1) { + (void)fprintf(stderr, "%s", err2); + return (-1); + } + in->outputArchitecture = kindex; + + kindex = 3; + } +#endif else if (!strcmp(buffer, "H5T_NATIVE_FLOAT")) { in->inputSize = 32; in->configOptionVector[INPUT_SIZE] = 1; @@ -3936,6 +3992,12 @@ createOutputDataType(struct Input *in) switch (in->outputArchitecture) { case 0: switch (in->outputSize) { +#ifdef H5_HAVE__FLOAT16 + case 16: + new_type = H5Tcopy(H5T_NATIVE_FLOAT16); + break; +#endif + case 32: new_type = H5Tcopy(H5T_NATIVE_FLOAT); break; @@ -3971,6 +4033,23 @@ createOutputDataType(struct Input *in) case 2: switch (in->outputSize) { + case 16: + switch (in->outputByteOrder) { + case -1: + case 0: + new_type = H5Tcopy(H5T_IEEE_F16BE); + break; + + case 1: + new_type = H5Tcopy(H5T_IEEE_F16LE); + break; + + default: + (void)fprintf(stderr, "%s", err3); + return (-1); + } + break; + case 32: switch (in->outputByteOrder) { case -1: @@ -4291,6 +4370,12 @@ createInputDataType(struct Input *in) switch (in->inputArchitecture) { case 0: switch (in->inputSize) { +#ifdef H5_HAVE__FLOAT16 + case 16: + new_type = H5Tcopy(H5T_NATIVE_FLOAT16); + break; +#endif + case 32: new_type = H5Tcopy(H5T_NATIVE_FLOAT); break; @@ -4326,6 +4411,23 @@ createInputDataType(struct Input *in) case 2: switch (in->inputSize) { + case 16: + switch (in->inputByteOrder) { + case -1: + case 0: + new_type = H5Tcopy(H5T_IEEE_F16BE); + break; + + case 1: + new_type = H5Tcopy(H5T_IEEE_F16LE); + break; + + default: + (void)fprintf(stderr, "%s", err3); + return (-1); + } + break; + case 32: switch (in->inputByteOrder) { case -1: @@ -4535,6 +4637,12 @@ createInputDataType(struct Input *in) case 2: case 3: switch (in->inputSize) { +#ifdef H5_HAVE__FLOAT16 + case 16: + new_type = H5Tcopy(H5T_NATIVE_FLOAT16); + break; +#endif + case 32: new_type = H5Tcopy(H5T_NATIVE_FLOAT); break; diff --git a/tools/src/h5ls/h5ls.c b/tools/src/h5ls/h5ls.c index 04c5ff3..bc0781c 100644 --- a/tools/src/h5ls/h5ls.c +++ b/tools/src/h5ls/h5ls.c @@ -427,6 +427,11 @@ print_native_type(h5tools_str_t *buffer, hid_t type, int ind) else if (H5Tequal(type, H5T_NATIVE_ULLONG) == true) { h5tools_str_append(buffer, "native unsigned long long"); } +#ifdef H5_HAVE__FLOAT16 + else if (H5Tequal(type, H5T_NATIVE_FLOAT16) == true) { + h5tools_str_append(buffer, "native _Float16"); + } +#endif else if (H5Tequal(type, H5T_NATIVE_FLOAT) == true) { h5tools_str_append(buffer, "native float"); } @@ -551,7 +556,13 @@ print_native_type(h5tools_str_t *buffer, hid_t type, int ind) static bool print_ieee_type(h5tools_str_t *buffer, hid_t type, int ind) { - if (H5Tequal(type, H5T_IEEE_F32BE) == true) { + if (H5Tequal(type, H5T_IEEE_F16BE) == true) { + h5tools_str_append(buffer, "IEEE 16-bit big-endian float"); + } + else if (H5Tequal(type, H5T_IEEE_F16LE) == true) { + h5tools_str_append(buffer, "IEEE 16-bit little-endian float"); + } + else if (H5Tequal(type, H5T_IEEE_F32BE) == true) { h5tools_str_append(buffer, "IEEE 32-bit big-endian float"); } else if (H5Tequal(type, H5T_IEEE_F32LE) == true) { diff --git a/tools/test/h5dump/CMakeTests.cmake b/tools/test/h5dump/CMakeTests.cmake index e997aa8..9a452e2 100644 --- a/tools/test/h5dump/CMakeTests.cmake +++ b/tools/test/h5dump/CMakeTests.cmake @@ -103,6 +103,7 @@ tfletcher32.ddl #tfloatsattrs.ddl #native #tfloatsattrs.wddl #special for windows + tfloat16.ddl tfpformat.ddl tgroup-1.ddl tgroup-2.ddl @@ -291,6 +292,7 @@ tfcontents2.h5 tfilters.h5 tfloatsattrs.h5 + tfloat16.h5 tfpformat.h5 tfvalues.h5 tgroup.h5 @@ -1302,6 +1304,9 @@ ADD_H5_TEST (tldouble 0 --enable-error-stack tldouble.h5) ADD_H5_TEST (tldouble_scalar 0 -p --enable-error-stack tldouble_scalar.h5) + # Add test for _Float16 type + ADD_H5_TEST (tfloat16 0 --enable-error-stack tfloat16.h5) + # test for vms ADD_H5_TEST (tvms 0 --enable-error-stack tvms.h5) diff --git a/tools/test/h5dump/expected/tfloat16.ddl b/tools/test/h5dump/expected/tfloat16.ddl new file mode 100644 index 0000000..a98200c --- /dev/null +++ b/tools/test/h5dump/expected/tfloat16.ddl @@ -0,0 +1,46 @@ +HDF5 "tfloat16.h5" { +GROUP "/" { + DATASET "DS16BITS" { + DATATYPE H5T_IEEE_F16LE + DATASPACE SIMPLE { ( 8, 16 ) / ( 8, 16 ) } + DATA { + (0,0): 16, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, + (1,0): 15, 0.5625, 1.0625, 1.5625, 2.0625, 2.5625, 3.0625, 3.5625, + (1,8): 4.0625, 4.5625, 5.0625, 5.5625, 6.0625, 6.5625, 7.0625, 7.5625, + (2,0): 14, 0.625, 1.125, 1.625, 2.125, 2.625, 3.125, 3.625, 4.125, + (2,9): 4.625, 5.125, 5.625, 6.125, 6.625, 7.125, 7.625, + (3,0): 13, 0.6875, 1.1875, 1.6875, 2.1875, 2.6875, 3.1875, 3.6875, + (3,8): 4.1875, 4.6875, 5.1875, 5.6875, 6.1875, 6.6875, 7.1875, 7.6875, + (4,0): 12, 0.75, 1.25, 1.75, 2.25, 2.75, 3.25, 3.75, 4.25, 4.75, 5.25, + (4,11): 5.75, 6.25, 6.75, 7.25, 7.75, + (5,0): 11, 0.8125, 1.3125, 1.8125, 2.3125, 2.8125, 3.3125, 3.8125, + (5,8): 4.3125, 4.8125, 5.3125, 5.8125, 6.3125, 6.8125, 7.3125, 7.8125, + (6,0): 10, 0.875, 1.375, 1.875, 2.375, 2.875, 3.375, 3.875, 4.375, + (6,9): 4.875, 5.375, 5.875, 6.375, 6.875, 7.375, 7.875, + (7,0): 9, 0.9375, 1.4375, 1.9375, 2.4375, 2.9375, 3.4375, 3.9375, + (7,8): 4.4375, 4.9375, 5.4375, 5.9375, 6.4375, 6.9375, 7.4375, 7.9375 + } + ATTRIBUTE "DS16BITS" { + DATATYPE H5T_IEEE_F16LE + DATASPACE SIMPLE { ( 128 ) / ( 128 ) } + DATA { + (0): 16, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, + (15): 7.5, 15, 0.5625, 1.0625, 1.5625, 2.0625, 2.5625, 3.0625, + (23): 3.5625, 4.0625, 4.5625, 5.0625, 5.5625, 6.0625, 6.5625, + (30): 7.0625, 7.5625, 14, 0.625, 1.125, 1.625, 2.125, 2.625, 3.125, + (39): 3.625, 4.125, 4.625, 5.125, 5.625, 6.125, 6.625, 7.125, 7.625, + (48): 13, 0.6875, 1.1875, 1.6875, 2.1875, 2.6875, 3.1875, 3.6875, + (56): 4.1875, 4.6875, 5.1875, 5.6875, 6.1875, 6.6875, 7.1875, + (63): 7.6875, 12, 0.75, 1.25, 1.75, 2.25, 2.75, 3.25, 3.75, 4.25, + (73): 4.75, 5.25, 5.75, 6.25, 6.75, 7.25, 7.75, 11, 0.8125, 1.3125, + (83): 1.8125, 2.3125, 2.8125, 3.3125, 3.8125, 4.3125, 4.8125, + (90): 5.3125, 5.8125, 6.3125, 6.8125, 7.3125, 7.8125, 10, 0.875, + (98): 1.375, 1.875, 2.375, 2.875, 3.375, 3.875, 4.375, 4.875, 5.375, + (107): 5.875, 6.375, 6.875, 7.375, 7.875, 9, 0.9375, 1.4375, 1.9375, + (116): 2.4375, 2.9375, 3.4375, 3.9375, 4.4375, 4.9375, 5.4375, + (123): 5.9375, 6.4375, 6.9375, 7.4375, 7.9375 + } + } + } +} +} diff --git a/tools/test/h5dump/h5dumpgentest.c b/tools/test/h5dump/h5dumpgentest.c index e12690c..2612259 100644 --- a/tools/test/h5dump/h5dumpgentest.c +++ b/tools/test/h5dump/h5dumpgentest.c @@ -119,6 +119,9 @@ #define FILE90 "tst_onion_dset_1d.h5" #define FILE91 "tst_onion_objs.h5" #define FILE92 "tst_onion_dset_ext.h5" +#ifdef H5_HAVE__FLOAT16 +#define FILE93 "tfloat16.h5" +#endif #define ONION_TEST_FIXNAME_SIZE 1024 #define ONION_TEST_PAGE_SIZE (uint32_t)32 @@ -412,6 +415,13 @@ typedef struct s1_t { #define F89_DATASETF128 "DS128BITS" #define F89_YDIM128 128 +#ifdef H5_HAVE__FLOAT16 +/* "FILE93" macros */ +#define F93_XDIM 8 +#define F93_YDIM 16 +#define F93_DATASET "DS16BITS" +#endif + static void gent_group(void) { @@ -11993,6 +12003,78 @@ error: return -1; } /* gent_onion_dset_extension */ +#ifdef H5_HAVE__FLOAT16 +static void +gent_float16(void) +{ + hid_t fid = H5I_INVALID_HID; + hid_t tid = H5I_INVALID_HID; + hid_t attr = H5I_INVALID_HID; + hid_t dataset = H5I_INVALID_HID; + hid_t space = H5I_INVALID_HID; + hid_t aspace = H5I_INVALID_HID; + hsize_t dims[2], adims[1]; + + struct { + H5__Float16 arr[F93_XDIM][F93_YDIM]; + } * dset16; + + H5__Float16 *aset16 = NULL; + H5__Float16 val16bits; + + dset16 = malloc(sizeof(*dset16)); + + aset16 = calloc(F93_XDIM * F93_YDIM, sizeof(H5__Float16)); + + fid = H5Fcreate(FILE93, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + + if ((tid = H5Tcopy(H5T_NATIVE_FLOAT16)) < 0) + goto error; + + if (H5Tget_size(tid) == 0) + goto error; + + /* Dataset of 16-bit float */ + dims[0] = F93_XDIM; + dims[1] = F93_YDIM; + space = H5Screate_simple(2, dims, NULL); + dataset = H5Dcreate2(fid, F93_DATASET, H5T_IEEE_F16LE, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + + val16bits = (H5__Float16)F93_YDIM; + for (size_t i = 0; i < dims[0]; i++) { + dset16->arr[i][0] = val16bits; + aset16[i * dims[1]] = dset16->arr[i][0]; + + for (size_t j = 1; j < dims[1]; j++) { + dset16->arr[i][j] = (H5__Float16)(j * dims[0] + i) / (H5__Float16)F93_YDIM; + aset16[i * dims[1] + j] = dset16->arr[i][j]; + } + + val16bits -= (H5__Float16)1; + } + + H5Dwrite(dataset, H5T_IEEE_F16LE, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset16); + + /* Attribute of 16-bit float */ + adims[0] = F93_XDIM * F93_YDIM; + aspace = H5Screate_simple(1, adims, NULL); + attr = H5Acreate2(dataset, F93_DATASET, H5T_IEEE_F16LE, aspace, H5P_DEFAULT, H5P_DEFAULT); + + H5Awrite(attr, H5T_IEEE_F16LE, aset16); + + H5Aclose(attr); + H5Sclose(aspace); + H5Sclose(space); + H5Dclose(dataset); + +error: + free(aset16); + free(dset16); + + H5Fclose(fid); +} +#endif + int main(void) { @@ -12097,5 +12179,9 @@ main(void) gent_onion_create_delete_objects(); gent_onion_dset_extension(); +#ifdef H5_HAVE__FLOAT16 + gent_float16(); +#endif + return 0; } diff --git a/tools/test/h5dump/testfiles/tfloat16.h5 b/tools/test/h5dump/testfiles/tfloat16.h5 Binary files differnew file mode 100644 index 0000000..a0cccc5 --- /dev/null +++ b/tools/test/h5dump/testfiles/tfloat16.h5 diff --git a/tools/test/h5dump/testh5dump.sh.in b/tools/test/h5dump/testh5dump.sh.in index fdeb17d..911ffc7 100644 --- a/tools/test/h5dump/testh5dump.sh.in +++ b/tools/test/h5dump/testh5dump.sh.in @@ -133,6 +133,7 @@ $SRC_H5DUMP_TESTFILES/tfcontents1.h5 $SRC_H5DUMP_TESTFILES/tfcontents2.h5 $SRC_H5DUMP_TESTFILES/tfilters.h5 $SRC_H5DUMP_TESTFILES/tfloatsattrs.h5 +$SRC_H5DUMP_TESTFILES/tfloat16.h5 $SRC_H5DUMP_TESTFILES/tfpformat.h5 $SRC_H5DUMP_TESTFILES/tfvalues.h5 $SRC_H5DUMP_TESTFILES/tgroup.h5 @@ -273,6 +274,7 @@ $SRC_H5DUMP_OUTFILES/tfamily.ddl $SRC_H5DUMP_OUTFILES/tfill.ddl $SRC_H5DUMP_OUTFILES/tfletcher32.ddl $SRC_H5DUMP_OUTFILES/tfloatsattrs.ddl +$SRC_H5DUMP_OUTFILES/tfloat16.ddl $SRC_H5DUMP_OUTFILES/tfpformat.ddl $SRC_H5DUMP_OUTFILES/tgroup-1.ddl $SRC_H5DUMP_OUTFILES/tgroup-2.ddl @@ -1404,6 +1406,9 @@ TOOLTEST tfloatsattrs.ddl -p --enable-error-stack tfloatsattrs.h5 TOOLTEST tldouble.ddl --enable-error-stack tldouble.h5 TOOLTEST tldouble_scalar.ddl -p --enable-error-stack tldouble_scalar.h5 +# test for _Float16 type +TOOLTEST tfloat16.ddl --enable-error-stack tfloat16.h5 + # test for vms TOOLTEST tvms.ddl --enable-error-stack tvms.h5 diff --git a/tools/test/h5ls/CMakeTests.cmake b/tools/test/h5ls/CMakeTests.cmake index 2d932b2..596162b 100644 --- a/tools/test/h5ls/CMakeTests.cmake +++ b/tools/test/h5ls/CMakeTests.cmake @@ -35,6 +35,7 @@ textlink.h5 textlinksrc.h5 textlinktar.h5 + tfloat16.h5 tgroup.h5 tgrp_comments.h5 tgrpnullspace.h5 @@ -88,6 +89,8 @@ textlinksrc-7-old.ls textlinksrc-nodangle-1.ls textlinksrc-nodangle-2.ls + tfloat16.ls + tfloat16_nosupport.ls tgroup.ls tgroup-1.ls tgroup-2.ls @@ -314,6 +317,23 @@ # when used file with no dangling links - expected exit code 0 ADD_H5_TEST (thlinks-nodangle-1 0 -w80 --follow-symlinks --no-dangling-links thlink.h5) + # tests for _Float16 type + if (${${HDF_PREFIX}_HAVE__FLOAT16}) + # If support is available for _Float16 type, the second test + # will fail as the type will be printed out as "native _Float16" + # rather than "IEEE 16-bit little-endian float". + ADD_H5_TEST (tfloat16 0 -w80 -v tfloat16.h5) + ADD_H5_TEST (tfloat16_nosupport 0 -w80 -v tfloat16.h5) + set_tests_properties (H5LS-tfloat16_nosupport PROPERTIES WILL_FAIL "true") + else () + # If support is NOT available for _Float16 type, the first test + # will fail as the type will be printed out as + # "IEEE 16-bit little-endian float" rather than "native _Float16" + ADD_H5_TEST (tfloat16 0 -w80 -v tfloat16.h5) + set_tests_properties (H5LS-tfloat16 PROPERTIES WILL_FAIL "true") + ADD_H5_TEST (tfloat16_nosupport 0 -w80 -v tfloat16.h5) + endif () + # test for wildcards in filename (does not work with cmake) # ADD_H5_TEST (tstarfile 0 -w80 t*link.h5) # ADD_H5_TEST (tqmarkfile 0 -w80 t?link.h5) diff --git a/tools/test/h5ls/expected/tfloat16.ls b/tools/test/h5ls/expected/tfloat16.ls new file mode 100644 index 0000000..68c0fe7 --- /dev/null +++ b/tools/test/h5ls/expected/tfloat16.ls @@ -0,0 +1,8 @@ +Opened "tfloat16.h5" with sec2 driver. +DS16BITS Dataset {8/8, 16/16} + Attribute: DS16BITS {128} + Type: native _Float16 + Location: 1:800 + Links: 1 + Storage: 256 logical bytes, 256 allocated bytes, 100.00% utilization + Type: native _Float16 diff --git a/tools/test/h5ls/expected/tfloat16_nosupport.ls b/tools/test/h5ls/expected/tfloat16_nosupport.ls new file mode 100644 index 0000000..70253c6 --- /dev/null +++ b/tools/test/h5ls/expected/tfloat16_nosupport.ls @@ -0,0 +1,8 @@ +Opened "tfloat16.h5" with sec2 driver. +DS16BITS Dataset {8/8, 16/16} + Attribute: DS16BITS {128} + Type: IEEE 16-bit little-endian float + Location: 1:800 + Links: 1 + Storage: 256 logical bytes, 256 allocated bytes, 100.00% utilization + Type: IEEE 16-bit little-endian float diff --git a/tools/test/h5ls/testh5ls.sh.in b/tools/test/h5ls/testh5ls.sh.in index 01f9402..3d306df 100644 --- a/tools/test/h5ls/testh5ls.sh.in +++ b/tools/test/h5ls/testh5ls.sh.in @@ -16,6 +16,7 @@ srcdir=@srcdir@ USE_FILTER_SZIP="@USE_FILTER_SZIP@" USE_FILTER_DEFLATE="@USE_FILTER_DEFLATE@" +HAVE__FLOAT16="@HAVE__FLOAT16@" TESTNAME=h5ls EXIT_SUCCESS=0 @@ -78,6 +79,7 @@ $SRC_H5DUMP_TESTFILES/tempty.h5 $SRC_H5DUMP_TESTFILES/textlink.h5 $SRC_H5DUMP_TESTFILES/textlinksrc.h5 $SRC_H5DUMP_TESTFILES/textlinktar.h5 +$SRC_H5DUMP_TESTFILES/tfloat16.h5 $SRC_H5DUMP_TESTFILES/tgroup.h5 $SRC_H5DUMP_TESTFILES/tgrp_comments.h5 $SRC_H5DUMP_TESTFILES/tgrpnullspace.h5 @@ -128,6 +130,8 @@ $SRC_H5LS_OUTFILES/textlinksrc-2-old.ls $SRC_H5LS_OUTFILES/textlinksrc-3-old.ls $SRC_H5LS_OUTFILES/textlinksrc-6-old.ls $SRC_H5LS_OUTFILES/textlinksrc-7-old.ls +$SRC_H5LS_OUTFILES/tfloat16.ls +$SRC_H5LS_OUTFILES/tfloat16_nosupport.ls $SRC_H5LS_OUTFILES/tsoftlinks-1.ls $SRC_H5LS_OUTFILES/tsoftlinks-2.ls $SRC_H5LS_OUTFILES/tsoftlinks-3.ls @@ -361,6 +365,13 @@ TOOLTEST tsoftlinks-nodangle-1.ls 1 -w80 --follow-symlinks --no-dangling-links t # when used file with no dangling links - expected exit code 0 TOOLTEST thlinks-nodangle-1.ls 0 -w80 --follow-symlinks --no-dangling-links thlink.h5 +# test for _Float16 type +if test $HAVE__FLOAT16 = "yes" ; then + TOOLTEST tfloat16.ls 0 -w80 -v tfloat16.h5 +else + TOOLTEST tfloat16_nosupport.ls 0 -w80 -v tfloat16.h5 +fi + # test for wildcards in filename (does not work with cmake) # this h5ls test script does not pass the filename properly like the h5dump test script??? #TOOLTEST tstarfile.ls 0 -w80 t*link.h5 |