egg: Fast and Extensible Equality Saturation

Max Willsey, Chandrakana Nandi, Yisu Remy Wang, Oliver Flatt, Zachary Tatlock, Pavel Panchekha

egg

  • Equality saturation
  • Fast: deferred invariant maintenance
  • Extensible: e-class analyses

Growing E-Graph

Equality Saturation

key invariant to maintain: the equivalence relation is closed under congruence. (a = b implies f(a) = f(b))

deferred invariant maintenance

find all patterns

initial term

e-graph

apply all matches

restore all invariants

optimized term

comparison of pseducode

Evaluation

Overall, congruence is 88x faster, and equality saturation is 21x faster

Intuition of the speed-up

  • Consider f1(x) ... fn(x) and y1 ... yn
  • workload: merge(x, y1) ... merge(x, yn)
  • traditional: O(n^2)
  • deferred only does O(n)

egg: A Rust library

  • An open source Rust library
  • https://docs.rs/egg/

Case study

  • Herbie: floating point
    • 3000x faster
  • SPORES: linear algebra kernels
    • 1.5-2x better
  • TASO(SOSP'19): superoptimization of ML Computational graph
    • substition of computational subgraphs
    • 23% better, 48x faster
  • Szalinski: CAD synthesis
    • 1000x faster
  • ..., TVM, Java testing, vectorization, hw/sw co-design, educational problems, ...

egg: Fast and Extensible Equality Saturation

By Xingyu Xie

egg: Fast and Extensible Equality Saturation

  • 1