Caviar:一种基于E图的TRS自动代码优化方法
Caviar: An E-graph Based TRS for Automatic Code Optimization
摘要:
在编译器中使用术语重写系统(TRS)来简化和证明表达式。编译器中最先进的TRS使用贪心算法,该算法以预定义的顺序应用一组重写规则(其中一些规则不是公理化的)。这会导致失去简化某些表达式的能力。E-图和等式饱和度通过以紧凑的方式表示不同的等价表达式来回避这个问题,从中可以提取最佳表达式。虽然基于e图的TRS可能比使用贪心算法的TRS更强大,但它更慢,因为表达式可能具有大量或有时无限数量的等效表达式。加速e图的构造是使e图在编译器中实用化的关键。在本文中,我们提出了鱼子酱,一个基于电子图的TRS证明表达式编译器内。鱼子酱的主要优点是它的速度。它可以证明表达式比基本e图TRS快得多。它依赖于三种技术:1)一种在达到目标时停止e-graph增长的技术,称为迭代级别检查; 2)一种在相等饱和算法中平衡探索和利用的机制,称为脉冲鱼子酱; 3)一种在检测到不可证明模式时在达到饱和之前停止e-graph构建的技术,称为不可证明模式检测(NPPD)。我们评估鱼子酱的Halide,优化编译器,依赖于一个贪婪的算法为基础的TRS简化和证明其表达式。所提出的技术允许Caviar加速用于证明表达式的任务的e图扩展。它们还允许Caviar证明Halide的TRS无法证明的表达式,同时仅慢0.68倍。
英文摘要:
Term Rewriting Systems (TRSs) are used in compilers to simplify and prove expressions. State-of-the-art TRSs in compilers use a greedy algorithm that applies a set of rewriting rules in a predefined order (where some of the rules are not axiomatic). This leads to a loss of the ability to simplify certain expressions. E-graphs and equality saturation sidestep this issue by representing the different equivalent expressions in a compact manner from which the optimal expression can be extracted. While an e-graph-based TRS can be more powerful than a TRS that uses a greedy algorithm, it is slower because expressions may have a large or sometimes infinite number of equivalent expressions. Accelerating e-graph construction is crucial for making the use of e-graphs practical in compilers. In this paper, we present Caviar, an e-graph-based TRS for proving expressions within compilers. The main advantage of Caviar is its speed. It can prove expressions much faster than base e-graph TRSs. It relies on three techniques: 1) a technique that stops e-graphs from growing when the goal is reached, called Iteration Level Check; 2) a mechanism that balances exploration and exploitation in the equality saturation algorithm, called Pulsing Caviar; 3) a technique to stop e-graph construction before reaching saturation when a non-provable pattern is detected, called Non-Provable Patterns Detection (NPPD). We evaluate caviar on Halide, an optimizing compiler that relies on a greedy-algorithm-based TRS to simplify and prove its expressions. The proposed techniques allow Caviar to accelerate e-graph expansion for the task of proving expressions. They also allow Caviar to prove expressions that Halide's TRS cannot prove while being only 0.68x slower.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。