-
Notifications
You must be signed in to change notification settings - Fork 38
Add Python bindings for SYCL IPC memory via dpctl #2331
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
Open
zxue2
wants to merge
2
commits into
IntelPython:master
Choose a base branch
from
zxue2:enable_ipc_mem
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+756
−1
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| if(DPCTL_HAS_IPC_MEMORY) | ||
| set(_cy_file ${CMAKE_CURRENT_SOURCE_DIR}/_ipc_memory.pyx) | ||
| get_filename_component(_trgt ${_cy_file} NAME_WLE) | ||
| build_dpctl_ext(${_trgt} ${_cy_file} "dpctl/ipc" RELATIVE_PATH "..") | ||
| target_link_libraries(DpctlCAPI INTERFACE ${_trgt}_headers) | ||
| endif() | ||
|
|
||
| # Always install __init__.py (handles graceful fallback when IPC not supported) | ||
| install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/__init__.py | ||
| DESTINATION ${CMAKE_INSTALL_PREFIX}/dpctl/ipc) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Data Parallel Control (dpctl) | ||
| # | ||
| # Copyright 2020-2026 Intel Corporation | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # distutils: language = c++ | ||
| # cython: language_level=3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # Data Parallel Control (dpctl) | ||
| # | ||
| # Copyright 2020-2026 Intel Corporation | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """ | ||
| **Data Parallel Control IPC** provides Python objects for inter-process | ||
| communication of SYCL USM memory. | ||
| - :class:`IPCMemoryHandle` wraps ``sycl::ext::oneapi::experimental::ipc::memory`` | ||
| to export/import USM device pointers across processes. | ||
| Requires oneAPI DPC++ compiler >= 2026.1 (with SYCL IPC memory runtime support). | ||
| """ | ||
|
|
||
| _IPC_MEMORY_AVAILABLE = False | ||
| _IPC_MEMORY_ERROR = "" | ||
|
|
||
| try: | ||
| from ._ipc_memory import IPCMemoryHandle | ||
| _IPC_MEMORY_AVAILABLE = True | ||
| except ImportError as _e: | ||
| _IPC_MEMORY_ERROR = ( | ||
| "dpctl.ipc.IPCMemoryHandle is not available. " | ||
| "SYCL IPC memory support was not detected at build time. " | ||
| "This requires oneAPI DPC++ compiler >= 2026.0 with " | ||
| "sycl::ext::oneapi::experimental::ipc::memory runtime support. " | ||
| f"(Import error: {_e})" | ||
| ) | ||
|
|
||
| class IPCMemoryHandle: | ||
| """Placeholder for unavailable IPC memory support.""" | ||
|
|
||
| def __init__(self, *args, **kwargs): | ||
| raise RuntimeError(_IPC_MEMORY_ERROR) | ||
|
|
||
| @staticmethod | ||
| def open(*args, **kwargs): | ||
| raise RuntimeError(_IPC_MEMORY_ERROR) | ||
|
|
||
| @staticmethod | ||
| def close_mapping(*args, **kwargs): | ||
| raise RuntimeError(_IPC_MEMORY_ERROR) | ||
|
|
||
|
|
||
| def is_ipc_memory_supported(): | ||
| """Return True if IPC memory is supported by the current SYCL runtime. | ||
| Returns: | ||
| bool: True if IPCMemoryHandle can be used, False otherwise. | ||
| """ | ||
| return _IPC_MEMORY_AVAILABLE | ||
|
|
||
|
|
||
| def check_ipc_memory_support(): | ||
| """Raise RuntimeError if IPC memory is not supported. | ||
| Use this for early failure at application startup. | ||
| Raises: | ||
| RuntimeError: if the SYCL IPC memory API is not available. | ||
| """ | ||
| if not _IPC_MEMORY_AVAILABLE: | ||
| raise RuntimeError(_IPC_MEMORY_ERROR) | ||
|
|
||
|
|
||
| __all__ = [ | ||
| "IPCMemoryHandle", | ||
| "is_ipc_memory_supported", | ||
| "check_ipc_memory_support", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Data Parallel Control (dpctl) | ||
| # | ||
| # Copyright 2020-2026 Intel Corporation | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # distutils: language = c++ | ||
| # cython: language_level=3 | ||
|
|
||
| """Declarations for the IPCMemoryHandle Cython extension type.""" | ||
|
|
||
| from .._backend cimport DPCTLSyclContextRef, DPCTLSyclDeviceRef, DPCTLSyclUSMRef | ||
| from .._sycl_context cimport SyclContext | ||
| from .._sycl_device cimport SyclDevice | ||
| from .._sycl_queue cimport SyclQueue | ||
| from ..memory._memory cimport _Memory, MemoryUSMDevice | ||
|
|
||
|
|
||
| cdef class IPCMemoryHandle: | ||
| cdef bytes _handle_bytes | ||
| cdef SyclContext _ctx | ||
| cdef bint _closed | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm conflicted on whether this belongs in a separate namespace or not. So far, we've been free with incorporating extensions into the main dpctl namespace, as long as we have fall-backs so that they don't crash, etc. when the extension is unavailable. This will enable us to use AdaptiveCpp in the future.
Having an entire submodule not be built is a bit different. Perhaps instead we can move this into
dpctl.memoryand implement fallbacks in the C-API and anis_availablefree function like we have forWorkGroupMemory, etc. to check for it