You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
with the help of Claude code, the long-standing memory leakage on NVIDIA GPUs in #127 has been finally fixed.
it turns out the issue is related to NVIDIA memory management related to cl_event object - when an event is passed to the queue, even the event is not used, clReleaseCommandQueue won't actually release the resources.
the fix is to remove the unused waitevent object.
after the fix, the benchmark show no memory leakage.
● I've found the root cause. Let me confirm the diagnosis is complete before fixing. The key facts:
Default build uses -DUSE_OS_TIMER (src/Makefile:9), so the kernel launch at line 698 (the #else branch) writes a cl_event into waittoread[devid].
kernelevent only exists in the non-OS-timer build (mmc_tictoc.c:49), so the clReleaseEvent(kernelevent) at line 1542 is compiled out in your build.
The events written to waittoread (line 698 kernel launch, line 742 reporter read, line 776 debug read) are never released, and the clWaitForEvents that would consume them is commented out (line 725). Synchronization actually
happens via clFinish.
This is the leak. Here's why it's NVIDIA-specific:
In OpenCL, clReleaseMemObject, clReleaseCommandQueue, and clReleaseContext only decrement reference counts — they don't free anything while a reference remains. Every outstanding cl_event holds an implicit reference to its
command queue and context. NVIDIA's runtime honors this strictly: as long as those leaked events live, the context's refcount never reaches zero, so the GPU allocations behind it are never freed. AMD/Intel/CPU runtimes reap
completed events (and their references) much more eagerly, so you don't see the leak there.
Let me look at the exact lines to fix.
Read 1 file (ctrl+o to expand)
● The diagnosis is complete. The events in waittoread are never consumed — the clWaitForEvents is commented out (line 725) and synchronization is done via clFinish (lines 727, 865) and blocking reads (CL_TRUE). So the safest,
cleanest fix is to stop creating these orphan events by passing NULL for the event argument. That removes the references pinning the NVIDIA context alive.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
with the help of Claude code, the long-standing memory leakage on NVIDIA GPUs in #127 has been finally fixed.
it turns out the issue is related to NVIDIA memory management related to
cl_eventobject - when an event is passed to the queue, even the event is not used,clReleaseCommandQueuewon't actually release the resources.the fix is to remove the unused waitevent object.
after the fix, the benchmark show no memory leakage.