Skip to content

Commit b712677

Browse files
committed
test(cuda.core): skip default managed pool tests without concurrent managed access
create_managed_memory_resource_or_skip() with no options looks up the device's default managed pool (cuMemGetMemPool with CU_MEM_ALLOCATION_TYPE_MANAGED). Without concurrent managed access that pool does not support managed allocations. _MMR_init turns CUDA_ERROR_NOT_SUPPORTED from the lookup into a RuntimeError that the helper skips on, but on some Windows MCDM machines the driver returns CUDA_ERROR_OUT_OF_MEMORY instead, so the tests fail. Check concurrent_managed_access before the lookup for the no-options case. Calls with options create a dedicated pool, which works without concurrent managed access, and are unchanged.
1 parent 106da2f commit b712677

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

‎cuda_core/tests/helpers/memory.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import pytest
77

8-
from cuda.core import ManagedMemoryResource, PinnedMemoryResource
8+
from cuda.core import Device, ManagedMemoryResource, PinnedMemoryResource
99
from cuda.core._utils.cuda_utils import CUDAError
1010

1111

@@ -33,6 +33,13 @@ def skip_if_managed_memory_unsupported(device):
3333

3434
def create_managed_memory_resource_or_skip(*args, xfail_device=None, **kwargs):
3535
# Keep the established "skip" helper name for call-site readability.
36+
if not args and kwargs.get("options") is None and not Device().properties.concurrent_managed_access:
37+
# Without options this looks up the device's default managed pool, which
38+
# supports managed allocations only with concurrent managed access. Check
39+
# the property instead of the lookup's error: the driver returns
40+
# CUDA_ERROR_NOT_SUPPORTED on some machines and CUDA_ERROR_OUT_OF_MEMORY
41+
# on others. Dedicated pools (options given) work without it.
42+
pytest.skip("Device does not support concurrent managed memory access")
3643
try:
3744
return ManagedMemoryResource(*args, **kwargs)
3845
except CUDAError as e:

‎cuda_core/tests/test_helpers.py‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from helpers.buffers import PatternGen, compare_equal_buffers, make_scratch_buffer, thread_unsafe_on_windows
1313
from helpers.latch import LatchKernel
1414
from helpers.logging import TimestampedLogger
15+
from helpers.memory import create_managed_memory_resource_or_skip
1516
from helpers.oom_diagnostics import (
1617
DEFAULT_FILENAME,
1718
OOM_MARKER,
@@ -467,3 +468,40 @@ def test_gl_context_not_on_nvidia_gpu_reason_rejects_other_vendors(monkeypatch,
467468
reason = gl_context_not_on_nvidia_gpu_reason()
468469
assert reason is not None
469470
assert "not on an NVIDIA GPU" in reason
471+
472+
473+
def _patch_managed_mr_factory(monkeypatch, concurrent_managed_access):
474+
# Stand in for the helper's Device and ManagedMemoryResource so the skip
475+
# decision does not depend on the local device.
476+
device = types.SimpleNamespace(
477+
properties=types.SimpleNamespace(concurrent_managed_access=concurrent_managed_access)
478+
)
479+
monkeypatch.setattr("helpers.memory.Device", lambda: device)
480+
factory = Mock(name="ManagedMemoryResource")
481+
monkeypatch.setattr("helpers.memory.ManagedMemoryResource", factory)
482+
return factory
483+
484+
485+
@pytest.mark.thread_unsafe(reason="patches module globals of helpers.memory")
486+
@pytest.mark.agent_authored(model="claude-opus-5.5")
487+
def test_managed_mr_helper_skips_default_pool_without_concurrent_access(monkeypatch):
488+
factory = _patch_managed_mr_factory(monkeypatch, concurrent_managed_access=False)
489+
with pytest.raises(pytest.skip.Exception, match="concurrent managed memory access"):
490+
create_managed_memory_resource_or_skip()
491+
factory.assert_not_called()
492+
493+
494+
@pytest.mark.thread_unsafe(reason="patches module globals of helpers.memory")
495+
@pytest.mark.parametrize(
496+
("concurrent_managed_access", "args", "kwargs"),
497+
[
498+
pytest.param(False, ("options",), {}, id="positional-options"),
499+
pytest.param(False, (), {"options": "options"}, id="keyword-options"),
500+
pytest.param(True, (), {}, id="default-pool-with-concurrent-access"),
501+
],
502+
)
503+
@pytest.mark.agent_authored(model="claude-opus-5.5")
504+
def test_managed_mr_helper_constructs_when_pool_is_usable(monkeypatch, concurrent_managed_access, args, kwargs):
505+
factory = _patch_managed_mr_factory(monkeypatch, concurrent_managed_access)
506+
assert create_managed_memory_resource_or_skip(*args, **kwargs) is factory.return_value
507+
factory.assert_called_once_with(*args, **kwargs)

0 commit comments

Comments
 (0)