Guess, Measure & Edit: Using Lowering to Lift Tensor Code
Recently, we have observed a steady growth in specialized hardware accelerators. These accelerators are typically programmed in high-level domain-specific languages (DSLs), enabling compilers to generate efficient code for rapidly evolving heterogeneous hardware. However, rewriting existing code to exploit DSL compiler performance is an onerous programmer task. This has led to recent interest in automatically translating or lifting code to DSLs. Current lifting techniques use language models or program synthesis to translate code. Although language models have proved remarkably successful in related translation tasks, they are prone to hallucinations. Program synthesis approaches are accurate but do not scale to complex tensor DSLs. This paper presents a novel approach, Guess, Measure & Edit; that exploits both language models and compiler technology to lift existing code to high-level DSLs. Given a source program, it uses a language model to guess an initial equivalent target program. It then compiles or lowers the guess and the original program, and measures the low-level distance between them using program similarity metrics. It iteratively uses these low-level metrics to guide high-level edits to the guess until it is correct. To validate this approach, we develop KONRUL which correctly lifts existing tensor algebra C code to einsum notation, the basis of tensor contraction DSLs. Our evaluation shows that KONRUL is fast and accurate, lifting 98% of an extensive benchmark suite and significantly outperforming 4 state-of-theart lifting schemes. KONRUL is scalable and is the only approach to correctly lift higher-dimensional tensor contraction code. Our lifted programs result in geomean speedups of $4.07 \times$ and $38.30 \times$ when ported to a multi-core CPU and GPU respectively.
Authors
- Luc Jaulmes (ORCID: https://orcid.org/0000-0002-5815-2504)
- Elizabeth Polgreen (ORCID: https://orcid.org/0000-0001-9032-7661)
- Jordi Armengol-Estapé (ORCID: https://orcid.org/0000-0001-8893-6185)
- Michael O’Boyle (ORCID: https://orcid.org/0000-0003-1619-5052)
- Jackson Woodruff (ORCID: https://orcid.org/0000-0003-2650-9596)
- José Wesley de Souza Magalhães (ORCID: https://orcid.org/0000-0003-2767-1130)
- Alexander Brauckmann (ORCID: https://orcid.org/0000-0001-5774-3970)
Institutions
- University of Edinburgh (GB)
Publication Details
- Published
- 2025-11-03
- DOI
- https://doi.org/10.1109/pact65351.2025.00029
- Primary Topic
- Logic, programming, and type systems
- Type
- article
- Field-Weighted Citation Impact
- 0.00