-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
RFC 100 text: Add RFC for float16 support #10146
base: master
Are you sure you want to change the base?
Changes from 4 commits
3402ba0
1eb5141
81a001f
cc20331
6349eba
c3c7695
89c624c
68fb0f8
c6e0c28
258ed5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
.. _rfc-100: | ||
|
||
============================= | ||
RFC 100: Support float16 type | ||
============================= | ||
|
||
============== ============================================= | ||
Author: Erik Schnetter | ||
Contact: eschnetter @ perimeterinstitute.ca | ||
Started: 2024-Jun-05 | ||
Status: Proposed | ||
Target: GDAL 3.11 | ||
============== ============================================= | ||
|
||
Summary | ||
------- | ||
|
||
This RFC adds support for the IEEE 16-bit floating point data type | ||
(aka ``half``, ``float16``). It adds new pixel data types | ||
``GDT_Float16`` and ``GDT_CFloat16``, backed by a new ``GFloat16`` C++ | ||
type. This type will be emulated in software if not available | ||
natively. | ||
|
||
Some drivers, in particular Zarr, will be extended to support this | ||
type. Drivers that do not support this type will be checked to ensure | ||
they report an appropriate errors when necessary. | ||
eschnett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Motivation | ||
---------- | ||
|
||
- The float16 type is increasingly common. It is supported by GPUs, by | ||
modern CPUs, and by modern compilers (e.g. GCC 12). | ||
|
||
- Using ``uint16`` values to shuffle ``float16`` values around is | ||
inconvenient and awkward. There is no mechanism in GDAL to mark | ||
attributes or datasets which ``uint16`` values should be interpreted | ||
as ``float16``. | ||
eschnett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- Some drivers (at least the HDF5, GTiff, and Zarr) already handle | ||
float16 by exposing it as float32, using software conversion | ||
routines. This type should be supported without converting to | ||
float32. | ||
|
||
- C++23 will introduce native support for ``std::float16_t``. However, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. eschnett#1 is an attempt of aliasing GFloat16 on std::float16_t if it is available There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! I'll probably merge it and then hash out the details. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once the RFC text has been updated taking into account above to reflect how C++23 std::float16_t will be handled, I'd be happy to give my +1 to the RFC. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Woohoo! Thank you both! I'm the same as Even for a +1. |
||
it will likely be several years until C++23 will be a requirement | ||
eschnett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for GDAL. A shorter-term solution is needed. | ||
eschnett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- Many other projects and storage libraries support float16. GDAL will | ||
fall behind if it doesn't. | ||
|
||
Details | ||
------- | ||
|
||
A new type ``GFloat16`` will be defined in C++. This type will be a | ||
eschnett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
thin wrapper around a native float16 type if one is available, such as | ||
e.g. ``_Float16`` in modern versions of GCC. Otherwise, a this type | ||
will be emulated (transparently to the user), and operations will be | ||
performed as ``float``. | ||
|
||
The following pixel data types are added: | ||
- ``GDT_Float16`` --> ``_Float16`` | ||
- ``GDT_CFloat16`` --> ``std::complex<_Float16`` | ||
eschnett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Some drivers (at least the HDF5, GTiff, and Zarr) already handle | ||
float16 by exposing it as float32, using software conversion routines. | ||
float16 is now supported directly, i.e., without converting to | ||
float32. In other drivers, the current behaviour is retained, which | ||
automatically converts float16 to float32. | ||
|
||
For simplicity there will be no new functions handling attributes for | ||
multidimensional datasets. Attributes of type float16 can still be | ||
read/written as raw values. | ||
|
||
Impacts in the code base | ||
------------------------ | ||
|
||
It is likely that a large fraction of the code base will be impacted. | ||
|
||
SWIG bindings | ||
------------- | ||
|
||
The SWIG bindings are extended where possible. Unfortunately, SWIG | ||
does not support the native float16 Python type, but it does support | ||
the float16 numpy type. This means that not all SWIG Python wrappers | ||
can support float16. | ||
|
||
Backward compatibility | ||
---------------------- | ||
|
||
C and C++ API and ABI are impacted. This design is backward-compatible | ||
manner, i.e. it does not break the ABI, and can thus be implemented in | ||
GDAL 3.x. | ||
eschnett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Main impacts are: | ||
|
||
* Two new enum values for ``GDALDataType`` | ||
|
||
* Some drivers already support float16 by converting from/to float32. | ||
This capability remains in a backward-compatible manner. In | ||
addition, these drivers might (if implemented) now also support | ||
reading/writing float16 values from/to float16 arrays in memory. | ||
|
||
* C Multidimension API impacts (and equivalent C++ methods): | ||
|
||
- :cpp:func:`GDALGroupCreateAttribute` | ||
- :cpp:func:`GDALMDArrayRead` | ||
- :cpp:func:`GDALMDArrayWrite` | ||
|
||
Risks | ||
----- | ||
|
||
The changes of this RFC add new features without removing or disabling | ||
any current features. The risk should be low. | ||
|
||
Documentation | ||
------------- | ||
|
||
Documentation will be added. | ||
|
||
Testing | ||
------- | ||
|
||
The C++ test suite will be updated. Tests will be implemented in C++ | ||
and Python. | ||
|
||
Related issues and PRs | ||
---------------------- | ||
|
||
- https://github.com/OSGeo/gdal/issues/10144: Supporting float16 | ||
|
||
For comparison: | ||
|
||
- https://github.com/OSGeo/gdal/pull/5257: [FEATURE] Add (initial) | ||
eschnett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
support Int64 and UInt64 raster data types | ||
|
||
No candidate implementation exists yet. | ||
|
||
Voting history | ||
-------------- | ||
|
||
TBD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this two back quote style?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A double backquote is rendered as "code" style, similar to a single backquote in Github markdown. I've taken it from RFC 99.