[Paper Review] Canonicalization of Batched Einstein Summations for Tuning Retrieval
The paper introduces a graph-based canonicalization of batched Einstein summation expressions to enable reusable, near-optimal code transformations in a tabulation-based system called Feinsum, achieving a geomean speedup of 4.7x over JAX on relevant benchmarks.
We present an algorithm for normalizing \emph{Batched Einstein Summation} expressions by mapping mathematically equivalent formulations to a unique normal form. Batches of einsums with the same Einstein notation that exhibit substantial data reuse appear frequently in finite element methods (FEM), numerical linear algebra, and computational chemistry. To effectively exploit this temporal locality for high performance, we consider groups of einsums in batched form. Representations of equivalent batched einsums may differ due to index renaming, permutations within the batch, and, due to the commutativity and associativity of multiplication operation. The lack of a canonical representation hinders the reuse of optimization and tuning knowledge in software systems. To this end, we develop a novel encoding of batched einsums as colored graphs and apply graph canonicalization to derive a normal form. In addition to the canonicalization algorithm, we propose a representation of einsums using functional array operands and provide a strategy to transfer transformations operating on the normal form to \emph{functional batched einsums} that exhibit the same normal form; crucial for fusing surrounding computations for memory bound einsums. We evaluate our approach against JAX, and observe a geomean speedup of $4.7 imes$ for einsums from the TCCG benchmark suite and an FEM solver.
Motivation & Objective
- Motivate and formalize the need for reusable, high-performance implementations of batched einsums in scientific computing workloads.
- Define batched einsums and their isomorphisms to capture data reuse across repeated computations.
- Develop a canonicalization procedure that maps batched einsums to a unique normal form for tabulated optimization.
- Enable transfer of optimizations from idealized batched einsums to practical functional batched einsums through a reusable database.
- Provide an open-source implementation (Feinsum) that matches functional batched einsums to idealized forms and maps to code transformations.
Proposed method
- Define a batched Einstein summation as an unordered collection of einsums with shared notation and per-batch operands.
- Model equivalent batched einsums via isomorphism definitions for both single einsums and batched variants.
- Develop a three-step canonicalization: map to a colored directed graph (induced graph), canonize the graph, and map back to a batched einsum.
- Use graph canonicalization to produce a normal form where isomorphic batched einsums have identical representations.
- Introduce functional batched einsums where operands are lambda-expressions to facilitate transformation transfer.
- Implement a database that stores transformations for canonical batched einsums and supports retrieval and application to practical programs.
Experimental results
Research questions
- RQ1How can batched einsums be canonically represented to remove syntactic heterogeneity and enable reuse of optimizations?
- RQ2Can a graph-based canonicalization (colored graphs) yield a unique normal form for batched einsums and their isomorphisms?
- RQ3How can optimizations developed for idealized batched einsums be transferred to functional batched einsums used in real applications?
- RQ4Does a tabulation-based approach with a canonical form improve performance on memory-bound workloads compared to traditional materialization-based strategies?
- RQ5What is the practical performance impact of Feinsum's approach on real benchmarks and solvers?
Key findings
- A canonical form for batched einsums is achievable via a three-step graph-based pipeline, enabling equivalence classes to collapse to a single representation.
- Functional batched einsums enable reuse and transfer of transformation knowledge to practical programs with lambda operands.
- An open-source Feinsum system implements canonicalization, matching to idealized forms, and a database mapping to high-performance code transformations.
- Feinsum demonstrates a geomean speedup of 4.7x for batched einsums drawn from the TCCG benchmark suite and an FEM solver when compared to JAX.
- The approach addresses memory-bound regimes by enabling transformations without requiring materialization of intermediates, improving memory bandwidth utilization.
- The work provides a practical pathway to near-roofline kernels for batched einsums through tabulation and reuse of optimization knowledge.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.