Skip to content

Locked exports: an export without a GPU

An export learns some facts from the device it runs on, and everything else is a function of the sources, the declarations and the toolchain. A lock records those facts once, on a GPU of the target device; a locked export then writes the same files byte for byte on a machine with no GPU, no CUDA driver and no torch, such as a CI runner or an image build, and fails when a file is not the lock's. The lock also says, for every operator, which implementation runs and what chose it: the declaration (by_arch=, by_bucket=, algos=), a rule of tilefish's, or a library's heuristic (below).

# on a GPU of the target device, into an empty directory; once per device, and again whenever an implementation changes
tilefish.runtime.export([encoder, decoder], "build/sm_103")
tilefish.runtime.write_lock("build/sm_103", "locks/sm_103.lock.json")          # commit the lock

# in CI and the image build, on a machine without a GPU
s = tilefish.runtime.export([encoder, decoder], "plans/sm_103", lock="locks/sm_103.lock.json")
s.digest   # the lock's digests.set: the pin the hosts load the plans with

write_lock(directory, path) reads files only (the manifest, the plans, the fusion reports, selection.json and the sha256 of every file); it does not export. export(..., lock=path) takes the same operators and options as the export it locks (buckets=, reuse=, verify=), and the architecture from the lock (arch=, when given, must be the lock's). A plan set, one graph, and kernels and externs alone are all locked the same way. Both raise tilefish.TilefishLockError, which names the first difference and what to do.

What a device contributes

fact made on the device by where an export writes it where the lock keeps it
the architecture the device every entry's arch, each plan's arch device.arch
the SM count the device each library entry's sm_count and declaration_digest device.sm_count (null without library entries)
a cuBLASLt algorithm (cublaslt.gemm, gemm_bias, matmul) the heuristic, or an imported table, checked by cublasLtMatmulAlgoCheck the entry's algo library.<stem>.algo
what a cuBLASLt algorithm is made of (its nine configuration attributes) cuBLASLt, reading the pin back (cublasLtMatmulAlgoConfigGetAttribute) selection.json selections.<op>.chosen[].config
the verification of a cublaslt.matmul pin the pin, run on special operands the entry's contract and verification library.<stem>.contract, .verification
a cuDNN pin (an engine and its knobs, or a legacy algorithm) cuDNN's heuristic, or an imported table, checked the entry's pin library.<stem>.pin
a canary (cublaslt.matmul, cudnn.conv_fwd) the pin, run on operands made of a seed the entry's canary library.<stem>.canary
the cuBLASLt and cuDNN versions the libraries each entry's cublaslt_version, cudnn_version toolchain.cublaslt, toolchain.cudnn
the verification of the fused regions each region run against its ops one by one <graph>.fusion.json, each region's verified fusion.<graph>

Nothing else needs a device. Triton compiles ahead of time for an architecture (Triton and Gluon kernels, generated kernels and fused regions), ptxas assembles a prebuilt PTX, a prebuilt cubin is used as it is; the plans (steps, buffers, the arena, the workspace: the declarations' workspace_bytes and the global scratch Triton reports), the warps of each bucket (by_bucket=), the TF32 guard and the SASS assertions (nvdisasm, the tilefish[sass] extra) are all made from the declarations and the binaries, and so is what chose each implementation (selection.json), but for the configuration of a cuBLASLt pin, which cuBLASLt reads back. Measured: the plan set of python/tests/locked_graphs.py (a generated kernel, a Triton extern, a Gluon extern, a prebuilt PTX and cubin, a pinned cuBLASLt GEMM, a cublaslt.matmul with an epilogue, a cuDNN convolution, two fused regions, a kernel whose global scratch is the plan's workspace, an extern with an implementation per architecture and a configuration per bucket, two buckets per graph, three canaries), exported on a B300 MIG slice (sm_103, 30 SMs, Python 3.11) and locked there, then exported from the lock on a CPU-only machine (Python 3.12, no torch, no CUDA driver) with the same Triton 3.5.1 and ptxas 12.9.86: 17 files, 0 differences, selection.json included, in 1.4 s from a cold build cache. Locked on an RTX 5090 (sm_120, 170 SMs) and exported from that lock on the same CPU-only machine: 17 files, 0 differences.

The lock file (tilefish.lock.v2)

Canonical JSON (sorted keys, one space of indent, a newline at the end), so a re-lock that changes nothing changes no byte, and its diff says what changed. Every field is required:

field what
schema "tilefish.lock.v2" ("tilefish.lock.v1", tilefish 0.0.14's, had no selections and graphs: it is refused, with a re-lock)
tilefish the version that wrote the export (the manifest and the plans name it, so a locked export needs the same)
device {"arch": "sm_103", "sm_count": 30}: the device the export ran on (sm_count is null when no library entry recorded it)
toolchain the versions the export recorded, each only when it has binaries or entries of it: triton and ptxas (the manifest's toolchain texts), cublaslt and cudnn (integers)
library per stem: impl, declaration_digest (the entry's: the declaration and the SM count), workspace_bytes, and the pin, algo (cuBLASLt, 128 hex digits) or pin (cuDNN); a cublaslt.matmul also has contract and verification; a canary is canary ({"seed", "out_digest"} or {"seed", "y_digest"})
fusion per graph, the regions an export verified: [{"region": the index of the region in the fusion report, "op": its kernel, "verified": what the report records}]
kernels per stem: cubin (the file), sha256 and sha256_code
selections per operator, what chose its implementation: the candidates its declaration offers, what this export took and who decided (next section)
graphs per graph, the operator each step runs, in order (copy and memset for those): {"steps": [...]} when every bucket runs the same, else {"buckets": [{"values": [...], "steps": [...]}, ...]}
digests manifest (the manifest's digest), plans (each plan's digest, by graph) and, for a plan set, set: the pins the hosts take
files the sha256 of every file of the directory, by its path (trace/ is left out, as it is outside every digest)

write_lock refuses a directory that is not one export of one device: entries of two architectures, two toolchains or two SM counts, a file an export does not write, entries or a fusion report no plan of the directory has (left by an export of another graph into it), a fusion report whose regions were not verified (an export made off the device warns and records skipped; export on the device, or with verify=False), a directory without selection.json (an older export's) or whose selection.json does not describe the manifest next to it, and a CuTe DSL kernel (below).

What chose each implementation: selections

A declaration says which implementation runs, or leaves it to tilefish. selections has one record per choice point: an extern (one record for an extern declared by_arch=, whatever implementation runs), a kernel tilefish generated (a @tilefish.kernel, a fused region, a copy, an extern with an epilogue hook), and a library declaration. A record has:

  • candidates: what the declaration offers, as declared. For an extern, each implementation ("declared" for an extern of one; under by_arch= its key, sm_120, a name or fallback) with its kernel (triton module:function, gluon module:function, a prebuilt binary's kind, symbol and sha256), its launch (grid, warps, stages, the value of every const parameter), the architectures it is for, and its by_bucket configurations with the buckets of each. For a generated kernel, what generated it. For a library declaration, its imported tables (algos), or the heuristic's posture and what it is asked (the workspace limit, split-K).
  • chosen: what this export took, the buckets that took the same together: at (the buckets, or every call), the candidate taken, chosen_by, the configuration where there is one (config: a by_bucket configuration or a generated kernel's warps per bucket as text; for a cuBLASLt pin, its nine attributes, the form an AlgoTable row takes; pin: a cuDNN pin with the names of its knobs), and the entries (stems) it made.
  • made_by, for an operator tilefish made: rule:fusion.v2, <graph> region <i> (<its ops>), rule:fusion.hook, ... (an extern with a region in its epilogue hook), rule:fusion.library-epilogue, ... (a cuBLASLt GEMM and the arithmetic after it, one cublaslt.matmul); and problem, a library declaration's signature and options.

chosen_by says who decided what the code did not leave open:

chosen_by what decided
by_arch the declaration's implementation per architecture (@tilefish.extern(by_arch=..., fallback=...)), of an extern that has more than one
by_bucket the declaration's configuration per bucket (by_bucket=lambda T: tilefish.config(...)); by_arch, by_bucket when both chose
algos an imported table of the declaration (algos=AlgoTable(...) or CudnnTable(...))
heuristic:<posture> the library's heuristic, asked under the declaration's posture: tilefish or torch (cuBLASLt), instant, mode_b or v7 (cuDNN)
rule:row.warps a generated kernel's warps, by the row template's rule: one warp per 256 lanes of BLOCK_D, from 1 to 16 (_row_warps in tilefish/lower.py, its note 6)
rule:row.ordered-warps revision 2's rule of a row of ordered sums (_ordered_row_warps in tilefish/lower.py, note 21)
rule:row.chunk-warps 2 warps for an argmax or argmin walked in chunks (ARG_CHUNK_WARPS in tilefish/lower.py, note 8)
rule:elementwise.warps the elementwise template's 4 warps (ELEMENTWISE_NUM_WARPS in tilefish/lower.py)
rule:copy a copy tilefish writes the Triton of (tilefish.contiguous, im2col, im2col1d, col2im1d: tilefish/_copyops.py)
call nothing: the operator has no declared alternative, and the code called it (a kernel that declares its num_warps, an extern of one implementation)
measured reserved: no export measures a choice

A @tilefish.kernel that declares num_warps= reads call; one that does not, the rule of its template. A choice made by the code that calls the operators (a graph that calls one extern or another, by its own if) is not one tilefish sees: each operator reads call, and graphs says which one each step runs. Declare such a choice with by_arch=, by_bucket= or algos= and the lock records it as one. For example (the locked set on a B300, an extern of locked_graphs.py, and a cuBLASLt GEMM the heuristic chose, one of its two buckets):

"lk_rows": {
 "candidates": {
  "fallback": {
   "by_bucket": {"4 warps, 3 stages, grid (M,); ROWS=1 COLS=256": "M=32", "8 warps, 3 stages, grid (cdiv(M, 8),); ROWS=8 COLS=256": "M=64"},
   "for": "any other architecture (the fallback)",
   "kernel": "triton locked_graphs:_lk_rows",
   "launch": "grid (M,), 4 warps, 3 stages; ROWS=1 COLS=256"
  },
  "sm_120": {
   "by_bucket": {"2 warps, 3 stages, grid (cdiv(M, 2),); ROWS=2 COLS=256": "M=32", "4 warps, 3 stages, grid (cdiv(M, 4),); ROWS=4 COLS=256": "M=64"},
   "for": "sm_120",
   "kernel": "triton locked_graphs:_lk_rows",
   "launch": "grid (M,), 2 warps, 3 stages; ROWS=1 COLS=256"
  }
 },
 "chosen": [
  {"at": "M=32", "candidate": "fallback", "chosen_by": "by_arch, by_bucket", "config": "4 warps, 3 stages, grid (M,); ROWS=1 COLS=256", "entries": ["lk_rows.M32"]},
  {"at": "M=64", "candidate": "fallback", "chosen_by": "by_arch, by_bucket", "config": "8 warps, 3 stages, grid (cdiv(M, 8),); ROWS=8 COLS=256", "entries": ["lk_rows.M64"]}
 ]
},
"lk_up": {
 "candidates": {"heuristic": {"asks": "cuBLASLt's heuristic, the first of 8 answers, 16-byte alignment, within 8519680 B of workspace, no split-K (a bias or an epilogue)", "posture": "tilefish"}},
 "chosen": [
  {"at": "M=32", "candidate": "heuristic", "chosen_by": "heuristic:tilefish", "entries": ["lk_up.M32"],
   "config": {"cluster_shape_id": 4, "cta_swizzling": 0, "custom_option": 0, "id": 66, "inner_shape_id": 0, "reduction_scheme": 0, "splitk_num": 1, "stages_id": 35, "tile_id": 59}}
 ],
 "problem": "a: Tensor[M, 256, bf16], b: Tensor[512, 256, bf16], bias: Tensor[512, bf16] -> Tensor[M, 512, bf16]; layout TN, f32 accumulate, epilogue bias"
}

A config the heuristic chose is in the form of an AlgoTable row: to make the choice the code's, put it in the declaration (algos=), and the selection then reads algos.

selection.json. Every export writes, next to the manifest, the selections of what it built, by architecture ({"schema": "tilefish.selection.v1", "selections": {"sm_103": {...}}}), merged by operator into a file that is there, as the manifest is. It is outside every digest, and no host reads it: the manifest, the plans, every digest and every cubin are the same with it as without it. write_lock copies the selections of the lock's architecture into the lock, holding them to the manifest (every entry in the selection of its operator, once; a library entry's chosen_by and cuDNN pin as the entry records them), and the lock's files hold the file.

What a locked export checks, in order

  1. The lock reads strictly (no duplicate key, every field typed); arch= is the lock's; the tilefish, Triton and ptxas versions are the lock's (the ptxas Triton compiles with, TRITON_PTXAS_PATH, or for an export of prebuilt PTX only, TILEFISH_PTXAS_PATH).
  2. Each library step takes the lock's record of its stem, whose declaration_digest must be the declaration's on a device of the lock's SM count (an operator, option or bucket that changed is refused); a cublaslt.matmul declared contract="measured-exact" is refused a binary-defined pin, and one with a canary (the default) needs the lock's canary, as an export does; the entry it makes must pass every rule a manifest reader has (section 9 of docs/en/manifest-schema-3.md). No heuristic is asked, no library is loaded, nothing runs on a device, with a device or without one.
  3. Each fused region the export would verify (the graph's verify, or verify=) takes the lock's record of it.
  4. Each binary is built and held to kernels.<stem> (its toolchain, then its sha256, saying whether the machine code differs) before anything is written.
  5. What chose each implementation is made again from the declarations, a cuBLASLt configuration from the declaration's table when it gives one as the nine attributes, else from the lock (cuBLASLt cannot be asked), and held to selections, field by field, before anything is written: a declaration that changed, or a lock edited by hand, is refused naming the field (says at selections.lk_rows.chosen[0].chosen_by ...).
  6. The files are written as an export writes them, and every file of the directory is held to files: a missing file, a file of other bytes (the cubins first, then the manifest, then the rest) and a file the lock does not have (export into an empty directory) are refused. The files a refusal at this step leaves are there to be compared with the export on the GPU; do not ship them.
  7. The directory, locked again, gives the lock itself: the digests a host is told to pin, the binaries' sha256_code, the pins, the regions' records, the selections and what each step runs are what the files say, so a lock edited by hand where no file shows it is refused too (a heuristic's config edited alone makes a selection.json of other bytes).

A stem, a region or a binary the lock does not have is refused with re-lock on a GPU of the target device: there is no fallback to a heuristic.

What is checked where

check export on the GPU locked export (no GPU) load on the GPU (Python, Rust, C++)
each binary is its source's, for its architecture built built, and held to the lock's sha256 each cubin against the manifest's sha256 and sha256_code; the manifest and the plans against the pin
the pin is what the declaration asks for the heuristic under the declaration's posture the lock's record of this declaration (declaration_digest) Python's replay compares the entry with the declaration (an imported table's algorithm too); Rust and C++ hold the plan's pin
the algorithm is valid: cublasLtMatmulAlgoCheck, the re-encoding, the reduction scheme and its opt-in, no TF32 or emulated f32, the workspace checked not checked (no library) checked at every load (Rust and C++: Manifest::gemm; Python: when a plan is prepared and before every run)
the cuBLASLt and cuDNN versions, the SM count, the architecture recorded the lock's another one is refused
a cuDNN pin is deterministic, of allowed numerical notes, its knobs in range, its plan finalizes; no NVIDIA_TF32_OVERRIDE checked not checked checked at every load
the canary computed the lock's run at the first load, another digest refused
a cublaslt.matmul pin against its formula (contract (ii)) measured the lock's record the record (Python refuses a binary-defined pin a declaration says measured-exact of); the canary ties the bytes to the run that measured it
fused regions against their ops one by one measured the lock's record not repeated
what chose each implementation (selections) made from the declarations; a cuBLASLt pin's configuration read back by cuBLASLt (a declared one must read back as declared) made again from the declarations and held to the lock; a heuristic's cuBLASLt configuration is the lock's, held by the sha256 of selection.json not read (no host reads selection.json); the hosts check the pins themselves, as above

So nothing an export checks goes unchecked when it runs without a GPU: every check a load makes is made as before, and what only an export measures (the heuristic's choice, the verification of a matmul pin and of the fused regions) was measured on the GPU that made the lock, of the binaries that the locked export is held to byte for byte. A lock is a trust anchor like a pin: a lock edited by hand, with the pins and the hashes changed together, writes what it says. Review a lock's diff as a change of the artefacts it describes, and commit it next to the code.

When to re-lock

When an implementation changes (a kernel, a declaration, what a by_arch=, by_bucket= or algos= chooses, an option, a bucket, the operators of the export), when tilefish, Triton or ptxas is upgraded, when cuBLASLt or cuDNN is (a pin is of a library version: a host refuses another), and for each new target device. A locked export that fails says what differs; re-lock on a GPU of that device and review the diff.

Limitations

  • CuTe DSL kernels are compiled by the DSL on a GPU, and their launch (grid, cluster, the parameters of the compiled host function) is captured on it (docs/en/cute.md): a locked export refuses them, and so does write_lock. Export a set with a CuTe DSL kernel on a GPU.
  • The same toolchain on both machines: the tilefish, Triton and ptxas versions are checked; anything else that changes a binary (a Triton setting, TILEFISH_DEBUG_PATHS) changes its sha256, and the locked export refuses it. The Python version does not reach a binary (3.11 and 3.12 above).
  • One lock per device. The architecture is checked; two devices of one architecture with other SM counts (a MIG slice, the whole GPU) are not told apart without a GPU: a locked export of the wrong lock succeeds, and the host refuses its library entries at the load ("pinned on a device with 30 SMs, but this device has 148").
  • One export per directory: a lock holds every file of its directory, so manifests of several architectures merged into one directory are not locked.
  • A lock is not an imported table (algos=, AlgoTable, CudnnTable): those are part of a declaration and of its digest, and an entry made from one says "algo_source": "imported", so they cannot reproduce an export that asked the heuristic. A lock records what the export pinned, whichever way it pinned it, cublaslt.matmul included (which takes no algos=).

The gate runs the hosts on locked artefacts: python/tests/rust_gate.py prepare WORK --locked DIR --lock FILE takes the plan set of locked_graphs.py from DIR (a locked export, made on a machine without a GPU, held to the lock and replayed under its set digest) instead of exporting it, so Python's replay, the Rust host and the C++ host load it, run its canaries and its cases, and compare holds their bytes to Python's.