@@ -110,6 +110,7 @@ from libc.stdlib cimport free, malloc
110
110
from ._sycl_platform cimport SyclPlatform
111
111
112
112
import collections
113
+ import functools
113
114
import warnings
114
115
115
116
__all__ = [
@@ -198,6 +199,37 @@ cdef void _init_helper(_SyclDevice device, DPCTLSyclDeviceRef DRef):
198
199
device._max_work_item_sizes = DPCTLDevice_GetMaxWorkItemSizes3d(DRef)
199
200
200
201
202
+ @ functools.lru_cache (maxsize = None )
203
+ def _cached_filter_string (d : SyclDevice ):
204
+ """
205
+ Internal utility to compute filter_string of input SyclDevice
206
+ and cached with `functools.cache`.
207
+
208
+ Args:
209
+ d (dpctl.SyclDevice):
210
+ A device for which to compute the filter string.
211
+ Returns:
212
+ out(str):
213
+ Filter string that can be used to create input device,
214
+ if the device is a root (unpartitioned) device.
215
+
216
+ Raises:
217
+ ValueError: if the input device is a sub-device.
218
+ """
219
+ cdef _backend_type BTy
220
+ cdef _device_type DTy
221
+ cdef int64_t relId = - 1
222
+ cdef SyclDevice cd = < SyclDevice> d
223
+ relId = DPCTLDeviceMgr_GetRelativeId(cd._device_ref)
224
+ if (relId == - 1 ):
225
+ raise ValueError (" This SyclDevice is not a root device" )
226
+ BTy = DPCTLDevice_GetBackend(cd._device_ref)
227
+ br_str = _backend_type_to_filter_string_part(BTy)
228
+ DTy = DPCTLDevice_GetDeviceType(cd._device_ref)
229
+ dt_str = _device_type_to_filter_string_part(DTy)
230
+ return " :" .join((br_str, dt_str, str (relId)))
231
+
232
+
201
233
cdef class SyclDevice(_SyclDevice):
202
234
""" SyclDevice(arg=None)
203
235
A Python wrapper for the :sycl_device:`sycl::device <>` C++ class.
@@ -1360,14 +1392,14 @@ cdef class SyclDevice(_SyclDevice):
1360
1392
1361
1393
@property
1362
1394
def filter_string (self ):
1363
- """ For a parent device, returns a fully specified filter selector
1364
- string`` backend:device_type:relative_id`` selecting the device.
1395
+ """ For a root device, returns a fully specified filter selector
1396
+ string ``" backend:device_type:relative_id" `` selecting the device.
1365
1397
1366
1398
Returns:
1367
1399
str: A Python string representing a filter selector string.
1368
1400
1369
1401
Raises:
1370
- TypeError: If the device is a sub-devices .
1402
+ TypeError: If the device is a sub-device .
1371
1403
1372
1404
:Example:
1373
1405
.. code-block:: python
@@ -1387,14 +1419,7 @@ cdef class SyclDevice(_SyclDevice):
1387
1419
cdef int64_t relId = - 1
1388
1420
pDRef = DPCTLDevice_GetParentDevice(self ._device_ref)
1389
1421
if (pDRef is NULL ):
1390
- BTy = DPCTLDevice_GetBackend(self ._device_ref)
1391
- DTy = DPCTLDevice_GetDeviceType(self ._device_ref)
1392
- relId = DPCTLDeviceMgr_GetRelativeId(self ._device_ref)
1393
- if (relId == - 1 ):
1394
- raise TypeError (" This SyclDevice is not a root device" )
1395
- br_str = _backend_type_to_filter_string_part(BTy)
1396
- dt_str = _device_type_to_filter_string_part(DTy)
1397
- return " :" .join((br_str, dt_str, str (relId)))
1422
+ return _cached_filter_string(self )
1398
1423
else :
1399
1424
# this a sub-device, free it, and raise an exception
1400
1425
DPCTLDevice_Delete(pDRef)
0 commit comments