Skip to content

[UR] Implement IPC physical_mem API in UR#22115

Draft
ldorau wants to merge 6 commits into
intel:syclfrom
ldorau:UR_Implement_IPC_physical_mem_API_in_UR
Draft

[UR] Implement IPC physical_mem API in UR#22115
ldorau wants to merge 6 commits into
intel:syclfrom
ldorau:UR_Implement_IPC_physical_mem_API_in_UR

Conversation

@ldorau
Copy link
Copy Markdown
Contributor

@ldorau ldorau commented May 26, 2026

Implement urIPCGetPhysMemHandleExp, urIPCPutPhysMemHandleExp,
urIPCOpenPhysMemHandleExp, and urIPCClosePhysMemHandleExp across all
adapters.

Level Zero adapter (full implementation, Linux only):

  • physical_mem.hpp: extend ur_physical_mem_handle_t_ with Device, Size,
    EnableIpc fields; add ZeIPCPhysMemHandleData struct (pid + DMA-BUF fd
    • size) for cross-process handle exchange via pidfd_getfd(2)
  • physical_mem.cpp: chain ze_external_memory_export_desc_t in
    urPhysicalMemCreate when ENABLE_IPC flag is set; extend
    urPhysicalMemGetInfo to return context, device, size and properties
  • memory.cpp: implement the four IPC functions using ZeIPCPhysMemHandleData
  • v2/memory.cpp: same implementation for the Level Zero v2 adapter
  • device.cpp: report UR_DEVICE_INFO_IPC_PHYSICAL_MEMORY_SUPPORT_EXP
    as true on Linux, false on Windows

Other adapters (CUDA, HIP, OpenCL, Native CPU, Offload):

  • Return UR_RESULT_ERROR_UNSUPPORTED_FEATURE from all four functions
  • Register function pointers in ur_interface_loader.cpp
  • Report UR_DEVICE_INFO_IPC_PHYSICAL_MEMORY_SUPPORT_EXP as false

Conformance tests:

  • Add urIPCGetPhysMemHandleExp.cpp, urIPCPutPhysMemHandleExp.cpp,
    urIPCOpenPhysMemHandleExp.cpp, urIPCClosePhysMemHandleExp.cpp
    with shared fixtures in urIPCPhysMemHandleExpFixtures.hpp
  • Update urPhysicalMemCreate.cpp to cover the ENABLE_IPC flag
  • Add ze_ipc_phys_mem_e2e.cpp: standalone Level Zero diagnostic test
    exercising the full export → put → open → close flow

@ldorau ldorau requested a review from slawekptak May 26, 2026 09:53
@ldorau
Copy link
Copy Markdown
Contributor Author

ldorau commented May 26, 2026

Commit 0dd180a will be removed

Comment thread unified-runtime/include/unified-runtime/ur_api.h
Comment thread unified-runtime/source/adapters/level_zero/memory.cpp Outdated
Comment thread unified-runtime/source/adapters/opencl/common.hpp
Comment thread unified-runtime/test/conformance/virtual_memory/ze_ipc_phys_mem_e2e.cpp Outdated
@ldorau ldorau force-pushed the UR_Implement_IPC_physical_mem_API_in_UR branch from 70701a0 to 523e104 Compare May 26, 2026 12:02
@ldorau
Copy link
Copy Markdown
Contributor Author

ldorau commented May 26, 2026

Rebased

@ldorau ldorau requested a review from slawekptak May 26, 2026 12:02
ldorau added 5 commits May 26, 2026 13:03
Add four new function specs to exp-inter-process-communication.yml
and update registry.yml to support IPC operations on physical memory
objects:
- urIPCGetPhysMemHandleExp: export an IPC handle for a physical_mem
- urIPCPutPhysMemHandleExp: release the exported IPC handle
- urIPCOpenPhysMemHandleExp: import an IPC handle into a physical_mem
- urIPCClosePhysMemHandleExp: close the imported physical_mem

Also add ENABLE_IPC flag to ur_physical_mem_flags_t in virtual_memory.yml
to allow allocating physical memory that can be shared via IPC handles.

Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
Add auto-generated files based on the IPC physical_mem spec changes
(urIPCGetPhysMemHandleExp, urIPCPutPhysMemHandleExp,
urIPCOpenPhysMemHandleExp, urIPCClosePhysMemHandleExp):

- ur_api.h, ur_api_funcs.def, ur_ddi.h: function declarations
- ur_print.h/hpp, ur_print.cpp: printing support
- ur_api.cpp: API dispatch stubs
- ur_ldrddi.cpp, ur_libapi.cpp: loader implementations
- ur_trcddi.cpp, ur_valddi.cpp: tracing and validation layers
- ur_mockddi.cpp: mock adapter
- loader.def.in, loader.map.in: loader symbol exports
- level_zero ur_interface_loader.cpp/.hpp: Level-Zero DDI table entries
- opencl common.hpp: updated generated include
- urinfo.hpp: updated urinfo tool

Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
Implement urIPCGetPhysMemHandleExp, urIPCPutPhysMemHandleExp,
urIPCOpenPhysMemHandleExp, and urIPCClosePhysMemHandleExp across all
adapters.

Level Zero adapter (full implementation, Linux only):
- physical_mem.hpp: extend ur_physical_mem_handle_t_ with Device, Size,
  EnableIpc fields; add ZeIPCPhysMemHandleData struct (pid + DMA-BUF fd
  + size) for cross-process handle exchange via pidfd_getfd(2)
- physical_mem.cpp: chain ze_external_memory_export_desc_t in
  urPhysicalMemCreate when ENABLE_IPC flag is set; extend
  urPhysicalMemGetInfo to return context, device, size and properties
- memory.cpp: implement the four IPC functions using ZeIPCPhysMemHandleData
- v2/memory.cpp: same implementation for the Level Zero v2 adapter
- device.cpp: report UR_DEVICE_INFO_IPC_PHYSICAL_MEMORY_SUPPORT_EXP
  as true on Linux, false on Windows

Other adapters (CUDA, HIP, OpenCL, Native CPU, Offload):
- Return UR_RESULT_ERROR_UNSUPPORTED_FEATURE from all four functions
- Register function pointers in ur_interface_loader.cpp
- Report UR_DEVICE_INFO_IPC_PHYSICAL_MEMORY_SUPPORT_EXP as false

Conformance tests:
- Add urIPCGetPhysMemHandleExp.cpp, urIPCPutPhysMemHandleExp.cpp,
  urIPCOpenPhysMemHandleExp.cpp, urIPCClosePhysMemHandleExp.cpp
  with shared fixtures in urIPCPhysMemHandleExpFixtures.hpp
- Update urPhysicalMemCreate.cpp to cover the ENABLE_IPC flag
- Add ze_ipc_phys_mem_e2e.cpp: standalone Level Zero diagnostic test
  exercising the full export → put → open → close flow

Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
- Remove [optional] tag from ppIPCPhysMemHandleData and
  pIPCPhysMemHandleDataSizeRet in exp-inter-process-communication.yml
  since NULL is rejected by UR_RESULT_ERROR_INVALID_NULL_POINTER.
  Add UR_RESULT_ERROR_INVALID_ARGUMENT return condition to document
  that hPhysMem must have been created with ENABLE_IPC flag.

- Add EnableIpc guard to urIPCGetPhysMemHandleExp in level_zero
  memory.cpp and v2/memory.cpp: return INVALID_ARGUMENT immediately
  if hPhysMem was not created with UR_PHYSICAL_MEM_FLAG_ENABLE_IPC,
  preventing a silent driver-level failure from zePhysicalMemGetProperties.

- Fix EnableIpc=false on imported handle in urIPCOpenPhysMemHandleExp
  in level_zero memory.cpp and v2/memory.cpp: set EnableIpc=true so
  that UR_PHYSICAL_MEM_INFO_PROPERTIES correctly reports IPC capability
  for handles obtained via urIPCOpenPhysMemHandleExp.

- Improve pidfd errno handling in urIPCOpenPhysMemHandleExp: save errno
  before close() overwrites it and return INVALID_ARGUMENT for EPERM
  (ptrace permission denied) vs INVALID_VALUE for other failures.

- Add InvalidArgumentNoIpcFlag negative test to
  urIPCGetPhysMemHandleExp.cpp: verifies that exporting a handle for
  physical memory created without ENABLE_IPC returns INVALID_ARGUMENT.

Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
The four IPC physical_mem functions (urIPCGetPhysMemHandleExp,
urIPCPutPhysMemHandleExp, urIPCOpenPhysMemHandleExp,
urIPCClosePhysMemHandleExp) were identical in the L0 v1 and v2 adapters.

Move them to the shared physical_mem.cpp which is already compiled into
both ur_adapter_level_zero and ur_adapter_level_zero_v2, eliminating
code duplication.

Remove the now-unused #ifdef __linux__ cerrno include from memory.cpp
in both adapters.

Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
@ldorau ldorau force-pushed the UR_Implement_IPC_physical_mem_API_in_UR branch from 523e104 to 4cbcfa8 Compare May 26, 2026 14:30
This file was a development-time diagnostic that used USM memory APIs
(zeMemGetIpcHandleFromFileDescriptorExp, zeMemGetFileDescriptorFromIpcHandleExp,
zeMemPutIpcHandle) which are unrelated to physical memory IPC. The UR
implementation uses pidfd_open/pidfd_getfd and zePhysicalMemCreate with
ze_external_memory_import_fd_t, not the USM IPC handle path.

Signed-off-by: Lukasz Dorau <lukasz.dorau@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.

2 participants