Skip to content

Commit 8d8b48a

Browse files
authored
Merge pull request #2331 from zxue2/enable_ipc_mem
Add Python bindings for SYCL IPC memory via dpctl
2 parents a3a53dc + 18f660d commit 8d8b48a

17 files changed

Lines changed: 1132 additions & 2 deletions

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ install(DIRECTORY
115115
)
116116

117117
# find Python before enabling pybind11
118-
find_package(Python REQUIRED COMPONENTS Development.Module)
118+
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
119119

120120
# Define CMAKE_INSTALL_xxx: LIBDIR, INCLUDEDIR
121121
include(GNUInstallDirs)

docs/doc_sources/api_reference/dpctl/memory.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,27 @@ Should the USM allocation fail, the following Python exception will be raised:
6666

6767
USMAllocationError
6868

69+
.. rubric:: IPC (Inter-Process Communication) Memory
70+
71+
Classes and functions for sharing USM device allocations across processes
72+
using IPC memory handles.
73+
74+
.. autosummary::
75+
:toctree: generated
76+
:template: autosummary/usmmemory.rst
77+
:nosignatures:
78+
79+
IPCMemoryHandle
80+
MemoryIPCDevice
81+
82+
.. autosummary::
83+
:toctree: generated
84+
:nosignatures:
85+
86+
SyclIPCGetMemHandle
87+
SyclIPCOpenMemHandle
88+
SyclIPCCloseMemHandle
89+
6990
.. toctree::
7091
:hidden:
7192

dpctl/_backend.pxd

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ cdef extern from "syclinterface/dpctl_sycl_enum_types.h":
101101
_emulated "emulated",
102102
_is_component "is_component",
103103
_is_composite "is_composite",
104+
_ext_oneapi_ipc_memory "ext_oneapi_ipc_memory",
104105

105106
ctypedef enum _partition_affinity_domain_type \
106107
"DPCTLPartitionAffinityDomainType":
@@ -601,6 +602,7 @@ cdef extern from "syclinterface/dpctl_sycl_extension_interface.h":
601602
DPCTLSyclWorkGroupMemoryRef Ref)
602603

603604
cdef bint DPCTLWorkGroupMemory_Available()
605+
cdef bint DPCTLIPCMem_Available()
604606

605607
cdef struct DPCTLOpaqueRawKernelArg
606608
ctypedef DPCTLOpaqueRawKernelArg *DPCTLSyclRawKernelArgRef
@@ -612,3 +614,19 @@ cdef extern from "syclinterface/dpctl_sycl_extension_interface.h":
612614
DPCTLSyclRawKernelArgRef Ref)
613615

614616
cdef bint DPCTLRawKernelArg_Available()
617+
618+
cdef extern from "syclinterface/dpctl_sycl_ipc_memory_interface.h":
619+
cdef int DPCTLIPCMem_GetHandle(
620+
DPCTLSyclUSMRef Ptr,
621+
DPCTLSyclContextRef CRef,
622+
char **DataOut,
623+
size_t *SizeOut)
624+
cdef DPCTLSyclUSMRef DPCTLIPCMem_OpenHandle(
625+
const char *HandleData,
626+
size_t HandleDataSize,
627+
DPCTLSyclContextRef CRef,
628+
DPCTLSyclDeviceRef DRef)
629+
cdef void DPCTLIPCMem_CloseHandle(
630+
DPCTLSyclUSMRef MappedPtr,
631+
DPCTLSyclContextRef CRef)
632+
cdef void DPCTLIPCMem_FreeHandleData(char *Data)

dpctl/_sycl_device.pyx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,18 @@ cdef class SyclDevice(_SyclDevice):
885885
cdef _aspect_type AT = _aspect_type._is_composite
886886
return DPCTLDevice_HasAspect(self._device_ref, AT)
887887

888+
@property
889+
def has_aspect_ext_oneapi_ipc_memory(self):
890+
""" Returns ``True`` if this device supports inter-process
891+
communication (IPC) memory handles, ``False`` otherwise.
892+
893+
Returns:
894+
bool:
895+
Indicates if device supports IPC memory.
896+
"""
897+
cdef _aspect_type AT = _aspect_type._ext_oneapi_ipc_memory
898+
return DPCTLDevice_HasAspect(self._device_ref, AT)
899+
888900
@property
889901
def image_2d_max_width(self):
890902
""" Returns the maximum width of a 2D image or 1D image in pixels.

dpctl/memory/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,27 @@
3030
"""
3131

3232
from ._memory import (
33+
IPCMemoryHandle,
34+
MemoryIPCDevice,
3335
MemoryUSMDevice,
3436
MemoryUSMHost,
3537
MemoryUSMShared,
38+
SyclIPCCloseMemHandle,
39+
SyclIPCGetMemHandle,
40+
SyclIPCOpenMemHandle,
3641
USMAllocationError,
3742
as_usm_memory,
3843
)
3944

4045
__all__ = [
46+
"IPCMemoryHandle",
47+
"MemoryIPCDevice",
4148
"MemoryUSMDevice",
4249
"MemoryUSMHost",
4350
"MemoryUSMShared",
4451
"USMAllocationError",
4552
"as_usm_memory",
53+
"SyclIPCGetMemHandle",
54+
"SyclIPCOpenMemHandle",
55+
"SyclIPCCloseMemHandle",
4656
]

dpctl/memory/_memory.pxd

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,12 @@ cdef public api class MemoryUSMDevice(_Memory) [
9090
object PyMemoryUSMDeviceObject, type PyMemoryUSMDeviceType
9191
]:
9292
pass
93+
94+
95+
cdef class MemoryIPCDevice(MemoryUSMDevice):
96+
@staticmethod
97+
cdef object create_ipc_from_usm_pointer_size_qref(
98+
DPCTLSyclUSMRef USMRef,
99+
Py_ssize_t nbytes,
100+
DPCTLSyclQueueRef QRef,
101+
)

0 commit comments

Comments
 (0)