Skip to content

Commit 9ca0e2e

Browse files
[UR] Change IPC handle get function to return the original pointer (#20490)
This commit makes the UR interfaces implementing urIPCGetMemHandleExp return the exact memory pointer from UMF instead of copying the handle data. This is done as the exact pointer is expected to be passed when calling umfPutIPCHandle in the urIPCPutMemHandleExp interface. --------- Signed-off-by: Larsen, Steffen <[email protected]>
1 parent a3f4959 commit 9ca0e2e

File tree

18 files changed

+44
-53
lines changed

18 files changed

+44
-53
lines changed

unified-runtime/include/ur_api.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unified-runtime/include/ur_ddi.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unified-runtime/include/ur_print.hpp

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ params:
3636
- type: void *
3737
name: pMem
3838
desc: "[in] pointer to device USM memory"
39-
- type: void*
40-
name: pIPCMemHandleData
39+
- type: void**
40+
name: ppIPCMemHandleData
4141
desc: "[out][optional] a pointer to the IPC memory handle data"
4242
- type: size_t*
4343
name: pIPCMemHandleDataSizeRet
@@ -47,7 +47,7 @@ returns:
4747
- $X_RESULT_ERROR_INVALID_NULL_HANDLE:
4848
- "`NULL == hContext`"
4949
- $X_RESULT_ERROR_INVALID_NULL_POINTER:
50-
- "`NULL == pIPCMemHandleData`"
50+
- "`NULL == ppIPCMemHandleData`"
5151
- "`NULL == pIPCMemHandleDataSizeRet`"
5252
- $X_RESULT_ERROR_OUT_OF_HOST_MEMORY
5353
- $X_RESULT_ERROR_OUT_OF_RESOURCES

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -592,28 +592,25 @@ CUsurfObject SurfaceMem::getSurface(const ur_device_handle_t Device) {
592592
}
593593

594594
UR_APIEXPORT ur_result_t UR_APICALL
595-
urIPCGetMemHandleExp(ur_context_handle_t, void *pMem, void *pIPCMemHandleData,
595+
urIPCGetMemHandleExp(ur_context_handle_t, void *pMem, void **ppIPCMemHandleData,
596596
size_t *pIPCMemHandleDataSizeRet) {
597597
umf_memory_pool_handle_t umfPool;
598598
auto urRet = umf::umf2urResult(umfPoolByPtr(pMem, &umfPool));
599599
if (urRet)
600600
return urRet;
601601

602602
// Fast path for returning the size of the handle only.
603-
if (!pIPCMemHandleData)
603+
if (!ppIPCMemHandleData)
604604
return umf::umf2urResult(
605605
umfPoolGetIPCHandleSize(umfPool, pIPCMemHandleDataSizeRet));
606606

607607
size_t fallbackUMFHandleSize = 0;
608608
size_t *umfHandleSize = pIPCMemHandleDataSizeRet != nullptr
609609
? pIPCMemHandleDataSizeRet
610610
: &fallbackUMFHandleSize;
611-
umf_ipc_handle_t umfHandle;
612-
urRet = umf::umf2urResult(umfGetIPCHandle(pMem, &umfHandle, umfHandleSize));
613-
if (urRet)
614-
return urRet;
615-
std::memcpy(pIPCMemHandleData, umfHandle, *umfHandleSize);
616-
return UR_RESULT_SUCCESS;
611+
return umf::umf2urResult(umfGetIPCHandle(
612+
pMem, reinterpret_cast<umf_ipc_handle_t *>(ppIPCMemHandleData),
613+
umfHandleSize));
617614
}
618615

619616
UR_APIEXPORT ur_result_t UR_APICALL

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ hipSurfaceObject_t SurfaceMem::getSurface(const ur_device_handle_t Device) {
642642
}
643643

644644
UR_APIEXPORT ur_result_t UR_APICALL urIPCGetMemHandleExp(ur_context_handle_t,
645-
void *, void *,
645+
void *, void **,
646646
size_t *) {
647647
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
648648
}

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,28 +1953,25 @@ ur_result_t urEnqueueWriteHostPipe(
19531953
}
19541954

19551955
ur_result_t urIPCGetMemHandleExp(ur_context_handle_t, void *pMem,
1956-
void *pIPCMemHandleData,
1956+
void **ppIPCMemHandleData,
19571957
size_t *pIPCMemHandleDataSizeRet) {
19581958
umf_memory_pool_handle_t umfPool;
19591959
auto urRet = umf::umf2urResult(umfPoolByPtr(pMem, &umfPool));
19601960
if (urRet)
19611961
return urRet;
19621962

19631963
// Fast path for returning the size of the handle only.
1964-
if (!pIPCMemHandleData)
1964+
if (!ppIPCMemHandleData)
19651965
return umf::umf2urResult(
19661966
umfPoolGetIPCHandleSize(umfPool, pIPCMemHandleDataSizeRet));
19671967

19681968
size_t fallbackUMFHandleSize = 0;
19691969
size_t *umfHandleSize = pIPCMemHandleDataSizeRet != nullptr
19701970
? pIPCMemHandleDataSizeRet
19711971
: &fallbackUMFHandleSize;
1972-
umf_ipc_handle_t umfHandle;
1973-
urRet = umf::umf2urResult(umfGetIPCHandle(pMem, &umfHandle, umfHandleSize));
1974-
if (urRet)
1975-
return urRet;
1976-
std::memcpy(pIPCMemHandleData, umfHandle, *umfHandleSize);
1977-
return UR_RESULT_SUCCESS;
1972+
return umf::umf2urResult(umfGetIPCHandle(
1973+
pMem, reinterpret_cast<umf_ipc_handle_t *>(ppIPCMemHandleData),
1974+
umfHandleSize));
19781975
}
19791976

19801977
ur_result_t urIPCPutMemHandleExp(ur_context_handle_t, void *pIPCMemHandleData) {

unified-runtime/source/adapters/level_zero/ur_interface_loader.hpp

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unified-runtime/source/adapters/level_zero/v2/memory.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -782,28 +782,25 @@ ur_result_t urMemImageGetInfo(ur_mem_handle_t /*hMemory*/,
782782
}
783783

784784
ur_result_t urIPCGetMemHandleExp(ur_context_handle_t, void *pMem,
785-
void *pIPCMemHandleData,
785+
void **ppIPCMemHandleData,
786786
size_t *pIPCMemHandleDataSizeRet) {
787787
umf_memory_pool_handle_t umfPool;
788788
auto urRet = umf::umf2urResult(umfPoolByPtr(pMem, &umfPool));
789789
if (urRet)
790790
return urRet;
791791

792792
// Fast path for returning the size of the handle only.
793-
if (!pIPCMemHandleData)
793+
if (!ppIPCMemHandleData)
794794
return umf::umf2urResult(
795795
umfPoolGetIPCHandleSize(umfPool, pIPCMemHandleDataSizeRet));
796796

797797
size_t fallbackUMFHandleSize = 0;
798798
size_t *umfHandleSize = pIPCMemHandleDataSizeRet != nullptr
799799
? pIPCMemHandleDataSizeRet
800800
: &fallbackUMFHandleSize;
801-
umf_ipc_handle_t umfHandle;
802-
urRet = umf::umf2urResult(umfGetIPCHandle(pMem, &umfHandle, umfHandleSize));
803-
if (urRet)
804-
return urRet;
805-
std::memcpy(pIPCMemHandleData, umfHandle, *umfHandleSize);
806-
return UR_RESULT_SUCCESS;
801+
return umf::umf2urResult(umfGetIPCHandle(
802+
pMem, reinterpret_cast<umf_ipc_handle_t *>(ppIPCMemHandleData),
803+
umfHandleSize));
807804
}
808805

809806
ur_result_t urIPCPutMemHandleExp(ur_context_handle_t, void *pIPCMemHandleData) {

unified-runtime/source/adapters/mock/ur_mockddi.cpp

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)