From 23fcd62281fc96b7000f5701d76edd8a65c1d3be Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Fri, 3 Jan 2025 19:36:21 -0800 Subject: [PATCH] Add get_device_id method to SyclDevice --- dpctl/_sycl_device.pyx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/dpctl/_sycl_device.pyx b/dpctl/_sycl_device.pyx index 91a8e9b123..819043d900 100644 --- a/dpctl/_sycl_device.pyx +++ b/dpctl/_sycl_device.pyx @@ -1950,9 +1950,7 @@ cdef class SyclDevice(_SyclDevice): cdef int get_overall_ordinal(self): """ If this device is a root ``sycl::device``, returns the ordinal - position of this device in the vector ``sycl::device::get_devices()`` - filtered to contain only devices with the same backend as this - device. + position of this device in the vector ``sycl::device::get_devices()``. Returns -1 if the device is a sub-device, or the device could not be found in the vector. @@ -2045,6 +2043,18 @@ cdef class SyclDevice(_SyclDevice): else: return str(relId) + def get_device_id(self): + cdef int dev_id = -1 + + if self.parent_device: + raise TypeError("This SyclDevice is not a root device") + + dev_id = self.get_overall_ordinal() + if dev_id < 0: + raise ValueError + return dev_id + + cdef api DPCTLSyclDeviceRef SyclDevice_GetDeviceRef(SyclDevice dev): """ C-API function to get opaque device reference from