Skip to content

Commit 23fcd62

Browse files
committed
Add get_device_id method to SyclDevice
1 parent 8edf7f3 commit 23fcd62

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

dpctl/_sycl_device.pyx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,9 +1950,7 @@ cdef class SyclDevice(_SyclDevice):
19501950

19511951
cdef int get_overall_ordinal(self):
19521952
""" If this device is a root ``sycl::device``, returns the ordinal
1953-
position of this device in the vector ``sycl::device::get_devices()``
1954-
filtered to contain only devices with the same backend as this
1955-
device.
1953+
position of this device in the vector ``sycl::device::get_devices()``.
19561954
19571955
Returns -1 if the device is a sub-device, or the device could not
19581956
be found in the vector.
@@ -2045,6 +2043,18 @@ cdef class SyclDevice(_SyclDevice):
20452043
else:
20462044
return str(relId)
20472045

2046+
def get_device_id(self):
2047+
cdef int dev_id = -1
2048+
2049+
if self.parent_device:
2050+
raise TypeError("This SyclDevice is not a root device")
2051+
2052+
dev_id = self.get_overall_ordinal()
2053+
if dev_id < 0:
2054+
raise ValueError
2055+
return dev_id
2056+
2057+
20482058
cdef api DPCTLSyclDeviceRef SyclDevice_GetDeviceRef(SyclDevice dev):
20492059
"""
20502060
C-API function to get opaque device reference from

0 commit comments

Comments
 (0)