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.
翻译:C编程语言及其衍生语言(如C++)规定了结构化数据集合的静态存储方式:开发人员必须选定一种不可变的数据模型——通常是数组结构(SoA)或结构数组(AoS)——除非在计算过程中手动重新排列(即转换)数据。AoS与SoA的优劣取决于执行上下文和算法步骤。我们提出一种基于C++属性的语言扩展,使开发人员能够指导编译器采用何种内存布局。编译器随后可在计算前自动将(部分)数据转换为目标格式,并在计算后将结果转换回原格式。由于所有转换仅通过注解实现,开发人员能够轻松尝试不同的存储格式,并选择需要进行内存重排的数据子集。我们的研究在Clang编译器中实现了这些注解,并通过光滑粒子流体动力学(SPH)代码展示了其潜在影响。