Skip to content

fix(core): take every kernel uniform from cachedUniform so none outlives its executor - #62

Merged
chmjkb merged 2 commits into
mainfrom
@chmjkb/leak-fix-kernel-uniforms
Oct 26, 2026
Merged

chmjkb merged 2 commits into
mainfrom
@chmjkb/leak-fix-kernel-uniforms

Conversation

@chmjkb

@chmjkb chmjkb commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

Description

Closes the kernel uniform leaks #60 found. Stacked on #61.

Eight kernels made their dims uniform with root.createBuffer(...) inside their handle, so it lived until the device did, past executor.dispose(): attention (batch, rows, rows split), attnDecode (decode, decode split), layerNorm, swigluChunk, conv1d, argmaxDot, gatherRowsFrom and writeRows. They now take it from cachedUniform and their bind group from cachedBindGroup, like attnFlash, rope and the other kernels already do. The uniforms are per device and keyed by value, so a new executor reuses them instead of making more.

attnDecodeHandle now lists its bind group entries one by one: the shared attention buffers carry a segs the decode layout has no slot for, which createBindGroup ignored and cachedBindGroup would key on.

The leak checks in eval.gpu.test.ts and zoo/leaks.gpu.test.ts no longer expect any uniform left over.

Kernel A/B against #61

pnpm --filter runntime bench:ab kernels -b @chmjkb/gpu-leak-fixes -k attention,reduce,shape,elementwise,conv,matmul: 150 of 150 cases same, max abs(A−B) 0 on every case.

Introduces a breaking change?

  • Yes
  • No

Type of change

  • Bug fix (change which fixes an issue)
  • New feature (change which adds functionality)
  • Documentation update (improves or adds clarity to existing documentation)
  • Performance (kernel tuning, graph building, anything related to performance)
  • Other (chores, tests, code style improvements etc.)

Testing instructions

  1. pnpm --filter runntime exec playwright install chromium (once per machine)
  2. pnpm --filter runntime test

Checklist

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly
  • My changes generate no new warnings

@xxpopielxx

Copy link
Copy Markdown
Member

LGTM once the stack is rebased.

@chmjkb
chmjkb added this pull request to stack #65 October 26, 2026 10:28
@chmjkb
chmjkb force-pushed the @chmjkb/leak-fix-kernel-uniforms branch 2 times, most recently from 90fc7dc to 55a0df6 Compare October 26, 2026 10:38
@chmjkb
chmjkb force-pushed the @chmjkb/leak-fix-kernel-uniforms branch from 55a0df6 to b4aeeaa Compare October 26, 2026 10:50
@chmjkb
chmjkb force-pushed the @chmjkb/leak-fix-kernel-uniforms branch from b4aeeaa to 8570d73 Compare October 26, 2026 10:52
@chmjkb
chmjkb force-pushed the @chmjkb/leak-fix-kernel-uniforms branch from 8570d73 to a429682 Compare October 26, 2026 10:53
@chmjkb
chmjkb marked this pull request as ready for review October 26, 2026 10:55
Base automatically changed from @chmjkb/gpu-leak-fixes to main October 26, 2026 11:19
@chmjkb
chmjkb force-pushed the @chmjkb/leak-fix-kernel-uniforms branch from a429682 to 77b49d7 Compare October 26, 2026 11:19
@chmjkb
chmjkb force-pushed the @chmjkb/leak-fix-kernel-uniforms branch from 77b49d7 to 13f36e1 Compare October 26, 2026 11:19
@chmjkb
chmjkb merged commit d0ccfe2 into main Oct 26, 2026
2 checks passed
@chmjkb
chmjkb deleted the @chmjkb/leak-fix-kernel-uniforms branch October 26, 2026 11:22
@chmjkb chmjkb added bug Something isn't working core Engine: graph ops, dispatch, buffer pool, weight loading kernels GPU kernels and kernel routes labels Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working core Engine: graph ops, dispatch, buffer pool, weight loading kernels GPU kernels and kernel routes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants