Skip to content

Improve float16 performance #2154

@bhawkins

Description

@bhawkins

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?

Metadata

Metadata

Assignees

Labels

Component - C LibraryCore C library issues (usually in the src directory)

Projects

Status

Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions