arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2502.16517cs.MScs.PFcs.PL
收藏

C++中基于注解引导的AoS到SoA转换及数据视图的GPU卸载

Annotation-guided AoS-to-SoA conversions and GPU offloading with data views in C++

Pawel K. Radtke, Tobias Weinzierl

AI总结:

提出基于属性的C++语言扩展,指导编译器动态选择AoS或SoA内存排列并自动转换数据,在Clang中实现并通过SPH代码验证,提升了性能但需重新思考性能工程。

摘要:

C++编程语言将类和结构体作为基本的建模实体。因此,C++代码倾向于使用结构体数组(AoS)来编码数据序列,尽管数组结构体(SoA)在某些计算中能产生更好的性能。我们提出了一种基于属性的C++语言扩展,允许开发人员指导编译器选择内存排列方式,即根据执行上下文和算法步骤在AoS和SoA之间动态选择最优方案。随后,编译器可以在计算前自动将数据转换为首选格式,并在计算后将结果转换回来。编译器处理了确定转换哪些数据以及如何管理数据转换的所有复杂性。我们的实现为Clang中的新注解实现了编译器扩展,并通过一个平滑粒子流体动力学(SPH)代码展示了其有效性,我们在Intel CPU、ARM CPU和Grace-Hopper GPU上对该代码进行了评估。虽然数据结构和操作符之间的关注点分离十分优雅并提供了性能提升,但新注解并未消除对性能工程的需求。相反,它们挑战了传统的性能认知,并需要重新思考如何编写高效的实现。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑