Live data from Hacker News

Elementary Functions and Not Following IEEE754 Floating-Point Standard (2020)

hlsl.co.uk

11–20 of 33 posts

Re: Elementary Functions and Not Following IEEE754 Floating-Point Standard (2020)

#11

It's really hard for me to think that this is a good solution. Normal users should be using Float64 (where there is no similar solution), and Float32 should only be used when Float64 computation is too expensive (e.g. GPUs). In such cases, it's hard to believe that doing the math in Float64 and converting will make anyone happy.

Single-precision is too expensive for GPUs, unfortunately.

I think you mean double precision?

Re: Elementary Functions and Not Following IEEE754 Floating-Point Standard (2020)

#13
post #2

It's worth noting that the C standard explicitly disclaims correct rounding for these IEEE 754 functions (C23§F.3¶20). Also, there's a group of people who have been running tests on common libms, reporting their current accuracy states here: https://members.loria.fr/PZimmermann/papers/accuracy.pdf (that paper is updated ~monthly).

From the referenced slides[1]:

The 2012 discovery of the Higgs boson at the ATLAS experiment in the LHC relied crucially on the ability to track charged particles with exquisite precision (10 microns over a 10m length) and high reliability (over 99% of roughly 1000 charged particles per collision correctly identified).

In an attempt to speed up the calculation, researchers found that merely changing the underlying math library (which should only affect at most the last bit) resulted in some collisions being missed or misidentified.

I was a user contributing to the LHC@Home BOINC project[2], where they ran into similar problems. They simulated beam stability, so iterated on the position of the simulated particles for millions of steps. As normal in BOINC each work unit is computed at least three times and if the results don't match the work unit is queued for additional runs.

They noticed that they got a lot of work units that failed the initial check compared to other BOINC projects. Digging into it they noticed that if a work unit was computed by the same CPU manufacturer, ie all Intel CPUs, then they passed as expected. But if the work unit had been processed by mixed CPUs, ie at least one run on Intel and one run on AMD, they very often disagreed.

That's when they discovered[3] this very issue about how the rounding of various floating point functions differed between vendors.

After switching to crlibm[4] for the elementary functions they used the mixed-vendor problem went away.

[1]: https://www.davidhbailey.com/dhbtalks/dhb-icerm-2020.pdf

[2]: https://en.wikipedia.org/wiki/LHC@home

[3]: https://accelconf.web.cern.ch/icap06/papers/MOM1MP01.pdf

[4]: https://ens-lyon.hal.science/ensl-01529804/file/crlibm.pdf

Re: Elementary Functions and Not Following IEEE754 Floating-Point Standard (2020)

#15

It's really hard for me to think that this is a good solution. Normal users should be using Float64 (where there is no similar solution), and Float32 should only be used when Float64 computation is too expensive (e.g. GPUs). In such cases, it's hard to believe that doing the math in Float64 and converting will make anyone happy.

> Float32 should only be used when Float64 computation is too expensive

Or when you're bottlenecked on memory and want to store each number in four bytes instead of eight.

Re: Elementary Functions and Not Following IEEE754 Floating-Point Standard (2020)

#16
post #6

Floating-point is hard, and standards seem like they cater to lawyers rather than devs. But a few things are slightly misleading in the post. 1. It correctly quotes the IEEE754-2008 standard: > A conforming function shall return results correctly rounded for the applicable rounding direction for all operands in its domain and even points out that the citation is from "Section 9. *Recommended* operations" (emphasis mi…

> "solving" the fp32 incorrect-rounding problem by using fp64 is naive (not guaranteed to always work, although it will with high probability)

The key thing is there are only 2*32 float32s so you can check all of them. It sounds to me like the author did this, and realized they needed some tweaks for correct answers with log.

Re: Elementary Functions and Not Following IEEE754 Floating-Point Standard (2020)

#17
post #14

Would working with unums side-step the issue for math problems?

No, the fundamental issue is the difficulty of proving correctly-rounded results, which means implementations end up returning different results in practice. Unums do nothing to address that issue, except possibly by virtue of not having multiple implementations in the first place.

Re: Elementary Functions and Not Following IEEE754 Floating-Point Standard (2020)

#18
post #8
post #2

It's worth noting that the C standard explicitly disclaims correct rounding for these IEEE 754 functions (C23§F.3¶20). Also, there's a group of people who have been running tests on common libms, reporting their current accuracy states here: https://members.loria.fr/PZimmermann/papers/accuracy.pdf (that paper is updated ~monthly).

That Zimmermann paper is far more useful than the article. Notably LLVM libm is correctly rounded for most single precision ops. Notable omission are crlibm/rlibm/core-math etc libs which claim to be more correct, but I suppose we can already be pretty confident about them.

The current correctly rounded libraries work well with 32-bit float, but only provably produce correct rounding with 64-bit float in some cases. It turns out it's rather difficult to prove that you will produce a correctly rounded result in all cases, even if you have an algorithm that works. That means that each of these libraries has only a sunset of operations.

Re: Elementary Functions and Not Following IEEE754 Floating-Point Standard (2020)

#19

It's really hard for me to think that this is a good solution. Normal users should be using Float64 (where there is no similar solution), and Float32 should only be used when Float64 computation is too expensive (e.g. GPUs). In such cases, it's hard to believe that doing the math in Float64 and converting will make anyone happy.

Single-precision is too expensive for GPUs, unfortunately.

They may be too expensive for ML (or really not pareto-optimal for ML), but people use GPUs for a lot of things.

Re: Elementary Functions and Not Following IEEE754 Floating-Point Standard (2020)

#20
post #8
post #2

It's worth noting that the C standard explicitly disclaims correct rounding for these IEEE 754 functions (C23§F.3¶20). Also, there's a group of people who have been running tests on common libms, reporting their current accuracy states here: https://members.loria.fr/PZimmermann/papers/accuracy.pdf (that paper is updated ~monthly).

That Zimmermann paper is far more useful than the article. Notably LLVM libm is correctly rounded for most single precision ops. Notable omission are crlibm/rlibm/core-math etc libs which claim to be more correct, but I suppose we can already be pretty confident about them.

I've found that LLVM is slightly worse than GCC on reproducibility once you get past the basic issues in libm. For example, LLVM will incorrectly round sqrt on ppc64el in some unusual circumstances:

https://github.com/J-Montgomery/rfloat/blob/8a58367db32807c8...

Post reply on HN