The performance gap between CPU and memory widens continuously. Choosing the best memory layout for each hardware architecture is increasingly important as more and more programs become memory bound. For portable codes that run across heterogeneous hardware architectures, the choice of the memory layout for data structures is therefore ideally decoupled from the rest of a program. This can be accomplished via a zero-runtime-overhead abstraction layer, underneath which memory layouts can be freely exchanged. We present the C++ library LLAMA, which provides such a data structure abstraction layer with example implementations for multidimensional arrays of nested, structured data. LLAMA provides fully C++ compliant methods for defining and switching custom memory layouts for user-defined data types. Providing two close-to-life examples, we show that the LLAMA-generated AoS (Array of Struct) and SoA (Struct of Array) layouts produce identical code with the same performance characteristics as manually written data structures. LLAMA's layout-aware copy routines can significantly speed up transfer and reshuffling of data between layouts compared with naive element-wise copying. The library is fully extensible with third-party allocators and allows users to support their own memory layouts with custom mappings.
翻译:CPU 和 内存之间的性能差距会持续扩大。 选择每个硬件架构的最佳内存布局越来越重要, 因为越来越多的程序将内存捆绑起来。 对于跨多种硬件架构运行的便携式代码, 因此数据结构的内存布局的选择最好与程序的其余部分脱钩。 这可以通过零运行时间覆盖式的抽象层实现, 在这种层下可以自由交换内存布局。 我们展示了 C++ 图书馆 LLAMAMA, 它提供了这样的数据结构抽象层, 并且为嵌套、 结构化数据的多维数阵列提供了示例。 LLAMAMA 提供了定义和转换用户定义数据类型自定义的自定义内存布局的完全C+兼容方法。 我们提供了两个近寿命示例。 我们显示, LMA 生成的 AoS (Struct Array) 和 SoA (Array) 版布局可以产生与手动数据结构相同的性能特性相同的代码。 LLNAMA 的布局认知复制程序可以大大加快用户之间的传输和重新配置数据布局间数据布局的功能布局与所有用户之间的自动平版图支持。