1. Design the IR and pass pipeline for a compiler targeting a spatial dataflow accelerator.
The full question
Design the IR and pass pipeline for a compiler targeting a spatial dataflow accelerator. Where does the memory-residency decision live, and why?
Model answer
Three levels of abstraction, mirroring what MLIR is built for and what the archived Groq compiler postings describe when they ask for LLVM plus MLIR plus ONNX experience.
High level: the model graph, framework-agnostic, ingested from ONNX or a framework exporter. Shapes and dtypes known, no hardware notion. Passes here are the classic graph rewrites: constant folding, operator fusion, layout canonicalisation, dead subgraph elimination, quantization annotation.
Mid level: a tensor dialect that knows the machine has functional slices (matrix, vector, shift/permute, memory, control) but not yet exact cycles. This is where you tile operations to slice geometry, decide parallelism strategy across chips, and materialise the communication operations. Crucially this is also where memory residency is decided, and it must be here rather than at the back end, because on a chip with no DRAM, residency is not a spill decision made after scheduling, it is a feasibility constraint that determines whether a partitioning is legal at all. If you defer it, the back end discovers infeasibility after the expensive work is done and has no legal fallback.
Low level: per-slice instruction sequences bound to exact cycles, plus a routing plan reserving links per cycle. Passes here are software pipelining, latency-exact bundling, deskew insertion for cross-chip flows, and verification against a bit-accurate functional simulator.
The pipeline should be resumable and diagnosable: when the mid level fails to find a legal partitioning, the useful output is which tensor overflowed which chip's budget, not a generic scheduling error. Compile times on spatial machines are long, so incremental compilation and a good cache keyed on subgraph plus target config are engineering requirements, not luxuries.
Worth sketching. The three-level lowering and where feasibility is decided.
flowchart TD
A["ONNX or framework graph"] --> B["Graph IR:<br/>fuse, fold, canonicalise"]
B --> C["Tensor IR:<br/>tile to slices, shard, place"]
C --> D{"Fits in SRAM?"}
D -->|"no"| C
D -->|"yes"| E["Scheduled IR:<br/>cycle-exact, routed"]
E --> F["Verify vs<br/>functional simulator"]Follow-ups: How would you represent chip-to-chip communication in the mid-level dialect? What is your strategy when compile time for a large model reaches hours?