arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2111.13040cs.PLcs.PF
收藏

草图引导的等式饱和:将等式饱和扩展到函数程序的复杂优化

Sketch-Guided Equality Saturation: Scaling Equality Saturation to Complex Optimizations of Functional Programs

Thomas Koehler, Phil Trinder, Michel Steuwer

摘要:

为不同的硬件和应用程序域生成高性能代码是一项挑战。带有map和reduce等模式的函数数组程序设计语言已经成功地与项重写结合起来,以定义和探索优化空间。然而,决定应用什么顺序的重写是困难的,并且对重写后的程序的性能有巨大的影响。相等饱和通过探索许多可能的方法来应用重写来避免这个问题,有效地在e图数据结构中表示许多等效程序。当重写函数语言术语时,等式饱和有一些限制,因为当前使用的是λ演算的朴素编码。我们提出了新的技术编码多态类型的lambda演算,并表明,有效的编码减少了运行时间和内存消耗的数量级的平等饱和。此外,等式饱和还不能扩展到复杂的编译器优化。这些从数千个重写步骤的长重写序列中出现,并且可能使用导致e图快速增长过大的重写规则的病态组合。本文介绍了\emph{sketch-guided equality saturation},一种允许程序员提供程序草图以指导重写的半自动技术。草图引导的等式饱和度评估了七个复杂的矩阵乘法优化,包括循环阻塞,矢量化和多线程。即使使用高效的λ演算编码,无指导的等式饱和也只能定位这些优化中最简单的两个,剩下的五个即使用一个小时的编译时间和60 GB的RAM也无法发现。通过指定三个或更少的草图指南,所有七个优化都可以在几秒钟的编译时间内找到,使用不到1GB的RAM,并生成高性能代码。

英文摘要:

Generating high-performance code for diverse hardware and application domains is challenging. Functional array programming languages with patterns like map and reduce have been successfully combined with term rewriting to define and explore optimization spaces. However, deciding what sequence of rewrites to apply is hard and has a huge impact on the performance of the rewritten program. Equality saturation avoids the issue by exploring many possible ways to apply rewrites, efficiently representing many equivalent programs in an e-graph data structure. Equality saturation has some limitations when rewriting functional language terms, as currently naive encodings of the lambda calculus are used. We present new techniques for encoding polymorphically typed lambda calculi, and show that the efficient encoding reduces the runtime and memory consumption of equality saturation by orders of magnitude. Moreover, equality saturation does not yet scale to complex compiler optimizations. These emerge from long rewrite sequences of thousands of rewrite steps, and may use pathological combinations of rewrite rules that cause the e-graph to quickly grow too large. This paper introduces \emph{sketch-guided equality saturation}, a semi-automatic technique that allows programmers to provide program sketches to guide rewriting. Sketch-guided equality saturation is evaluated for seven complex matrix multiplication optimizations, including loop blocking, vectorization, and multi-threading. Even with efficient lambda calculus encoding, unguided equality saturation can locate only the two simplest of these optimizations, the remaining five are undiscovered even with an hour of compilation time and 60GB of RAM. By specifying three or fewer sketch guides all seven optimizations are found in seconds of compilation time, using under 1GB of RAM, and generating high performance code.

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

↑