sass2mlir / NVIDIA GPU binary compiler

Recover computation.
Rebuild the kernel.

A shipped GPU binary fixes its layout, registers, and schedule. sass2mlir recovers the computation, transforms it in MLIR, and emits a new execution structure.

The central case study turns admitted FlashAttention-2 binaries into fresh Hopper programs, using policies informed by FlashAttention-3 machine code.

1.220×aggregate throughput / FA2
97.32%of native FA3 throughput
108workload cells on H100 NVL
32 / 108cells still slower than FA2

October 14 research snapshot · geometric means of complete-invocation ratios · two admitted FP16 source programs. Read the measurement scope ↓

01 / The contribution

From instructions back to a program.

Disassembly shows what a kernel does instruction by instruction. A useful binary compiler also needs to recover which values belong together, how they move through control flow, and when asynchronous work has finished. Those connections make it possible to change the program’s execution structure.

sass2mlir connects a physical machine representation, PepesilviaIR (PSIR), to a hybrid SSA/raw MLIR dialect. PSIR owns instruction words, physical effects, and emission. MLIR exposes computation for recovery and transformation. The FlashAttention path raises source equations into vector, arithmetic, and math IR before choosing a new tile layout and generating the device program.

The sass-mlir executable supports both offline cubin optimization and runtime application interception. sass-mlir intercept preloads a plugin into an existing CUDA program; the kernel-rewrite plugin applies selected MLIR passes as supported modules load, then supplies rewritten images to CUDA. Follow the runtime quickstart to select kernels, choose passes and confirm the rewrite report.

Source computationCompiler reconstruction
  1. 01

    Lift the binary

    SASS → PSIR → MLIR
    Recover CFG, SSA, and physical operands.

  2. 02

    Recover equations

    Follow actual definitions.
    Raise softmax and matrix dependencies.

  3. 03

    Build a new program

    Retile, construct roles,
    overlap transfers and computation.

  4. 04

    Allocate & emit

    Check completion and allocation.
    Emit fresh SASS + a launch contract.

FA3 observations inform the transformation policies. The compiler applies them to computation recovered from FA2; native FA3 is a separate performance comparator. The current CLI requires a pinned FA3 ABI container; normalization forms are constructed independently and the selected body is replaced completely.

02 / What the compiler must preserve

The contracts behind every rewrite.

The hardest lessons came from candidates that looked valid but were wrong: a guarded write lost its old value; an edited instruction still emitted its old raw word; a legal issue code failed numerically; an address fell within bounds but outside the actual written footprint. The attention reconstruction added concrete ABI obligations too: complete matrix-register spans and an initialized, reserved R1 across all 512 threads. These lessons define the compiler’s obligations.

  1. Meaning on every path

    Preserve SSA bindings, predicates, old destinations, and implicit effects. Make any rounding change an explicit policy.

  2. Ownership through completion

    Keep registers and memory owned until their physical readers and asynchronous operations finish. SSA last-use and an empty scoreboard are insufficient.

  3. Honest encoding and coverage

    Regenerate edited words without stale raw authority. Check the exact operand form and every required memory cell; incomplete evidence causes refusal.

  4. One consistent published artifact

    Repair branches and metadata with layout changes. Bind the device program to its launch contract and keep the original intact on failure.

Some footprint, swizzle, and geometry predicates have Isabelle model proofs. Lifting, C++ transcription, hardware behavior, synchronization, and numerical equivalence remain separate obligations. Each pass must explain which evidence it has and where that evidence stops.

03 / The representation

SSA reasoning. Physical obligations.

MLIR: what the computation means

Block arguments represent SSA joins. Structured operands connect values to physical registers. A guarded definition also reads the destination’s old value: out = guard ? new : old. Transformations must preserve that dependency.

PSIR: how the machine executes it

Register tuples, encoder-owned bit masks, instruction layout, and pending accesses stay explicit. Allocation and scheduling share physical completion tracking; ordinary SSA last-use cannot release a register still read by an asynchronous operation.

Untouched instructions retain authoritative 128-bit raw words and emit verbatim. Edited instructions give up that authority and regenerate through the common PSIR emitter. A pass must account for encoding ownership, scheduling, displaced branches, and container metadata. Opaque words can be preserved; preservation does not establish that they can be transformed.

The shared per-SM database covers 22 disassembler targets, from sm_70 through sm_121a, with 245 distinct mnemonic heads. The active dialect represents instructions through the shared sass.inst carrier, alongside sass.func and sass.exit. Table coverage is separate from the narrower architecture and operand requirements of each transformation.

04 / Case study

FlashAttention-2 → a fresh Hopper kernel.

The compiler follows the admitted FA2 binary’s matrix endpoints and online maximum, exponentiation, denominator, probability packing and output rescaling through their SSA definitions. Recovery retains instruction witnesses and refuses changed or unaccounted-for arithmetic. Mask, iteration and epilogue facts additionally depend on the bounded reviewed program profile.

The recovered equations are instantiated in a new M192 layout with 512 threads: one producer and three math warpgroups. Causal attention uses N128 tiles and a dynamic work queue; noncausal attention uses N192 tiles and static assignment. The compiler constructs transfers, HGMMA operations, scalar work, output stores, and the ownership protocols between them.

A complete reconstruction

The measured programs contain 2,234 causal and 1,929 noncausal instruction words, all freshly regenerated. Publication binds the cubin to a typed launch sidecar, including its parameter layout, block size, and shared-memory requirements.

This path requires a supported host adapter and launch contract. Its scope is two admitted source programs with finite, non-aliasing dense FP16 buffers, H=8, D=64, equal Q/K lengths, scale 1/8, no dropout, B1/2/4 and power-of-two S128–32,768. The current reference supplies the pinned ABI container; normalization forms are constructed independently and the selected executable body is rebuilt from source-derived IR. Retiling changes rounding, so acceptance uses an explicit numerical policy and execution tests.

05 / Scheduling research

A legal encoding still needs a correct schedule.

Scheduling combines form-specific encodings, dependency-bearing native schedules, and execution counterexamples. The deduplicated CUDA 12.5/13.0 library census contains 255,370,688 16-byte slots in 297,692 distinct bodies across 13 sampled architectures. These are static code observations; dependency extraction admits a smaller scalar subset.

The control field named yield participates in a joint issue encoding with form-dependent group, batch, and reuse information. Editing it independently can produce an unsupported combination. An empty scoreboard also cannot establish fixed-pipeline readiness or discharge HGMMA and TMA completion obligations.

The implementation checks physical RAW, WAR, and WAW dependencies, register holds, scoreboard slots, and separate asynchronous protocols. Its experimental Hopper scalar policy admits exact forms in bounded windows. Unsupported contexts retain their controls or reject the edit. Numerical execution remains a required check even when the model accepts a schedule.

This investigation builds on redplait’s reverse-engineering work, including the denvdis machine descriptions and his SASS assembler and parser articles. They informed the joint-field interpretation and exposed preservation and form-selection gaps in our implementation.

06 / Evaluation

The gains, and the remaining gap.

The accepted October 14 study compares FA2, a fixed generated program per mask, and native single-split FA3 on an H100 NVL. It crosses B=1/2/4, H=8, D=64, nine sequence lengths from 128 to 32,768, both masks, and native versus CUDA Graph submission: 108 workload cells. Each cell averages three process means, each measured after 128 warmups and 1,024 launches.

Geometric means over 27 cells per row. Above 1× favors the generated program.
SubmissionMaskThroughput / FA2FA3 throughput retainedFaster than FA2
NativeCausal1.322×96.68%21 / 27
NativeNoncausal1.122×97.75%17 / 27
CUDA GraphCausal1.334×97.07%21 / 27
CUDA GraphNoncausal1.120×97.78%17 / 27

Download all 108 measured timings, including the actual FA2, generated-program and FA3 elapsed times and all three process means. The CSV records milliseconds.

Across the 108 cell ratios, aggregate throughput is 1.220× FA2 and 97.32% of FA3. 32 cells remain slower than FA2; 90 remain slower than FA3. Long sequences usually benefit more; short sequences expose substantial regressions.

Inspect the native-submission workload matrix
FA2 latency / generated latency. H=8, D=64. Values below 1× are regressions.
SequenceNoncausal B1B2B4Causal B1B2B4
1280.761×0.721×0.703×0.820×0.794×0.810×
2560.773×0.777×0.769×0.827×0.855×0.824×
5120.987×0.970×0.970×1.024×1.017×1.011×
1,0241.074×1.068×0.873×1.130×1.125×1.392×
2,0481.251×1.044×1.388×1.294×1.912×1.820×
4,0961.074×1.378×1.337×2.160×1.848×1.575×
8,1921.406×1.412×1.505×1.926×1.690×1.621×
16,3841.430×1.517×1.558×1.743×1.673×1.629×
32,7681.533×1.574×1.559×1.705×1.670×1.633×

What these numbers measure

Complete invocations include required scheduler resets and may include CPU enqueue gaps. Parameters and TMA descriptors are cached for the generated program; native FA3 prepares them per native invocation. Loading, allocation, and graph instantiation are outside timing. Native and graph sessions are reported separately; the headline averages cell ratios rather than pooling their times.

The frozen measured cohort passes ordinary, memcheck, and synccheck gates, with output/LSE checks against both references and FP64 attention checks. Large random cases sample FP64 rows; analytic tile inputs check all rows. Finite extreme-input counterexamples limit numerical acceptance to the tested inputs. Unlocked clocks and sampled device monitoring limit timing interpretation. These results belong to that frozen revision and are complete-invocation comparisons. Full Nsight profiling remains unaccepted: a causal application replay raised an illegal instruction, with the cause unresolved.

07 / The manual

Build a pass you can justify.

A good pass states what it accepts, what it changes, and which checks can reject it. The tutorial follows the existing FMA contraction pass from matching through publication: SSA and physical-effect checks, an explicit fused-rounding policy, slot-preserving replacement, and independent encoding checks. It then shows where to integrate a pass and how to check the contract it changes.

  1. 01
    Inspect, lift, and verify a cubin

    Get a concrete kernel into the current toolchain and establish an identity baseline.

  2. 02
    Learn the contracts before changing the program

    Connect meaning, physical completion, encoding ownership, coverage, layout, and launch obligations.

  3. 03
    Write and validate your first pass

    Trace the real FMA implementation, define admission, handle raw authority, and check the affected contract.

  4. 04
    Scale up to structural reconstruction

    Follow source recovery, semantic transformation, allocation, scheduling, and launch publication.

Project status

Research compiler. Explicit boundaries.

The active implementation includes shared PSIR emission, the MLIR transformation pipeline, analysis and constrained allocation, container reconstruction, runtime integration, and the source-derived attention path. Separate historical host checks exercise container identity, metadata serialization, self-patching, and supported resizing across 38 cubin inputs; those checks do not establish GPU correctness.

The method is described in the manuscript SASS2MLIR: Transforming FlashAttention Binaries through Recovered Computation and Scheduling, currently in preparation. The source is AGPL-3.0-or-later; public source and paper links will be added when available. The manual reflects the October implementation. Broader program admission, a complete joint scheduling codec, and general hardware semantic equivalence remain outside the demonstrated results.