Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
abdec47
wip
rparolin Mar 17, 2026
c418050
wip
rparolin Mar 17, 2026
b879fa5
fixing ci compiler errors
rparolin Mar 17, 2026
04ee3de
skipping tests that aren't supported
rparolin Mar 17, 2026
9ab3f46
cu12 support
rparolin Mar 17, 2026
bd75bc3
Merge branch 'main' into rparolin/managed_mem_advise_prefetch
rparolin Mar 17, 2026
1b1343b
Merge branch 'main' into rparolin/managed_mem_advise_prefetch
rparolin Mar 17, 2026
a948066
Moving to function from Buffer class methods to free standing functio…
rparolin Mar 17, 2026
1457599
precommit format
rparolin Mar 17, 2026
acb4024
iterating on implementation
rparolin Mar 18, 2026
d10ab07
Simplify managed-memory helpers: remove long-form aliases, cache look…
rparolin Mar 18, 2026
ae1de36
Merge branch 'main' into rparolin/managed_mem_advise_prefetch
rparolin Mar 18, 2026
c250c92
fix(test): reset _V2_BINDINGS cache so legacy-signature tests take th…
rparolin Mar 18, 2026
89329d9
fix(test): require concurrent_managed_access for advise tests that hi…
rparolin Mar 18, 2026
8a75d1b
fix: validate managed buffer before checking discard_prefetch binding…
rparolin Mar 18, 2026
9e9b1e0
refactor: extract managed memory ops into dedicated _managed_memory_o…
rparolin Mar 18, 2026
90f0711
pre-commit fix
rparolin Mar 18, 2026
b4d252c
Removing blank file
rparolin Mar 19, 2026
faaa1d8
wip
rparolin Mar 19, 2026
18786be
Merge branch 'main' into rparolin/managed_mem_advise_prefetch
rparolin Apr 6, 2026
9766ddc
Merge remote-tracking branch 'upstream/main' into rparolin/managed_me…
rparolin Apr 27, 2026
cf2f20d
fix(cuda.core): update binding_version import after upstream merge
rparolin Apr 27, 2026
db3bac2
revert: drop managed_memory shim in cuda.core.experimental
rparolin Apr 27, 2026
20d036e
feat(cuda.core): add Location dataclass for managed memory
rparolin Apr 27, 2026
c2dae53
feat(cuda.core): add _coerce_location helper
rparolin Apr 28, 2026
935c8ba
test(cuda.core): update monkeypatch target after binding_version rename
rparolin Apr 28, 2026
dc46535
refactor(cuda.core): tighten memory-attr query
rparolin Apr 28, 2026
818f5d2
feat(cuda.core): unified 1..N managed_memory.prefetch with cydriver
rparolin Apr 28, 2026
e296e72
feat(cuda.core): add managed_memory.discard
rparolin Apr 28, 2026
e697131
feat(cuda.core): unified 1..N managed_memory.discard_prefetch with cy…
rparolin Apr 28, 2026
3bc1021
feat(cuda.core): unified 1..N managed_memory.advise + drop legacy app…
rparolin Apr 28, 2026
fa23869
refactor(cuda.core): use Buffer.is_managed property in managed_memory…
rparolin Apr 28, 2026
68bdd14
docs(cuda.core): document Location, discard, and 1..N managed_memory ops
rparolin Apr 28, 2026
b4d9cbf
chore(cuda.core): drop narrative comments and tighten _coerce_locatio…
rparolin Apr 28, 2026
ee96758
chore(cuda.core): satisfy pre-commit hooks
rparolin Apr 28, 2026
d6f60f2
refactor(cuda.core): move managed_memory ops to cuda.core.utils
rparolin Apr 28, 2026
3176271
chore(cuda.core): use __all__ in utils instead of per-import noqa
rparolin Apr 28, 2026
782f6a9
chore(cuda.core): collapse nested if in Location.__post_init__ (SIM102)
rparolin Apr 28, 2026
0789bf6
test(cuda.core): share one DummyUnifiedMemoryResource per batched test
rparolin Apr 28, 2026
e0c782a
test(cuda.core): query all buffers before closing in test_batched_sam…
rparolin Apr 28, 2026
10de998
review(cuda.core): address PR #1775 feedback
rparolin Apr 30, 2026
ab9a3ab
test(cuda.core): split managed-memory ops tests into tests/memory/
rparolin Apr 30, 2026
a3f342f
test(cuda.core): fix options regex for AdviseOptions ("an" vs "a")
rparolin Apr 30, 2026
c2a9662
chore(cuda.core): drop unused utils import + trailing blank lines
rparolin Apr 30, 2026
bede674
feat(cuda.core): add ManagedBuffer subclass + Host location
rparolin Apr 30, 2026
f59af4e
chore(cuda.core): simplify ManagedBuffer per /simplify review
rparolin Apr 30, 2026
5147a7d
ci: re-trigger CI (transient cuInit INVALID_DEVICE on l4 runner)
rparolin Apr 30, 2026
2151e61
refactor(cuda.core): use libcpp.vector for batched-op C arrays (R14)
rparolin May 1, 2026
5c6d054
fix(cuda.core): restore CUDA_ERROR_NOT_INITIALIZED auto-init in _quer…
rparolin May 1, 2026
47d5609
refactor(cuda.core): make Host a plain class instead of a dataclass (R1)
rparolin May 1, 2026
a40bb81
feat(cuda.core)!: drop int location shorthand from managed-memory ops…
rparolin May 1, 2026
c43e81e
docs(cuda.core): add AccessedBySet to api_private.rst (R5)
rparolin May 1, 2026
71e9daa
docs(cuda.core): note the legacy NUMA round-trip limitation on prefer…
rparolin May 1, 2026
df928a0
refactor(cuda.core): use collections.abc.Sequence for input checks (R…
rparolin May 1, 2026
f522916
refactor(cuda.core): narrow Buffer.from_handle to Buffer-only (R3)
rparolin May 1, 2026
6204c57
refactor(cuda.core): single API surface per operation (R9, R10, R11)
rparolin May 1, 2026
36012fd
refactor(cuda.core): build advise reverse-lookup eagerly at module lo…
rparolin May 1, 2026
067fb15
refactor(cuda.core): factor shared body of _do_batch_{prefetch,discar…
rparolin May 1, 2026
a9cd713
test(cuda.core): reuse production _get_int_attr in managed-memory tes…
rparolin May 1, 2026
d75a7bd
feat(cuda.core): cu12 fallback for prefetch_batch (N3)
rparolin May 1, 2026
0af5bd4
test(cuda.core): cover AccessedBySet read methods (N7)
rparolin May 1, 2026
b0d1a21
feat(cuda.core): cu13 NUMA round-trip for ManagedBuffer.preferred_loc…
rparolin May 1, 2026
4c228eb
docs(cuda.core): replace stale utils autosummary entries
rparolin May 1, 2026
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(cuda.core): make Host a plain class instead of a dataclass (R1)
Per Leo's review on PR #1775 (_host.py:9), drop the @DataClass(frozen=True)
in favor of a hand-written class with property accessors. Matches Leo's
original sketch from the 2026-04-28 drive-by comment and aligns with
how Device is structured in this codebase.

Behavior preserved: Host(), Host(numa_id=N), and Host.numa_current()
all work identically. __eq__, __hash__, and immutability are
hand-rolled rather than dataclass-generated.

is_numa_current is no longer an __init__ kwarg — it's internal state
settable only via the Host.numa_current() classmethod. Two existing
TestHost cases updated:
  - test_numa_current_with_id_rejected → test_numa_current_only_via_classmethod
  - test_frozen → test_immutable (AttributeError instead of FrozenInstanceError)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
  • Loading branch information
rparolin and claude committed May 1, 2026
commit 47d5609e98fefeb7896e9a9dcc38c708370990d2
39 changes: 28 additions & 11 deletions cuda_core/cuda/core/_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

from __future__ import annotations

from dataclasses import dataclass


@dataclass(frozen=True)
class Host:
"""Host (CPU) location for managed-memory operations.

Expand All @@ -22,19 +19,39 @@ class Host:
and to ``ManagedBuffer.preferred_location`` / ``accessed_by``.
"""

numa_id: int | None = None
is_numa_current: bool = False
__slots__ = ("_is_numa_current", "_numa_id")

def __init__(self, numa_id: int | None = None) -> None:
if numa_id is not None and (not isinstance(numa_id, int) or numa_id < 0):
raise ValueError(f"numa_id must be a non-negative int, got {numa_id!r}")
object.__setattr__(self, "_numa_id", numa_id)
object.__setattr__(self, "_is_numa_current", False)

@property
def numa_id(self) -> int | None:
return self._numa_id

def __post_init__(self) -> None:
if self.is_numa_current and self.numa_id is not None:
raise ValueError("Host.numa_current() cannot have an explicit numa_id")
if self.numa_id is not None and (not isinstance(self.numa_id, int) or self.numa_id < 0):
raise ValueError(f"numa_id must be a non-negative int, got {self.numa_id!r}")
@property
def is_numa_current(self) -> bool:
return self._is_numa_current

@classmethod
def numa_current(cls) -> Host:
"""Construct a ``Host`` referring to the calling thread's NUMA node."""
return cls(is_numa_current=True)
h = cls()
object.__setattr__(h, "_is_numa_current", True)
return h

def __setattr__(self, name: str, value) -> None:
raise AttributeError(f"{type(self).__name__} is immutable; cannot set {name!r}")

def __eq__(self, other: object) -> bool:
if not isinstance(other, Host):
return NotImplemented
return self._numa_id == other._numa_id and self._is_numa_current == other._is_numa_current

def __hash__(self) -> int:
return hash((Host, self._numa_id, self._is_numa_current))

def __repr__(self) -> str:
if self.is_numa_current:
Expand Down
13 changes: 6 additions & 7 deletions cuda_core/tests/memory/test_managed_ops.py
Comment thread
rparolin marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,14 @@ def test_invalid_numa_id(self):
with pytest.raises(ValueError, match="numa_id must be a non-negative int"):
Host(numa_id=-1)

def test_numa_current_with_id_rejected(self):
with pytest.raises(ValueError, match="numa_current"):
Host(numa_id=0, is_numa_current=True)

def test_frozen(self):
import dataclasses
def test_numa_current_only_via_classmethod(self):
# is_numa_current is internal state, only settable via Host.numa_current()
with pytest.raises(TypeError):
Host(is_numa_current=True) # type: ignore[call-arg]

def test_immutable(self):
h = Host(numa_id=2)
with pytest.raises(dataclasses.FrozenInstanceError):
with pytest.raises(AttributeError):
h.numa_id = 3

def test_eq_hash(self):
Expand Down
Loading