← Back to Pull requests

[STF] Blocking context resources: unpin host memory once a graph context has run #12874

Closed
unknown closed this pull request without merging on Dec 01, 2026 11:51 UTC
View on GitHub
unknown unknown commented on Nov 29, 2026 14:57 UTC
Author

Description

No issue is filed for this yet.

The bug. The graph backend pins a host buffer the user gives to a logical data and never unpins it: unpin_host_memory() is a no-op there, because the copies are graph nodes that run later. The registration outlives the context. When the same address range is reused, a later and unrelated context either fails with cudaErrorHostMemoryAlreadyRegistered, or skips the pin and fails a copy with cudaErrorInvalidValue. This shows up as an intermittent failure of the Python STF tests, e.g. test_cuda_kernel_chained right after a graph test on the same worker (job log of #12556).

Blocking context resources. A ctx_resource can now declare that its release needs the work submitted on the stream to be complete (release_is_blocking()):

  • the resource set drains the stream once, then releases the blocking resources;

  • a context that finalizes asynchronously (bound to a caller-provided stream) refuses them in add_resource();

  • a scope of a stackable context does not block: it allows them if its parent does, and hands them to its parent at the pop. The root releases them when it finalizes;

  • the resource set of a context is protected by a mutex. Resources are added by tasks submitted from several threads and by logical data destroyed on any thread; without it a test adding resources from 8 threads corrupts the heap.
  • Unpinning host memory. The graph data interfaces get a real unpin_host_memory() and report unpin_host_memory_is_deferred(). When a logical data that STF pinned is destroyed in a graph context, the unpinning becomes a blocking resource, released when the context finalizes. The stream backend is unchanged.

    A graph context bound to a caller-provided stream cannot hold that resource, so it refuses a host buffer that is not registered, when the logical data is created. This is an error on purpose rather than a silent fall back to copies from pageable memory, which would make such a context slower with nothing to show why. The remedy is to register the buffer first, or to use a context whose finalize() is blocking. A buffer the caller registered is left alone everywhere.

    Scope allocator. The stackable context had its own version of the same mechanism for stream_adapter: a nested scope passed its adapter to its parent through a dedicated list, and a top-level scope cleared it at the pop, synchronizing its stream when a buffer was not stream-ordered. The pending frees are now resources of the scope's context: stream-ordered buffers are freed behind the launch as before, the others are a blocking resource. The dedicated list and its hand-off code are removed.

    Behavior changes to review:

  • an unregistered host buffer given to a graph context on a caller-provided stream is now an error;

  • host memory allocated inside a stackable scope is freed when the stackable context finalizes, not at the pop of the scope. A pop no longer synchronizes for it.
  • Not addressed here: a context that is never finalized still leaves its registrations in place, and address_is_pinned() still checks only the start address.

    Checklist


  • New or existing tests cover these changes: cudax/test/stf/graph/host_unpin.cu (unpin after finalize, refusal and acceptance on a caller-provided stream, hand-off through one and two scopes, release ordered after the graph of the scope, host memory of the scope allocator, concurrent add_resource), python/cuda_stf/tests/stf/test_host_pinning.py.

  • The documentation is up to date with these changes: docs/cudax/stf/custom_data_interface.rst.
  • 🤖 Generated with Claude Code

    Diff: 466 lines (+349 / -117) across 5 files Reviewer: caugonnet Review duration: 2694m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.46) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.46 · 466 lines diff across 5 files
    0.46
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.368
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #12874"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.6% (MEDIUM) · Higher = larger blast radius
    45.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18% · Safe to merge
    18%
    Repository