mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[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
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4212
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 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)
e8fe100tools: 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)b49ee23tests: register cuda_spill_guard, check_cuda_spills.py over the kernel libraries of a CUDA build (SKIP_RETURN_CODE 77; CUDA only, not HIP)396e3c0check_cuda_spills: the 37 Strata kernels with a stack frame at296b59d2as measured allowances; llama.cpp's vendored ggml kernels (no namespace) are skipped, theirs to gate07daf0echeck_cuda_spills: no demangler, or a demangler that fails, is a skip (77), not a pass692edcccheck_cuda_spills: the ALLOWED table re-measured atcbfd5b92(v0.2.1 + 55)f4d848echeck_cuda_spills: native_gu_multi_kernel's sm_86 allowance re-measured at011c9e60(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_TESTSregisterscuda_spill_guard, which reads the kernel libraries that were built anyway withcuobjdump --dump-resource-usage(per entry function, persm_: REG, STACK, LOCAL, SHARED) and fails naming the kernel, thesm_and the two numbers when a Strata kernel has a frame outside its measured allowance. No build-flag change, no GPU at test time, mirrorstools/check_isa_guard.py. The allowance table carries the measured state ofcbfd5b92(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, fromcuobjdump --dump-resource-usage, demangled withcu++filtbeside it or binutilsc++filt. A kernel must have STACK 0 and LOCAL 0 on everysm_unlessALLOWEDcarries its allowance for thatsm_: 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 intostrata_mmq,strata_mmq_w4a4,strata_kq) are skipped by the one property that singles them out — no namespace at all; every Strata kernel sits instrata::,q36k::or an anonymous namespace — and the report line counts them.--listprints every kernel on everysm_as CSV, judging nothing; that is how the table was produced. Exit 0 clean / 1 violation / 77 whencuobjdump, 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): registerscuda_spill_guardunderSTRATA_ENABLE_CUDA AND STRATA_BUILD_TESTS AND NOT STRATA_ENABLE_HIP AND NOT STRATA_HIP_GFX906over$<TARGET_FILE:…>ofstrata_kernels,strata_core,strata_engine,strata_prefill,strata_qwen35,strata_mmq,strata_mmq_w4a4,strata_kq(each guarded byif(TARGET);strata_kqis 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 asnot in ALLOWEDon 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 thecbfd5b92measurement of the previous head (1804 / 412 / 3608 / 270; 136 spills in 30 kernels; 134 arrays): one allowance moved and nothing else —native_gu_multi_kernelon sm_86, 96 → 144 B. v0.2.2's 8-lane trellis rows (5f81c5dc,01f8c325; TG 144 / 145 withSTAGE_GRID) keeprow_dot_160_sub8'sfloat 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 isexpdec_down_kernelon 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 of692edccb.)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"thenninja -C build strata_kernels strata_core strata_engine strata_prefill strata_qwen35 strata_mmq strata_mmq_w4a4 strata_kq— this branch (f4d848e5, rebased on011c9e60), the container above, 5 min 07 s; the-Xptxas -vlog 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.native_gu_multi_kernelsm_86 144 → 143) fails with exit 1 and oneVIOLATION … 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 indexedfloat buf[1024]failing asnot in ALLOWEDon both arches and a missing library / missingcuobjdumpexiting 77.cbfd5b92table with 4 violations, allnative_gu_multi_kernelon sm_86 (STACK 128 / 144 over 96,iq_kernels.cu.o); at the first filing's296b59d2table 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
011c9e60so 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 toSTRATA_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.