Compiler support for semi-manual AoS-to-SoA conversions with data views

Pawel K. Radtke,Tobias Weinzierl
2024-09-05
Abstract:The C programming language and its cousins such as C++ stipulate the static storage of sets of structured data: Developers have to commit to one, invariant data model -- typically a structure-of-arrays (SoA) or an array-of-structs (AoS) -- unless they manually rearrange, i.e.~convert it throughout the computation. Whether AoS or SoA is favourable depends on the execution context and algorithm step. We propose a language extension based upon C++ attributes through which developers can guide the compiler what memory arrangements are to be used. The compiler can then automatically convert (parts of) the data into the format of choice prior to a calculation and convert results back afterwards. As all conversions are merely annotations, it is straightforward for the developer to experiment with different storage formats and to pick subsets of data that are subject to memory rearrangements. Our work implements the annotations within Clang and demonstrates their potential impact through a smoothed particle hydrodynamics (SPH) code.
Programming Languages
What problem does this paper attempt to address?
The problem that this paper attempts to solve is how to efficiently convert between Array - of - Structs (AoS) and Structure - of - Arrays (SoA) in high - performance computing to meet different algorithm requirements and execution contexts. Specifically: 1. **Requirement for Memory Layout Conversion**: In modern high - performance computing, different data layouts (such as AoS and SoA) have a great impact on performance. AoS is suitable for some scenarios that require random access, while SoA performs better in vectorized computing and cache utilization. However, developers usually need to choose a fixed data layout at compile time, which limits the flexibility of the code and the space for performance optimization. 2. **Challenges of Dynamic Memory Layout Conversion**: Manually implementing the AoS - to - SoA conversion in the code is not only cumbersome but also error - prone. Existing methods are either static global strategies that cannot adapt to the specific steps of the algorithm or dynamic local strategies that require a great deal of manual intervention. 3. **Proposed Solution**: The paper proposes a language extension based on C++ attributes, allowing developers to use annotations to guide the compiler to automatically perform the AoS - to - SoA conversion in specific code blocks. This conversion is temporary and does not change the layout of the original data, thus providing flexible performance optimization means while keeping the code concise. 4. **Specific Implementation**: By implementing this language extension in the Clang compiler, the compiler can automatically perform data conversion according to the annotations at runtime and restore the original data layout after the calculation is completed. In this way, developers can easily experiment with different data layouts to find the best performance configuration. 5. **Application Scenarios**: The paper shows the potential of this method in practical applications through a Smoothed Particle Hydrodynamics (SPH) code example. The results show that in some computationally intensive kernels, temporarily converting to SoA can significantly improve performance, especially on multi - core systems. In summary, this paper aims to provide a lightweight and non - invasive method that enables developers to optimize performance by simply using annotations to guide the compiler to perform dynamic memory layout conversion without modifying the existing code.