Skip to content

test(cuda.core): run the managed-memory concurrent-access warning tests - #3651

Open
mdboom wants to merge 2 commits into
NVIDIA:mainfrom
mdboom:issue3573
Open

mdboom wants to merge 2 commits into
NVIDIA:mainfrom
mdboom:issue3573

Conversation

@mdboom

@mdboom mdboom commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes #3573. Part of #2077.

Summary

test_warning_emitted and test_warning_emitted_only_once needed a GPU that supports managed memory pools but lacks concurrent managed access. No CI platform has that combination, so both tests skipped everywhere.

The once-per-process warning check now reads the attribute through the existing public property instead of calling the driver itself, and the tests fake that property, with no test hook in production code:

 cdef inline _check_concurrent_managed_access():
     if _concurrent_access_warned: return          # every call after the first returns here
     with _concurrent_access_lock:
         ...
-        cuDeviceGetAttribute(&c_concurrent, CONCURRENT_MANAGED_ACCESS, 0)
-        if not c_concurrent:
+        if not Device(0).properties.concurrent_managed_access:
             warnings.warn(...)
         _concurrent_access_warned = True
 tests/test_managed_memory_warning.py
+class _PropertiesWithoutConcurrentManagedAccess:   # reports concurrent_managed_access = False,
+    ...                                            # delegates everything else to the real properties
 @pytest.fixture
 def faked_no_concurrent_managed_access(init_cuda, monkeypatch):
+    monkeypatch.setattr(Device, "properties", property(lambda self: _PropertiesWithoutConcurrentManagedAccess(...)))
     reset_concurrent_access_warning()
  • Only the property value is faked. Creating the resource, the warning text and category, and the once-per-process lock all run for real.
  • The check still queries device 0 (the attribute is system-wide on sm_60+) and still runs once per process, so resource creation after the first pays nothing extra.
  • Device is a Python class and properties an ordinary property, so the patch needs no production support; monkeypatch restores it. The two tests are marked thread_unsafe because the patch and the warning flag are process-wide.
  • test_default_pool_error_without_concurrent_access still needs real hardware, because it tests the driver's own behavior.
  • The "not currently run in any CI job" markers are removed.

Evidence

CI coverage: the two tests should now run in the 31 CI configurations where the existing ManagedMemoryResource tests (for example test_mempool_attributes[ManagedMemoryResource-...]) pass on main. Those are every Linux CUDA 13 row, CTK 13.0.2 and 13.5.0 on x86-64 and aarch64, on T4, L4, A100, H100, GB300, GH200, RTX PRO 6000 and the 2-GPU rows. Windows and CUDA 12 rows skip, as the other managed-memory tests do.

Locally (cuda.core built from this branch): both warning tests pass. The local GPU does support concurrent managed access, so the warning fires only because the property is patched. The managed-memory tests in test_memory.py pass (41 passed, 8 skipped).

Confirming in CI: in this PR's CI run, the Linux CUDA 13 cuda.core jobs should report both tests PASSED, where main reports them SKIPPED. For example:

gh run view <CI run id> --repo NVIDIA/cuda-python --log | grep -E "test_managed_memory_warning.py::test_warning_emitted"

Merge Danger

Door: two-way.

Blast Radius: small. The production change replaces one direct cuDeviceGetAttribute call with the cached Device(0).properties.concurrent_managed_access lookup, in a check that runs once per process; the warning behavior is unchanged.

Reviewers: please feel free to push commits directly to this PR to improve it.

🤖 Generated with Claude Code

test_warning_emitted and test_warning_emitted_only_once needed a GPU that
supports managed memory pools but lacks concurrent managed access. No CI
platform has that combination, so they never ran.

Add a private _set_concurrent_managed_access_for_testing hook that
overrides the CU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS value the
warning check sees (a cdef int, so the check stays a direct C call). Only
the attribute value is faked: resource creation, the warning and its
once-per-process lock run for real. A new fixture sets the override and
resets the warning flag, and restores both afterwards.

test_default_pool_error_without_concurrent_access still needs real hardware,
since it tests the driver's own behavior.

Remove the "not currently run in any CI job" markers.

Closes NVIDIA#3573.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mdboom mdboom added this to the cuda.core 1.4.0 milestone Nov 30, 2026
@mdboom mdboom added test Improvements or additions to tests cuda.core Everything related to the cuda.core module labels Nov 30, 2026
@mdboom mdboom self-assigned this Nov 30, 2026
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Explain Change →

Summary

Summary by CodeRabbit

  • Bug Fixes
    • The managed-memory warning now reflects the device’s reported concurrent-access support. When that support is unavailable, the warning continues to appear only once.
  • Tests
    • Warning behavior is tested across simulated device capability states. Tests that require memory-pool support skip devices that do not provide it.

The concurrent-managed-access warning check now reads Device(0).properties.concurrent_managed_access. Both warning tests patch that property to simulate a device without concurrent managed access and reset warning state around each test.

Changes: Managed-access warning tests

Layer / File(s) Summary
Property check and warning tests
cuda_core/cuda/core/_memory/_managed_memory_resource.pyx, cuda_core/tests/test_managed_memory_warning.py
The check reads concurrent managed access from Device.properties. The tests patch the property, reset warning state, and test warning emission and once-only behavior. The tests skip devices without memory-pool support and are marked thread-unsafe.

Assessment against linked issues

Objective Addressed Explanation
Allow both warning tests to simulate a device without concurrent managed access while retaining real resource creation and warning behavior [#3573] ✅

Suggested reviewers: andy-jost, juenglin

Change: Other · Severity of issue fixed: Low

Merge Risk: Minimal · up to 6dba0

This change moves the managed-memory concurrent-access warning check onto Device.properties and lets the warning tests simulate a missing capability. It has no apparent production impact, since the warning condition and once-per-process behavior are unchanged. The risk of merging is minimal.

Security architecture risk: Low · up to 6dba0

The warning still checks the same GPU capability and does not change memory permissions. The new lookup can leave an incomplete device cache on the calling thread if its first initialization fails, so retrying on that thread may not recover.

Retained concerns

  • Trivial · reliability · inferred: The new warning path can publish an incomplete thread-local Device list. If allocation fails before the first entry is appended, later Device(0) lookups on that thread reuse the empty list instead of rebuilding it, and managed-memory construction can keep failing despite the warning check being eligible to retry. The cache behavior predates the PR; the new exposure is from constructors that previously reached the warning check without initializing that cache.

View findings in the submitted review

Security review details

Security Blast Radius

  • inferred — The supported recovery issue is confined to the initializing thread's cache. The warning flag is process-wide, but a failed lookup does not mark it complete or prevent another thread with a usable cache from completing the check.

Trust Boundaries and Controls

  • observed — The production lookup still uses the fixed device ordinal 0 and the same driver capability. It does not select a device from caller input or switch the current CUDA context.

Resilience and Maintainability Implications

  • observed — The post-pool diagnostic does not change pool ownership. The dedicated-pool handle retains its last-reference deleter; the current-pool path still borrows its handle.

Hardening Proposals

  • proposed — Build the Device list locally and publish it to thread-local storage only after all entries are initialized, so a failed first attempt leaves the next call free to rebuild it.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@github-actions

Copy link
Copy Markdown
Contributor

…on test hook

Remove _set_concurrent_managed_access_for_testing and its override global
from _managed_memory_resource. The once-per-process warning check now reads
Device(0).properties.concurrent_managed_access instead of calling
cuDeviceGetAttribute itself, so the tests can monkeypatch Device.properties
with a proxy that reports no concurrent managed access.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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.

Architecture findings (1)

Advisory architecture findings (1)

  • Trivial — The new warning path can publish an incomplete thread-local Device list. If allocation fails before the first entry is appended, later Device(0) lookups on that thread reuse the empty list instead of rebuilding it, and managed-memory construction can keep failing despite the warning check being eligible to retry. The cache behavior predates the PR; the new exposure is from constructors that previously reached the warning check without initializing that cache.
Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 8d24882 and 6dba05a.

Files selected for processing: 2

  • cuda_core/cuda/core/_memory/_managed_memory_resource.pyx
  • cuda_core/tests/test_managed_memory_warning.py

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

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.core Everything related to the cuda.core module test Improvements or additions to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(cuda.core): add a test hook so the concurrent-managed-access warning tests run

1 participant