Skip to content

Commit fc642d1

Browse files
committed
Change which uuid API is "default"
1 parent 8d316b9 commit fc642d1

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

cuda_core/cuda/core/system/_device.pyx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,20 @@ cdef class Device:
133133
board serial identifier.
134134

135135
In the upstream NVML C++ API, the UUID includes a ``gpu-`` or ``mig-``
136-
prefix. If you want that prefix, use the `uuid_with_prefix` property.
136+
prefix. If you a `uuid` without that prefix (for example, to interact
137+
with CUDA), use the `uuid_without_prefix` property.
137138
"""
138-
# NVML UUIDs have a `GPU-` or `MIG-` prefix. We remove that here.
139-
return nvml.device_get_uuid(self._handle)[4:]
139+
return nvml.device_get_uuid(self._handle)
140140

141141
@property
142-
def uuid_with_prefix(self) -> str:
142+
def uuid_without_prefix(self) -> str:
143143
"""
144144
Retrieves the globally unique immutable UUID associated with this
145145
device, as a 5 part hexadecimal string, that augments the immutable,
146146
board serial identifier.
147147
"""
148-
return nvml.device_get_uuid(self._handle)
148+
# NVML UUIDs have a `GPU-` or `MIG-` prefix. We remove that here.
149+
return nvml.device_get_uuid(self._handle)[4:]
149150

150151
@property
151152
def pci_bus_id(self) -> str:
@@ -272,7 +273,7 @@ cdef class Device:
272273
# search all the devices for one with a matching UUID.
273274

274275
for cuda_device in CudaDevice.get_all_devices():
275-
if cuda_device.uuid == self.uuid:
276+
if cuda_device.uuid == self.uuid_without_prefix:
276277
return cuda_device
277278

278279
raise RuntimeError("No corresponding CUDA device found for this NVML device.")

cuda_core/tests/system/test_system_device.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_to_cuda_device():
5757
cuda_device = device.to_cuda_device()
5858

5959
assert isinstance(cuda_device, CudaDevice)
60-
assert cuda_device.uuid == device.uuid
60+
assert cuda_device.uuid == device.uuid_without_prefix
6161

6262
# Technically, this test will only work with PCI devices, but are there
6363
# non-PCI devices we need to support?
@@ -227,9 +227,9 @@ def test_device_serial():
227227
assert len(serial) > 0
228228

229229

230-
def test_device_uuid():
230+
def test_device_uuid_without_prefix():
231231
for device in system.Device.get_all_devices():
232-
uuid = device.uuid
232+
uuid = device.uuid_without_prefix
233233
assert isinstance(uuid, str)
234234

235235
# Expands to GPU-8hex-4hex-4hex-4hex-12hex, where 8hex means 8 consecutive
@@ -750,9 +750,9 @@ def test_mig():
750750
assert isinstance(mig_device, system.Device)
751751

752752

753-
def test_uuid_with_prefix():
753+
def test_uuid():
754754
for device in system.Device.get_all_devices():
755-
uuid_with_prefix = device.uuid_with_prefix
756-
assert isinstance(uuid_with_prefix, str)
757-
assert uuid_with_prefix.startswith(("GPU-", "MIG-"))
758-
assert uuid_with_prefix[4:] == device.uuid
755+
uuid = device.uuid
756+
assert isinstance(uuid, str)
757+
assert uuid.startswith(("GPU-", "MIG-"))
758+
assert uuid == device.uuid

0 commit comments

Comments
 (0)