• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IntelPython / dpctl / 14537256782

18 Apr 2025 03:10PM UTC coverage: 86.41% (+0.001%) from 86.409%
14537256782

Pull #2056

github

web-flow
Merge f63bdbb79 into f57963e87
Pull Request #2056: extend pre-commit hooks with cython-lint

3014 of 3710 branches covered (81.24%)

Branch coverage included in aggregate %.

205 of 263 new or added lines in 18 files covered. (77.95%)

4 existing lines in 3 files now uncovered.

12189 of 13884 relevant lines covered (87.79%)

7003.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.12
/dpctl/_sycl_queue_manager.pyx
1
#                      Data Parallel Control (dpctl)
1✔
2
#
3
# Copyright 2020-2025 Intel Corporation
4
#
5
# Licensed under the Apache License, Version 2.0 (the "License");
6
# you may not use this file except in compliance with the License.
7
# You may obtain a copy of the License at
8
#
9
#    http://www.apache.org/licenses/LICENSE-2.0
10
#
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS,
13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
# See the License for the specific language governing permissions and
15
# limitations under the License.
16
#
17
# distutils: language = c++
18
# cython: language_level=3
19
# cython: linetrace=True
20

21
import logging
1✔
22
from contextvars import ContextVar
1✔
23
from ._sycl_context cimport SyclContext
24
from ._sycl_device cimport SyclDevice
25

26
__all__ = [
1✔
27
    "_global_device_queue_cache",
28
    "get_device_cached_queue",
29
]
30

31
_logger = logging.getLogger(__name__)
1✔
32

33

34
cdef class _DeviceDefaultQueueCache:
35
    cdef dict __device_queue_map__
36

37
    def __cinit__(self):
38
        self.__device_queue_map__ = dict()
1✔
39

40
    def get_or_create(self, key):
1✔
41
        """Return instance of SyclQueue and indicator if cache
42
        has been modified"""
43
        if (
1✔
44
            isinstance(key, tuple)
1✔
45
            and len(key) == 2
1✔
46
            and isinstance(key[0], SyclContext)
1✔
47
            and isinstance(key[1], SyclDevice)
1✔
48
        ):
49
            ctx_dev = key
1✔
50
            q = None
1✔
51
        elif isinstance(key, SyclDevice):
1✔
52
            q = SyclQueue(key)
1✔
53
            ctx_dev = q.sycl_context, key
1✔
54
        elif isinstance(key, str):
1✔
55
            q = SyclQueue(key)
1✔
56
            ctx_dev = q.sycl_context, q.sycl_device
1✔
57
        else:
58
            raise TypeError
×
59
        if ctx_dev in self.__device_queue_map__:
1✔
60
            return self.__device_queue_map__[ctx_dev], False
1✔
61
        if q is None:
1✔
NEW
62
            q = SyclQueue(*ctx_dev)
×
63
        self.__device_queue_map__[ctx_dev] = q
1✔
64
        return q, True
1✔
65

66
    cdef _update_map(self, dev_queue_map):
1✔
67
        self.__device_queue_map__.update(dev_queue_map)
1✔
68

69
    def __copy__(self):
1✔
70
        cdef _DeviceDefaultQueueCache _copy = _DeviceDefaultQueueCache.__new__(
1✔
71
            _DeviceDefaultQueueCache
72
        )
73
        _copy._update_map(self.__device_queue_map__)
1✔
74
        return _copy
1✔
75

76

77
_global_device_queue_cache = ContextVar(
1✔
78
    "global_device_queue_cache",
79
    default=_DeviceDefaultQueueCache()
1✔
80
)
81

82

83
cpdef object get_device_cached_queue(object key):
1✔
84
    """Returns a cached queue associated with given device.
85

86
    Args:
87
        key : Either a 2-tuple consisting of a :class:`dpctl.SyclContext` and
88
            a :class:`dpctl.SyclDevice`, or a :class:`dpctl.SyclDevice`
89
            instance, or a filter string identifying a device.
90

91
    Returns:
92
        :class:`dpctl.SyclQueue`: A cached SYCL queue associated with the
93
        input device.
94

95
    Raises:
96
        TypeError: If the input key is not one of the accepted types.
97

98
    """
99
    _cache = _global_device_queue_cache.get()
1✔
100
    q_, changed_ = _cache.get_or_create(key)
1✔
101
    if changed_:
1✔
102
        _global_device_queue_cache.set(_cache)
1✔
103
    return q_
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc