Skip to content

Commit 83b2de7

Browse files
authored
cuda.core: report host accessibility for NUMA-located VMM resources (#2503)
`VirtualMemoryResource.__init__` classifies "host", "host_numa" and "host_numa_current" all as host-located (it clears `self.device` for each), but `is_host_accessible` compared with `== "host"`. A resource configured with `location_type="host_numa"` or `"host_numa_current"` therefore reported `is_host_accessible is False` *and* `is_device_accessible is False` -- an impossible answer that propagates to `Buffer.is_host_accessible`, which forwards to the memory resource. Share a single `_HOST_LOCATION_TYPES` set between the constructor and the property so the two classifications cannot drift again.
1 parent 5199241 commit 83b2de7

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

cuda_core/cuda/core/_memory/_virtual_memory_resource.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@
3333

3434
__all__ = ["VirtualMemoryResource", "VirtualMemoryResourceOptions"]
3535

36+
# Location types whose physical backing lives in host memory. Shared by
37+
# VirtualMemoryResource.__init__ and is_host_accessible so the two cannot drift.
38+
_HOST_LOCATION_TYPES = frozenset(
39+
{
40+
VirtualMemoryLocationType.HOST,
41+
VirtualMemoryLocationType.HOST_NUMA,
42+
VirtualMemoryLocationType.HOST_NUMA_CURRENT,
43+
}
44+
)
45+
3646

3747
@dataclass
3848
class VirtualMemoryResourceOptions:
@@ -169,8 +179,7 @@ def __init__(self, device_id: Device | int, config: VirtualMemoryResourceOptions
169179
self.config: VirtualMemoryResourceOptions = check_or_create_options( # type: ignore[assignment]
170180
VirtualMemoryResourceOptions, config, "VirtualMemoryResource options", keep_none=False
171181
)
172-
# Matches ("host", "host_numa", "host_numa_current")
173-
if "host" in self.config.location_type:
182+
if self.config.location_type in _HOST_LOCATION_TYPES:
174183
self.device = None
175184

176185
if not self.device and self.config.location_type == "device":
@@ -609,7 +618,7 @@ def is_host_accessible(self) -> bool:
609618
"""
610619
Indicates whether the allocated memory is accessible from the host.
611620
"""
612-
return self.config.location_type == "host"
621+
return self.config.location_type in _HOST_LOCATION_TYPES
613622

614623
@property
615624
def device_id(self) -> int:

cuda_core/tests/test_memory.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,6 +1875,23 @@ def test_vmm_options_handle_type_win32_raises():
18751875
VirtualMemoryResourceOptions._handle_type_to_driver("win32")
18761876

18771877

1878+
@pytest.mark.agent_authored(model="claude-opus-5")
1879+
@pytest.mark.parametrize("location_type", ["host", "host_numa", "host_numa_current"])
1880+
def test_vmm_host_location_types_report_host_accessible(location_type):
1881+
"""Every host-backed location type reports is_host_accessible.
1882+
1883+
__init__ classifies "host", "host_numa" and "host_numa_current" alike when
1884+
deciding the resource is not bound to a device, so is_host_accessible must
1885+
agree; otherwise a NUMA-located resource claims to be neither host- nor
1886+
device-accessible.
1887+
"""
1888+
device = Device()
1889+
device.set_current()
1890+
mr = VirtualMemoryResource(device, config=VirtualMemoryResourceOptions(location_type=location_type))
1891+
assert mr.device is None
1892+
assert mr.is_host_accessible is True
1893+
1894+
18781895
def test_device_memory_resource_peer_accessible_by_non_owned(mempool_device):
18791896
"""peer_accessible_by on a non-owned (default) DMR queries the driver live."""
18801897
dev = mempool_device

0 commit comments

Comments
 (0)