sass2mlir / Manual

Fusion & CUDA Graphs

What the current fusion machinery checks, where geometry stops being proof, and why host launch contracts matter.

Application boundary

A kernel boundary carries more than launch overhead

Fusion can remove an intermediate memory round trip or a launch. It also removes a boundary that separated register ownership, launch geometry, and memory visibility. A useful compiler must establish the replacement for each of those properties before publishing executable code.

The current tree has a runtime fuse plugin under passes/fuse/, separate from the ordinary sass-mlir optimize --passes ... MLIR stages. Its source includes pair analysis, image synthesis, graph inspection, and graph substitution. These routes have different admission and host-integration requirements; their presence is not a general fusion guarantee or a shared performance result.

Pair analysis

An elementwise bridge needs the same element

The pair checker first requires matching SM targets and decodable bodies. Its elementwise path checks the producer’s output address against the consumer’s input address, including their thread-to-element mapping. Unsupported producer barriers, shared-memory cooperation, and structural control flow block this simple bridge.

Matching symbolic parameter offsets is not enough to establish that two runtime arguments name the same buffer. The launch side must bind the parameters and geometry required by the candidate. If synthesis combines parameter reads from both bodies, the host must supply that combined parameter layout.

The write-through pair path retains producer stores and replaces the selected consumer load with a register transfer. It still needs register renumbering, encoding checks, supported branch layout, and consistent cubin metadata. Image rewriting alone cannot arrange the corresponding producer/consumer launches.

Landmarks: passes/fuse/contracts.cpp, pair_emit.cpp, image.cpp, and intercept.cpp.

Recompute

Address geometry is a diagnostic

The recompute diagnostic compares projected launch-root coefficients and a modeled constant-stride induction axis. Within the producer, selected input loads must agree with the store’s roots and nonzero induction identity. Across separately lifted functions, the first consumer projection is compared after renaming that identity.

It refuses unsupported nonlinear expressions, root-dependent strides, multiple uncancelled induction axes, and unproved operand semantics. Projection identities belong to an immutable function epoch and cannot be reused after edits.

Landmarks: contracts/recompute.cpp and docs/contracts/recompute.md.

Graph substitution

Publish the device and host changes together

Graph substitution is a launch-side transformation. The plugin matches a walked stage list at graph instantiation, builds a replacement, and associates it with that execution object. The replacement must retain the original execution’s parameter bindings, required ordering, resource limits, and lifetime rules. Unsupported stages or missing inputs require refusal.

Removing a store/load boundary can also remove a rounding point. Reusing memory or registers can change asynchronous ownership. A smaller node count therefore says nothing by itself about numerical correctness, progress, occupancy, or speed. Validate the admitted application and launch contract before timing it.

The FlashAttention study reports native and CUDA Graph submission for the reconstructed attention program. Those measurements are not evidence that the general fusion plugin is faster or correct for other workloads.

Read the compiler contracts before extending fusion, and the CLI reference for the boundary between MLIR optimization stages and runtime plugins.