Skip to content

Add Python bindings for SYCL IPC memory via dpctl#2331

Merged
ndgrigorian merged 11 commits into
IntelPython:masterfrom
zxue2:enable_ipc_mem
Jul 8, 2026
Merged

Add Python bindings for SYCL IPC memory via dpctl#2331
ndgrigorian merged 11 commits into
IntelPython:masterfrom
zxue2:enable_ipc_mem

Conversation

@zxue2

@zxue2 zxue2 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

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).

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 3 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

Test In Docker (oneAPI 2026.0 installed):

python -c "
import dpctl
from dpctl.memory import MemoryUSMDevice
from dpctl.ipc import IPCMemoryHandle
d = dpctl.SyclDevice('level_zero:gpu')
q = dpctl.SyclQueue(d)
mem = MemoryUSMDevice(4096, queue=q)
h = IPCMemoryHandle(mem)
raw = h.to_bytes()
print(f'IPC handle: {len(raw)} bytes')
mem2 = IPCMemoryHandle.open(raw, d, nbytes=4096)
print(f'Opened: {mem2.nbytes} bytes on {mem2.sycl_device.name}')
IPCMemoryHandle.close_mapping(mem2)
print('close OK')
"

IPC handle: 120 bytes
Opened: 4096 bytes on Intel(R) Arc(TM) Pro B60 Graphics
close OK

Comment thread dpctl/ipc/_ipc_memory.pyx Outdated
Comment thread dpctl/ipc/_ipc_memory.pyx Outdated
Comment thread dpctl/ipc/_ipc_memory.pyx Outdated
Comment thread dpctl/ipc/_ipc_memory.pyx Outdated
Comment thread dpctl/ipc/_ipc_memory.pxd Outdated
@zxue2 zxue2 force-pushed the enable_ipc_mem branch 2 times, most recently from 83bb9b4 to b2c490f Compare July 2, 2026 13:22
@coveralls

coveralls commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 75.485% (-0.2%) from 75.677% — zxue2:enable_ipc_mem into IntelPython:master

@zxue2 zxue2 force-pushed the enable_ipc_mem branch 6 times, most recently from a626c94 to 7f907d0 Compare July 3, 2026 07:32
@ndgrigorian ndgrigorian force-pushed the enable_ipc_mem branch 2 times, most recently from 2b2a3ec to 0a67e67 Compare July 6, 2026 01:29
Comment thread dpctl/memory/_memory.pyx
Comment thread dpctl/memory/_memory.pyx
Comment thread dpctl/memory/_memory.pyx Outdated
Comment thread libsyclinterface/include/syclinterface/dpctl_sycl_ipc_memory_interface.h Outdated
Comment thread dpctl/memory/_memory.pyx Outdated
@zxue2 zxue2 force-pushed the enable_ipc_mem branch from 552dadb to 0125279 Compare July 7, 2026 13:43
@zxue2

zxue2 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

also add fix about "Remove unnecessary context parameters"

@ndgrigorian

Copy link
Copy Markdown
Collaborator

@zxue2
can we also add the IPC functions, IPCMemoryHandle, and MemoryIPCDevice to the docs? There is an RST for the memory, it should be straightfoward, if formatting is bad we can follow up

ndgrigorian
ndgrigorian previously approved these changes Jul 7, 2026

@ndgrigorian ndgrigorian left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aside from above changes LGTM

@zxue2

zxue2 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@zxue2 can we also add the IPC functions, IPCMemoryHandle, and MemoryIPCDevice to the docs? There is an RST for the memory, it should be straightfoward, if formatting is bad we can follow up

Please kindly check "public IPC class and update the docs"

@zxue2 zxue2 force-pushed the enable_ipc_mem branch from 7ef8173 to 85d4e18 Compare July 8, 2026 02:27
ndgrigorian
ndgrigorian previously approved these changes Jul 8, 2026

@ndgrigorian ndgrigorian left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM if no more comments from @antonwolfy

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>
zxue2 and others added 7 commits July 8, 2026 18:20
add has_aspect_ext_oneapi_ipc_memory checks in __init__ and open()

Signed-off-by: Zhan Xue <zhan.xue@intel.com>
Signed-off-by: Zhan Xue <zhan.xue@intel.com>
create_ipc_from_usm_pointer_size_qref(): Wrap the MemoryIPCDevice
construction in try/except. On failure, null base._memory_ptr to
signal that __dealloc__ already closed the handle. On success, null
base._memory_ptr to prevent base's own dealloc from touching it.
Also null _memory_ptr in the SyclQueueCreationError path so the caller
knows it still owns the handle.

IPCMemoryHandle.open(): Split the single try/except into two:
- SyclQueue creation failure: handle not yet transferred, close it.
- create_ipc_from_usm_pointer_size_qref raises ValueError: failed
  before construction (queue copy), handle not closed, close it.
- Any other exception from construction: __dealloc__ already closed
  the handle, do NOT close again.

Signed-off-by: Zhan Xue <zhan.xue@intel.com>
Signed-off-by: Zhan Xue <zhan.xue@intel.com>
Signed-off-by: Zhan Xue <zhan.xue@intel.com>
Comment thread dpctl/memory/_memory.pyx Outdated
Comment thread dpctl/tests/test_sycl_ipc_memory.py
Comment thread dpctl/memory/_memory.pyx
Comment thread dpctl/memory/_memory.pyx Outdated

@antonwolfy antonwolfy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @zxue2, no more comments from me

@ndgrigorian ndgrigorian merged commit 8d8b48a into IntelPython:master Jul 8, 2026
100 of 101 checks passed
zxue2 added 3 commits July 9, 2026 06:16
Signed-off-by: Zhan Xue <zhan.xue@intel.com>
Signed-off-by: Zhan Xue <zhan.xue@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants