Commit 5ae1dd9
Reproducible floating-point summations
Summary:
Introduce ReproducibleFloatingAccumulator. Header-only C++ library for reproducible (order-independent) floating-point summation using binned floating-point arithmetic, adapted from ReproBLAS v2.1.0.
Key features of the accumulator:
- Reproducible summation independent of summation order
- Accuracy at least as good as conventional summation, and tunable via FOLD
- Handles overflow, underflow, NaN, and infinity reproducibly
- Single read-only pass over summands; minimal memory (2*FOLD floats - usually 6 since FOLD=3 is sufficient for most purposes)
Public interface:
- Default, copy, and implicit scalar construction
- operator+=/-= for scalars and accumulators
- Binary operator+/- (including scalar-accumulator mixed expressions)
- operator== for bitwise equality
- Explicit conversion to native float via operator ftype() and value()
- Batch add() via iterator pairs, C++20 ranges, or single values
- Manual unsafe_add/renorm path for performance-critical loops
- Error bound computation
- fmt::formatter specialization (always available via fmt/format.h)
- static_assert(FOLD >= 2) to catch invalid instantiation
# Example
```
ReproducibleAccumulator<double> rfa;
for (const auto& x : kDoubleData) {
rfa += x;
}
rfa.value(); // Same result irrespective of ordering of kDoubleData
```
# Benchmark
```
============================================================================
[...]/ReproducibleAccumulatorBenchmark.cpp relative time/iter iters/s
============================================================================
SumDouble_OneAtATime_10 50.69ns 19.73M
SumDouble_BatchAdd_10 55.744% 90.93ns 11.00M
----------------------------------------------------------------------------
SumDouble_OneAtATime_1000 4.11us 243.32K
SumDouble_BatchAdd_1000 132.29% 3.11us 321.88K
----------------------------------------------------------------------------
SumDouble_OneAtATime_1M 4.11ms 243.12
SumDouble_BatchAdd_1M 137.09% 3.00ms 333.30
----------------------------------------------------------------------------
SumFloat_OneAtATime_1M 4.14ms 241.69
SumFloat_BatchAdd_1M 137.35% 3.01ms 331.96
----------------------------------------------------------------------------
SumDouble_NaiveBaseline_1M 1.03ms 975.29
SumFloat_NaiveBaseline_1M 1.02ms 975.89
----------------------------------------------------------------------------
SumDouble_Kahan_1M 13.31ms 75.11
SumFloat_Kahan_1M 13.32ms 75.10
----------------------------------------------------------------------------
SumDouble_LongDouble_1M 2.39ms 418.41
SumFloat_LongDouble_1M 2.39ms 418.72
```
Reviewed By: yfeldblum
Differential Revision: D97780214
fbshipit-source-id: 07399b5f905f3a021252560ad80df47fe53db21a1 parent 3b8cab2 commit 5ae1dd9
File tree
7 files changed
+2019
-0
lines changed- folly
- math
- test
7 files changed
+2019
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1419 | 1419 | | |
1420 | 1420 | | |
1421 | 1421 | | |
| 1422 | + | |
1422 | 1423 | | |
1423 | 1424 | | |
1424 | 1425 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
0 commit comments