[Paper Review] Composable and Modular Code Generation in MLIR: A Structured and Retargetable Approach to Tensor Compiler Construction
This paper presents a composable and modular code generation framework in MLIR that enables structured, retargetable tensor compiler construction by leveraging hierarchical decomposition of tensor operations, SSA and imperative semantics, and progressive lowering. The approach achieves high performance on CPU/GPU with minimal tuning, replacing legacy libraries like Eigen in production systems.
Despite significant investment in software infrastructure, machine learning systems, runtimes and compilers do not compose properly. We propose a new design aiming at providing unprecedented degrees of modularity, composability and genericity. This paper discusses a structured approach to the construction of domain-specific code generators for tensor compilers, with the stated goal of improving the productivity of both compiler engineers and end-users. The approach leverages the natural structure of tensor algebra. It has been the main driver for the design of progressive lowering paths in \MLIR. The proposed abstractions and transformations span data structures and control flow with both functional (SSA form) and imperative (side-effecting) semantics. We discuss the implications of this infrastructure on compiler construction and present preliminary experimental results.
Motivation & Objective
- Address the lack of modularity and composability in existing ML compiler stacks, which leads to duplicated effort and poor performance portability.
- Overcome the limitations of monolithic, non-composable code generators by introducing composable transformations and programmable operations in MLIR.
- Enable high-performance, portable code generation for tensor computations by preserving high-level structure throughout compilation.
- Facilitate seamless integration with numerical libraries (e.g., Eigen) and hardware-specific back-ends via ABI-compliant, retargetable vector abstractions.
- Support both functional (SSA) and imperative (side-effecting) programming models to enable broad applicability across tensor compilers.
Proposed method
- Use MLIR’s progressive lowering to decompose high-level tensor operations into smaller, composable tiles while preserving algebraic structure.
- Implement composable transformations that fuse, tile, and lower operations to vector primitives, supporting both immutable tensors and in-memory buffers.
- Introduce a declarative Python DSL for defining custom operations with first-class IR citizenship and C/C++/Python ABI interoperability.
- Leverage MLIR’s affine dialect to embed polyhedral scheduling within SSA form, enabling composable, retargetable optimizations.
- Apply in-place bufferization to materialize tensor programs efficiently in memory, supporting dense, sparse, and quantized representations.
- Use structured operations to abstract over complex lowering sequences, avoiding phase-ordering issues and enabling pass fusion.
Experimental results
Research questions
- RQ1How can tensor compiler construction be made modular and composable to reduce duplication and improve maintainability?
- RQ2Can progressive lowering with composable abstractions preserve high-level structure while enabling efficient code generation for diverse hardware?
- RQ3To what extent can MLIR’s IR and transformation infrastructure replace legacy numerical libraries like Eigen in production systems?
- RQ4How do composable transformations and retargetable vector abstractions improve performance portability across CPU and GPU platforms?
- RQ5Can a unified, extensible framework for code generation be built that supports both functional and imperative semantics in tensor compilers?
Key findings
- The proposed MLIR-based code generation flow achieved strong single-threaded CPU performance even without systematic tuning, demonstrating the effectiveness of composable abstractions.
- The framework successfully replaced uses of the Eigen library in Google-wide production systems, proving real-world viability and performance competitiveness.
- Progressive lowering with composable transformations enabled high-level optimizations to be applied systematically, reducing phase-ordering issues.
- The integration of affine scheduling with SSA form in MLIR’s affine dialect allowed for scalable, composable loop optimizations without sacrificing expressiveness.
- Early results show that a simple genetic search combined with autotuning over affine scheduling strategies can achieve competitive performance in both bandwidth- and latency-bound regimes.
- ABI compliance at function boundaries enabled seamless interoperability with C/C++ and Python, easing integration with existing frameworks and numerical libraries.
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.