|
| 1 | +# Data Parallel Control (dpctl) |
| 2 | +# |
| 3 | +# Copyright 2020-2026 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 | +""" |
| 18 | +**Data Parallel Control IPC** provides Python objects for inter-process |
| 19 | +communication of SYCL USM memory. |
| 20 | +
|
| 21 | +- :class:`IPCMemoryHandle` wraps ``sycl::ext::oneapi::experimental::ipc::memory`` |
| 22 | + to export/import USM device pointers across processes. |
| 23 | +
|
| 24 | +Requires oneAPI DPC++ compiler >= 2026.1 (with SYCL IPC memory runtime support). |
| 25 | +""" |
| 26 | + |
| 27 | +_IPC_MEMORY_AVAILABLE = False |
| 28 | +_IPC_MEMORY_ERROR = "" |
| 29 | + |
| 30 | +try: |
| 31 | + from ._ipc_memory import IPCMemoryHandle |
| 32 | + _IPC_MEMORY_AVAILABLE = True |
| 33 | +except ImportError as _e: |
| 34 | + _IPC_MEMORY_ERROR = ( |
| 35 | + "dpctl.ipc.IPCMemoryHandle is not available. " |
| 36 | + "SYCL IPC memory support was not detected at build time. " |
| 37 | + "This requires oneAPI DPC++ compiler >= 2026.0 with " |
| 38 | + "sycl::ext::oneapi::experimental::ipc::memory runtime support. " |
| 39 | + f"(Import error: {_e})" |
| 40 | + ) |
| 41 | + |
| 42 | + class IPCMemoryHandle: |
| 43 | + """Placeholder for unavailable IPC memory support.""" |
| 44 | + |
| 45 | + def __init__(self, *args, **kwargs): |
| 46 | + raise RuntimeError(_IPC_MEMORY_ERROR) |
| 47 | + |
| 48 | + @staticmethod |
| 49 | + def open(*args, **kwargs): |
| 50 | + raise RuntimeError(_IPC_MEMORY_ERROR) |
| 51 | + |
| 52 | + @staticmethod |
| 53 | + def close_mapping(*args, **kwargs): |
| 54 | + raise RuntimeError(_IPC_MEMORY_ERROR) |
| 55 | + |
| 56 | + |
| 57 | +def is_ipc_memory_supported(): |
| 58 | + """Return True if IPC memory is supported by the current SYCL runtime. |
| 59 | +
|
| 60 | + Returns: |
| 61 | + bool: True if IPCMemoryHandle can be used, False otherwise. |
| 62 | + """ |
| 63 | + return _IPC_MEMORY_AVAILABLE |
| 64 | + |
| 65 | + |
| 66 | +def check_ipc_memory_support(): |
| 67 | + """Raise RuntimeError if IPC memory is not supported. |
| 68 | +
|
| 69 | + Use this for early failure at application startup. |
| 70 | +
|
| 71 | + Raises: |
| 72 | + RuntimeError: if the SYCL IPC memory API is not available. |
| 73 | + """ |
| 74 | + if not _IPC_MEMORY_AVAILABLE: |
| 75 | + raise RuntimeError(_IPC_MEMORY_ERROR) |
| 76 | + |
| 77 | + |
| 78 | +__all__ = [ |
| 79 | + "IPCMemoryHandle", |
| 80 | + "is_ipc_memory_supported", |
| 81 | + "check_ipc_memory_support", |
| 82 | +] |
0 commit comments