ROCM-26531 - Fix capture graph leak on execution-context stream detach#7773
Open
victzhan wants to merge 2 commits into
Open
ROCM-26531 - Fix capture graph leak on execution-context stream detach#7773victzhan wants to merge 2 commits into
victzhan wants to merge 2 commits into
Conversation
When an ExecutionCtx is destroyed while one of its streams has an active stream capture, Stream::Detach() invalidated the capture but never freed the captured hip::Graph. The graph could no longer be reclaimed because hipStreamEndCapture_common early-returns hipErrorStreamDetached (via CHECK_STREAM_DETACHED) before reaching its ReleaseCaptureGraph() cleanup, and hipStreamDestroy's EndCapture() only nulls the pointer. The graph (owned solely by pCaptureGraph_) was therefore orphaned, producing the LeakSanitizer "Direct leak of 776 byte(s)" reported in ROCM-26531. Free the captured graph at the detach point, gated on the origin stream so it is deleted exactly once. Forked (parallel) capture streams only alias the origin's graph, so clear their pointer first to avoid a double free. Fixes: ROCM-26531 Co-authored-by: Cursor <cursoragent@cursor.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
Fix the ROCM-26531 LeakSanitizer regression where destroying an execution context that owns a stream with an active capture leaks the captured graph.
Technical Details
Free the captured graph in Stream::Detach() when the capture is invalidated, since the detached stream can no longer reach hipStreamEndCapture's cleanup. Only the origin frees it; forked streams just clear their aliased pointer to avoid a double free.
JIRA ID
ROCM-26531
Test Plan
Ran the two failing capture-detach tests and all other relative tests
Test Result
No regression
Submission Checklist