Revealing Floating-Point Accumulation Orders in Software/Hardware Implementations

Peichen Xie, Yanjie Gao, Yang Wang, Jilong Xue

TL;DR

This paper introduces FPRev, a novel diagnostic tool that automatically uncovers the hidden accumulation orders of floating-point operations in software and hardware. This is crucial for ensuring numerical reproducibility in scientific computing and deep learning, as inconsistent accumulation orders can lead to subtle but significant errors. FPRev achieves this through clever numerical testing, offering a practical solution for developers to understand and replicate complex computations.

What Problem Does This Paper Address?

In the world of computing, especially in scientific and high-performance domains, floating-point arithmetic is everywhere. Operations like summing up numbers or performing matrix multiplications are fundamental. However, the exact order in which these operations are performed (the "accumulation order") isn't always standardized. This means that the same calculation might yield slightly different results on different machines or even with different software libraries. This lack of consistency, known as the non-associativity of floating-point addition, is a major headache for developers trying to ensure their code is reproducible and reliable, especially in safety-critical applications. Existing methods for understanding these orders are often cumbersome (requiring source code analysis) or don't scale well.

Methods

The core innovation of this paper is FPRev, a diagnostic tool that uses a non-intrusive, testing-based approach to reveal accumulation orders. The key idea is to leverage the "swamping phenomenon" in floating-point arithmetic. By carefully crafting test inputs that include a very large number (M) and its negative counterpart (-M) alongside many ones, FPRev can deduce how these numbers are combined. The output of the operation, when compared to the expected result, reveals information about which numbers were "masked" by the M and -M pair, effectively mapping out the structure of the accumulation process.

FPRev builds upon a basic solution (BasicFPRev) that constructs a "summation tree" to visualize the order. The refined FPRev algorithm improves efficiency by calculating necessary values "on demand" and introduces support for multi-term fused summation, a specialized operation found in modern GPU matrix accelerators like NVIDIA's Tensor Cores. This multiway tree structure allows FPRev to model these complex, non-standard operations.

Datasets

Not discussed in the paper. The paper focuses on testing existing software libraries and hardware implementations rather than training models on datasets.

Key Insights and Ideas

  • The "Hidden Order" Problem is Real and Widespread: The paper demonstrates that many popular libraries (like NumPy and PyTorch) have undocumented accumulation orders, especially when using underlying hardware acceleration.
  • Numerical Reproducibility is a Major Challenge: Inconsistent accumulation orders are a significant barrier to achieving reliable and reproducible results in scientific computing and deep learning.
  • Clever Testing Can Uncover Complex Behavior: FPRev's use of specially crafted inputs (masked all-one arrays) is a powerful technique for reverse-engineering the internal logic of floating-point operations.
  • Modern Hardware Adds Complexity: Specialized hardware like Tensor Cores use non-standard fused summation techniques that require a more sophisticated approach (multiway trees) to model.
  • FPRev Offers a Practical Solution: The tool provides a way for developers to understand and replicate these hidden orders, enabling more robust software development.

Key Results

FPRev was successfully applied to popular libraries like NumPy and PyTorch on various CPUs and GPUs.

  • NumPy and PyTorch Summation: For single-precision summation, NumPy and PyTorch showed consistent accumulation orders across different CPUs and GPUs, respectively, indicating good reproducibility for these specific operations.
  • BLAS Operations and Matrix Accelerators: Other operations, particularly those relying on BLAS backends and matrix accelerators (like Tensor Cores), exhibited non-reproducible behavior and varied accumulation orders across different hardware. For instance, PyTorch's half-precision matrix multiplication on Tensor Cores showed different summation tree structures (5-way, 9-way, 17-way) on NVIDIA V100, A100, and H100 GPUs.
  • Efficiency: FPRev demonstrated significantly better performance than a naive brute-force approach, with its execution time growing polynomially rather than exponentially with the number of summands. FPRev was also consistently more efficient than its basic version (BasicFPRev), especially for more complex operations. For example, for matrix multiplication with 256 summands, FPRev was up to 82.1x faster than BasicFPRev.

Limitations and Future Work

  • Scope: FPRev is designed for operations with deterministic accumulation orders. It does not cover randomized or input-dependent summation algorithms.
  • Dynamic Range and Precision: For data types with very low dynamic range or low accumulation precision, the masking technique might require adjustments. The authors suggest modifications to handle these cases, extending FPRev's applicability to formats like FP8.
  • Future Work: The authors plan to extend FPRev to detect other floating-point behaviors in matrix accelerators, such as rounding modes and accumulator precision. They also aim to further optimize FPRev's efficiency, potentially through randomized selection of test inputs.

Summary updated

BibTeX
@inproceedings{xie2025revealing,
  author = {Peichen Xie and Yanjie Gao and Yang Wang and Jilong Xue},
  title = {{Revealing Floating-Point Accumulation Orders in Software/Hardware Implementations}},
  booktitle = {USENIX ATC},
  year = {2025},
  url = {https://openreview.net/forum?id=aYWNoghCCG},
}
Figure