[UR] Implement IPC physical_mem API in UR#22115
Draft
ldorau wants to merge 6 commits into
Draft
Conversation
Contributor
Author
|
Commit 0dd180a will be removed |
slawekptak
reviewed
May 26, 2026
70701a0 to
523e104
Compare
Contributor
Author
|
Rebased |
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>
523e104 to
4cbcfa8
Compare
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implement urIPCGetPhysMemHandleExp, urIPCPutPhysMemHandleExp,
urIPCOpenPhysMemHandleExp, and urIPCClosePhysMemHandleExp across all
adapters.
Level Zero adapter (full implementation, Linux only):
EnableIpc fields; add ZeIPCPhysMemHandleData struct (pid + DMA-BUF fd
urPhysicalMemCreate when ENABLE_IPC flag is set; extend
urPhysicalMemGetInfo to return context, device, size and properties
as true on Linux, false on Windows
Other adapters (CUDA, HIP, OpenCL, Native CPU, Offload):
Conformance tests:
urIPCOpenPhysMemHandleExp.cpp, urIPCClosePhysMemHandleExp.cpp
with shared fixtures in urIPCPhysMemHandleExpFixtures.hpp
exercising the full export → put → open → close flow