Fluid Simulations Accelerated With 16 Bits: Approaching 4x Speedup on A64FX by Squeezing ShallowWaters.jl Into Float16

Milan Klöwer, Sam Hatfield, Matteo Croci, Peter D. Düben, T. N. PalmerJournal of Advances in Modeling Earth Systems 2022

TL;DR

This paper demonstrates that running fluid simulations entirely in 16-bit precision (Float16) on the A64FX processor can achieve nearly 4x speedups over traditional 64-bit calculations. By carefully scaling the model equations and employing compensated summation for time integration, they overcome the precision and dynamic range limitations of Float16, making it a viable option for accelerating Earth-system models.

What Problem Does This Paper Address?

Modern weather and climate simulations rely heavily on 64-bit double-precision floating-point numbers (Float64) for accuracy. However, this comes at a significant computational cost, limiting the resolution and complexity of models that can be run in a timely manner. While there's a growing debate about whether such extreme precision is always necessary given the inherent uncertainties in climate data, the computational bottleneck remains. The advent of new hardware like Fujitsu's A64FX, which powers the Fugaku supercomputer, offers support for 16-bit half-precision (Float16), promising substantial performance gains. The challenge lies in adapting existing complex models to this low-precision format, which has a much smaller dynamic range and can lead to significant rounding errors and overflows/underflows.

Methods

The authors tackle the challenges of using Float16 in fluid simulations through a multi-pronged approach:

  • Equation Scaling: They systematically rescale the shallow water equations to fit within the limited dynamic range of Float16. This involves introducing scaling factors for variables and their derivatives.
  • Sherlogs.jl: A novel analysis-number format is introduced to log the bit patterns of all arithmetic results during a simulation. This allows for detailed inspection of number distributions, identifying potential range issues and the extent of subnormal number usage.
  • Compensated Summation: To mitigate precision loss in the critical time integration step, they implement compensated summation. This technique, adapted from earlier work, adds a compensation variable to track and correct rounding errors during summation, preventing their accumulation. This is shown to be more efficient than traditional mixed-precision approaches.
  • Subnormal Number Handling: Recognizing that subnormal numbers are inefficiently handled on the A64FX, they employ scaling strategies to minimize their occurrence, effectively pushing the simulation into the more efficient normal number range of Float16.

Datasets

Not discussed in the paper. The study uses a simulated dataset generated by the Shallow Waters.jl model itself.

Key Insights and Ideas

  • Float16 is not just for Deep Learning: This work demonstrates that 16-bit arithmetic, often associated with deep learning, can be effectively and precisely applied to scientific simulations like fluid dynamics.
  • Scaling is Paramount: Simply translating existing Float64 code to Float16 will likely fail. Systematic scaling of equations is crucial to map the problem's dynamic range onto the limited range of Float16.
  • Compensated Summation is a Game-Changer for Time Integration: This technique offers a way to maintain accuracy in precision-critical time-stepping routines using only 16-bit arithmetic, outperforming mixed-precision methods in terms of speed.
  • Subnormals are Performance Killers: The inefficient handling of subnormal numbers on certain hardware (like A64FX) necessitates careful scaling to avoid them, even if it means slightly reducing the effective dynamic range.
  • Sherlogs.jl is a Powerful Debugging Tool: This analysis format provides invaluable insight into how numbers behave within a simulation, enabling targeted optimization for low-precision formats.

Key Results

  • Speedup: The authors achieve speedups of up to 3.8x on the A64FX processor when running Shallow Waters.jl entirely in Float16 compared to Float64.
  • Compensated Time Integration Speedup: Incorporating compensated time integration, which maintains precision, still yields significant speedups of up to 3.6x.
  • Precision: The compensated time integration method ensures that rounding errors are comparable to or better than mixed-precision approaches, and the overall error growth is significantly reduced compared to uncompensated Float16.
  • Range Utilization: Through systematic scaling, the model utilizes 97% of the available representable numbers in Float16, minimizing unused bit patterns.
  • Subnormal Reduction: Scaling strategies reduced the occurrence of subnormal numbers to 0.04% of arithmetic results.
  • Mass Conservation: The compensated time integration conserves mass with minimal change (<0.002% over 500 days), comparable to Float64.

Limitations and Future Work

  • Model Simplification: Shallow Waters.jl is a simplified model compared to full-fledged Earth-system models. The authors acknowledge that fitting more complex models into Float16 might require further scaling constants or different approaches for various model components (e.g., vertical layers).
  • Generalizability of Compensated Summation: While effective for time integration, the authors suggest that compensated summation might be needed in other parts of complex models as well.
  • Open Question of Full 16-bit Models: It remains an open question whether all calculations in complex weather and climate models can be performed with 16-bit arithmetic.
  • Future Directions: The paper suggests that further scaling techniques and potentially adapted compensated summation methods could be necessary for more complex models. The development of 16-bit models, while challenging, promises a new generation of computationally efficient Earth-system models.

Summary updated

Abstract

Most Earth-system simulations run on conventional central processing units in 64-bit double precision floating-point numbers Float64, although the need for high-precision calculations in the presence of large uncertainties has been questioned. Fugaku, currently the world's fastest supercomputer, is based on A64FX microprocessors, which also support the 16-bit low-precision format Float16. We investigate the Float16 performance on A64FX with ShallowWaters.jl, the first fluid circulation model that runs entirely with 16-bit arithmetic. The model implements techniques that address precision and dynamic range issues in 16 bits. The precision-critical time integration is augmented to include compensated summation to minimize rounding errors. Such a compensated time integration is as precise but faster than mixed precision with 16 and 32-bit floats. As subnormals are inefficiently supported on A64FX the very limited range available in Float16 is 6 × 10<sup>-5</sup> to 65,504. We develop the analysis-number format Sherlogs.jl to log the arithmetic results during the simulation. The equations in ShallowWaters.jl are then systematically rescaled to fit into Float16, using 97% of the available representable numbers. Consequently, we benchmark speedups of up to 3.8x on A64FX with Float16. Adding a compensated time integration, speedups reach up to 3.6x. Although ShallowWaters.jl is simplified compared to large Earth-system models, it shares essential algorithms and therefore shows that 16-bit calculations are indeed a competitive way to accelerate Earth-system simulations on available hardware.
BibTeX
@article{klower2022fluid,
  author = {Milan Klöwer and Sam Hatfield and Matteo Croci and Peter D. Düben and T. N. Palmer},
  title = {{Fluid Simulations Accelerated With 16 Bits: Approaching 4x Speedup on A64FX by Squeezing ShallowWaters.jl Into Float16}},
  journal = {Journal of Advances in Modeling Earth Systems},
  year = {2022},
  doi = {10.1029/2021ms002684},
}
Figure