@@ -923,6 +923,21 @@ cdef cydriver.CUcontext _get_primary_context(int dev_id) except?NULL:
923923 return ctx
924924
925925
926+ cdef str _compute_device_uuid(int device_id ):
927+ """ Compute the UUID for a device. Internal helper function."""
928+ cdef cydriver.CUuuid uuid
929+ cdef cydriver.CUdevice dev = device_id
930+ with nogil:
931+ IF CUDA_CORE_BUILD_MAJOR == " 12" :
932+ HANDLE_RETURN(cydriver.cuDeviceGetUuid_v2(& uuid, dev))
933+ ELSE : # 13.0+
934+ HANDLE_RETURN(cydriver.cuDeviceGetUuid(& uuid, dev))
935+ cdef bytes uuid_b = cpython.PyBytes_FromStringAndSize(uuid.bytes, sizeof(uuid.bytes))
936+ cdef str uuid_hex = uuid_b.hex()
937+ # 8-4-4-4-12
938+ return f" {uuid_hex[:8]}-{uuid_hex[8:12]}-{uuid_hex[12:16]}-{uuid_hex[16:20]}-{uuid_hex[20:]}"
939+
940+
926941class Device :
927942 """ Represent a GPU and act as an entry point for cuda.core features.
928943
@@ -1058,17 +1073,7 @@ class Device:
10581073
10591074 """
10601075 if self._uuid is None:
1061- cdef cydriver.CUuuid uuid
1062- cdef cydriver.CUdevice this_dev = self ._id
1063- with nogil:
1064- IF CUDA_CORE_BUILD_MAJOR == "12":
1065- HANDLE_RETURN(cydriver.cuDeviceGetUuid_v2(&uuid , this_dev ))
1066- ELSE: # 13.0+
1067- HANDLE_RETURN(cydriver.cuDeviceGetUuid(&uuid , this_dev ))
1068- cdef bytes uuid_b = cpython.PyBytes_FromStringAndSize(uuid.bytes, sizeof(uuid.bytes))
1069- cdef str uuid_hex = uuid_b.hex()
1070- # 8-4-4-4-12
1071- self._uuid = f" {uuid_hex[:8]}-{uuid_hex[8:12]}-{uuid_hex[12:16]}-{uuid_hex[16:20]}-{uuid_hex[20:]}"
1076+ self._uuid = _compute_device_uuid(self ._id)
10721077 return self._uuid
10731078
10741079 @property
0 commit comments