CG-Kit is a new code generation toolkit that we propose as a solution for portability and maintainability for scientific computing applications. The development of CG-Kit is rooted in the urgent need created by the shifting landscape of high-performance computing platforms and the algorithmic complexities of a particular large-scale multiphysics application: Flash-X. This combination leads to unique challenges including handling an existing large code base in Fortran and/or C/C++, subdivision of code into a great variety of units supporting a wide range of physics and numerical methods, different parallelization techniques for distributed- and shared-memory systems and accelerator devices, and heterogeneity of computing platforms requiring coexisting variants of parallel algorithms. The challenges demand that developers determine custom abstractions and granularity for code generation. CG-Kit tackles this with standalone tools that can be combined into highly specific and, we argue, highly effective portability and maintainability tool chains. Here we present the design of our new tools: parametrized source trees, control flow graphs, and recipes. The tools are implemented in Python. Although the tools are agnostic to the programming language of the source code, we focus on C/C++ and Fortran. Code generation experiments demonstrate the generation of variants of parallel algorithms: first, multithreaded variants of the basic AXPY operation (scalar-vector addition and vector-vector multiplication) to introduce the application of CG-Kit tool chains; and second, variants of parallel algorithms within a hydrodynamics solver, called Spark, from Flash-X that operates on block-structured adaptive meshes. In summary, code generated by CG-Kit achieves a reduction by over 60% of the original C/C++/Fortran source code.
翻译:摘要:CG-Kit是一种新型代码生成工具包,我们将其作为科学计算应用的可移植性与可维护性解决方案提出。CG-Kit的开发根植于高性能计算平台格局变迁以及特定大规模多物理场应用(Flash-X)的算法复杂性共同催生的迫切需求。这一组合带来了独特挑战,包括:处理现有的Fortran和/或C/C++大型代码库、将代码细分为支持广泛物理场与数值方法的多类单元、针对分布式内存系统、共享内存系统及加速设备采用不同并行化技术,以及计算平台异构性要求并行算法变体共存。这些挑战要求开发者确定代码生成的自定义抽象层次与粒度。CG-Kit通过可组合的独立工具应对此问题,这些工具能构建高度特定化——我们认为也是高度有效的——可移植性与可维护性工具链。本文介绍了新工具的设计:参数化源代码树、控制流图和配方。这些工具以Python实现。尽管工具与源代码编程语言无关,但我们重点聚焦C/C++和Fortran。代码生成实验展示了并行算法变体的生成:首先,针对基础AXPY操作(标量-向量加法与向量-向量乘法)生成多线程变体,以展示CG-Kit工具链的应用;其次,从Flash-X中提取名为Spark的流体动力学求解器,为其运行于块结构自适应网格的并行算法生成变体。综上所述,CG-Kit生成的代码可将原始C/C++/Fortran源代码量减少超过60%。