Skip to content

Commit eadc0bd

Browse files
Merge pull request #1079 from IntelPython/cached-queue-use-filter-string-support
Cached queue use filter string support
2 parents ec19e60 + 4329722 commit eadc0bd

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

dpctl/_sycl_queue_manager.pyx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,22 @@ cdef class _DeviceDefaultQueueCache:
303303
self.__device_queue_map__ = dict()
304304

305305
def get_or_create(self, key):
306-
"""Return instance of SyclQueue and indicator if cache has been modified"""
307-
if isinstance(key, tuple) and len(key) == 2 and isinstance(key[0], SyclContext) and isinstance(key[1], SyclDevice):
306+
"""Return instance of SyclQueue and indicator if cache
307+
has been modified"""
308+
if (
309+
isinstance(key, tuple)
310+
and len(key) == 2
311+
and isinstance(key[0], SyclContext)
312+
and isinstance(key[1], SyclDevice)
313+
):
308314
ctx_dev = key
309315
q = None
310316
elif isinstance(key, SyclDevice):
311317
q = SyclQueue(key)
312318
ctx_dev = q.sycl_context, key
319+
elif isinstance(key, str):
320+
q = SyclQueue(key)
321+
ctx_dev = q.sycl_context, q.sycl_device
313322
else:
314323
raise TypeError
315324
if ctx_dev in self.__device_queue_map__:
@@ -322,12 +331,16 @@ cdef class _DeviceDefaultQueueCache:
322331
self.__device_queue_map__.update(dev_queue_map)
323332

324333
def __copy__(self):
325-
cdef _DeviceDefaultQueueCache _copy = _DeviceDefaultQueueCache.__new__(_DeviceDefaultQueueCache)
334+
cdef _DeviceDefaultQueueCache _copy = _DeviceDefaultQueueCache.__new__(
335+
_DeviceDefaultQueueCache)
326336
_copy._update_map(self.__device_queue_map__)
327337
return _copy
328338

329339

330-
_global_device_queue_cache = ContextVar('global_device_queue_cache', default=_DeviceDefaultQueueCache())
340+
_global_device_queue_cache = ContextVar(
341+
'global_device_queue_cache',
342+
default=_DeviceDefaultQueueCache()
343+
)
331344

332345

333346
cpdef object get_device_cached_queue(object key):

dpctl/tests/test_sycl_queue_manager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,5 @@ def test__DeviceDefaultQueueCache():
245245

246246
assert not changed
247247
assert q1 == q2
248+
q3 = get_device_cached_queue(d.filter_string)
249+
assert q3 == q1

0 commit comments

Comments
 (0)