Annotation-guided AoS-to-SoA conversions and GPU offloading with data views in C++
arXiv:2502.16517 · doi:10.1002/cpe.70199
Abstract
The C++ programming language provides classes and structs as fundamental modeling entities. Consequently, C++ code tends to favour array-of-structs (AoS) for encoding data sequences, even though structure-of-arrays (SoA) yields better performance for some calculations. We propose a C++ language extension based on attributes that allows developers to guide the compiler in selecting memory arrangements, i.e.~to select the optimal choice between AoS and SoA dynamically depending on both the execution context and algorithm step. The compiler can then automatically convert data into the preferred format prior to the calculations and convert results back afterward. The compiler handles all the complexity of determining which data to convert and how to manage data transformations. Our implementation realises the compiler-extension for the new annotations in Clang and demonstrates their effectiveness through a smoothed particle hydrodynamics (SPH) code, which we evaluate on an Intel CPU, an ARM CPU, and a Grace-Hopper GPU. While the separation of concerns between data structure and operators is elegant and provides performance improvements, the new annotations do not eliminate the need for performance engineering. Instead, they challenge conventional performance wisdom and necessitate rethinking approaches how to write efficient implementations.
References in corpus (7)
- The cosmological simulation code GADGET-2
- Improving convergence in smoothed particle hydrodynamics simulations without pairing instability
- Smoothed Particle Hydrodynamics and Magnetohydrodynamics
- SWIFT: A modern highly-parallel gravity and smoothed particle hydrodynamics solver for astrophysical and cosmological applications
- SoAx: A generic C++ Structure of Arrays for handling Particles in HPC Codes
- Two Particle-in-Grid Realisations on Spacetrees
- Compiler support for semi-manual AoS-to-SoA conversions with data views