Skip to content

Commit fe60cba

Browse files
ldorauCopilot
andcommitted
[UR] Implement IPC physical_mem API
Implement urIPCGetPhysMemHandleExp, urIPCPutPhysMemHandleExp, urIPCOpenPhysMemHandleExp, and urIPCClosePhysMemHandleExp. Level Zero v2 adapter (Linux, BMG/Xe2+ only): - physical_mem.hpp and physical_mem.cpp moved to v2/ subdirectory - urIPCGetPhysMemHandleExp: calls zeMemGetIpcHandleWithProperties passing ze_physical_mem_handle_t cast to (const void *) directly, using ze_ipc_mem_handle_type_ext_desc_t with ZE_IPC_MEM_HANDLE_TYPE_FLAG_DEFAULT; detects fd-based handles via fcntl(F_GETFD) and returns UR_RESULT_ERROR_UNSUPPORTED_FEATURE - urIPCOpenPhysMemHandleExp: calls zeMemOpenIpcHandle with flags=0 - urIPCPutPhysMemHandleExp: calls zeMemPutIpcHandle - urIPCClosePhysMemHandleExp: delegates to urPhysicalMemRelease - virtual_mem.cpp: urVirtualMemMap returns UR_RESULT_ERROR_INVALID_ARGUMENT for IPC-opened handles; the virtual address is already established by zeMemOpenIpcHandle and is accessed via urPhysicalMemGetInfo(UR_PHYSICAL_MEM_INFO_IPC_VIRTUAL_ADDRESS) - device.cpp: report UR_DEVICE_INFO_IPC_PHYSICAL_MEMORY_SUPPORT_EXP as isIntelBMGOrNewer() on Linux, false on Windows - Add isIntelBMGOrNewer() helper (IP version threshold 0x05004000, first Xe2 stepping BMG_G21_A0); IPC entry points return UR_RESULT_ERROR_UNSUPPORTED_FEATURE on pre-Xe2 devices Level Zero v1 adapter: - physical_mem.cpp provides only the four non-IPC functions (urPhysicalMemCreate/Retain/Release/GetInfo) - Add stub definitions for the four IPC functions returning UR_RESULT_ERROR_UNSUPPORTED_FEATURE so the L0v1 adapter links correctly 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 urIPCGetPhysMemHandleExp.cpp, urIPCPutPhysMemHandleExp.cpp, urIPCOpenPhysMemHandleExp.cpp, urIPCClosePhysMemHandleExp.cpp - Add urIPCPhysMemHandleExpFixtures.hpp with urIPCPhysMemTest, urIPCPhysMemHandleTest, urIPCOpenedPhysMemTest fixtures Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 33b8d68 commit fe60cba

42 files changed

Lines changed: 930 additions & 84 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

unified-runtime/include/unified-runtime/ur_api.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11306,8 +11306,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urIPCGetPhysMemHandleExp(
1130611306
UR_APIEXPORT ur_result_t UR_APICALL urIPCPutPhysMemHandleExp(
1130711307
/// [in] handle of the context object
1130811308
ur_context_handle_t hContext,
11309-
/// [in] a pointer to the IPC physical memory handle data
11310-
void *pIPCPhysMemHandleData);
11309+
/// [in] a pointer to the IPC physical memory handle data obtained with
11310+
/// urIPCGetPhysMemHandleExp
11311+
const void *pIPCPhysMemHandleData);
1131111312

1131211313
///////////////////////////////////////////////////////////////////////////////
1131311314
/// @brief Opens an inter-process physical memory handle to get the
@@ -11336,8 +11337,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urIPCOpenPhysMemHandleExp(
1133611337
ur_context_handle_t hContext,
1133711338
/// [in] handle of the device object the physical memory was allocated on
1133811339
ur_device_handle_t hDevice,
11339-
/// [in] the IPC physical memory handle data
11340-
void *pIPCPhysMemHandleData,
11340+
/// [in] the IPC physical memory handle data obtained with
11341+
/// urIPCGetPhysMemHandleExp
11342+
const void *pIPCPhysMemHandleData,
1134111343
/// [in] size of the IPC physical memory handle data
1134211344
size_t ipcPhysMemHandleDataSize,
1134311345
/// [out] pointer to the physical memory handle
@@ -16642,7 +16644,7 @@ typedef struct ur_ipc_get_phys_mem_handle_exp_params_t {
1664216644
/// allowing the callback the ability to modify the parameter's value
1664316645
typedef struct ur_ipc_put_phys_mem_handle_exp_params_t {
1664416646
ur_context_handle_t *phContext;
16645-
void **ppIPCPhysMemHandleData;
16647+
const void **ppIPCPhysMemHandleData;
1664616648
} ur_ipc_put_phys_mem_handle_exp_params_t;
1664716649

1664816650
///////////////////////////////////////////////////////////////////////////////
@@ -16652,7 +16654,7 @@ typedef struct ur_ipc_put_phys_mem_handle_exp_params_t {
1665216654
typedef struct ur_ipc_open_phys_mem_handle_exp_params_t {
1665316655
ur_context_handle_t *phContext;
1665416656
ur_device_handle_t *phDevice;
16655-
void **ppIPCPhysMemHandleData;
16657+
const void **ppIPCPhysMemHandleData;
1665616658
size_t *pipcPhysMemHandleDataSize;
1665716659
ur_physical_mem_handle_t **pphPhysMem;
1665816660
} ur_ipc_open_phys_mem_handle_exp_params_t;

unified-runtime/include/unified-runtime/ur_ddi.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,12 +1958,12 @@ typedef ur_result_t(UR_APICALL *ur_pfnIPCGetPhysMemHandleExp_t)(
19581958
///////////////////////////////////////////////////////////////////////////////
19591959
/// @brief Function-pointer for urIPCPutPhysMemHandleExp
19601960
typedef ur_result_t(UR_APICALL *ur_pfnIPCPutPhysMemHandleExp_t)(
1961-
ur_context_handle_t, void *);
1961+
ur_context_handle_t, const void *);
19621962

19631963
///////////////////////////////////////////////////////////////////////////////
19641964
/// @brief Function-pointer for urIPCOpenPhysMemHandleExp
19651965
typedef ur_result_t(UR_APICALL *ur_pfnIPCOpenPhysMemHandleExp_t)(
1966-
ur_context_handle_t, ur_device_handle_t, void *, size_t,
1966+
ur_context_handle_t, ur_device_handle_t, const void *, size_t,
19671967
ur_physical_mem_handle_t *);
19681968

19691969
///////////////////////////////////////////////////////////////////////////////

unified-runtime/scripts/core/exp-inter-process-communication.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ params:
177177
- type: $x_context_handle_t
178178
name: hContext
179179
desc: "[in] handle of the context object"
180-
- type: void*
180+
- type: const void*
181181
name: pIPCPhysMemHandleData
182-
desc: "[in] a pointer to the IPC physical memory handle data"
182+
desc: "[in] a pointer to the IPC physical memory handle data obtained with urIPCGetPhysMemHandleExp"
183183
returns:
184184
- $X_RESULT_ERROR_INVALID_CONTEXT
185185
- $X_RESULT_ERROR_INVALID_NULL_HANDLE:
@@ -201,9 +201,9 @@ params:
201201
- type: $x_device_handle_t
202202
name: hDevice
203203
desc: "[in] handle of the device object the physical memory was allocated on"
204-
- type: void *
204+
- type: const void *
205205
name: pIPCPhysMemHandleData
206-
desc: "[in] the IPC physical memory handle data"
206+
desc: "[in] the IPC physical memory handle data obtained with urIPCGetPhysMemHandleExp"
207207
- type: size_t
208208
name: ipcPhysMemHandleDataSize
209209
desc: "[in] size of the IPC physical memory handle data"

unified-runtime/source/adapters/cuda/device.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
11731173
hDevice->get()));
11741174
return ReturnValue(static_cast<ur_bool_t>(IPCSupported));
11751175
}
1176+
case UR_DEVICE_INFO_IPC_PHYSICAL_MEMORY_SUPPORT_EXP:
1177+
return ReturnValue(false);
11761178
case UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP:
11771179
case UR_DEVICE_INFO_COMMAND_BUFFER_EVENT_SUPPORT_EXP:
11781180
return ReturnValue(true);

unified-runtime/source/adapters/cuda/memory.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,3 +639,24 @@ UR_APIEXPORT ur_result_t UR_APICALL urIPCCloseMemHandleExp(ur_context_handle_t,
639639
void *pMem) {
640640
return umf::umf2urResult(umfCloseIPCHandle(pMem));
641641
}
642+
643+
UR_APIEXPORT ur_result_t UR_APICALL urIPCGetPhysMemHandleExp(
644+
ur_context_handle_t, ur_physical_mem_handle_t, void **, size_t *) {
645+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
646+
}
647+
648+
UR_APIEXPORT ur_result_t UR_APICALL
649+
urIPCPutPhysMemHandleExp(ur_context_handle_t, const void *) {
650+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
651+
}
652+
653+
UR_APIEXPORT ur_result_t UR_APICALL
654+
urIPCOpenPhysMemHandleExp(ur_context_handle_t, ur_device_handle_t, const void *,
655+
size_t, ur_physical_mem_handle_t *) {
656+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
657+
}
658+
659+
UR_APIEXPORT ur_result_t UR_APICALL
660+
urIPCClosePhysMemHandleExp(ur_context_handle_t, ur_physical_mem_handle_t) {
661+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
662+
}

unified-runtime/source/adapters/cuda/ur_interface_loader.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,10 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetIPCExpProcAddrTable(
510510
pDdiTable->pfnPutMemHandleExp = urIPCPutMemHandleExp;
511511
pDdiTable->pfnOpenMemHandleExp = urIPCOpenMemHandleExp;
512512
pDdiTable->pfnCloseMemHandleExp = urIPCCloseMemHandleExp;
513+
pDdiTable->pfnGetPhysMemHandleExp = urIPCGetPhysMemHandleExp;
514+
pDdiTable->pfnPutPhysMemHandleExp = urIPCPutPhysMemHandleExp;
515+
pDdiTable->pfnOpenPhysMemHandleExp = urIPCOpenPhysMemHandleExp;
516+
pDdiTable->pfnClosePhysMemHandleExp = urIPCClosePhysMemHandleExp;
513517

514518
return UR_RESULT_SUCCESS;
515519
}

unified-runtime/source/adapters/hip/device.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
10211021
static_cast<ur_exp_device_2d_block_array_capability_flags_t>(0));
10221022
case UR_DEVICE_INFO_IPC_MEMORY_SUPPORT_EXP:
10231023
return ReturnValue(false);
1024+
case UR_DEVICE_INFO_IPC_PHYSICAL_MEMORY_SUPPORT_EXP:
1025+
return ReturnValue(false);
10241026
case UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP: {
10251027
int RuntimeVersion = 0;
10261028
UR_CHECK_ERROR(hipRuntimeGetVersion(&RuntimeVersion));

unified-runtime/source/adapters/hip/memory.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,3 +658,24 @@ UR_APIEXPORT ur_result_t UR_APICALL urIPCCloseMemHandleExp(ur_context_handle_t,
658658
void *) {
659659
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
660660
}
661+
662+
UR_APIEXPORT ur_result_t UR_APICALL urIPCGetPhysMemHandleExp(
663+
ur_context_handle_t, ur_physical_mem_handle_t, void **, size_t *) {
664+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
665+
}
666+
667+
UR_APIEXPORT ur_result_t UR_APICALL
668+
urIPCPutPhysMemHandleExp(ur_context_handle_t, const void *) {
669+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
670+
}
671+
672+
UR_APIEXPORT ur_result_t UR_APICALL
673+
urIPCOpenPhysMemHandleExp(ur_context_handle_t, ur_device_handle_t, const void *,
674+
size_t, ur_physical_mem_handle_t *) {
675+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
676+
}
677+
678+
UR_APIEXPORT ur_result_t UR_APICALL
679+
urIPCClosePhysMemHandleExp(ur_context_handle_t, ur_physical_mem_handle_t) {
680+
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
681+
}

unified-runtime/source/adapters/hip/ur_interface_loader.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,10 @@ UR_DLLEXPORT ur_result_t UR_APICALL urGetIPCExpProcAddrTable(
503503
pDdiTable->pfnPutMemHandleExp = urIPCPutMemHandleExp;
504504
pDdiTable->pfnOpenMemHandleExp = urIPCOpenMemHandleExp;
505505
pDdiTable->pfnCloseMemHandleExp = urIPCCloseMemHandleExp;
506+
pDdiTable->pfnGetPhysMemHandleExp = urIPCGetPhysMemHandleExp;
507+
pDdiTable->pfnPutPhysMemHandleExp = urIPCPutPhysMemHandleExp;
508+
pDdiTable->pfnOpenPhysMemHandleExp = urIPCOpenPhysMemHandleExp;
509+
pDdiTable->pfnClosePhysMemHandleExp = urIPCClosePhysMemHandleExp;
506510

507511
return UR_RESULT_SUCCESS;
508512
}

unified-runtime/source/adapters/level_zero/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ if(UR_BUILD_ADAPTER_L0)
2525
${CMAKE_CURRENT_SOURCE_DIR}/usm.hpp
2626
${CMAKE_CURRENT_SOURCE_DIR}/memory.hpp
2727
${CMAKE_CURRENT_SOURCE_DIR}/kernel.hpp
28-
${CMAKE_CURRENT_SOURCE_DIR}/physical_mem.hpp
2928
${CMAKE_CURRENT_SOURCE_DIR}/platform.hpp
3029
${CMAKE_CURRENT_SOURCE_DIR}/program.hpp
3130
${CMAKE_CURRENT_SOURCE_DIR}/queue.hpp
@@ -132,7 +131,6 @@ if(UR_BUILD_ADAPTER_L0_V2)
132131
${CMAKE_CURRENT_SOURCE_DIR}/device.hpp
133132
${CMAKE_CURRENT_SOURCE_DIR}/image_common.hpp
134133
${CMAKE_CURRENT_SOURCE_DIR}/platform.hpp
135-
${CMAKE_CURRENT_SOURCE_DIR}/physical_mem.hpp
136134
${CMAKE_CURRENT_SOURCE_DIR}/program.hpp
137135
${CMAKE_CURRENT_SOURCE_DIR}/helpers/kernel_helpers.hpp
138136
${CMAKE_CURRENT_SOURCE_DIR}/helpers/memory_helpers.hpp
@@ -145,7 +143,6 @@ if(UR_BUILD_ADAPTER_L0_V2)
145143
${CMAKE_CURRENT_SOURCE_DIR}/image_common.cpp
146144
${CMAKE_CURRENT_SOURCE_DIR}/ur_interface_loader.cpp
147145
${CMAKE_CURRENT_SOURCE_DIR}/platform.cpp
148-
${CMAKE_CURRENT_SOURCE_DIR}/physical_mem.cpp
149146
${CMAKE_CURRENT_SOURCE_DIR}/program.cpp
150147
${CMAKE_CURRENT_SOURCE_DIR}/helpers/kernel_helpers.cpp
151148
${CMAKE_CURRENT_SOURCE_DIR}/helpers/memory_helpers.cpp
@@ -170,6 +167,7 @@ if(UR_BUILD_ADAPTER_L0_V2)
170167
${CMAKE_CURRENT_SOURCE_DIR}/v2/kernel.hpp
171168
${CMAKE_CURRENT_SOURCE_DIR}/v2/memory.hpp
172169
${CMAKE_CURRENT_SOURCE_DIR}/v2/lockable.hpp
170+
${CMAKE_CURRENT_SOURCE_DIR}/v2/physical_mem.hpp
173171
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_api.hpp
174172
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_batched.hpp
175173
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_immediate_in_order.hpp
@@ -187,6 +185,7 @@ if(UR_BUILD_ADAPTER_L0_V2)
187185
${CMAKE_CURRENT_SOURCE_DIR}/v2/event.cpp
188186
${CMAKE_CURRENT_SOURCE_DIR}/v2/kernel.cpp
189187
${CMAKE_CURRENT_SOURCE_DIR}/v2/memory.cpp
188+
${CMAKE_CURRENT_SOURCE_DIR}/v2/physical_mem.cpp
190189
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_api.cpp
191190
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_batched.cpp
192191
${CMAKE_CURRENT_SOURCE_DIR}/v2/queue_create.cpp

0 commit comments

Comments
 (0)