Skip to content

fix(lookup): free charset_len_buffer (GPU buffer leak aborting multi-config-group lookups) - #129

Merged
bandrel merged 1 commit into
masterfrom
fix/opencl-charset-len-buffer-leak
Jul 24, 2026
Merged

bandrel merged 1 commit into
masterfrom
fix/opencl-charset-len-buffer-leak

Conversation

@bandrel

@bandrel bandrel commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Symptom

Multi-config-group lookups abort partway through with Failed to create context: -6 (CL_OUT_OF_HOST_MEMORY) — observed at config group ~7 of a full-size table campaign.

Root cause

charset_len_buffer is created in both host_thread_false_alarm() and host_thread_precompute() but freed in neither — only the batch-precompute path (batch_precompute_all_hashes) released it. Every GPU false-alarm / per-hash-precompute invocation leaked one GPU memory buffer. Across config groups these accumulate on the device until clCreateContext() can no longer allocate.

Evidence

Wrapped the OpenCL create/release entry points with live counters and dumped them per config group:

group-1-start  ctx=0 buf=0  ...
group-2-start  ctx=0 buf=6      <- +6 buffers, contexts/queues/programs/kernels all balanced
group-3-start  ctx=0 buf=12
...
group-10-start ctx=0 buf=54

Only buf climbed (monotonic, ~one per GPU false-alarm invocation). After adding the frees, buf stays flat at 0 across all 10 groups and the full run completes (exit=0, 0 context errors, potential-match counts unchanged).

Fix

Add the missing CLFREEBUFFER(charset_len_buffer) to both cleanup paths. Shared host code, so this affected all backends (OpenCL/CUDA/Metal).

Verification

  • make linux, make cuda, make macos all build.
  • dell3 OpenCL run: buffer counter flat across 10 config groups (was +N/group); full lookup completes cleanly.

🤖 Generated with Claude Code

charset_len_buffer was created in host_thread_false_alarm() and
host_thread_precompute() but freed in neither — only the batch-precompute
path released it. Every GPU false-alarm/precompute invocation therefore
leaked one GPU memory buffer. Across a multi-config-group lookup these
accumulate on the device until clCreateContext() fails with
CL_OUT_OF_HOST_MEMORY (-6), aborting lookups partway through (observed at
config group ~7 on a full-size table campaign).

Root cause confirmed with live create/release counters wrapping the OpenCL
allocator: buffer count climbed monotonically per config group (ctx/queue/
program/kernel stayed balanced) and went flat after adding these frees.

Shared host code, so this affected all backends (OpenCL/CUDA/Metal).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@bandrel
bandrel force-pushed the fix/opencl-charset-len-buffer-leak branch from beec310 to 9252d5e Compare July 24, 2026 15:03
@bandrel
bandrel merged commit 8deb401 into master Jul 24, 2026
3 checks passed
@bandrel
bandrel deleted the fix/opencl-charset-len-buffer-leak branch July 24, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant