Skip to content

cuda.core: Add conditional retry when default mempool reservation fails with OOM - #2474

Draft
juenglin wants to merge 4 commits into
NVIDIA:mainfrom
juenglin:retry-on-oom
Draft

cuda.core: Add conditional retry when default mempool reservation fails with OOM#2474
juenglin wants to merge 4 commits into
NVIDIA:mainfrom
juenglin:retry-on-oom

Conversation

@juenglin

@juenglin juenglin commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Addresses #2381

Device.memory_resource could fail with CUDA_ERROR_OUT_OF_MEMORY on a device with
ample free memory. A memory pool's virtual address reservation is only returned when
the pool is torn down, and cuMemPoolDestroy waits on the stream-ordered
cuMemFreeAsync calls for the pool's outstanding allocations. While those frees sit
queued behind unfinished work, the address space is recoverable but not yet
recovered — enough to fail the next pool lookup wherever address space is scarce.
get_device_mempool now drains the context once and retries:

  • Retries only on CUDA_ERROR_OUT_OF_MEMORY; every other status returns unchanged.
  • Retries at most once, with a cuCtxSynchronize
  • The happy path is untouched; the synchronize only runs where we were about to raise.
  • If the synchronize itself fails, the original OOM is preserved. The handle layer has
    a single thread-local error slot, so reporting the drain's failure instead would
    misattribute why the pool was unavailable.

Scope and cost

  • Best effort across devices. The drain covers the current context, but
    get_device_mempool takes a device_id. When that device is not current, the retry
    retires unrelated work and will not recover the target pool. It then falls back to
    reporting the original OOM, so this is a missed recovery rather than a wrong result.
  • Bounded on the success path. The driver creates the default pool lazily, and once
    it exists the lookup cannot fail. A retry that succeeds therefore costs one
    synchronize per device per process, not one per allocation. A retry that fails can
    recur, so a run that stays exhausted pays one drain per attempt — cheap on an idle
    GPU, but not free.
  • Not a blanket fix. Only the default-pool path retries. cuMemPoolCreate (used by
    pinned, managed, and options-based resources) and cuGraphAddMemAllocNode can fail
    the same way and are unchanged.

Testing

cuda_core/tests/test_mempool_oom_retry.py reproduces the failure and verifies recovery
in a single run: it exhausts the address space, blocks the deallocation stream on an
event behind a slow kernel, drops the pools, asserts the un-retried lookup still fails,
then asserts the retried one succeeds and actually blocked. It runs in a spawned child
process because the default pool is created lazily — once it exists the lookup cannot
fail, so a process that already touched it could not reproduce this. Confirmed to fail
against main for the right reason. It skips on machines whose address space is too
large to exhaust.

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@copy-pr-bot

copy-pr-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the cuda.core Everything related to the cuda.core module label Jul 31, 2026
@juenglin juenglin added the bug Something isn't working label Jul 31, 2026
@juenglin juenglin self-assigned this Jul 31, 2026
@juenglin juenglin added this to the cuda.core 1.2.0 milestone Jul 31, 2026
@juenglin juenglin changed the title cuda.core: Add conditional retry when mempool reservation fails with OOM cuda.core: Add conditional retry when defaylt mempool reservation fails with OOM Jul 31, 2026
@juenglin juenglin changed the title cuda.core: Add conditional retry when defaylt mempool reservation fails with OOM cuda.core: Add conditional retry when default mempool reservation fails with OOM Jul 31, 2026
@juenglin

Copy link
Copy Markdown
Contributor Author

/ok to test

@juenglin juenglin added the P0 High priority - Must do! label Jul 31, 2026
@github-actions

Copy link
Copy Markdown

@juenglin

juenglin commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test

@juenglin

juenglin commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test

@juenglin

juenglin commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test

@juenglin

juenglin commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cuda.core Everything related to the cuda.core module P0 High priority - Must do!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant