TL;DR
This paper introduces an MLIR-based compiler pipeline that automatically translates stencil computations into highly optimized code for the Cerebras Wafer-Scale Engine (WSE). This breakthrough allows existing stencil codes to run on the WSE without manual rewriting, achieving performance comparable to or better than hand-tuned code and significantly outperforming traditional HPC architectures.
What Problem Does This Paper Address?
The Cerebras Wafer-Scale Engine (WSE) offers unprecedented computational power with its massive array of processing elements. However, its unique, highly asynchronous, actor-like execution model presents a significant barrier to adoption for High-Performance Computing (HPC) applications. Traditional programming models and compiler toolchains are ill-suited for this architecture, requiring programmers to fundamentally recast their algorithms and write complex, low-level Cerebras Software Language (CSL) code. This steep learning curve and manual effort have hindered the WSE's widespread use in HPC. The paper addresses this by proposing an automated compilation approach that bridges the gap between standard stencil representations and the WSE's specialized execution model.
Methods
The core of this work is an MLIR (Multi-Level Intermediate Representation) based compiler pipeline. MLIR's extensible nature allows for the creation of domain-specific dialects and transformations. The authors introduce three new MLIR dialects:
csl-stencil: Captures stencil computations and their explicit communication requirements, specific to the WSE.csl-wrapper: A domain-agnostic dialect for packaging program-wide parameters and layout information, essential for the WSE's staged compilation.csl-ir: A direct re-implementation of a large subset of the CSL programming language, serving as the final intermediate representation before CSL code generation.
The pipeline systematically transforms an architecture-agnostic stencil dialect into these WSE-specific dialects through a series of five groups of transformations:
- Decomposition and Data Dependencies: Decomposes the 3D stencil onto the WSE's 2D PE grid and tensorizes the Z-dimension, mapping columns of data to individual PEs. Introduces
dmp.swapoperations to denote data exchanges. - Realize Placement and Communication: Replaces
dmp.swapwithcsl-stencil.prefetchoperations, explicitly handling data fetching and splitting communication into chunks to overlap with computation. Wrapscsl-stenciloperations incsl-wrapper. - Memory Realization: Converts tensor representations to
memreftypes, mapping them to physical memory. Computations are translated from thearithdialect to thelinalgdialect to support CSL's Destination-Passing Style (DPS). - Map to Actor Execution Model: Lowers
csl-stencil.applyoperations into software actors (tasks) that are activated by incoming messages, mirroring the WSE's asynchronous, actor-based execution. Top-level loops are transformed into control-flow task graphs. - Lowering to
csl-ir: Mapslinalgcomputations tocsl-irusing Data Structure Descriptors (DSDs) for efficient memory access.memrefoperations are lowered tocsl-ir, and thecsl-wrapper.moduleis translated to generate the final CSL code.
The pipeline leverages existing MLIR infrastructure and domain-specific DSLs (Devito, PSyclone, Flang) as frontends.
Datasets
The paper evaluates its approach using five benchmarks: Jacobian, Diffusion, Acoustic, 25-Point Seismic, and UVKBE. These benchmarks are derived from existing HPC applications and are representative of common stencil computations. No new datasets were introduced; rather, the focus was on porting and optimizing existing computational kernels.
Key Insights and Ideas
- MLIR as a Unifying Abstraction: MLIR's extensible dialect system proves highly effective for bridging the semantic gap between diverse frontends and a highly specialized architecture like the WSE.
- Actor Model as a Natural Fit: The paper reinforces the idea that viewing the WSE's execution as an actor model is crucial for understanding and programming it, and that compiler transformations can automate this mapping.
- Retaining High-Level Information: Unlike compilers for conventional architectures, the WSE compiler flow benefits from retaining high-level stencil information throughout the pipeline, enabling more effective optimization for its dataflow, cache-less nature.
- Performance Gains from Asynchronous Execution: By effectively managing asynchronous communication and computation, the generated code can achieve significant speedups, even outperforming hand-tuned implementations that may not fully exploit the WSE's capabilities.
- Developer Productivity: The automated pipeline drastically reduces the lines of code required compared to manual CSL programming, making the WSE more accessible to a wider range of developers.
Key Results
- Performance: The MLIR pipeline achieves performance comparable to, and in some cases better than, manually optimized CSL code for the WSE.
- WSE3 vs. Competitors: For the Devito acoustic benchmark, the WSE3 achieved performance approximately 14x faster than 128 Nvidia A100 GPUs and 20x faster than 128 nodes of a CPU-based Cray-EX supercomputer.
- WSE2 vs. WSE3: The WSE3 generally outperforms the WSE2, with improvements up to 38.1% due to architectural enhancements, particularly in switching logic.
- Lines of Code Reduction: The generated CSL code using the pipeline requires significantly fewer lines of code compared to manual CSL kernel development or DSL-based approaches. For example, the Jacobian benchmark required only 28 lines of code with the pipeline versus 964 for full CSL.
Limitations and Future Work
- Stencil Shapes: The current runtime communication library is primarily designed for star-shaped stencils. Supporting other stencil shapes (e.g., box-shaped) would require library updates.
- Hardware Routing: While the pipeline handles software-actor level code generation, future work could explore hardware routing configurations and switching updates.
- Integration with Other DSLs: The authors suggest integrating their approach with other stencil DSLs that might adopt MLIR, further broadening its applicability.
- Actor Model Exploration: The paper highlights the actor model as a consistent programming paradigm for the WSE and suggests further community exploration of this model for WSE and other CGRA-like accelerators.
- Performance Comparison Nuances: The authors acknowledge that direct performance comparisons can be challenging due to differing problem sizes and experimental setups across studies.
Summary updated