Skip to content

Commit

Permalink
Add get_device_id method to SyclDevice
Browse files Browse the repository at this point in the history
  • Loading branch information
ndgrigorian committed Jan 7, 2025
1 parent 8edf7f3 commit 23fcd62
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions dpctl/_sycl_device.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 23fcd62

Please sign in to comment.