Skip to content

Commit 64d18bd

Browse files
authored
Merge pull request #596 from vinser52/svinogra_ipc_api
Add umfPoolGetIPCHandleSize API
2 parents 245d916 + 5c3b4da commit 64d18bd

File tree

5 files changed

+53
-8
lines changed

5 files changed

+53
-8
lines changed

include/umf/ipc.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ extern "C" {
1919

2020
typedef struct umf_ipc_data_t *umf_ipc_handle_t;
2121

22+
///
23+
/// @brief Returns the size of IPC handles for the specified pool.
24+
/// @param hPool [in] Pool handle
25+
/// @param size [out] size of IPC handle in bytes.
26+
/// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
27+
umf_result_t umfPoolGetIPCHandleSize(umf_memory_pool_handle_t hPool,
28+
size_t *size);
29+
2230
///
2331
/// @brief Creates an IPC handle for the specified UMF allocation.
2432
/// @param ptr pointer to the allocated memory.

src/ipc.c

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,36 @@
1919
#include "utils_common.h"
2020
#include "utils_log.h"
2121

22+
umf_result_t umfPoolGetIPCHandleSize(umf_memory_pool_handle_t hPool,
23+
size_t *size) {
24+
umf_result_t ret = UMF_RESULT_SUCCESS;
25+
if (hPool == NULL) {
26+
LOG_ERR("pool handle is NULL.");
27+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
28+
}
29+
30+
if (size == NULL) {
31+
LOG_ERR("size is NULL.");
32+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
33+
}
34+
35+
// We cannot use umfPoolGetMemoryProvider function because it returns
36+
// upstream provider but we need tracking one
37+
umf_memory_provider_handle_t hProvider = hPool->provider;
38+
assert(hProvider);
39+
40+
size_t providerIPCHandleSize;
41+
ret = umfMemoryProviderGetIPCHandleSize(hProvider, &providerIPCHandleSize);
42+
if (ret != UMF_RESULT_SUCCESS) {
43+
LOG_ERR("cannot get IPC handle size.");
44+
return ret;
45+
}
46+
47+
*size = sizeof(umf_ipc_data_t) + providerIPCHandleSize;
48+
49+
return ret;
50+
}
51+
2252
umf_result_t umfGetIPCHandle(const void *ptr, umf_ipc_handle_t *umfIPCHandle,
2353
size_t *size) {
2454
size_t ipcHandleSize = 0;
@@ -29,25 +59,23 @@ umf_result_t umfGetIPCHandle(const void *ptr, umf_ipc_handle_t *umfIPCHandle,
2959
return ret;
3060
}
3161

32-
// We cannot use umfPoolGetMemoryProvider function because it returns
33-
// upstream provider but we need tracking one
34-
umf_memory_provider_handle_t provider = allocInfo.pool->provider;
35-
assert(provider);
36-
37-
size_t providerIPCHandleSize;
38-
ret = umfMemoryProviderGetIPCHandleSize(provider, &providerIPCHandleSize);
62+
ret = umfPoolGetIPCHandleSize(allocInfo.pool, &ipcHandleSize);
3963
if (ret != UMF_RESULT_SUCCESS) {
4064
LOG_ERR("cannot get IPC handle size.");
4165
return ret;
4266
}
4367

44-
ipcHandleSize = sizeof(umf_ipc_data_t) + providerIPCHandleSize;
4568
umf_ipc_data_t *ipcData = umf_ba_global_alloc(ipcHandleSize);
4669
if (!ipcData) {
4770
LOG_ERR("failed to allocate ipcData");
4871
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
4972
}
5073

74+
// We cannot use umfPoolGetMemoryProvider function because it returns
75+
// upstream provider but we need tracking one
76+
umf_memory_provider_handle_t provider = allocInfo.pool->provider;
77+
assert(provider);
78+
5179
ret = umfMemoryProviderGetIPCHandle(provider, allocInfo.base,
5280
allocInfo.baseSize,
5381
(void *)ipcData->providerIpcData);

src/libumf.def.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ EXPORTS
5050
umfPoolCreateFromMemspace
5151
umfPoolDestroy
5252
umfPoolFree
53+
umfPoolGetIPCHandleSize
5354
umfPoolGetLastAllocationError
5455
umfPoolGetMemoryProvider
5556
umfPoolMalloc

src/libumf.map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ UMF_1.0 {
5050
umfPoolCreateFromMemspace;
5151
umfPoolDestroy;
5252
umfPoolFree;
53+
umfPoolGetIPCHandleSize;
5354
umfPoolGetLastAllocationError;
5455
umfPoolGetMemoryProvider;
5556
umfPoolMalloc;

test/ipcFixtures.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ struct umfIpcTest : umf_test::test,
112112
MemoryAccessor *memAccessor = nullptr;
113113
};
114114

115+
TEST_P(umfIpcTest, GetIPCHandleSize) {
116+
size_t size = 0;
117+
umf_result_t ret = umfPoolGetIPCHandleSize(pool.get(), &size);
118+
EXPECT_EQ(ret, UMF_RESULT_SUCCESS);
119+
EXPECT_GT(size, 0);
120+
}
121+
115122
TEST_P(umfIpcTest, BasicFlow) {
116123
constexpr size_t SIZE = 100;
117124
std::vector<int> expected_data(SIZE);

0 commit comments

Comments
 (0)