Files
leleka/docs/sm86-assets.md
T

191 lines
16 KiB
Markdown

# sm_86 (RTX 30-series) assets
Every sealed PTX in `crates/cuda-driver` targets `sm_120` (RTX 5090). An sm_120 PTX does not load on any other
architecture, so before this change nothing GPU-side loaded on the RTX 3080 Laptop (cc 8.6). This document describes
the companion set that makes the same code run on cc 8.6 <= cc < 12.0 devices, what was and was not verified, and how
to regenerate it. All claims are structural (a file exists, `ptxas` accepts it, entry names and parameter counts
match). **No numerical, quality or performance claim is made anywhere here.**
## Scheme (least invasive)
* The 127 sealed sm_120 PTX files, every Rust pin (`(length, sha256)`, `AssetSpec`, `PINS`, ...) and every admission
check are untouched. The default build is the sm_120 build.
* `crates/cuda-driver/ptx-sm86/<name>.ptx` holds one sm_86 companion per sealed sm_120 PTX (plain PTX, no NUL) and
`MANIFEST.json` (method, rules applied, sm_120 and sm_86 digests, ptxas verdict, what is not built).
* `crates/cuda-driver/src/sm86_table.rs` is generated: companions sorted by the SHA-256 of the **sealed sm_120 body**,
each with its own `(length incl. NUL, sha256)` pin.
* Cargo feature `sm86` (`leleka-cuda-driver`, forwarded by `leleka-runtime` and `strata-desktop-core`), off by
default. With it, the 27 `cuModuleLoadData` sites call `arch_ptx::image(sealed_image)`: on a device with
8.6 <= cc < 12.0 the companion is looked up by digest and admitted only through `sealed_ptx::pinned`; otherwise (cc 12.x,
no companion, pin failure, any query error) the sealed image is passed through unchanged. One binary therefore serves both
cards: build once with `--features sm86`.
* Four capability gates that required exactly cc 12 (`mmq_capabilities` in `ffi.rs`, `mtp_original_{full,prefill,scalar}_ffi.rs`)
accept sm_86-class devices under the feature (`arch_ptx::{mmq_cc_ok, cc_major_ok}`).
* `LELEKA_SM86_TRACE=1` prints one line per swapped module.
* Touches to files others edit: `ffi.rs` (11 one-token load-site edits + the MMQ gate), no edit to `mmq_original_group.rs`,
`cache_original_prompt.rs` or `backend_original_serve_smoke.rs`.
## How a companion is made
`scripts/gpu-bringup/sm86_assets.py` (needs the pinned toolkit; `survey`, `infer`, `build`, `compare`, `check`).
1. **retarget (default, 126 of 127).** The sealed sm_120 text with `.target sm_120` -> `.target sm_86` and nothing else, plus
three rules (recorded per file in `MANIFEST.json`). Two cover sm_90+ instructions:
`griddepcontrol.*` lines are deleted (`quantize-d4-selected.ptx`, x1; the tree never launches with the programmatic
stream-serialization attribute, so they are no-ops), and `min.relu.s32 d,a,b` becomes `min.s32 d,a,b; max.s32 d,d,0`
(`original_sampler.ptx`, `native_head_sampler.ptx`, x4 each). Accepted only if `ptxas -arch=sm_86` accepts the result.
The third is a latent bug of three hand-written PTX (`bf16_f32_mmvf` x3, `gr_fixed` x1, `gr_batch_preview` x1): `mov.u64 R, shared_sym;`
followed by `cvta.to.shared.u64 R, R;` converts an address that is already a shared-window address as if it were generic. sm_120
tolerates it; on the 3080 it faulted (CUDA error 700 in `full_matrix_transport_gpu`, case `dense-bf16-gdn-z`) and the smoke passes with the
cvta line removed in the companion (`shared_cvta` rule). The sealed sm_120 files are untouched; the same pattern should be fixed at
the source of those hand-written PTX.
Every companion is accepted only if `ptxas -arch=sm_86` accepts it.
Reason for the default: the instruction stream, the launch bounds, the shared-memory layout and the path-hashed
anonymous-namespace entry names that the Rust window code looks up (`_ZN6strata7kernels..._GLOBAL__N__<crc32 of the
build path>_...`) are exactly the sealed ones, so host-side geometry written against the sm_120 compile still applies.
nvcc's `_GLOBAL__N__` hash is the CRC-32 of the absolute source path, so a recompile in another directory renames those
entries; a native recompile is therefore not drop-in for the window kernels.
2. **recompile (fallback, 1 of 127).** `mtp_original_prefill_quant.ptx` contains genuinely Blackwell code (256-bit
loads need sm_100+, `cvt.*e4m3x2` needs sm_89+). It is rebuilt from `mtp_original_prefill_quant.cu` with the round-trip
verified recipe (`nvcc -ptx -O3 -arch=sm_86 -std=c++17 --fmad=true --ftz=false`) and exports the same entries and parameter
counts, but it is a different code path (217 KB against 1.34 MB of PTX), so it is the item to look at first if a
numerical comparison on the 3080 disagrees.
3. **portable (3):** `gr_read_guard.ptx` (sm_80), `matvec.ptx`, `vector_add.ptx` (sm_75) load unchanged on both cards.
4. **not covered (1, still an unsealed placeholder):** `native_parity.ptx` (documented exception, no recipe). The six placeholders of the
first pass (`mmq_original_group_{swiglu,mul,fixup}`, `mtp_original_scalar_{gr,norm}`, `kernels/mapped_expert_copy`) were sealed on the
5090 branch and have companions since the merge of `claude/port-gpu-bringup` (9c0605a). When more files are sealed for sm_120, rerun
`sm86_assets.py build` (the retarget needs no recipe) and commit the regenerated `ptx-sm86/`, `MANIFEST.json` and `sm86_table.rs`;
`sm86_assets.py check` and the unit test `every_sealed_sm120_file_has_a_companion_or_a_documented_reason` fail if a newly sealed file
has no companion.
### Recipe evidence (`scripts/gpu-bringup/sm86-recipes.json`, `sm86_assets.py infer`)
Compiling every `.cu` for sm_120 with the seal-plan recipe (or the two generic candidates: precise, `--use_fast_math`) and
comparing with the sealed file, with the path hash masked: 25 files reproduce byte for byte (all the 13.2.86-sealed plan
assets that have a `.cu`), 59 more match the entry set and the fast-math class, 28 sealed files have no source in the
tree (llama.cpp-adapted `q*_q8_1`, `moe_group_*`, `mmq-*`, `iq*_q8_1`, `bf16_f32_mmvf`, `head_greedy`, `quantize-d4-selected`, ...), and 9
have a `.cu` whose compile does **not** reproduce the sealed entry names: `mtp_original_full_{fused_gr,head_iq,head_native,head_sampler}`,
`mtp_s2_fixed`, `native_head_{iq,native,sampler}`, `qsa_prompt_select` (the second, content-derived hash in the entry names differs, i.e. the
sealed PTX was built from a different source/header state than the one in the tree). That is a finding about the sealed 5090 assets, independent
of sm_86; the retarget path is unaffected by it.
`sm86_assets.py compare` then compiled the 84 verified recipes natively for sm_86: all 84 compile, `ptxas -arch=sm_86` accepts them, entry
names (path hash masked) and parameter counts equal the companions', launch bounds (`.maxntid`/`.minnctapersm`) equal the companions' in
all 84 (5 differ only in how `, 1, 1` is written), static shared bytes equal; 1 of 84 is byte-identical to its retargeted companion
(`device_poison`). The instruction streams differ (different NVVM output for another target and, for the older sealed files, another
nvcc), which is the reason the default is the retarget of the sealed text; the native compiles are not installed.
## Toolchain used (WSL2 Ubuntu 24.04, no root toolkit)
* CUDA 13.2.2 components from `deploy/cuda-toolkit.lock.json` via `scripts/bootstrap-cuda-toolkit.py` (every archive checked
against the pinned sha256): `nvcc`/`ptxas` 13.2.86, same as the 2026-10-15 sm_120 seal.
* Rust 1.99.0 through `scripts/install-pinned-rustup.sh` (rustup 1.29.0, checksummed), `build-essential` (gcc 13.3).
* The driver `dlopen`s `libcublas.so.12`: NVIDIA redist libcublas 12.9.1.4,
`https://developer.download.nvidia.com/compute/cuda/redist/libcublas/linux-x86_64/libcublas-linux-x86_64-12.9.1.4-archive.tar.xz`,
sha256 `546addc4a9d82b8f23aa9ba9274b6bc0429a63008a31c759884ac24880796057`; put its `lib/` on `LD_LIBRARY_PATH`.
Regenerate:
```sh
python3 scripts/bootstrap-cuda-toolkit.py --output ~/cuda-toolkits/13.2.2
python3 scripts/gpu-bringup/sm86_assets.py infer --toolkit ~/cuda-toolkits/13.2.2 --work ~/sm86-work # optional evidence
python3 scripts/gpu-bringup/sm86_assets.py build --toolkit ~/cuda-toolkits/13.2.2 --work ~/sm86-work
python3 scripts/gpu-bringup/sm86_assets.py check
cargo test -p leleka-cuda-driver --features cuda-driver,sm86 --lib arch_ptx
```
## Running the model-free smokes on an RTX 3080 Laptop
```sh
export LD_LIBRARY_PATH=$HOME/cublas-12.9.1.4/x/libcublas-linux-x86_64-12.9.1.4-archive/lib
SMOKE_SM86=1 scripts/gpu-bringup/run_gpu_smokes.sh --run --release
```
First result (before the merge below), run on 2026-10-15/16 (WSL2 Ubuntu 24.04, kernel 5.15.167.4-microsoft-standard-WSL2, NVIDIA GeForce RTX 3080 Laptop GPU,
cc 8.6, 16 GiB, Windows driver 617.42 with GPU passthrough, rustc 1.99.0, `--release`, `--features sm86`, companions made with nvcc/ptxas 13.2.86,
libcublas 12.9.1.4). Commit of the tree: the one that contains this file. 73 tests in 17 groups, all PASS (a pass needs cargo exit 0 and the expected
number of tests run):
| group | tests | result |
| --- | --- | --- |
| driver-basic | 3 | PASS |
| seal-loads (window assets load and export every entry; RT bank) | 3 | PASS |
| new-pins (experimental KV/keyless/cvec, KAR level decode, flash-attn / s_gemv / poison) | 9 | PASS |
| transport | 10 | PASS |
| gr / gdn / moe-mmq / qsa / ple / mtp | 3 / 3 / 11 / 1 / 2 / 2 | PASS |
| dispatch | 2 | PASS |
| runtime-gr / -gdn / -moe / -qsa / -ple / -mtp | 3 / 9 / 5 / 4 / 1 / 2 | PASS |
| misc-device | 0 tests exist | PASS (empty) |
Not run, and why: `model-assets` (30 tests; they read the shards, KAR archive, MTP pack or oracle fixtures and are not started without
`--allow-model-runs` and the variables) and `mock-only` (CPU mock harness protocol tests, no GPU). One real failure was found and fixed on
the way: the first run stopped in `transport` at `complete_selected_matrices_match_legacy_64_row_bits` (CUDA error 700 in case
`dense-bf16-gdn-z`), which skipped every group that depends on `transport`; cause and fix are the `shared_cvta` rule above. Nothing in this table is a
Blackwell-only exclusion: the Blackwell-specific content found is `mtp_original_prefill_quant` (recompiled, item 2), which these smokes do not
exercise numerically. As the smokes say themselves, passing means the modules load and the listed entries run with the checked
results of those tests; it is not a qualification of the Original path on this card. With `LELEKA_SM86_TRACE=1` the `seal-loads` window test
reports 22 swapped modules, which also shows the swap is what makes the loads possible: an sm_120 image cannot load on cc 8.6.
Non-GPU unit tests on the same tree (`--release`, the ignored GPU tests stay ignored): `leleka-cuda-driver --lib` 338 passed without `sm86`
and 343 with it (the 5 new `arch_ptx` tests: sorted/unique table, every companion passes its pin, `.target sm_86` and the same entries and
parameter counts as its sealed original, every sealed sm_120 file has a companion or a documented reason, swap only for sealed images);
`leleka-runtime --lib --features sm86` 428 passed; `scripts/gpu-bringup/tests/test_sm86_assets.py` 6 passed. The pre-existing
`test_gpu_bringup.py::test_full_fake_pipeline_on_a_scratch_copy` fails on this tree independently of this work (it expects unsealed
placeholders; `device_poison` is already sealed).
## Real-model run on the 3080 (described, not started)
Not done here. What it needs, from the repo's own documents:
* Build: `cargo build --release --locked -p strata-desktop-core --features sm86 --bin leleka-inference --bin leleka-daemon`
(same for `leleka-cli`), run with `LD_LIBRARY_PATH` containing the libcublas 12 directory. `LELEKA_SM86_TRACE=1` shows the swapped modules.
* Inputs (`docs/original-serve.md`): the two pinned IQ3_S shards, the compressed KAR archive (the 51.5 GiB level-2 archive is mentioned in
`docs/model-assets.md`) plus its provenance, the MTP pack and staging dir. Copy them to the WSL ext4 disk first; `/mnt/c` is a 9p mount
and far slower. The KAR is passed as an inherited descriptor (`exec 9<archive`, `--kar-archive-fd 9`).
* Memory: the target profile assumed 32 GB VRAM and 128 GB RAM. The 3080 has 16 GiB, the host 48 GiB, WSL defaults to about half
of the RAM (raise it in `.wslconfig`). Use a `--gpu-budget` below 16 GiB (the smoke default of 28 GiB, `LELEKA_ORIGINAL_SERVE_BUDGET_GIB`,
is too large), a small `--context-tokens`, and expect the admission code to refuse configurations that do not fit. Whether the
mode-17 path fits in 16 GiB at all is unknown.
* Backend: pin `--backend-mode` (`original` refuses naming the first missing asset; `auto` may fall back to `preview`) and record it. The
unsealed `native_parity.ptx` is the one asset left without a companion.
* Reporting: any run is a correctness/bring-up record, not a benchmark (AGENTS.md); record hardware, driver 617.42 (WSL2 passthrough),
nvcc 13.2.86, model digests, `--features sm86`, cache state, token counts. Compare against the sm_120 reference only with the same
prompts and greedy sampling, and self-determinism first (`docs/gpu-bringup.md` section f).
## Update: merge of claude/port-gpu-bringup 9c0605a, regression script, probes
* `claude/port-gpu-bringup` (9c0605a) was merged into `claude/sm86-assets` without conflicts. `ffi.rs` keeps both the widened `mmq_shared`
list and the `arch_ptx::image` load-site edits; no new `cuModuleLoadData` site appeared; no sealed sm_120 PTX differs from
`claude/port-gpu-bringup`. 127 companions now (6 new), `native_parity.ptx` the only unsealed one.
* `scripts/gpu-bringup/regress_3080.sh [--repo P] [--commit REF|WORKTREE] [--only a,b] [--skip a,b]` (inside WSL) exports the commit, builds the
`sm86` feature set with a shared target dir and prints one PASS/FAIL line per item and the total time: `companions`, `unit-driver`,
`unit-runtime`, `build-binaries`, `smoke:<group>` (the 18 model-free groups), `probe-arena`, `probe-executor`, `probe-00/01/10/20/30/40`
(40 = synthetic verifier, 6 requests with the MTP drafter), `probe-cpu-pool`. A probe fails on a ` ERR` step line as well as on a panic.
From Windows: `wsl -d Ubuntu -- bash /mnt/c/<repo>/scripts/gpu-bringup/regress_3080.sh --repo /mnt/c/<repo> --commit HEAD`.
* A real bug found by the executor probe and fixed in `arch_ptx::companion_for`: `qsa_native_batch.ptx` is stored with its own NUL and
`concat!(include_str!(..), "\0")` adds a second, so the digest never matched, the sm_120 image went to the driver and
`original_qsa_resident_prompt_device` failed with `cuModuleLoadData` code 218 (INVALID_PTX). Every terminal NUL is now stripped before the lookup.
With `LELEKA_SM86_TRACE=1` an image with no companion is reported; in the full regression only the three portable sm_75/sm_80 images
(`matvec`, `vector_add`, `gr_read_guard`) are passed through, 172 distinct modules are swapped.
* Result on the 3080 (commit `ab46f18`): 31 of 31 items PASS in 344 s including a cold-ish build: 18 smoke groups (73+ tests, `misc-device` now
10 tests incl. `short_prompts_record_on_the_drafters_own_scalar_owner_not_on_a_standalone_one`, run with its `LELEKA_MTP_SCALAR_SHORT_GPU=yes`),
arena, executor, preflight 00/01/10/20/30/40, cpu pool, unit tests.
### Limits probed on the 16 GiB card (probes only, synthetic weights, nothing numerical)
| probe | setting | result |
| --- | --- | --- |
| arena (MMQ expert-group arena) | capacity 2048 / 4096 / 8192 at 14-15 GiB budget | OK |
| arena | capacity >= 10240 | `InvalidProjectionShape`: host-side `(1..=8192)` capacity check in `mmq_original_group.rs`, not a device limit |
| executor (prompt devices, QSA resident, scalar prefill) | capacity 2048..8192 | OK |
| executor | capacity >= 12288 | `InvalidQwenShape`: host-side `(1..=8192)` checks in `gdn_prompt_device.rs` / `qsa_prompt_device.rs` |
| preflight 20 (prefill arena layout) | capacity 2048 / 4096 / 8192 / 16384 / 32768 | OK, 2.0 / 2.8 / 4.3 / 7.4 / 13.6 GiB allocated |
| preflight 20 | capacity 65536 at 15 GiB | `BudgetExceeded` (expected) |
| preflight 40 (verifier + MTP drafter, 6 requests) | T = 6, 8, 12, 16; cells 262144 and 524288; budget 3..14 GiB; 12 requests | OK |
| preflight 40 | projection kinds 8,12,13,14 x expert formats (18,20) (22,20) (23,20) | OK |
All the failing rows are host-side shape guards that do not depend on the device; no sm_86-only limit (shared memory opt-in is 99 KiB on both
cards, the 16 GiB budget was never the binding constraint for the probes) was found in the probes. This is not evidence about the
real model, whose resident set is far larger than anything the probes allocate.