Skip to content

[UR] Implement IPC physical_mem API in UR#22115

Open
ldorau wants to merge 3 commits into
intel:syclfrom
ldorau:UR_Implement_IPC_physical_mem_API_in_UR
Open

[UR] Implement IPC physical_mem API in UR#22115
ldorau wants to merge 3 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)

  • Extend ur_physical_mem_handle_t_ with Device, Size, EnableIpc,
    and IpcVirtualAddress fields; ZeIPCPhysMemHandleData holds a
    ze_ipc_mem_handle_t + size (self-contained 64-byte opaque blob).
  • Producer calls zeMemGetIpcHandleWithProperties with
    ze_ipc_mem_handle_type_ext_desc_t / ZE_IPC_MEM_HANDLE_TYPE_FLAG_DEFAULT,
    passing the ze_physical_mem_handle_t cast to const void* (spec-defined
    behavior). Older drivers may return ZE_RESULT_ERROR_INVALID_ARGUMENT
    instead of ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; both are mapped to
    UR_RESULT_ERROR_UNSUPPORTED_FEATURE.
  • Consumer calls zeMemOpenIpcHandle which establishes the virtual mapping
    directly; the pointer is stored in IpcVirtualAddress.
  • urVirtualMemMap is a no-op for IPC-opened handles.
  • 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.
  • Report UR_DEVICE_INFO_IPC_PHYSICAL_MEMORY_SUPPORT_EXP as false.

Conformance tests

  • Add tests for all four entry points with shared fixtures.
  • Tests skip when the feature is unsupported (device info query or runtime
    UR_RESULT_ERROR_UNSUPPORTED_FEATURE from urIPCGetPhysMemHandleExp).

@ldorau ldorau requested a review from slawekptak May 26, 2026 09:53
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 Outdated
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 ldorau force-pushed the UR_Implement_IPC_physical_mem_API_in_UR branch from 523e104 to 4cbcfa8 Compare May 26, 2026 14:30
@ldorau ldorau marked this pull request as ready for review May 27, 2026 08:22
@ldorau ldorau requested review from a team as code owners May 27, 2026 08:22
@ldorau ldorau requested a review from pbalcer May 27, 2026 08:22
@ldorau
Copy link
Copy Markdown
Contributor Author

ldorau commented May 27, 2026

The Offload CI job fails because of #22125

@ldorau ldorau force-pushed the UR_Implement_IPC_physical_mem_API_in_UR branch from a9eb70a to 6dac91d Compare May 27, 2026 11:12
@ldorau
Copy link
Copy Markdown
Contributor Author

ldorau commented May 27, 2026

Rebased

@ldorau ldorau force-pushed the UR_Implement_IPC_physical_mem_API_in_UR branch from 29aee2c to 4a61124 Compare May 27, 2026 13:01
@ldorau ldorau marked this pull request as draft May 27, 2026 20:28
@ldorau ldorau force-pushed the UR_Implement_IPC_physical_mem_API_in_UR branch from 6113038 to 572be16 Compare May 28, 2026 08:49
ur_physical_mem_handle_t hPhysMem,
void **ppIPCPhysMemHandleData,
size_t *pIPCPhysMemHandleDataSizeRet) {
#ifdef __linux__
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are L0 driver IPC calls specific to Linux?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, currently only implementation for Linux is needed. A Windows one will differ.

void **ppIPCPhysMemHandleData,
size_t *pIPCPhysMemHandleDataSizeRet) {
#ifdef __linux__
if (!hContext)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Majority of those checks should probably be done on the validation layer side.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed

@ldorau ldorau force-pushed the UR_Implement_IPC_physical_mem_API_in_UR branch from 572be16 to 37d96d9 Compare May 28, 2026 10:37
ldorau added 2 commits May 28, 2026 11:23
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.

Add a new enumerator to ur_physical_mem_info_t that allows querying the
virtual address established by zeMemOpenIpcHandle when a physical memory
handle is opened via urIPCOpenPhysMemHandleExp.  Returns nullptr for
non-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_PHYSICAL_MEM_FLAG_ENABLE_IPC, UR_DEVICE_INFO_IPC_PHYSICAL_MEMORY_SUPPORT_EXP):

- 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
- urinfo.hpp: updated urinfo tool

Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
@ldorau ldorau force-pushed the UR_Implement_IPC_physical_mem_API_in_UR branch 4 times, most recently from 75afc3f to 3c08b2b Compare May 29, 2026 13:35
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, and IpcVirtualAddress fields; replace the old pid+fd-based
  ZeIPCPhysMemHandleData with {ze_ipc_mem_handle_t IpcHandle; size_t Size}
  (72-byte self-contained struct; IPC functions are guarded by #ifdef __linux__)
- physical_mem.cpp: implement the four IPC functions matching the approach
  from the Level Zero CTS (commit 2d0d1218 in level-zero.tests):
  * urIPCGetPhysMemHandleExp (producer): calls zeMemGetIpcHandleWithProperties
    passing ze_physical_mem_handle_t cast to (const void*) directly — no prior
    virtual mapping required; uses ze_ipc_mem_handle_type_ext_desc_t with
    ZE_STRUCTURE_TYPE_IPC_MEM_HANDLE_TYPE_EXT_DESC and
    ZE_IPC_MEM_HANDLE_TYPE_FLAG_DEFAULT to request a local same-machine IPC
    handle; detects drivers that return an fd-based handle instead of an opaque
    blob (via fcntl(F_GETFD) on the first 4 bytes) and returns
    UR_RESULT_ERROR_UNSUPPORTED_FEATURE so callers skip gracefully; also maps
    ZE_RESULT_ERROR_INVALID_ARGUMENT / ZE_RESULT_ERROR_UNSUPPORTED_FEATURE from
    the driver to UR_RESULT_ERROR_UNSUPPORTED_FEATURE for graceful skip on
    older drivers that do not support physical-mem IPC at all
  * urIPCOpenPhysMemHandleExp (consumer): calls zeMemOpenIpcHandle with
    ZE_IPC_MEMORY_FLAG_BIAS_UNCACHED, matching the CTS consumer side; stores
    the returned virtual address in IpcVirtualAddress (ZePhysicalMem is null
    on the consumer side)
  * urIPCPutPhysMemHandleExp: calls zeMemPutIpcHandle
  * urIPCClosePhysMemHandleExp: delegates to urPhysicalMemRelease, which calls
    zeMemCloseIpcHandle for IPC-opened handles (IpcVirtualAddress != nullptr)
    and zePhysicalMemDestroy for regular handles
- virtual_mem.cpp: urVirtualMemMap is a no-op for IPC-opened handles since
  zeMemOpenIpcHandle already establishes the virtual mapping
- 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
- Add urIPCPhysMemHandleExpFixtures.hpp with urIPCPhysMemTest,
  urIPCPhysMemHandleTest, urIPCOpenedPhysMemTest fixtures
- Tests skip when UR_DEVICE_INFO_IPC_PHYSICAL_MEMORY_SUPPORT_EXP is false
  or when urIPCGetPhysMemHandleExp returns UR_RESULT_ERROR_UNSUPPORTED_FEATURE
  at runtime (e.g. on drivers that return fd-based handles)

Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
@ldorau ldorau requested a review from nrspruit May 29, 2026 14:45
@ldorau
Copy link
Copy Markdown
Contributor Author

ldorau commented May 29, 2026

@nrspruit please review 2 files: unified-runtime/source/adapters/level_zero/physical_mem.cpp and unified-runtime/source/adapters/level_zero/physical_mem.hpp

@ldorau
Copy link
Copy Markdown
Contributor Author

ldorau commented May 29, 2026

The Offload CI job fails because of #22125

@ldorau ldorau marked this pull request as ready for review May 29, 2026 14:55
@ldorau ldorau requested a review from kswiecicki May 29, 2026 15:03
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.

3 participants