Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve float16 performance #2154

Open
bhawkins opened this issue Oct 9, 2022 · 4 comments
Open

Improve float16 performance #2154

bhawkins opened this issue Oct 9, 2022 · 4 comments
Assignees
Labels
Component - C Library Core C library issues (usually in the src directory) Priority - 1. High 🔼 These are important issues that should be resolved in the next release Type - Improvement Improvements that don't add a new feature or functionality
Milestone

Comments

@bhawkins
Copy link

bhawkins commented Oct 9, 2022

Using HDF5 to read data stored as 16-bit floating point into a 32-bit buffer is extremely slow, around 16x slower than an equivalent conversion in numpy. I uploaded a demo here. For simplicity I used h5py, but one can obtain the same result using the HDF5 C API. HDF5 also seems to discard any payload bits in NaN values. I suspect the slowdown is due to the very general implementation for custom float types in HDF5 here

hdf5/src/H5Tconv.c

Lines 4267 to 4271 in 306db40

* Function: H5T__conv_f_f
*
* Purpose: Convert one floating point type to another. This is a catch
* all for floating point conversions and is probably not
* particularly fast!

versus the float16-specific handling in numpy.

The case I really care about involves a structured data type (for complex values), which is 44x slower than a numpy workaround. That demo is available here, though I haven't isolated a cause for that extra factor of 3x.

It seems like ideally there'd be a H5T__conv_half_single routine that uses hardware to convert from _Float16 (example). I guess this might require adding a native_half type, which seems like a big job. Or maybe just a special case in H5T__conv_f_f?

@bhawkins
Copy link
Author

I implemented a demo using just the C API, available here

https://github.com/bhawkins/demo_hdf5_c4

Profiling confirms that the slowdown is indeed in H5T__conv_f_f, which is more than 30 times slower than whatever clang does.

As context, this issue is highly relevant to an upcoming NASA mission called NISAR. It is an imaging radar that will soon produce a freely available, global dataset of several petabytes. The data has high dynamic range and high entropy, so float16 encoding is an appealing solution to reduce file sizes.

Software support for float16 varies, and in several scenarios the obvious or default behavior is to use the HDF5 API to convert to float32 on read, which gets bogged down as in the above demos. This is notably the behavior of GDAL, which forms the basis of a wide variety of GIS applications. So while it is possible to work around this problem on an ad hoc basis in each application, there would be a potentially wide-ranging benefit to simply making the libhdf5 code path faster.

@derobins derobins self-assigned this May 3, 2023
@derobins derobins added Priority - 1. High 🔼 These are important issues that should be resolved in the next release Component - C Library Core C library issues (usually in the src directory) Type - Improvement Improvements that don't add a new feature or functionality labels May 3, 2023
@derobins derobins changed the title [Feature Request] float16 performance Improve float16 performance May 3, 2023
@derobins derobins modified the milestones: 1.14.4, 1.14.5 Jan 19, 2024
@derobins
Copy link
Member

We plan to add native float16 support but it probably won't be ready until 1.14.5

@mkitti
Copy link
Contributor

mkitti commented Jan 22, 2024

We just had some recent interest in this in JuliaIO/HDF5.jl#341 (comment) . It would be great if there was native float16 and bfloat16 support.

@jhendersonHDF
Copy link
Collaborator

Hi @bhawkins and @mkitti, if you happen to get the chance it would be appreciated if you could look over the RFC for 16-bit float (and complex number) support at https://forum.hdfgroup.org/t/hdf5-rfc-adding-support-for-16-bit-floating-point-and-complex-number-datatypes-to-hdf5/11975 and give any feedback that you may have in that forum thread. Thanks!

@derobins derobins modified the milestones: 1.14.5, 2.0.0 Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component - C Library Core C library issues (usually in the src directory) Priority - 1. High 🔼 These are important issues that should be resolved in the next release Type - Improvement Improvements that don't add a new feature or functionality
Projects
None yet
Development

No branches or pull requests

4 participants