Skip to content

Commit 4ffb490

Browse files
committed
fix(cuda.core): gate cu13 managed-memory paths on driver version, not bindings only
Per PR NVIDIA#1775 review feedback (leofang). The cu13 paths in _managed_buffer.preferred_location and _reject_numa_host_on_cuda12 gated on binding_version() >= (13, 0, 0) only, mirroring the regressions that PR NVIDIA#2054 and PR NVIDIA#2064 fixed for other modules. With cuda-bindings 13.x installed but a CUDA 12.x runtime driver, the v2 CU_MEM_RANGE_ATTRIBUTE_PREFERRED_LOCATION_* attributes and the HOST_NUMA{,_CURRENT} location types fail deep in the driver with CUDA_ERROR_INVALID_VALUE. Both checks now AND driver_version() >= (13, 0, 0) into the gate, and the _reject_numa_host_on_cuda12 error message names both required versions.
1 parent 98c7671 commit 4ffb490

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

cuda_core/cuda/core/_memory/_managed_buffer.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
_read_preferred_location_v2,
1818
)
1919
from cuda.core._utils.cuda_utils import driver, handle_return
20-
from cuda.core._utils.version import binding_version
20+
from cuda.core._utils.version import binding_version, driver_version
2121

2222
if TYPE_CHECKING:
2323
from cuda.core._memory._buffer import MemoryResource
@@ -182,9 +182,14 @@ def preferred_location(self) -> Device | Host | None:
182182
host), so ``Host(numa_id=N)`` set via the setter round-trips back
183183
as ``Host()``.
184184
"""
185-
if binding_version() >= (13, 0, 0):
185+
# The v2 path uses CU_MEM_RANGE_ATTRIBUTE_PREFERRED_LOCATION_{TYPE,ID},
186+
# both added in CUDA 13. Require both bindings and the runtime driver
187+
# to be 13.0+; otherwise fall back to the legacy device-ordinal path.
188+
# See PR #2054 / #2064 for prior bindings-only-check regressions.
189+
if binding_version() >= (13, 0, 0) and driver_version() >= (13, 0, 0):
186190
return _read_preferred_location_v2(self)
187-
# CUDA 12 legacy path (no NUMA info available).
191+
# CUDA 12 legacy path (no NUMA info available; also taken when
192+
# bindings are 13.x but the runtime driver is still 12.x).
188193
loc_id = _get_int_attr(self, _ATTR_PREFERRED)
189194
if loc_id == -2:
190195
return None

cuda_core/cuda/core/_memory/_managed_location.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from dataclasses import dataclass
77
from typing import Literal
88

9-
from cuda.core._utils.version import binding_version
9+
from cuda.core._utils.version import binding_version, driver_version
1010

1111
_LocationKind = Literal["device", "host", "host_numa", "host_numa_current"]
1212

@@ -34,11 +34,15 @@ def _reject_numa_host_on_cuda12(spec: _LocSpec) -> None:
3434
deep inside the Cython layer with ``RuntimeError``, raise a
3535
``TypeError`` at the call boundary with actionable wording.
3636
"""
37-
if binding_version() >= (13, 0, 0):
37+
# The host-NUMA kinds map to CU_MEM_LOCATION_TYPE_HOST_NUMA{,_CURRENT},
38+
# both added in CUDA 13. Require both bindings and the runtime driver to
39+
# be 13.0+; bindings-only is insufficient (PR #2054 / #2064 precedent).
40+
if binding_version() >= (13, 0, 0) and driver_version() >= (13, 0, 0):
3841
return
3942
if spec.kind in ("host_numa", "host_numa_current"):
4043
raise TypeError(
41-
"Host(numa_id=...) / Host.numa_current() require a CUDA 13 build of cuda.core; use Host() on CUDA 12"
44+
"Host(numa_id=...) / Host.numa_current() require both cuda-bindings 13.0+ "
45+
"and a CUDA 13+ runtime driver; use Host() instead"
4246
)
4347

4448

0 commit comments

Comments
 (0)