Partial differential equation (PDE) solvers are extensively utilized across numerous scientific and engineering fields. However, achieving high performance and scalability often necessitates intricate and low-level programming, particularly when leveraging deterministic sparsity patterns in structured grids. In this paper, we propose an innovative domain-specific language (DSL), Mat2Stencil, with its compiler, for PDE solvers on structured grids. Mat2Stencil introduces a structured sparse matrix abstraction, facilitating modular, flexible, and easy-to-use expression of solvers across a broad spectrum, encompassing components such as Jacobi or Gauss-Seidel preconditioners, incomplete LU or Cholesky decompositions, and multigrid methods built upon them. Our DSL compiler subsequently generates matrix-free code consisting of generalized stencils through multi-stage programming. The code allows spatial loop-carried dependence in the form of quasi-affine loops, in addition to the Jacobi-style stencil's embarrassingly parallel on spatial dimensions. We further propose a novel automatic parallelization technique for the spatially dependent loops, which offers a compile-time deterministic task partitioning for threading, calculates necessary inter-thread synchronization automatically, and generates an efficient multi-threaded implementation with fine-grained synchronization. Implementing 4 benchmarking programs, 3 of them being the pseudo-applications in NAS Parallel Benchmarks with $6.3\%$ lines of code and 1 being matrix-free High Performance Conjugate Gradients with $16.4\%$ lines of code, we achieve up to $1.67\times$ and on average $1.03\times$ performance compared to manual implementations.
翻译:偏微分方程求解器广泛应用于众多科学与工程领域。然而,实现高性能与可扩展性通常需要复杂且低层次的编程,尤其是在利用结构化网格中确定性稀疏模式时。本文提出了一种创新的领域特定语言Mat2Stencil及其编译器,专用于结构化网格上的PDE求解器。Mat2Stencil引入了一种结构化稀疏矩阵抽象,支持以模块化、灵活且易用的方式表达广泛求解器组件,包括Jacobi或Gauss-Seidel预处理子、不完全LU或Cholesky分解,以及基于它们构建的多重网格方法。我们的DSL编译器随后通过多阶段编程生成由广义模板构成的免矩阵代码。该代码允许以拟仿射循环形式存在的空间循环携带依赖,此外还支持Jacobi风格模板在空间维度上的易并行性。我们进一步提出了一种针对空间依赖循环的新型自动并行化技术,该技术提供编译时确定性任务划分以便线程化,自动计算必要的线程间同步,并生成具有细粒度同步的高效多线程实现。通过实现4个基准测试程序(其中3个为NAS并行基准测试中的伪应用程序,代码行数仅为其6.3%;1个为无矩阵高性能共轭梯度法,代码行数仅为其16.4%),我们达到了相对于手动实现高达1.67倍、平均1.03倍的性能。