Skip to content

Commit 03124f4

Browse files
committed
Hide handle as an implementation detail
1 parent 533f158 commit 03124f4

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

cuda_core/cuda/core/system/_device.pyx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ cdef class EventData:
188188
"""
189189
The device on which the event occurred.
190190
"""
191-
return Device(handle=self._event_data.device)
191+
device = Device.__new__()
192+
device._handle = self._event_data.device
193+
return device
192194

193195
@property
194196
def event_type(self) -> EventType:
@@ -555,17 +557,16 @@ cdef class Device:
555557
index: int | None = None,
556558
uuid: bytes | str | None = None,
557559
pci_bus_id: bytes | str | None = None,
558-
handle: int | None = None
559560
):
560-
initialize()
561-
562-
args = [index, uuid, pci_bus_id, handle]
561+
args = [index, uuid, pci_bus_id]
563562
cdef int arg_count = sum(arg is not None for arg in args)
564563

565564
if arg_count > 1:
566-
raise ValueError("Handle requires only one of `index`, `uuid`, `pci_bus_id` or `handle`.")
565+
raise ValueError("Handle requires only one of `index`, `uuid`, or `pci_bus_id`.")
567566
if arg_count == 0:
568-
raise ValueError("Handle requires either a device `index`, `pci_bus_id`, or `uuid`.")
567+
raise ValueError("Handle requires either a device `index`, `uuid`, or `pci_bus_id`.")
568+
569+
initialize()
569570

570571
if index is not None:
571572
self._handle = nvml.device_get_handle_by_index_v2(index)
@@ -577,8 +578,6 @@ cdef class Device:
577578
if isinstance(pci_bus_id, bytes):
578579
pci_bus_id = pci_bus_id.decode("ascii")
579580
self._handle = nvml.device_get_handle_by_pci_bus_id_v2(pci_bus_id)
580-
elif handle is not None:
581-
self._handle = handle
582581

583582
@classmethod
584583
def get_all_devices(cls) -> Iterable[Device]:

0 commit comments

Comments
 (0)