RECURSUM:通过分层代码生成实现递推关系的自动代码生成超越专家优化
RECURSUM: Automated Code Generation for Recurrence Relations Exceeds Expert Optimization via LayeredCodegen
AI总结:
RECURSUM通过分层代码生成技术,利用Python DSL生成优化的C++代码,实现递推关系的高效计算,其速度提升显著,且消除了领域知识与C++元编程的双重专业壁垒。
摘要:
自动代码生成可以系统性地超越专家手工优化,用于递推关系——在正交多项式、特殊函数、数值积分和分子积分评估中普遍存在的计算基础构件。我们提出了RECURSUM,一种基于Python的领域特定语言,通过三个后端生成优化的C++代码:模板元编程用于编译时评估,一种新的分层代码生成后端具有架构优化,以及运行时循环评估。该DSL使用einsum启发式的记法来指定递推关系、有效性约束和基本情况,用10-30行Python代码生成650多行生产C++代码。分层代码生成在专家手工实现上实现了9.8倍的加速,在模板元编程用于McMurchie-Davidson Hermite系数上实现了1.9倍的加速。架构分析揭示了三个可量化的效应:(1)零拷贝输出参数消除了返回值的开销(70-80%的加速),(2)保证的函数内联消除了编译器拒绝的开销(15-20%),(3)精确大小的堆栈缓冲区实现了100%的缓存效率,与MAX大小的数组相比为27%。我们验证了24种递推类型,涵盖纯数学(Legendre、Chebyshev、Hermite、Laguerre多项式)、数值分析(Clenshaw、Golub-Welsch)和量子化学(McMurchie-Davidson、Rys四次积分、Boys函数)。生产基准测试显示加速传播到完整算法,生成的代码与专家基准线在3.3%以内匹配。RECURSUM证明了系统化的代码生成是递推算法的性能上限。通过消除双重专业知识壁垒(领域知识+C++元编程),该框架使高性能科学计算民主化——建立一个自动化生成系统性超越手动优化的范式。
英文摘要:
Automated code generation can systematically exceed expert hand-optimization for recurrence relations--computational primitives ubiquitous in orthogonal polynomials, special functions, numerical integration, and molecular integral evaluation. We present RECURSUM, a Python DSL generating optimized C++ for arbitrary recurrence relations via three backends--template metaprogramming, a novel LayeredCodegen backend, and runtime loop-based evaluation--specifying recurrences in 10--30 lines of Python that generate 650+ lines of production C++. LayeredCodegen achieves 9.8$\times$ speedup over expert hand-written code and 1.9$\times$ over template metaprogramming for McMurchie-Davidson Hermite coefficients, through zero-copy output parameters, guaranteed inlining, and exact-sized stack buffers. A DAG-topological generalization of this architecture--built to express the four-center electron-repulsion integral that LayeredCodegen's tower model cannot--beats libint2, a mature, two-decade-refined production library, on 12 of 14 Cartesian integral classes, with $\sim$2$\times$ faster contracted Coulomb/exchange (J/K) matrix construction (alkanes and 3-D DNA fragments alike) and 1.1--2.7$\times$ faster one-electron integrals, completing the full Hartree-Fock integral set from one DAG framework. We validate 24 recurrence types spanning pure mathematics, numerical analysis, and quantum chemistry; production benchmarks confirm these speedups propagate to complete algorithms, matching expert baselines within 3.3\%. By eliminating the dual expertise barrier of domain knowledge and C++ metaprogramming, RECURSUM establishes systematic code generation--not hand-tuning--as the performance ceiling for recurrence algorithms.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。