|
| 1 | +# Data Parallel Control (dpctl) |
| 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 | +from .._backend cimport ( |
| 22 | + DPCTLWorkGroupMemory_Available, |
| 23 | + DPCTLWorkGroupMemory_Create, |
| 24 | + DPCTLWorkGroupMemory_Delete, |
| 25 | +) |
| 26 | + |
| 27 | + |
| 28 | +cdef class _WorkGroupMemory: |
| 29 | + def __dealloc__(self): |
| 30 | + if(self._mem_ref): |
| 31 | + DPCTLWorkGroupMemory_Delete(self._mem_ref) |
| 32 | + |
| 33 | +cdef class WorkGroupMemory: |
| 34 | + """ |
| 35 | + WorkGroupMemory(nbytes) |
| 36 | + Python class representing the ``work_group_memory`` class from the |
| 37 | + Workgroup Memory oneAPI SYCL extension for low-overhead allocation of local |
| 38 | + memory shared by the workitems in a workgroup. |
| 39 | +
|
| 40 | + Args: |
| 41 | + nbytes (int) |
| 42 | + number of bytes to allocate in local memory. |
| 43 | + Expected to be positive. |
| 44 | + """ |
| 45 | + def __cinit__(self, Py_ssize_t nbytes): |
| 46 | + if not DPCTLWorkGroupMemory_Available(): |
| 47 | + raise RuntimeError("Workgroup memory extension not available") |
| 48 | + |
| 49 | + self._mem_ref = DPCTLWorkGroupMemory_Create(nbytes) |
| 50 | + |
| 51 | + @staticmethod |
| 52 | + def is_available(): |
| 53 | + return DPCTLWorkGroupMemory_Available() |
| 54 | + |
| 55 | + property _ref: |
| 56 | + """Returns the address of the C API ``DPCTLWorkGroupMemoryRef`` |
| 57 | + pointer as a ``size_t``. |
| 58 | + """ |
| 59 | + def __get__(self): |
| 60 | + return <size_t>self._mem_ref |
0 commit comments