@@ -50,6 +50,7 @@ from ._backend cimport (
5050 DPCTLDevice_IsGPU,
5151 DPCTLDevice_IsHost,
5252 DPCTLDeviceMgr_PrintDeviceInfo,
53+ DPCTLDeviceMgr_GetRelativeId,
5354 DPCTLFilterSelector_Create,
5455 DPCTLDeviceSelector_Delete,
5556 DPCTLDeviceSelector_Score,
@@ -78,7 +79,7 @@ from ._backend cimport (
7879 DPCTLDevice_GetParentDevice,
7980)
8081from . import backend_type, device_type
81- from libc.stdint cimport uint32_t
82+ from libc.stdint cimport uint32_t, int64_t
8283from libc.stdlib cimport malloc, free
8384import warnings
8485import collections
@@ -126,6 +127,34 @@ cdef list _get_devices(DPCTLDeviceVectorRef DVRef):
126127 return devices
127128
128129
130+ cdef str _backend_type_to_filter_string_part(DPCTLSyclBackendType BTy):
131+ if BTy == _backend_type._CUDA:
132+ return " cuda"
133+ elif BTy == _backend_type._HOST:
134+ return " host"
135+ elif BTy == _backend_type._LEVEL_ZERO:
136+ return " level_zero"
137+ elif BTy == _backend_type._OPENCL:
138+ return " opencl"
139+ else :
140+ return " unknown"
141+
142+
143+ cdef str _device_type_to_filter_string_part(DPCTLSyclDeviceType DTy):
144+ if DTy == _device_type._ACCELERATOR:
145+ return " accelerator"
146+ elif DTy == _device_type._AUTOMATIC:
147+ return " automatic"
148+ elif DTy == _device_type._CPU:
149+ return " cpu"
150+ elif DTy == _device_type._GPU:
151+ return " gpu"
152+ elif DTy == _device_type._HOST_DEVICE:
153+ return " host"
154+ else :
155+ return " unknown"
156+
157+
129158cdef class SyclDevice(_SyclDevice):
130159 """ Python equivalent for cl::sycl::device class.
131160
@@ -719,6 +748,8 @@ cdef class SyclDevice(_SyclDevice):
719748
720749 @property
721750 def parent_device (self ):
751+ """ Parent device for a sub-device, or None for a root device.
752+ """
722753 cdef DPCTLSyclDeviceRef pDRef = NULL
723754 pDRef = DPCTLDevice_GetParentDevice(self ._device_ref)
724755 if (pDRef is NULL ):
@@ -736,3 +767,27 @@ cdef class SyclDevice(_SyclDevice):
736767 return self .equals(< SyclDevice> other)
737768 else :
738769 return False
770+
771+ @property
772+ def filter_string (self ):
773+ """ For a parent device returns a tuple (backend, device_kind, relative_id).
774+ Raises an exception for sub-devices.
775+ """
776+ cdef DPCTLSyclDeviceRef pDRef = NULL
777+ cdef DPCTLSyclBackendType BTy
778+ cdef DPCTLSyclDeviceType DTy
779+ cdef int64_t relId = - 1
780+ pDRef = DPCTLDevice_GetParentDevice(self ._device_ref)
781+ if (pDRef is NULL ):
782+ BTy = DPCTLDevice_GetBackend(self ._device_ref)
783+ DTy = DPCTLDevice_GetDeviceType(self ._device_ref)
784+ relId = DPCTLDeviceMgr_GetRelativeId(self ._device_ref)
785+ if (relId == - 1 ):
786+ raise TypeError (" This SyclDevice is not a root device" )
787+ br_str = _backend_type_to_filter_string_part(BTy)
788+ dt_str = _device_type_to_filter_string_part(DTy)
789+ return " :" .join((br_str, dt_str, str (relId)))
790+ else :
791+ # this a sub-device, free it, and raise an exception
792+ DPCTLDevice_Delete(pDRef)
793+ raise TypeError (" This SyclDevice is not a root device" )
0 commit comments