Home · ASPLOS 2023 · Compilers & Programming Languages

The Sparse Abstract Machine

Olivia Hsu, Maxwell Strange, Ritvik Sharma, Jaeyeon Won, Kunle Olukotun, Joel S. Emer and 2 others

Conference
ASPLOS 2023
Published
2023
Pages
710-726
Citations
38

Sparse tensor algebra accelerators were point solutions — one expression, one loop order, baked into silicon — and general expressions had to shatter into matrix-multiply chains with order-of-magnitude asymptotic penalties; SAM supplies the missing LLVM-like layer, flattening sparse tensors into streams with hierarchical control tokens and defining nine composable dataflow blocks that express EVERY tensor-algebra expression in any iteration order with fusion — plus a compiler (Custard) from index notation down, and the demonstration that prior accelerators are just particular SAM graphs.

The argument in one glance

  1. Problem

    Sparse tensor algebra meets hardware one expression at a time

    Sparse tensor algebra — Einsum-style expressions over tensors stored without their zeros — underlies scientific computing, graph analytics, and ML. Streaming dataflow accelerators promise huge efficiency for it, and a wave of designs appeared: SIGMA, GAMMA, OuterSPACE, and more. But nearly all are FIXED-FUNCTION: one expression (usually sparse matrix multiply), one iteration order, one format, hardened into silicon. Any other expression must be factorized into a chain of matrix multiplies with transposes and temporaries.

  2. What people did

    Programmable sparse hardware, and compilers for everything else

    Three programmable designs (the SPU, ExTensor, Capstan) showed that reconfigurable sparse dataflow hardware is buildable. Meanwhile, on the software side, the TACO compiler already handles ALL of sparse tensor algebra — any expression, any format, any loop order, fused — for CPUs, GPUs, and clusters, from a three-part input: tensor index notation, a format language, and a scheduling language.

  3. Why it fell short

    No interface exists between the compiler world and the dataflow world

    The programmable accelerators support only fragments of the domain. And TACO cannot target them: its lowering fundamentally embeds sparse co-iteration into von Neumann control flow — while loops, if statements, indirect index arithmetic — which dataflow architectures REMOVE to gain their efficiency. Factorization, the workaround, is asymptotically poisonous for sparse data: an unfused expression's cost can scale with the full tensor volume where the fused version scales with nonzeros — often an order of magnitude or worse. Every accelerator therefore needs its own bespoke software story, and none can be compared or composed.

  4. This paper's idea

    An LLVM for sparse dataflow

    The Sparse Abstract Machine (SAM) defines the missing interface: sparse tensors modeled as fibertrees and flattened into streams carrying hierarchical control tokens, plus nine composable dataflow block types — level scanners, intersecters, unioners, repeaters, ALUs, reducers, coordinate droppers, level writers, arrays — that together express EVERY sparse tensor algebra expression, in any iteration order, fused or factorized, tiled and parallelized. Custard compiles TACO's three input languages into SAM graphs; a generated simulator executes them; and prior accelerators like OuterSPACE fall out as particular SAM graphs. Compiler and hardware can now evolve independently against one contract.

Why this problem is worth solving

Einsum-style expressions over tensors (generalized matrices) where some operands are stored compressed, omitting zeros — e.g., matrix multiply X_ij = Σ_k B_ik·C_kj, or SDDMM X_ij = Σ_k B_ij·C_ik·D_jk. A computational language with a long mathematical pedigree that subsumes linear algebra and appears across science, graph analytics, and ML
is one of computing’s most rewarding acceleration targets — and its acceleration story had bifurcated into two worlds that couldn’t talk. Hardware people built
spatial architectures (fixed-function ASICs or coarse-grained reconfigurable arrays) where computation is laid out as a graph of units connected by streams, gaining pipelining, locality, and parallelism precisely by REMOVING general-purpose control flow — no while loops, no branches, no arbitrary indirection
that were fast and narrow; compiler people built systems like TACO that were completely general and could not reach the new hardware at all.

The paper’s framing borrows the most successful idea in compiler history: what LLVM did for instruction-based processors — a shared abstract machine that lets front-ends and back-ends evolve independently — sparse dataflow needs too. Without it, every accelerator is a silo: its capabilities can’t be stated precisely, its performance can’t be compared like-for-like, its software is a hand-built library, and general expressions pay the factorization tax (unfused sparse computation can be asymptotically worse — cost scaling with dense volume instead of nonzero count). An abstract machine answers all four at once: it is the capability statement, the comparison substrate, the compiler target, and the fused-execution model. The ambition is infrastructural rather than a single speedup number — which is exactly what makes this paper’s influence compound.

What people did before, and where it broke

  • Fixed-function point solutions. Each hardens one expression and one loop order: SIGMA does inner-product (i→j→k) sparse matrix multiply — clean output, but it enumerates all (i,j) pairs before intersecting at k, asymptotically poor; GAMMA does Gustavson’s i→k→j linear-combination-of-rows, better asymptotics at the cost of merge hardware; OuterSPACE does outer-product k→i→j with a whole-matrix merge phase. Each choice is a legitimate point in a tradeoff space — but silicon freezes the choice.
  • Factorization as the escape hatch. Arbitrary tensor contractions reduce to matmul chains via transposes, tensor-to-matrix conversions, and temporaries. For sparse data this is not a minor tax: sequences of matrix multiplies run an order of magnitude slower than bespoke fused contractions, and unfused execution can change the complexity class — runtime growing with tensor volume rather than nonzero count.
  • Programmable sparse hardware without full generality. The SPU streams arrays through a CGRA with intersection hardware; ExTensor hierarchically intersects with skipping; Capstan adds sparse support to an RDA. All influenced SAM’s primitives — none supports the full feature set general tensor algebra needs (arbitrary traversal and co-traversal, broadcast repetition, reductions, assignment, compressed formats, arbitrary iteration order, fusion).
  • TACO’s von Neumann lock-in. The compiler with full generality lowers co-iteration into while loops, ifs, and indirect accesses — constructs dataflow hardware lacks by design. Converting that control flow back into dataflow would require heroic synthesis; SAM instead defines a different lowering target where sparse iteration is first-class.

What SAM is

The Sparse Abstract Machine, bottom-up

  1. Data model: fibertrees

    A sparse tensor is a coordinate tree — one level per dimension, where each coordinate owns a fiber (list) of child coordinates, and only nonzero subtrees appear. The fibertree abstracts AWAY the storage format: compressed (CSR-like segment/coordinate arrays), uncompressed (dense counting), bitvectors, linked lists — all are level implementations behind one interface.

  2. Streams with hierarchical control tokens new

    To move tensors on wires, SAM flattens fibertrees into streams: values/coordinates punctuated by stop tokens whose LEVEL encodes tree structure (S0 ends a fiber, S1 ends a fiber-of-fibers…) and a done token D ends the tensor. One flat stream thus carries arbitrary-dimensional sparsity — no pointers, no random access — which is exactly what streaming hardware can transport.

  3. Nine composable block types new

    Level scanners walk one tensor dimension, chaining via reference streams to traverse multidimensional tensors. Intersecters (for multiply — a·0 = 0) and unioners (for add — a+0 = a) merge coordinate streams from multiple tensors. Repeaters broadcast one operand across another's dimension. ALUs multiply/add values; reducers sum along a dimension. Coordinate droppers discard coordinates whose results vanished; level writers build the output tensor level by level; arrays hold data in memory.

  4. Optimization extensions new

    Locators replace stream co-iteration with direct lookup (leader-follower intersection), enabling coordinate skipping ("galloping") with feedback from intersecters to scanners; bitvector levels trade coordinate lists for bit manipulation; tiling splits fibertree levels so a tile-sequencing SAM graph feeds a computation SAM graph within finite memories; parallelization is stream vectorization (wire buses) plus graph duplication.

  5. Custard: the compiler down to SAM new

    Reuses TACO's three front-end languages (index notation, formats, schedules) and its concrete-index-notation IR, then a NEW lowerer places blocks mechanically: a level scanner per (tensor, index variable), a repeater where a tensor lacks an index variable, an intersecter or unioner where paths meet, then the compute tree, then output construction with droppers as needed.

  6. A generated simulator — and prior chips as graphs new

    SAM graphs bind automatically to a cycle-approximate streaming simulator, enabling design-space exploration; and prior accelerators are expressible as particular SAM graphs — OuterSPACE's two-phase outer-product algorithm, for instance, is a SAM graph with a linked-list level writer and a separate merge graph.

From Stanford, MIT, and NVIDIA-adjacent collaborators (ASPLOS 2023) — authors span TACO (Kjølstad), fibertrees (Emer), and the Stanford AHA reconfigurable-hardware effort (Horowitz, Olukotun), whose subsequent silicon builds on these ideas. Open-source.

The idea

Flatten the tree into a stream, and sparsity becomes transportable. Dataflow hardware moves streams, not data structures — so SAM’s foundational move is a wire encoding of multidimensional sparsity: fibertrees serialized with hierarchical stop tokens, where the token’s level says how many nesting levels just ended (S0: this fiber; S1: the fiber of fibers; D: the whole tensor). This single idea decouples everything downstream: blocks operate on flat streams with local rules (“on S0, emit accumulated sum”), formats become interchangeable level implementations behind the scanner interface, and no block ever needs random access or a pointer. It is the sparse-streaming analog of what serialized IRs did for compilers.

Sparse iteration is algebra, so co-iteration is set algebra. The reason sparse code generation breeds while-loops is co-iteration: walking two compressed tensors in lockstep, advancing whichever lags. SAM observes that tensor algebra only ever needs two co-iteration semantics — intersection (multiplying, because a·0 = 0 lets you skip mismatches) and union (adding, because a+0 = a means nothing is skipped) — and freezes them into two block types with identical interfaces. Together with repeaters (broadcast), reducers (summation), and droppers (output compression), the messy control flow of sparse loops becomes a wiring diagram. The ablation over 23,794 real user algorithms from the TACO website shows this block set is minimal: remove any primitive and part of the domain becomes inexpressible.

One machine, every algorithm — so the tradeoffs finally become visible. Because SAM separates expression from schedule from format, the design points that used to be different chips become different graphs over the same blocks: all six loop orders of sparse matrix multiply (SIGMA’s, GAMMA’s, and OuterSPACE’s among them), fused versus factorized SDDMM, skip-enabled versus streaming intersection, bitvectors versus coordinate lists. The paper’s evaluation exploits exactly this: simulate the whole space, observe that k-first orders beat inner-product by an order of magnitude, that fusion’s advantage grows with sparsity, that locating wins when compute is modest — and conclude, with evidence, what programmable sparse hardware must therefore support. The abstract machine is simultaneously the argument for building it.

Gustavson’s SpMM as a SAM graph

X_ij = Σ_k B_ik·C_kj, linear-combination-of-rows (i→k→j), on DCSR matrices

Fibertree = per-dimension coordinate tree. Stop token S_n = end of a level-n structure; D = end of tensor. Scanner = walks one dimension's fibers; reference streams chain scanners. DCSR = doubly-compressed sparse row. This is the paper's running example (its Figure 4).

Step 1 of 7

The schedule picks the wiring

The expression is fixed; the SCHEDULE (iteration order i→k→j, formats, fusion) determines the graph. Gustavson's order intersects at k early — before any repetition — which is why it asymptotically crushes the inner-product order that enumerates all (i,j) pairs first.

same blocks, different wiring = SIGMA, GAMMA, or OuterSPACE
six ijk permutations; k-position dictates asymptotics

Why it works

  • Dataflow hardware transports streams, not data structures → fibertrees flattened with hierarchical stop tokens carry arbitrary-dimensional sparsity over plain wires → every block needs only local, token-triggered rules, and no general control flow is ever reintroduced.
  • Tensor algebra’s identities (a·0 = 0, a+0 = a) mean co-iteration only ever needs intersection and union → two merge blocks with fixed interfaces replace the while-loop/if jungles TACO generates → the domain’s irregularity is contained in nine primitive types, shown minimal by ablation over 23,794 real algorithms.
  • Scanner and writer interfaces are format-agnostic → compressed, dense, bitvector, and linked-list levels swap behind the same contract → algorithms and formats decouple, and one graph serves many storage choices.
  • Expression, schedule, and format are independent inputs → all six SpMM dataflows, fused and factorized SDDMM, and skipping/ bitvector/tiling variants are graphs over the same blocks → the design space becomes searchable by simulation instead of by fabricating chips, and the case for programmable hardware (orders must vary: k-first wins by 10× here, inner-product wins memory elsewhere) is made with data.
  • A stable abstract machine between compiler and hardware → Custard lowers mechanically (scanners from tensor paths, merges where paths meet, repeaters for missing variables) while implementations optimize below the interface → the LLVM dynamic: both sides evolve without renegotiating the contract.

What it costs

  • An abstract machine, not a chip. Evaluation runs on a cycle-approximate simulator; no silicon performance, area, or energy numbers exist in this paper. SAM’s bet is infrastructural — the payoff arrives when hardware implementations and compilers adopt the interface (as the authors’ subsequent CGRA silicon did).
  • Automatic binding to existing accelerators is future work. Custard emits SAM graphs; mapping those onto SPU, ExTensor, or Capstan configurations remains manual.
  • Pre-tiled tensors assumed. Like ExTensor and Capstan, SAM assumes tensors arrive tiled to fit accelerator memories; dynamic re-splitting of compressed structures requires a full scan and sits outside the streaming model’s comfort zone.
  • Tensor algebra, not all of sparse computing. The domain is Einsum-style expressions; iterative solvers’ control flow, data-dependent convergence, and non-algebraic kernels live outside the machine.
  • Streams serialize. The model’s simplicity comes from flat streams with token punctuation; exploiting reordering or out-of-order merging beyond what vectorization and graph duplication give requires extensions.

The evaluation

The evaluation matches the artifact: not one speedup number but four demonstrations of generality and analytical power. (1) Necessity: over the TACO website’s 23,794 user-compiled algorithms (3,839 distinct), removing any SAM primitive renders part of the domain inexpressible. (2) Tradeoff exploration: simulating all six SpMM dataflows shows inner-product orders losing by ≥10× to k-first orders; fused SDDMM beats factorized by the predicted asymptotic margins (nnz·K vs I·J·K); skipping, bitvectors, and splitting each win on the data patterns theory predicts. (3) Finite memory: tiled SAM graphs sequence tiles through buffer hierarchies, exposing memory-configuration tradeoffs. (4) Hardware representation: OuterSPACE’s two-phase outer-product design — multiply phase, linked-list intermediate, merge phase — is drawn as a SAM graph, with SPU, ExTensor, and Capstan discussed as further instances.

Three generations of sparse tensor algebra acceleration

PropertyFixed-function accelerators (SIGMA, GAMMA, OuterSPACE)Programmable sparse hardware (SPU, ExTensor, Capstan)SAM + Custard
Expression coverage
Iteration orders & algorithmsConfigurable within each design's idiom
FormatsFixed per design (e.g., DCSR for OuterSPACE, plus a bespoke linked-list intermediate)Design-specific
Compiler storyExpert-written libraries per chip
Role in the ecosystemPoint solutions — instructive, incomparableEvidence that programmable sparse dataflow hardware is feasible
Evaluation via a cycle-approximate streaming simulator auto-generated from SAM graphs (Python), with Custard (C++, TACO front-end) producing the graphs. Necessity ablation over 23,794 TACO-website algorithms; dataflow study on 95%-sparse random matrices (I=J=250, K=100); fusion study on ijk-SDDMM sweeping K∈{1,10,100}; iteration-acceleration study on urandom/runs/blocks synthetic vectors; OuterSPACE reproduced as a SAM graph including its linked-list intermediate and merge phase.Underlined values explain themselves when clicked.

Check yourself

Check your understanding

  1. 1. Fixed-function accelerators compute general tensor expressions by factorizing them into sequences of matrix multiplies. Predict why this is far more damaging for SPARSE tensor algebra than for dense.

  2. 2. SAM sends multidimensional sparse tensors through FLAT streams punctuated by "stop tokens" of different levels (S0, S1, …, D). What problem does this encoding solve, and how?

  3. 3. TACO already compiles ALL of sparse tensor algebra. Why can't it target dataflow accelerators, and what does SAM change about the lowering rather than the front-end?

  4. 4. SAM claims to be "LLVM for sparse dataflow." Which THREE pieces of evidence in the paper support the analogy beyond rhetoric?

Sources

Related papers on Compilers & Programming Languages

See all 162 →