Skip to content

test(bindings): cap the pools in the memPool attribute tests - #3140

Merged
juenglin merged 3 commits into
NVIDIA:mainfrom
juenglin:test-cap-mempool-attr-pools
Oct 17, 2026
Merged

juenglin merged 3 commits into
NVIDIA:mainfrom
juenglin:test-cap-mempool-attr-pools

Conversation

@juenglin

@juenglin juenglin commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

follow-on to #2381 and #3011

test_cuda_memPool_attr and test_cudart_MemPool_attr create a memory pool with maxSize left at 0. Such a pool reserves virtual address space of about twice the installed device memory. In a 39-bit address space (riscv64 Sv39, 256 GiB of user address space) that reservation fails with CUDA_ERROR_OUT_OF_MEMORY on large-memory GPUs, even though the GPU is nearly empty. Both tests only query and set pool attributes, so they now create a 2 MiB pool (maxSize = POOL_SIZE), the same cap test_interop_memPool uses since #3011.

test_cuda_graphMem_attr allocates from the device's graph memory pool. That pool is managed by the driver and, unlike pools from cuMemPoolCreate, cannot be capped (cuda.h documents no maxSize for CUDA_MEM_ALLOC_NODE_PARAMS.poolProps). Its reservation can still fail in a 39-bit address space, especially when another uncapped pool already exists in the process. The test already had a CUDA_ERROR_OUT_OF_MEMORY branch from #2000 that cleaned up the graph and stream, but since #3004 removed the xfail helper it then fell through to the failing assertion. This PR adds a local xfail_on_graph_mempool_oom fixture that the branch calls after cleanup, so the test reports XFAIL instead of failing when graph memory pool creation runs out of address space.

Validation:

  • The three tests pass on x86_64 with an RTX 6000 Ada.
  • With cuGraphAddMemAllocNode patched to return CUDA_ERROR_OUT_OF_MEMORY, test_cuda_graphMem_attr reports XFAIL.
  • Not yet run on a machine with a 96 GB GPU, where the original failures were seen.

Checklist

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

test_cuda_memPool_attr and test_cudart_MemPool_attr created pools with
maxSize 0, which reserves virtual address space of about twice the
device memory. In a 39-bit address space (riscv64 Sv39) this fails with
CUDA_ERROR_OUT_OF_MEMORY on large-memory GPUs. Create 2 MiB pools
instead; the tests only query and set pool attributes.

The graph memory pool used by test_cuda_graphMem_attr cannot be capped
the same way, so xfail that test when cuGraphAddMemAllocNode returns
CUDA_ERROR_OUT_OF_MEMORY. Previously the OOM branch cleaned up and then
failed the assertion.
@juenglin juenglin added this to the cuda.bindings next milestone Oct 16, 2026
@juenglin juenglin added test Improvements or additions to tests cuda.bindings Everything related to the cuda.bindings module labels Oct 16, 2026
@copy-pr-bot

copy-pr-bot Bot commented Oct 16, 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 16, 2026
@juenglin
juenglin requested a review from rwgk October 16, 2026 22:56
@juenglin

Copy link
Copy Markdown
Contributor Author

/ok to test c183f19

@juenglin
juenglin marked this pull request as ready for review October 16, 2026 23:01
@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

📝 Summary

Summary by CodeRabbit

  • Tests
    • CUDA memory-pool tests now use a 2 MiB allocation limit, reducing the risk of failures on systems with limited virtual address space.
    • Graph memory-pool tests now report out-of-memory allocation results as expected test failures after cleaning up associated resources.

The memory-pool tests set a 2 MiB maximum pool size. The graph memory-pool test marks allocation failures with CUDA_ERROR_OUT_OF_MEMORY as expected failures after cleanup.

Changes: Memory pool tests

Layer / File(s) Summary
Cap test memory pools
cuda_bindings/tests/test_cuda.py, cuda_bindings/tests/test_cudart.py
Both test modules set poolProps.maxSize to 2 MiB.
Handle graph pool allocation failures
cuda_bindings/tests/test_cuda.py
The graph memory-pool test checks allocation errors after graph and stream cleanup. It marks CUDA_ERROR_OUT_OF_MEMORY as an expected failure.

Priority: ➖ Normal

Change: Bug fix

Merge Risk: 🔵 Low · up to c183f

The graph-memory test can report XFAIL for an allocation regression as well as for address-space exhaustion, weakening CI’s signal. Narrowing the expected failure is advisable; the issue is limited to test reporting.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: NVIDIA/cuda-python/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 08bf1385-72e9-418d-9e6c-efea69bae525
📥 Commits

Reviewing files that changed from the base of the PR and between e8dacbc and c183f19.

📒 Files selected for processing: 2
  • cuda_bindings/tests/test_cuda.py
  • cuda_bindings/tests/test_cudart.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 9 remain after this review.

Comment on lines +469 to +484
@pytest.fixture
def xfail_on_graph_mempool_oom():
"""Return a check that xfails the calling test if the graph memory pool cannot be created.

The graph memory pool reserves virtual address space of about twice the
device memory, and unlike pools from cuMemPoolCreate it cannot be capped.
On systems with a limited virtual address space this reservation can fail
with CUDA_ERROR_OUT_OF_MEMORY, especially when another uncapped pool
already exists in the process.
"""

def check(err):
if err == cuda.CUresult.CUDA_ERROR_OUT_OF_MEMORY:
pytest.xfail("graph memory pool creation failed with CUDA_ERROR_OUT_OF_MEMORY")

return check

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '450,530p' cuda_bindings/tests/test_cuda.py
rg -n 'xfail_on_graph_mempool_oom|cuGraphAddMemAllocNode|test_cuda_graphMem_attr|CUDA_ERROR_OUT_OF_MEMORY' cuda_bindings/tests/test_cuda.py

Repository: NVIDIA/cuda-python

Length of output: 4065


🏁 Script executed:

# Read the complete graph-memory test and locate the device fixture and API declaration/docs
sed -n '485,570p' cuda_bindings/tests/test_cuda.py
rg -n -F --glob '*.py' -e 'def device' -e 'deviceGetAttribute' -e 'cuGraphAddMemAllocNode' cuda_bindings/tests tests || test "$?" -eq 1
rg -n -F --glob '*.{py,pyx,pxd,c,h}' -e 'cuGraphAddMemAllocNode' cuda_bindings | head -40

Repository: NVIDIA/cuda-python

Length of output: 9972


🏁 Script executed:

sed -n '46384,46520p' cuda_bindings/cuda/bindings/driver.pyx
sed -n '145,195p' cuda_bindings/tests/conftest.py
rg -n -F --glob '*.py' -e 'cuDeviceTotalMem' -e 'CU_DEVICE_ATTRIBUTE_TOTAL_CONSTANT_MEMORY' -e 'cuDeviceGetAttribute' cuda_bindings/tests/conftest.py cuda_bindings/tests/test_cuda.py | head -80

Repository: NVIDIA/cuda-python

Length of output: 8642


🌐 Web query:

official CUDA Driver API cuGraphAddMemAllocNode CUDA_ERROR_OUT_OF_MEMORY virtual address space graph memory pool

💡 Result:

**`cuGraphAddMemAllocNode` does not list `CUDA_ERROR_OUT_OF_MEMORY` as a documented return value** in the CUDA Driver API 13.4 reference. Its listed results are `CUDA_SUCCESS`, `CUDA_ERROR_DEINITIALIZED`, `CUDA_ERROR_NOT_INITIALIZED`, and `CUDA_ERROR_INVALID_VALUE`. The reference does caution that the call may also surface errors from earlier asynchronous launches. ([docs.nvidia.com](https://docs.nvidia.com/cuda/cuda-driver-api/cuda_driver_api/group__CUDA__GRAPH.html))

The API assigns the allocation’s virtual address when the node is created, and that address stays fixed across graph instantiations and launches. CUDA can reuse virtual address ranges for allocations whose graph-ordered lifetimes do not overlap, and can reuse physical memory across graphs that do not execute simultaneously. ([docs.nvidia.com](https://docs.nvidia.com/cuda/cuda-driver-api/cuda_driver_api/group__CUDA__GRAPH.html))

**What the docs don’t establish:** they don’t say that `CUDA_ERROR_OUT_OF_MEMORY` from this call specifically means virtual-address-space exhaustion, nor do they document that this call allocates from a user-selected memory pool. So that diagnosis cannot be concluded from the return-code list alone. Check which CUDA operation actually reports the error and whether it’s a prior asynchronous error; separately inspect graph-memory usage with `cuDeviceGetGraphMemAttribute` and consider `cuDeviceGraphMemTrim` for unused cached graph memory. ([docs.nvidia.com](https://docs.nvidia.com/cuda/cuda-driver-api/cuda_driver_api/group__CUDA__GRAPH.html))

Citations:

- 1: https://docs.nvidia.com/cuda/cuda-driver-api/cuda_driver_api/group__CUDA__GRAPH.html
- 2: https://docs.nvidia.com/cuda/cuda-driver-api/cuda_driver_api/group__CUDA__GRAPH.html
- 3: https://docs.nvidia.com/cuda/cuda-driver-api/cuda_driver_api/group__CUDA__GRAPH.html

suggestion: Gate this XFAIL on the known virtual-address-space limitation.

params.bytesize is 1, but cuGraphAddMemAllocNode returns only a CUresult; this branch does not identify why the driver returned CUDA_ERROR_OUT_OF_MEMORY. Any unrelated allocation or driver regression with the same result skips the success assertion and all graph-memory assertions. The API documentation does not define this error as a virtual-address-space-specific result. Use a predicate that identifies the known address-space configuration; otherwise let the error fail the test. pytest.skip and xfail(strict=False) would not narrow this condition.

@github-actions

Copy link
Copy Markdown
Contributor

@juenglin
juenglin merged commit 6bc28b0 into NVIDIA:main Oct 17, 2026
107 checks passed
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