sass2mlir / Manual

CLI reference

The current sass-mlir interface: inspection, MLIR, ordered optimization, host verification, research diagnostics, and ABI plugins.

Reference

One entry point: sass-mlir

Use build/sass-mlir from a supplied source checkout, or sass-mlir if installed on your PATH. The project and runtime ABI keep the name sass2mlir. There is no sass2mlir compatibility launcher.

build/sass-mlir --help
build/sass-mlir optimize --help
build/sass-mlir research --help

The source of truth is exe/sass-mlir.cpp, alongside docs/cli.md in the source tree. Options are command-specific: --kernel belongs to optimize, and --threads is accepted by lift, verify, and scan. There is no global --arch, --fn, -q, or -o convention. --output aliases --out.

Core workflow

Inspect, lift, lower, optimize, verify

CommandInput and output
inspectList a cubin’s SM and kernel sections; also accepts a directory
liftCubin to printed MLIR; --out writes one .mlir per cubin
lowerTextual MLIR to one raw .bin per kernel section
optimizeCubin to a separate cubin using explicitly selected stages
verifyHost encoding round-trip checks, without GPU execution
passesList the transformations known to the MLIR build
build/sass-mlir inspect kernel.cubin
build/sass-mlir lift kernel.cubin --out ir --threads 1
build/sass-mlir lower ir/kernel.mlir --out bins
build/sass-mlir optimize kernel.cubin --passes uniform --out candidate.cubin
build/sass-mlir verify candidate.cubin --threads 1

lift prints MLIR to stdout for a single cubin when --out is absent. A directory input requires --out and retains relative paths. lower defaults to the current output directory and sanitizes section names for its .bin filenames. It does not create a cubin container. lift, lower, optimize, and passes require the MLIR-enabled build.

optimize defaults to kernel.optimized.cubin for a file, or <input>.optimized/ for a directory. An existing output directory receives the input filename. Input and output must differ; directory trees must not contain each other, including through symlinks. Image optimization processes files serially.

Selection

An ordered, explicit pass list

build/sass-mlir passes
build/sass-mlir optimize kernel.cubin \
  --passes uniform,fma-fuse --kernel saxpy --out candidate.cubin

--kernel matches a substring of a kernel or section name; omission selects all text sections. A filter matching nothing is an error. A matched section with no admitted rewrite still produces an output file, with zero changes reported.

Passes execute in the supplied order. Repeated names execute again, empty comma-separated fields are ignored, and whitespace remains literal: use uniform,fma-fuse, with no space after the comma. Names are checked before any stage runs. There is currently no configuration-file interface for this CLI.

StageCurrent role and contract
fma-fuseContract admitted unguarded FMUL/FADD pairs; explicit permission for fused rounding
deftzRemove FFMA flush-to-zero modifiers; a numerical-policy change
uniformMove admitted warp-uniform values to uniform registers
hgmmaConvert admitted matrix regions; each stage runs uniformization and spill-elimination prerequisites when UMOV is available
tmaAnalyze TMA address contracts; its selection alone is not a promise of a rewritten transfer
flash-attentionThe supported producer/consumer attention conversion stage; pc is its research alias

The shared driver retains one lifted MLIR module across stages and publishes once. Each resizing stage completes its branch and schedule repair before the next stage. Encoding failures or unmappable metadata refuse publication. Eligibility, execution correctness, and performance remain separate questions.

Verification

Preservation and regeneration are different checks

build/sass-mlir verify kernel.cubin --threads 1
build/sass-mlir verify kernel.cubin --psir-only --threads 1
build/sass-mlir verify kernel.cubin --mlir-only --threads 1
build/sass-mlir verify kernel.cubin --regen --threads 1

The default uses both PSIR and MLIR checks when MLIR is available. The three mode flags are mutually exclusive; --mlir-only and --regen require MLIR. A reduced build uses PSIR verification by default.

Untouched instructions can emit retained raw words. --regen tests structural regeneration and accounts for raw preservation separately from encoding success. Unsupported architectures, empty inputs, encoding-merge failures, and changed regenerated bytes are failures. Trailing section bytes are counted and preserved. An undecoded word means this decoder could not decode it; it does not mean that NVIDIA’s disassembler hid it.

To compare against the external disassembler:

build/sass-mlir scan kernel.cubin --threads 1 --eval-out eval.tsv

scan uses nvdisasm and also accepts --nvdisasm, --text-out, --bin-out, --mismatch-out, and --unknown-out; consult scan --help for output formats. It runs on the host. Neither scanner agreement nor verify establishes GPU numerical correctness or scoreboard progress.

Research

Diagnostics have an explicit prefix

build/sass-mlir research analyze kernel.cubin --defuse --liveness
build/sass-mlir research analyze kernel.cubin --reaching --uniformity
build/sass-mlir research check-hgmma kernel.cubin
build/sass-mlir research check-tma kernel.cubin
build/sass-mlir research parse-check ir/kernel.mlir

analyze reads cubins and reports the selected analyses. check-hgmma and check-tma report eligibility; they do not publish an optimized image. parse-check checks textual MLIR stability. The remaining research commands are symaddr, pc-convert, warpsplit, grow, opt, check-arch, desc-selftest, remap-selftest, nvinfo-check, and cubin-write; their fixture and experiment contracts live in the source documentation. research opt runs generic MLIR CSE/canonicalization on a text file; it is not the SASS cubin optimization driver.

The old top-level roundtrip, apply, harvest, and regalloc workflows are not this interface. Use verify for encoding checks, optimize for the shared MLIR pipeline, and ABI plugins for runtime integration.

Attention experiments

Fresh-program routes have launch contracts

The exclusive flash-attention-program, flash-attention-resynth, and flash-attention-target selections require --reference and their reviewed source/reference fixtures. They are not general replacements for arbitrary attention kernels.

build/sass-mlir optimize original.cubin --passes flash-attention-program \
  --reference fa3.cubin --kernel SOURCE_SYMBOL --out attention.mlir
build/sass-mlir research parse-check attention.mlir

flash-attention-program emits diagnostic logical-program MLIR, defaults to original.attention.mlir, and requires a .mlir output extension. This output retains publication markers and cannot be passed to lower as a runnable kernel.

flash-attention-resynth publishes a freshly lowered cubin and a .launch.json contract for the admitted fp16 D64 SM90 programs. Its current contract selects P storage from causal/noncausal mode and requires finite FP16 Q/K/V inputs and the supported typed launch adapter. Finite inputs alone do not guarantee the numerical policy: extreme-input counterexamples remain. The frozen October 14 measured program and its composite launch have bounded GPU correctness and performance evidence. That study does not validate arbitrary current builds, other fixtures, or every finite input. Follow the attention research notes for the tested scope and the source/launch binding.

Runtime integration

ABI plugins are separate from MLIR stages

build/sass-mlir plugins --plugins-dir build/passes/nop-count
build/sass-mlir plugin nop-count kernel.cubin \
  --plugins-dir build/passes/nop-count
SASS2MLIR_KERNEL=saxpy SASS2MLIR_PASS=uniform \
  build/sass-mlir intercept \
  "$PWD/build/passes/kernel-rewrite/sass2mlir-pass-kernel-rewrite.so" \
  -- ./application

plugins lists runtime shared libraries in the selected directory; the search is not recursive. plugin invokes an ABI plugin offline. Only module callbacks can supply replacement bytes, written to <input>.rewritten; instruction callbacks report changes without emitting their edited ASTs. intercept preloads the selected library; everything after -- belongs to the application. The kernel-rewrite example uses the built plugin path from the source root; replace saxpy with the desired kernel substring and ./application with your CUDA program and arguments.

These libraries serve capture and application integration. The kernel-rewrite plugin calls the same MLIR rewrite entry as optimize; FMA is not a separate plugin. passes lists MLIR transformations, while plugins lists runtime libraries. Do not build one .so per new MLIR optimization.

Runtime selectionMeaning
SASS2MLIR_KERNELRequired kernel-name substring for module rewriting.
SASS2MLIR_PASSRequired pass name or ordered comma-separated MLIR pipeline.
SASS2MLIR_MLIRCOREOptional path to the core library; by default the plugin loads libsass2mlir-mlircore.so from its own directory.

The plugin offers rewritten cubin bytes to the real CUDA loader before the application resolves and launches its kernels. Check its matched/changed/word counts alongside the interceptor’s replaced a … module or patched … bytes message. Observation-only fatbin inspection can prepare a candidate without applying it; observation-only … loading the original confirms that boundary. Missing selection or a refused rewrite also retains the original image. This generic module-rewrite route preserves the application’s launch ABI; flash-attention-resynth explicitly requires its separate typed adapter. See runtime optimization in the quickstart for the complete flow and report checks.

Next: the pass-writing manual.