Memory-Constrained Graph Scheduling
A C++ scheduler for the Google MLSys 2026 contest (Track A) that fuses and tiles ML accelerator graphs to cut latency without overflowing on-chip SRAM.
20265 min
Given a computation DAG of MatMul and pointwise ops, produce an execution schedule that minimizes total latency while never exceeding fast-memory (SRAM) capacity. The solver is written in C++ and implements greedy fusion with cycle detection, granularity search, zig-zag tile ordering and tensor retention.
#The Problem
An accelerator can only compute on data that sits in its fast on-chip memory, and that memory is far smaller than the tensors in a real model. Everything else lives in slow memory (HBM), and moving it costs bandwidth. A scheduler decides how data moves between the two so the whole graph finishes as fast as possible.
The contest gives you a DAG of MatMul and pointwise ops and asks for a schedule with the lowest total latency that never exceeds fast-memory capacity. You choose how ops are grouped into subgraphs, how big each tile is, the order tiles run in, and which tensors stay resident between subgraphs.
Five benchmark graphs were public, from 5 to 103 ops. Teams are ranked on twenty withheld graphs: on each one, a team scores the best submitted latency divided by its own, and the points are summed.
#The Latency Model
Each tile costs whichever is slower, its compute or its memory traffic:
A schedule's latency is the sum of that maximum over every tile in every subgraph, so the job is to minimise that sum. Memory savings only count on tiles where memory is the larger term; on a compute-bound tile they change nothing.
#The Levers
#Fusion
Putting a producer and its consumer in the same subgraph makes the tensor between them ephemeral, so it never makes the round trip through HBM. The catch is that every op in a subgraph shares one tile granularity, and the merged working set still has to fit. On the larger benchmarks the big weight tensors are what stop fusion: the merged working sets exceed fast memory.
#Granularity [w, h, k]
w and h set the output tile, and k sets how much of a MatMul's reduction dimension is processed per step. Bigger tiles mean fewer tiles and fewer repeated loads, but a bigger working set. A small k keeps the accumulator resident and streams thin slices of the inputs, which lets chained MatMuls fuse when a full-K working set would not fit. It changes the working set, not the total bytes moved per tile.
#Traversal order
For a MatMul tiled into a grid, each tile needs a strip of A (fixed by its row) and a strip of B (fixed by its column). Walking along a row reuses the A strip from one tile to the next. Raster order then jumps back to the start of the next row and reloads both strips. Zig-zag reverses direction on each row, so the first tile of the new row is in the same column as the last tile of the old one and the B strip carries over.
That saves one strip load per row turn, so the gain depends on grid shape. On one subgraph of benchmark 9, a grid two tiles wide and four rows tall, reusing strips along rows and across turns cut that subgraph's latency by 40% compared with loading both strips for every tile. On a wide grid the turns are a small fraction of the tiles. It did nothing on benchmarks 13 and 17: their subgraphs were either a single tile or compute-bound.
#Retention and recomputation
When a tensor leaves one subgraph and feeds another, there are three options. Spill it to HBM and pay bandwidth twice. Keep it resident in fast memory and pay capacity. Or recompute it inside the consuming subgraph and pay compute instead of bandwidth.
Retention rarely fit. Most intermediates on the benchmarks are close to, or larger than, fast-memory capacity, so there is no room to hold one next to the next subgraph's working set. We also worked through recomputation for the skip connections in benchmark 9: recomputing the skip tensor costs compute on every tile, while spilling it costs one write and one read in total, so spilling won and recomputation stayed out of the solver.
#The Solver
The solver is C++. It starts with every op in its own subgraph. Fusion is a greedy hill-climb: score every pair of connected subgraphs by how much a merge lowers latency, apply the best merge, and repeat until no merge helps. Before any merge it runs a BFS to check that merging would not create a cycle in the subgraph DAG, since an indirect path between the two would make the schedule impossible to order.
A second pass then applies merges that leave latency unchanged but make more tensors ephemeral. Under this model that changes no scores on compute-bound graphs, but it removes HBM traffic that a more detailed cost model might still charge for. On benchmark 17 it folded each five-MatMul attention chain into one subgraph and took the graph from 73 subgraphs to 17.
For each subgraph, granularity search tries power-of-two values of w, h and k, discards any whose working set exceeds capacity, and keeps the lowest-latency one, preferring larger tiles on ties. Every MatMul subgraph with more than one tile gets a zig-zag order. Finally, for each pair of consecutive subgraphs, a tensor passed from the first to the second is retained if it fits in both working sets.
The organizers' evaluator wasn't runnable standalone for us, so we wrote our own checker. It verifies that every op is scheduled exactly once, subgraphs are in topological order, every tile's working set fits, and the reported latencies match a recomputation. We also hand-checked the solver against worked example 1B in the problem statement.
#Results
These are our own latencies from that checker, compared with running every op unfused. The official score is relative to other teams on withheld graphs, so these numbers are not a ranking.
| Benchmark | Ops | Subgraphs | Speedup over unfused |
|---|---|---|---|
| 1 | 5 | 2 | 2.30× |
| 5 | 19 | 7 | 1.57× |
| 9 | 32 | 24 | 1.34× |
| 13 | 63 | 21 | 1.03× |
| 17 | 103 | 17 | 1.02× |
The gains shrink as the graphs grow, and for different reasons. Benchmark 9 is memory-bound but its skip tensors are consumed in two subgraphs, so they can't become ephemeral, and fusing the whole block makes the large down-projection weights reload on every tile. Benchmark 13 is capacity-bound: its best tiling leaves about 9K of 600K fast memory free, and both larger k and narrower tiles were slower or ran out of memory. Benchmark 17 is compute-bound by roughly 30 to 1, so nothing that saves memory moves its latency.