Skip to content

Commit fe490f7

Browse files
committed
Add Python bindings for SYCL IPC memory via dpctl
Add inter-process communication (IPC) support for SYCL USM memory, enabling zero-copy GPU memory sharing across processes. It wraps sycl::ext::oneapi::experimental::ipc::memory (get/open/close/put). C API (libsyclinterface): - dpctl_sycl_ipc_memory_interface.h: declares DPCTLIPCMem_GetHandle, DPCTLIPCMem_OpenHandle, DPCTLIPCMem_CloseHandle, DPCTLIPCMem_FreeHandleData - dpctl_sycl_ipc_memory_interface.cpp: implements the C API by calling the SYCL experimental ipc::memory functions; auto-discovered by CMake. Cython declarations: - _backend.pxd: extern block for the 4 new C functions Python subpackage (dpctl.ipc): - IPCMemoryHandle: Cython extension class wrapping IPC memory export/import __init__(usm_memory): calls get() + put(), stores handle as bytes to_bytes(): serializable payload for cross-process transport open(handle_bytes, device, nbytes): returns MemoryUSMDevice close_mapping(usm_memory): explicitly closes an IPC mapping Signed-off-by: Zhan Xue <zhan.xue@intel.com>
1 parent baf89c9 commit fe490f7

12 files changed

Lines changed: 731 additions & 0 deletions

File tree

‎dpctl/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,4 @@ target_link_libraries(DpctlCAPI INTERFACE ${_trgt}_headers)
206206
add_subdirectory(program)
207207
add_subdirectory(memory)
208208
add_subdirectory(utils)
209+
add_subdirectory(ipc)

‎dpctl/_backend.pxd‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,3 +606,19 @@ cdef extern from "syclinterface/dpctl_sycl_extension_interface.h":
606606
DPCTLSyclRawKernelArgRef Ref)
607607

608608
cdef bint DPCTLRawKernelArg_Available()
609+
610+
cdef extern from "syclinterface/dpctl_sycl_ipc_memory_interface.h":
611+
cdef int DPCTLIPCMem_GetHandle(
612+
DPCTLSyclUSMRef Ptr,
613+
DPCTLSyclContextRef CRef,
614+
char **DataOut,
615+
size_t *SizeOut)
616+
cdef DPCTLSyclUSMRef DPCTLIPCMem_OpenHandle(
617+
const char *HandleData,
618+
size_t HandleDataSize,
619+
DPCTLSyclContextRef CRef,
620+
DPCTLSyclDeviceRef DRef)
621+
cdef void DPCTLIPCMem_CloseHandle(
622+
DPCTLSyclUSMRef MappedPtr,
623+
DPCTLSyclContextRef CRef)
624+
cdef void DPCTLIPCMem_FreeHandleData(char *Data)

‎dpctl/ipc/CMakeLists.txt‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
if(DPCTL_HAS_IPC_MEMORY)
2+
set(_cy_file ${CMAKE_CURRENT_SOURCE_DIR}/_ipc_memory.pyx)
3+
get_filename_component(_trgt ${_cy_file} NAME_WLE)
4+
build_dpctl_ext(${_trgt} ${_cy_file} "dpctl/ipc" RELATIVE_PATH "..")
5+
target_link_libraries(DpctlCAPI INTERFACE ${_trgt}_headers)
6+
endif()
7+
8+
# Always install __init__.py (handles graceful fallback when IPC not supported)
9+
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/__init__.py
10+
DESTINATION ${CMAKE_INSTALL_PREFIX}/dpctl/ipc)

‎dpctl/ipc/__init__.pxd‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
# distutils: language = c++
18+
# cython: language_level=3

‎dpctl/ipc/__init__.py‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
]

‎dpctl/ipc/_ipc_memory.pxd‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
# distutils: language = c++
18+
# cython: language_level=3
19+
20+
"""Declarations for the IPCMemoryHandle Cython extension type."""
21+
22+
from .._backend cimport DPCTLSyclContextRef, DPCTLSyclDeviceRef, DPCTLSyclUSMRef
23+
from .._sycl_context cimport SyclContext
24+
from .._sycl_device cimport SyclDevice
25+
from .._sycl_queue cimport SyclQueue
26+
from ..memory._memory cimport _Memory, MemoryUSMDevice
27+
28+
29+
cdef class IPCMemoryHandle:
30+
cdef bytes _handle_bytes
31+
cdef SyclContext _ctx
32+
cdef bint _closed

0 commit comments

Comments
 (0)