Skip to content

Cached queue use filter string support #1079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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