Skip to content

test(bindings): use a capped mempool in test_interop_memPool - #3011

Open
juenglin wants to merge 4 commits into
NVIDIA:mainfrom
juenglin:cython-memPool-capped-pool
Open

juenglin wants to merge 4 commits into
NVIDIA:mainfrom
juenglin:cython-memPool-capped-pool

Conversation

@juenglin

@juenglin juenglin commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Description

follow-on to #2381

test_interop_memPool in the cuda_bindings Cython and Python tests used the device's default memory pool. Creating the default pool reserves virtual address space of roughly twice the installed device memory, and that reservation is not returned for the lifetime of the process. On address-space-constrained systems this can fail with CUDA_ERROR_OUT_OF_MEMORY even when plenty of device memory is free, which is the failure mode described in #2381. It also follows the convention in cuda_core/tests/AGENTS.md: tests that need a pool should create a capped one.

This PR changes both tests to:

  • create a small pool (maxSize = 2 MiB) with cuMemPoolCreate
  • set it with cudaDeviceSetMemPool
  • read it back with cudaDeviceGetMemPool and assert it is the same handle, then pass it to cuDeviceSetMemPool
  • destroy the pool before destroying the context

The capped pool is set before it is queried because cuDeviceGetMemPool and cudaDeviceGetMemPool also create the default pool when no pool has been set. Running the test no longer grows the process virtual size (5 GiB before and after, measured locally on an RTX 6000 Ada).

Both tests still check the driver/runtime handle round trip. The Python test no longer needs the xfail_if_mempool_oom guard. The two *GetDefaultMemPool calls are no longer made in either test, so cuda_bindings no longer exercises them directly.

Checklist

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

The default mempool reserves ~2x device memory of virtual address space
on first use, which cannot be satisfied in a 39-bit address space
(riscv64 Sv39) and made the test flaky. Create a 2 MiB pool instead and
set it before querying it, since the pool getters also create the
default pool.
@copy-pr-bot

copy-pr-bot Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@juenglin juenglin self-assigned this Oct 2, 2026
@github-actions github-actions Bot added the cuda.bindings Everything related to the cuda.bindings module label Oct 2, 2026
@juenglin juenglin added the test Improvements or additions to tests label Oct 2, 2026
@juenglin juenglin added this to the cuda.bindings next milestone Oct 2, 2026
@juenglin

juenglin commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test a8c7196

@juenglin
juenglin requested a review from rwgk October 2, 2026 21:42
@juenglin
juenglin marked this pull request as ready for review October 2, 2026 21:53
Mirror the Cython change: create a 2 MiB pool and set it before
querying it, so the test no longer creates the default pool and no
longer needs the xfail_if_mempool_oom guard.
@juenglin juenglin changed the title test(cython): use a capped mempool in test_interop_memPool test(bindings): use a capped mempool in test_interop_memPool Oct 2, 2026
@juenglin

juenglin commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 870ea5d

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

@rwgk rwgk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed this PR with codex, then went ahead and made the one simple suggested fix under commit ff06d41.

I'm not familiar with the tested production code, so I used codex to narrate the changes with relevant background to me. I'm approving based on what I learned through that narration. (I'm intentionally not posting the narration because it's tailored to me.)


codex GPT-6.1-Sol ultra findings

[P2] Both mempool tests need serialization. The new Python Set/Get sequence and Cython equivalent each install a distinct pool on device 0. CUDA’s current pool is device state, and free-threaded CI runs four concurrent copies. This permits:

  • Worker A sets pool A.
  • Worker B sets pool B.
  • Worker A reads pool B and fails the identity assertion.

Previously, all workers selected the same default pool. Add @pytest.mark.thread_unsafe(reason="changes the device's current memory pool") to both tests; the pytest plugin supports this serialization.

I found no other substantive defects. The capped-pool approach fits the background, handle conversions look correct, and CUDA documents that destroying the current pool restores the default selection. Two nonblocking points remain: Cython cleanup should mirror Python’s try/finally, and removing the default-pool getters deliberately reduces direct API coverage.

I reviewed both changed files at 870ea5d, the full Slack thread through slack-local-bridge, and issue #2381. All 121 checks are successful or skipped. Logs show both affected tests passing in Linux free-threaded CI and Windows MCDM CI; those passes do not exclude the race. RISC-V/Sv39 behavior remains unverified, and the local environment has no accessible NVIDIA driver for reproduction.

@rwgk

rwgk commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

/ok to test 02fe137

This branch has not been deployed

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

Labels

cuda.bindings Everything related to the cuda.bindings module test Improvements or additions to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants