You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[C++] vendor a half precision floating point library #22806
Clang and GCC provide _Float16 and there are numerous polyfills which can emulate a 16 bit float for other platforms. This would fill a hole in the kernels and other code which don't currently support HALF_FLOAT.
Antoine Pitrou / @pitrou:
See also ARROW-3802. Numpy has dedicated float16 routines that we could reuse. Given that it's Numpy it's probably well-maintained.
Antoine Pitrou / @pitrou:
As for built-in float16 types it looks a bit more complicated, e.g. clang:
Clang supports two half-precision (16-bit) floating point types: __fp16 and _Float16. These types are supported in all language modes.
__fp16 is supported on every target, as it is purely a storage format; see below. _Float16 is currently only supported on the following targets, with further targets pending ABI standardization:
I think if available software implementations are unsatisfactory, it'd be preferable to write a very minimal version of our own and handle any operations by first converting to 32 bit float. This should be sufficient since we'd be able to use a native type most of the time. In that case, we'd only need to maintain:
The cmake logic/flags necessary to enable native IEEE 754-2008 half precision floats when available
The conversions soft 16 bit float <=> 32 bit float
Including bitwise equivalence to native 16 bit floats when available
I think if available software implementations are unsatisfactory, it'd be preferable to write a very minimal version of our own and handle any operations by first converting to 32 bit float.
If the HW-based conversions are available on all major CPUs (and compilers!), and they are fast enough, then I guess it's a sufficient approach.
Activity
asfimport commentedon Sep 18, 2019
Antoine Pitrou / @pitrou:
See also ARROW-3802. Numpy has dedicated float16 routines that we could reuse. Given that it's Numpy it's probably well-maintained.
There may be other projects around.
asfimport commentedon Sep 18, 2019
Antoine Pitrou / @pitrou:
As for built-in float16 types it looks a bit more complicated, e.g. clang:
asfimport commentedon Sep 18, 2019
Antoine Pitrou / @pitrou:
Also there are conversion intrinsic on recent x86 CPUs:
https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=half-precision
https://en.wikipedia.org/wiki/F16C
rok commentedon Apr 16, 2023
I've looked at some libraries to see what is usually used:
Half seems pretty complete so I think it or FP16 would make good candidates.
cc @pitrou @bkietz
pitrou commentedon Apr 17, 2023
Both look rather unmaintained. We could decide to maintain a fork in the source tree, but this would need assessing their technical quality as well.
Something as simple as https://github.com/Maratyszcza/FP16/blob/0a92994d729ff76a58f692d3028ca1b64b145d91/include/fp16/bitcasts.h#L30-L34 is undefined behaviour:
(from https://en.cppreference.com/w/cpp/language/union)
bkietz commentedon Apr 18, 2023
I think if available software implementations are unsatisfactory, it'd be preferable to write a very minimal version of our own and handle any operations by first converting to 32 bit float. This should be sufficient since we'd be able to use a native type most of the time. In that case, we'd only need to maintain:
soft 16 bit float <=> 32 bit floatpitrou commentedon Apr 18, 2023
If the HW-based conversions are available on all major CPUs (and compilers!), and they are fast enough, then I guess it's a sufficient approach.
pitrou commentedon Apr 24, 2023
Some interesting details discussed here:
https://www.corsix.org/content/converting-fp32-to-fp16
adamreeve commentedon Jan 26, 2024
#36073 added a new
arrow::util::Float16class, with a comment saying the routines are "partially adapted from Numpy's C implementation".So it looks like this can be closed? And unblock related work like #20213
pitrou commentedon Jan 26, 2024
Thanks for the heads up @adamreeve . Yes, you're right, this can be closed now!