Skip to content

fix(cuda): release resources on init failure, and close three stale state.md rows - #1279

Merged
lusoris merged 2 commits into
masterfrom
fix/gpu-init-leaks-and-hip-mirror
Sep 5, 2026
Merged

lusoris merged 2 commits into
masterfrom
fix/gpu-init-leaks-and-hip-mirror

Conversation

@lusoris

@lusoris lusoris commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Four GPU bugs were open in docs/state.md. Auditing them against master, three were already fixed and the ledger was stale — the single most expensive kind of drift, because it sends people to re-do finished work. One was real and is fixed here.

Bug Verdict Evidence
T-HIP-MOTION-V2-MIRROR-OFF-BY-ONE-2026-06-13 already fixed PR #905 (dcd3cad656); motion_v2_score.hip:62-69 already reads 2*sup - idx - 2
T-SYCL-INIT-LEAKS-EXC-2026-06-19 already fixed PR #1006 (24cc85391e)
T-SPEED-GPU-REGISTRY-ORPHAN-2026-06-19 already fixed PR #1004 (a0bf83c214)
T-CUDA-INIT-SUBMIT-LEAKS-2026-06-19 real, fixed here see below

The real one

CUDA feature extractors leak already-acquired resources when init fails part-way: integer_ms_ssim_cuda.c and integer_psnr_hvs_cuda.c return -ENOMEM without releasing the device buffers, PTX module and lifecycle stream they had already taken, and the SpEED extractors share the pattern. Each error path now routes through the null-safe close spine the surrounding files already use, rather than scattering frees.

All four state.md rows move to Recently closed — the three stale ones with the commit that actually fixed them, so the ledger stops lying.

Type

  • fix — bug fix
  • cuda — backend-specific

Checklist

  • Commits follow Conventional Commits.
  • make format && make lint is green locally.
  • Unit tests pass — meson test --suite=fast: 112 Ok, 0 Fail.
  • If I touched any SIMD/GPU code path, I ran /cross-backend-diff and the worst ULP is ≤ 2. — n/a: these are init/teardown error paths, not numeric kernels. No score can change, because a leaking init is one that already failed.
  • If I touched a feature extractor with SIMD/GPU twins, I either updated every twin or listed the gap. — the leak pattern was audited across the CUDA extractors; SYCL and HIP were checked and are already clean (PR fix(sycl): close on init error paths + null-check USM buffers + exception safety #1006).
  • If I added a new .c / .cpp / .cu / .h / .hpp, it has the license header. — n/a, no new sources.
  • If this is a breaking change, the commit message uses !. — n/a.
  • If this PR adds an ADR, the row lives in docs/adr/_index_fragments/. — n/a; bug fix, and the three stale rows need no new decision.
  • Docs — docs/backends/cuda/overview.md § "Error-path resource release (PR fix(cuda): release resources on init failure, and close three stale state.md rows #1279)" describes the release order and that there is no user-visible delta.

Bug-status hygiene (ADR-0165)

  • docs/state.md updated — all four rows moved to Recently closed, the stale three annotated with the PR that actually fixed them.

Netflix golden-data gate (ADR-0024)

  • I did not modify any assertAlmostEqual(...) score in the Netflix golden Python tests. make test-netflix-golden: 271 passed, 12 skipped, 0 failed.

Cross-backend numerical results

No numerical delta is possible: every change is on an init failure path, which by definition produces no scores. The HIP mirror — the one item in this batch that would have moved numbers — turned out to be already correct on master.

Deep-dive deliverables (ADR-0108)

  • Research digest — no digest needed: trivial. Three of four items were closed by reading git log; the fourth is a leak audit of error paths.
  • Decision matrix — no alternatives: only-one-way fix. A resource acquired before a failure must be released; the only choice was scattered frees vs. the existing close spine, and the surrounding files already answer that.
  • AGENTS.md invariant note — no rebase-sensitive invariants: core/src/feature/cuda/ is wholly fork-added; upstream Netflix has no CUDA SpEED or MS-SSIM extractor.
  • Reproducer / smoke-test command — below.
  • CHANGELOG fragment — changelog.d/fixed/cuda-speed-init-leak-regression.md.
  • Rebase note — docs/rebase-notes.md.

Reproducer

Confirm the three stale rows really were fixed before this PR:

git log --oneline -1 dcd3cad656                      # PR #905  — HIP motion_v2 mirror
sed -n '62,69p' core/src/feature/hip/integer_motion_v2/motion_v2_score.hip   # -> 2*sup - idx - 2
git log --oneline -1 24cc85391e                      # PR #1006 — SYCL init leaks
git log --oneline -1 a0bf83c214                      # PR #1004 — SpEED GPU registry

Then the gates:

meson setup core core/build -Denable_cuda=false -Denable_sycl=false && ninja -C core/build -j 8
meson test -C core/build --suite=fast --num-processes 4   # 112 Ok, 0 Fail
make test-netflix-golden                                   # 271 passed, 12 skipped, 0 failed
bash scripts/ci/twin-drift-check.sh                        # PASS

Known follow-ups

Three of four rows being stale suggests docs/state.md drifts faster than it is swept. Worth a periodic reconciliation of Open rows against git log — the cost of a stale row is a wasted investigation, which is exactly what happened here.

The HIP mirror could not be re-verified on live hardware: this host's AMD Phoenix iGPU (gfx1036) errors under ROCm 7.2. The verdict rests on reading the kernel source, which is unambiguous, not on a device run.

🤖 Generated with Claude Code

@lusoris lusoris added this to the 1.0.0 — First release milestone Sep 4, 2026
…h release in the backend page

The ADR-0165 touch gate rejects the '#TBD' placeholder that the state.md row and its
redirect comment carried; both now cite PR #1279. The ADR-0100 doc-substance gate
requires a docs/backends/cuda/ edit for a CUDA feature-kernel change: the overview
page gains a short 'Error-path resource release' note (no user-visible delta).
@lusoris
lusoris merged commit 0a8faa2 into master Sep 5, 2026
73 of 81 checks passed
@lusoris
lusoris deleted the fix/gpu-init-leaks-and-hip-mirror branch September 5, 2026 09:09
@lusoris lusoris added the type:bug Something isn't working label Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant