|
| 1 | +# Data Parallel Control (dpctl) |
| 2 | +# |
| 3 | +# Copyright 2020-2021 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 | +"""This file implements Python buffer protocol using Sycl USM shared and host |
| 22 | +allocators. The USM device allocator is also exposed through this module for |
| 23 | +use in other Python modules. |
| 24 | +""" |
| 25 | + |
| 26 | + |
| 27 | +import dpctl |
| 28 | + |
| 29 | +from .._sycl_queue cimport SyclQueue |
| 30 | + |
| 31 | +__all__ = ["get_execution_queue", ] |
| 32 | + |
| 33 | + |
| 34 | +cdef bint queue_equiv(SyclQueue q1, SyclQueue q2): |
| 35 | + """ Queues are equivalent if contexts are the same, |
| 36 | + devices are the same, and properties are the same.""" |
| 37 | + return ( |
| 38 | + (q1 is q2) or |
| 39 | + ( |
| 40 | + (q1.sycl_context == q2.sycl_context) and |
| 41 | + (q1.sycl_device == q2.sycl_device) and |
| 42 | + (q1.is_in_order == q2.is_in_order) and |
| 43 | + (q1.has_enable_profiling == q2.has_enable_profiling) |
| 44 | + ) |
| 45 | + ) |
| 46 | + |
| 47 | + |
| 48 | +def get_execution_queue(qs): |
| 49 | + """ Given a list of :class:`dpctl.SyclQueue` objects |
| 50 | + returns the execution queue under compute follows data paradigm, |
| 51 | + or returns `None` if queues are not equivalent. |
| 52 | + """ |
| 53 | + if not isinstance(qs, (list, tuple)): |
| 54 | + raise TypeError( |
| 55 | + "Expected a list or a tuple, got {}".format(type(qs)) |
| 56 | + ) |
| 57 | + if len(qs) == 0: |
| 58 | + return None |
| 59 | + elif len(qs) == 1: |
| 60 | + return qs[0] if isinstance(qs[0], dpctl.SyclQueue) else None |
| 61 | + for q1, q2 in zip(qs, qs[1:]): |
| 62 | + if not isinstance(q1, dpctl.SyclQueue): |
| 63 | + return None |
| 64 | + elif not isinstance(q2, dpctl.SyclQueue): |
| 65 | + return None |
| 66 | + elif not queue_equiv(<SyclQueue> q1, <SyclQueue> q2): |
| 67 | + return None |
| 68 | + return qs[0] |
0 commit comments