Skip to content

Commit

Permalink
Merge pull request #1079 from IntelPython/cached-queue-use-filter-str…
Browse files Browse the repository at this point in the history
…ing-support

Cached queue use filter string support
  • Loading branch information
oleksandr-pavlyk authored Feb 21, 2023
2 parents ec19e60 + 4329722 commit eadc0bd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
21 changes: 17 additions & 4 deletions dpctl/_sycl_queue_manager.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,22 @@ cdef class _DeviceDefaultQueueCache:
self.__device_queue_map__ = dict()

def get_or_create(self, key):
"""Return instance of SyclQueue and indicator if cache has been modified"""
if isinstance(key, tuple) and len(key) == 2 and isinstance(key[0], SyclContext) and isinstance(key[1], SyclDevice):
"""Return instance of SyclQueue and indicator if cache
has been modified"""
if (
isinstance(key, tuple)
and len(key) == 2
and isinstance(key[0], SyclContext)
and isinstance(key[1], SyclDevice)
):
ctx_dev = key
q = None
elif isinstance(key, SyclDevice):
q = SyclQueue(key)
ctx_dev = q.sycl_context, key
elif isinstance(key, str):
q = SyclQueue(key)
ctx_dev = q.sycl_context, q.sycl_device
else:
raise TypeError
if ctx_dev in self.__device_queue_map__:
Expand All @@ -322,12 +331,16 @@ cdef class _DeviceDefaultQueueCache:
self.__device_queue_map__.update(dev_queue_map)

def __copy__(self):
cdef _DeviceDefaultQueueCache _copy = _DeviceDefaultQueueCache.__new__(_DeviceDefaultQueueCache)
cdef _DeviceDefaultQueueCache _copy = _DeviceDefaultQueueCache.__new__(
_DeviceDefaultQueueCache)
_copy._update_map(self.__device_queue_map__)
return _copy


_global_device_queue_cache = ContextVar('global_device_queue_cache', default=_DeviceDefaultQueueCache())
_global_device_queue_cache = ContextVar(
'global_device_queue_cache',
default=_DeviceDefaultQueueCache()
)


cpdef object get_device_cached_queue(object key):
Expand Down
2 changes: 2 additions & 0 deletions dpctl/tests/test_sycl_queue_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,5 @@ def test__DeviceDefaultQueueCache():

assert not changed
assert q1 == q2
q3 = get_device_cached_queue(d.filter_string)
assert q3 == q1

0 comments on commit eadc0bd

Please sign in to comment.