[PR #2683] [CLOSED] [Engine] tests: cuda_spill_guard fails the CUDA test build when a Strata kernel spills or keeps a per-thread array in local memory #4212

Closed
opened 2026-11-07 15:34:04 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2683
Author: @Avicennasis
Created: 10/15/2026
Status: ❌ Closed

Base: main ← Head: fix/cuda-spill-gate-296b59d2


📝 Commits (6)

  • e8fe100 tools: check_cuda_spills.py fails when a CUDA kernel spills or keeps a per-thread array in local memory (cuobjdump's STACK / LOCAL per entry function and sm_, no GPU needed)
  • b49ee23 tests: register cuda_spill_guard, check_cuda_spills.py over the kernel libraries of a CUDA build (SKIP_RETURN_CODE 77; CUDA only, not HIP)
  • 396e3c0 check_cuda_spills: the 37 Strata kernels with a stack frame at 296b59d2 as measured allowances; llama.cpp's vendored ggml kernels (no namespace) are skipped, theirs to gate
  • 07daf0e check_cuda_spills: no demangler, or a demangler that fails, is a skip (77), not a pass
  • 692edcc check_cuda_spills: the ALLOWED table re-measured at cbfd5b92 (v0.2.1 + 55)
  • f4d848e check_cuda_spills: native_gu_multi_kernel's sm_86 allowance re-measured at 011c9e60 (v0.2.2): 144 B, was 96

📊 Changes

3 files changed (+485 additions, -0 deletions)

View changed files

📝 CMakeLists.txt (+22 -0)
➕ tools/check_cuda_spills.py (+342 -0)
➕ tools/test_check_cuda_spills.py (+121 -0)

📄 Description

Problem and result

A CUDA kernel that spills registers, or keeps a per-thread array it could not promote, pays a round trip to device memory through L1 on every access, in the hottest loops the engine has — and nothing in the build says so. Spills are compiler-output facts like #1522 and #1469: they appear in the resource report and nowhere in the source, they move with the toolkit and the sm_, and they cost decode throughput silently. Today the tree does not read that report.

After: STRATA_BUILD_TESTS registers cuda_spill_guard, which reads the kernel libraries that were built anyway with cuobjdump --dump-resource-usage (per entry function, per sm_: REG, STACK, LOCAL, SHARED) and fails naming the kernel, the sm_ and the two numbers when a Strata kernel has a frame outside its measured allowance. No build-flag change, no GPU at test time, mirrors tools/check_isa_guard.py. The allowance table carries the measured state of cbfd5b92 (v0.2.1 + 55) on sm_86 and sm_120, so the gate is green today and documents what is there; from here it holds the line.

#2682 (re-filed from #1758, which the 2026-10-13 sweep closed). Both were closed in the 0.2.0-beta tracker reset on 2026-10-19; this is the rebase + re-run the reset asked for. The exceptions-table shape with one measured allowance per (kernel, sm_) is the one DeepGEMM uses (DG_JIT_CHECK_NO_SPILLS / DG_JIT_CHECK_NO_LOCAL_MEMORY). No maintainer agreement on scope was sought beyond that: it is a test-only addition with no change to any build default.

Approach

  • tools/check_cuda_spills.py (new): per library, per entry function, per SASS arch, from cuobjdump --dump-resource-usage, demangled with cu++filt beside it or binutils c++filt. A kernel must have STACK 0 and LOCAL 0 on every sm_ unless ALLOWED carries its allowance for that sm_: 50 entries, 69 (kernel, sm_) allowances, each the measured maximum with one line above it saying what the array is, or what spilled (ptxas -v: spill stores / loads at the register count it settled on, and the launch bounds). Keyed by the demangled name without template arguments and parameters, so every instantiation of a template kernel shares one entry. The vendored llama.cpp ggml kernels (mul_mat_q, quantize_*; instantiated into strata_mmq, strata_mmq_w4a4, strata_kq) are skipped by the one property that singles them out — no namespace at all; every Strata kernel sits in strata::, q36k:: or an anonymous namespace — and the report line counts them. --list prints every kernel on every sm_ as CSV, judging nothing; that is how the table was produced. Exit 0 clean / 1 violation / 77 when cuobjdump, a demangler or a library is missing, or a library yields no SASS entry (a pass with nothing counted is not a pass).
  • CMakeLists.txt (+22): registers cuda_spill_guard under STRATA_ENABLE_CUDA AND STRATA_BUILD_TESTS AND NOT STRATA_ENABLE_HIP AND NOT STRATA_HIP_GFX906 over $<TARGET_FILE:…> of strata_kernels, strata_core, strata_engine, strata_prefill, strata_qwen35, strata_mmq, strata_mmq_w4a4, strata_kq (each guarded by if(TARGET); strata_kq is a shared library on main now, which both the generator expression and the reader accept), passing ${CUDAToolkit_BIN_DIR}/cuobjdump. find_package(Python3 QUIET) guarded — no Python, no test, with a status line saying so. SKIP_RETURN_CODE 77, TIMEOUT 600.
  • tools/test_check_cuda_spills.py (new): 8 tests over synthetic resource rows and stand-in demanglers, no toolkit needed.

Compatibility: nothing changes for a build without STRATA_BUILD_TESTS; HIP builds register nothing. The table lists sm_86 and sm_120 only — a build for another arch reports its framed kernels as not in ALLOWED on its first run, and those numbers go in the same way.

Measured on 011c9e60 (v0.2.2; CUDA 13.1, nvcc/cuobjdump V13.1.80, cmake 3.28.3 + ninja 1.11.1, Release, CMAKE_CUDA_ARCHITECTURES="86;120", Ubuntu 24.04.3 container, no GPU) — the eight libraries hold 1836 Strata kernels (412 once template instantiations collapse), 3672 (kernel, sm_) entries, 284 with a stack frame: 141 are register spills in 30 distinct kernels, 143 are spill-free per-thread arrays. 1101 vendored ggml kernels (2356 entries) skipped. LOCAL is 0 everywhere on this toolkit: spills and local arrays both land in STACK. Against the cbfd5b92 measurement of the previous head (1804 / 412 / 3608 / 270; 136 spills in 30 kernels; 134 arrays): one allowance moved and nothing else — native_gu_multi_kernel on sm_86, 96 → 144 B. v0.2.2's 8-lane trellis rows (5f81c5dc, 01f8c325; TG 144 / 145 with STAGE_GRID) keep row_dot_160_sub8's float p[4][NC] per thread: two instantiations at 144 B with no spill at 77–80 registers, two at 128 B with 28 / 32 bytes of spill at 48; its sm_120 maximum (112) holds. No key is new, none shrank, none dropped: still 50 kernels / 69 allowances. The largest spill in the tree is expdec_down_kernel on sm_86: 428 B of spill stores / 600 B of loads at 64 registers, 272-byte frame. (The step before, 296b59d2 → cbfd5b92 — 13 kernels with a frame new, 3 moved, 1 dropped — is in the message of 692edccb.)

Validation

Passed:

  • cmake -S . -B build -G Ninja -DSTRATA_ENABLE_CUDA=ON -DSTRATA_BUILD_TESTS=ON -DCMAKE_CUDA_ARCHITECTURES="86;120" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CUDA_FLAGS="-Xptxas -v" then ninja -C build strata_kernels strata_core strata_engine strata_prefill strata_qwen35 strata_mmq strata_mmq_w4a4 strata_kq — this branch (f4d848e5, rebased on 011c9e60), the container above, 5 min 07 s; the -Xptxas -v log is where the spill stores / loads in the table's comment lines come from (the first filing checked that it leaves the SASS identical).
  • python3 tools/check_cuda_spills.py --cuobjdump /usr/local/cuda/bin/cuobjdump build/libstrata_kernels.a build/libstrata_core.a build/libstrata_engine.a build/libstrata_prefill.a build/libstrata_qwen35.a build/libstrata_mmq.a build/libstrata_mmq_w4a4.a build/libstrata_kq.so — exit 0; per library … 0 not allowed, e.g. libstrata_kernels.a: 1678 kernels on sm_120, sm_86 (3356 entries; 0 vendored ggml entries skipped), 264 use stack / local memory, 0 not allowed.
  • ctest --test-dir build -R cuda_spill_guard --output-on-failure — 1/1 Test #154: cuda_spill_guard … Passed 1.45 sec.
  • python3 tools/test_check_cuda_spills.py — Ran 8 tests … OK.
  • Red, against the committed script: one allowance lowered by a byte (native_gu_multi_kernel sm_86 144 → 143) fails with exit 1 and one VIOLATION … sm_86: STACK 144 LOCAL 0 (over its allowance STACK 143 LOCAL 0) [iq_kernels.cu.o] line per instantiation at 144 (2); the first filing also showed a scratch kernel with a dynamically indexed float buf[1024] failing as not in ALLOWED on both arches and a missing library / missing cuobjdump exiting 77.
  • Before the allowance was re-measured, the same build failed the gate at the cbfd5b92 table with 4 violations, all native_gu_multi_kernel on sm_86 (STACK 128 / 144 over 96, iq_kernels.cu.o); at the first filing's 296b59d2 table it had been 67: the gate sees what moved.

Failed: none observed.

Not run: a build for sm_75, sm_89 or any other arch (the table has sm_86 and sm_120 entries only, so another arch reports its framed kernels on first run); HIP (no cuobjdump; the test is not registered there); nothing was run on a GPU — none is needed, the gate reads compiler output, so no decode-throughput claim is made here; MSVC.

Limits

A spill is a finding, not a licence: the entries document the state of 011c9e60 so the gate can hold the line from here, and lowering any allowance is a separate, measured change. The allowances will need re-measuring whenever the toolkit changes (CUDA 13.1 today). If you would rather have the capture live elsewhere (a CMake option next to STRATA_BUILD_TESTS, a CI step over the build log), say so and I will move it; the table and the numbers stay the same.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/2683 **Author:** [@Avicennasis](https://github.com/Avicennasis) **Created:** 10/15/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/cuda-spill-gate-296b59d2` --- ### 📝 Commits (6) - [`e8fe100`](https://github.com/Niko1221/Strata/commit/e8fe1009739b917d221830e58b937fcb2d738c70) tools: check_cuda_spills.py fails when a CUDA kernel spills or keeps a per-thread array in local memory (cuobjdump's STACK / LOCAL per entry function and sm_, no GPU needed) - [`b49ee23`](https://github.com/Niko1221/Strata/commit/b49ee236102b51c9f177c3d29a52cc2e09d0a276) tests: register cuda_spill_guard, check_cuda_spills.py over the kernel libraries of a CUDA build (SKIP_RETURN_CODE 77; CUDA only, not HIP) - [`396e3c0`](https://github.com/Niko1221/Strata/commit/396e3c0c38eb2ee8d29d216285fad39b2581afcc) check_cuda_spills: the 37 Strata kernels with a stack frame at 296b59d2 as measured allowances; llama.cpp's vendored ggml kernels (no namespace) are skipped, theirs to gate - [`07daf0e`](https://github.com/Niko1221/Strata/commit/07daf0ea39d03555b7dbf9a1d22ea4f7565022b2) check_cuda_spills: no demangler, or a demangler that fails, is a skip (77), not a pass - [`692edcc`](https://github.com/Niko1221/Strata/commit/692edccba77602e58256ae9958d7f4623503d3f5) check_cuda_spills: the ALLOWED table re-measured at cbfd5b92 (v0.2.1 + 55) - [`f4d848e`](https://github.com/Niko1221/Strata/commit/f4d848e5d946c8518a991067e490ff9b77f96139) check_cuda_spills: native_gu_multi_kernel's sm_86 allowance re-measured at 011c9e60 (v0.2.2): 144 B, was 96 ### 📊 Changes **3 files changed** (+485 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+22 -0) ➕ `tools/check_cuda_spills.py` (+342 -0) ➕ `tools/test_check_cuda_spills.py` (+121 -0) </details> ### 📄 Description ## Problem and result A CUDA kernel that spills registers, or keeps a per-thread array it could not promote, pays a round trip to device memory through L1 on every access, in the hottest loops the engine has — and nothing in the build says so. Spills are compiler-output facts like #1522 and #1469: they appear in the resource report and nowhere in the source, they move with the toolkit and the `sm_`, and they cost decode throughput silently. Today the tree does not read that report. After: `STRATA_BUILD_TESTS` registers `cuda_spill_guard`, which reads the kernel libraries that were built anyway with `cuobjdump --dump-resource-usage` (per entry function, per `sm_`: REG, STACK, LOCAL, SHARED) and fails naming the kernel, the `sm_` and the two numbers when a Strata kernel has a frame outside its measured allowance. No build-flag change, no GPU at test time, mirrors `tools/check_isa_guard.py`. The allowance table carries the measured state of `cbfd5b92` (v0.2.1 + 55) on sm_86 and sm_120, so the gate is green today and documents what is there; from here it holds the line. ## Related discussion #2682 (re-filed from #1758, which the 2026-10-13 sweep closed). Both were closed in the 0.2.0-beta tracker reset on 2026-10-19; this is the rebase + re-run the reset asked for. The exceptions-table shape with one measured allowance per (kernel, `sm_`) is the one DeepGEMM uses (`DG_JIT_CHECK_NO_SPILLS` / `DG_JIT_CHECK_NO_LOCAL_MEMORY`). No maintainer agreement on scope was sought beyond that: it is a test-only addition with no change to any build default. ## Approach - `tools/check_cuda_spills.py` (new): per library, per entry function, per SASS arch, from `cuobjdump --dump-resource-usage`, demangled with `cu++filt` beside it or binutils `c++filt`. A kernel must have STACK 0 and LOCAL 0 on every `sm_` unless `ALLOWED` carries its allowance for that `sm_`: 50 entries, 69 (kernel, `sm_`) allowances, each the measured maximum with one line above it saying what the array is, or what spilled (ptxas -v: spill stores / loads at the register count it settled on, and the launch bounds). Keyed by the demangled name without template arguments and parameters, so every instantiation of a template kernel shares one entry. The vendored llama.cpp ggml kernels (`mul_mat_q`, `quantize_*`; instantiated into `strata_mmq`, `strata_mmq_w4a4`, `strata_kq`) are skipped by the one property that singles them out — no namespace at all; every Strata kernel sits in `strata::`, `q36k::` or an anonymous namespace — and the report line counts them. `--list` prints every kernel on every `sm_` as CSV, judging nothing; that is how the table was produced. Exit 0 clean / 1 violation / 77 when `cuobjdump`, a demangler or a library is missing, or a library yields no SASS entry (a pass with nothing counted is not a pass). - `CMakeLists.txt` (+22): registers `cuda_spill_guard` under `STRATA_ENABLE_CUDA AND STRATA_BUILD_TESTS AND NOT STRATA_ENABLE_HIP AND NOT STRATA_HIP_GFX906` over `$<TARGET_FILE:…>` of `strata_kernels`, `strata_core`, `strata_engine`, `strata_prefill`, `strata_qwen35`, `strata_mmq`, `strata_mmq_w4a4`, `strata_kq` (each guarded by `if(TARGET)`; `strata_kq` is a shared library on main now, which both the generator expression and the reader accept), passing `${CUDAToolkit_BIN_DIR}/cuobjdump`. `find_package(Python3 QUIET)` guarded — no Python, no test, with a status line saying so. `SKIP_RETURN_CODE 77`, `TIMEOUT 600`. - `tools/test_check_cuda_spills.py` (new): 8 tests over synthetic resource rows and stand-in demanglers, no toolkit needed. Compatibility: nothing changes for a build without `STRATA_BUILD_TESTS`; HIP builds register nothing. The table lists sm_86 and sm_120 only — a build for another arch reports its framed kernels as `not in ALLOWED` on its first run, and those numbers go in the same way. **Measured on `011c9e60` (v0.2.2; CUDA 13.1, nvcc/cuobjdump V13.1.80, cmake 3.28.3 + ninja 1.11.1, Release, `CMAKE_CUDA_ARCHITECTURES="86;120"`, Ubuntu 24.04.3 container, no GPU)** — the eight libraries hold 1836 Strata kernels (412 once template instantiations collapse), 3672 (kernel, `sm_`) entries, 284 with a stack frame: 141 are register spills in 30 distinct kernels, 143 are spill-free per-thread arrays. 1101 vendored ggml kernels (2356 entries) skipped. LOCAL is 0 everywhere on this toolkit: spills and local arrays both land in STACK. Against the `cbfd5b92` measurement of the previous head (1804 / 412 / 3608 / 270; 136 spills in 30 kernels; 134 arrays): one allowance moved and nothing else — `native_gu_multi_kernel` on sm_86, 96 → 144 B. v0.2.2's 8-lane trellis rows (5f81c5dc, 01f8c325; TG 144 / 145 with `STAGE_GRID`) keep `row_dot_160_sub8`'s `float p[4][NC]` per thread: two instantiations at 144 B with no spill at 77–80 registers, two at 128 B with 28 / 32 bytes of spill at 48; its sm_120 maximum (112) holds. No key is new, none shrank, none dropped: still 50 kernels / 69 allowances. The largest spill in the tree is `expdec_down_kernel` on sm_86: 428 B of spill stores / 600 B of loads at 64 registers, 272-byte frame. (The step before, `296b59d2` → `cbfd5b92` — 13 kernels with a frame new, 3 moved, 1 dropped — is in the message of 692edccb.) ## Validation **Passed:** - `cmake -S . -B build -G Ninja -DSTRATA_ENABLE_CUDA=ON -DSTRATA_BUILD_TESTS=ON -DCMAKE_CUDA_ARCHITECTURES="86;120" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CUDA_FLAGS="-Xptxas -v"` then `ninja -C build strata_kernels strata_core strata_engine strata_prefill strata_qwen35 strata_mmq strata_mmq_w4a4 strata_kq` — this branch (`f4d848e5`, rebased on `011c9e60`), the container above, 5 min 07 s; the `-Xptxas -v` log is where the spill stores / loads in the table's comment lines come from (the first filing checked that it leaves the SASS identical). - `python3 tools/check_cuda_spills.py --cuobjdump /usr/local/cuda/bin/cuobjdump build/libstrata_kernels.a build/libstrata_core.a build/libstrata_engine.a build/libstrata_prefill.a build/libstrata_qwen35.a build/libstrata_mmq.a build/libstrata_mmq_w4a4.a build/libstrata_kq.so` — exit 0; per library `… 0 not allowed`, e.g. `libstrata_kernels.a: 1678 kernels on sm_120, sm_86 (3356 entries; 0 vendored ggml entries skipped), 264 use stack / local memory, 0 not allowed`. - `ctest --test-dir build -R cuda_spill_guard --output-on-failure` — `1/1 Test #154: cuda_spill_guard … Passed 1.45 sec`. - `python3 tools/test_check_cuda_spills.py` — `Ran 8 tests … OK`. - Red, against the committed script: one allowance lowered by a byte (`native_gu_multi_kernel` sm_86 144 → 143) fails with exit 1 and one `VIOLATION … sm_86: STACK 144 LOCAL 0 (over its allowance STACK 143 LOCAL 0) [iq_kernels.cu.o]` line per instantiation at 144 (2); the first filing also showed a scratch kernel with a dynamically indexed `float buf[1024]` failing as `not in ALLOWED` on both arches and a missing library / missing `cuobjdump` exiting 77. - Before the allowance was re-measured, the same build failed the gate at the `cbfd5b92` table with 4 violations, all `native_gu_multi_kernel` on sm_86 (STACK 128 / 144 over 96, `iq_kernels.cu.o`); at the first filing's `296b59d2` table it had been 67: the gate sees what moved. **Failed:** none observed. **Not run:** a build for sm_75, sm_89 or any other arch (the table has sm_86 and sm_120 entries only, so another arch reports its framed kernels on first run); HIP (no `cuobjdump`; the test is not registered there); nothing was run on a GPU — none is needed, the gate reads compiler output, so no decode-throughput claim is made here; MSVC. ## Limits A spill is a finding, not a licence: the entries document the state of `011c9e60` so the gate can hold the line from here, and lowering any allowance is a separate, measured change. The allowances will need re-measuring whenever the toolkit changes (CUDA 13.1 today). If you would rather have the capture live elsewhere (a CMake option next to `STRATA_BUILD_TESTS`, a CI step over the build log), say so and I will move it; the table and the numbers stay the same. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:34:04 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4212
No description provided.