Skip to content

Commit bffefda

Browse files
committed
use pools not only providers in IPC tests
1 parent b8088be commit bffefda

11 files changed

+106
-73
lines changed

test/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,14 @@ function(add_umf_ipc_test)
397397
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
398398

399399
set_tests_properties(${TEST_NAME} PROPERTIES LABELS "umf")
400+
set_tests_properties(${TEST_NAME} PROPERTIES TIMEOUT 60)
400401
if(NOT UMF_TESTS_FAIL_ON_SKIP)
401402
set_tests_properties(${TEST_NAME} PROPERTIES SKIP_RETURN_CODE 125)
402403
endif()
403404
endfunction()
404405

405406
if(LINUX)
406-
if(NOT UMF_DISABLE_HWLOC)
407+
if(NOT UMF_DISABLE_HWLOC AND UMF_POOL_SCALABLE_ENABLED)
407408
build_umf_test(
408409
NAME
409410
ipc_os_prov_consumer
@@ -457,7 +458,9 @@ if(LINUX)
457458

458459
# TODO add IPC tests for CUDA
459460

460-
if(UMF_BUILD_GPU_TESTS AND UMF_BUILD_LEVEL_ZERO_PROVIDER)
461+
if(UMF_BUILD_GPU_TESTS
462+
AND UMF_BUILD_LEVEL_ZERO_PROVIDER
463+
AND UMF_BUILD_LIBUMF_POOL_DISJOINT)
461464
build_umf_test(
462465
NAME
463466
ipc_level_zero_prov_consumer
@@ -468,6 +471,7 @@ if(LINUX)
468471
providers/level_zero_helpers.cpp
469472
LIBS
470473
ze_loader
474+
disjoint_pool
471475
${UMF_UTILS_FOR_TEST})
472476
build_umf_test(
473477
NAME
@@ -479,6 +483,7 @@ if(LINUX)
479483
providers/level_zero_helpers.cpp
480484
LIBS
481485
ze_loader
486+
disjoint_pool
482487
${UMF_UTILS_FOR_TEST})
483488
target_include_directories(umf_test-ipc_level_zero_prov_producer
484489
PRIVATE ${LEVEL_ZERO_INCLUDE_DIRS})

test/common/ipc_common.c

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ int consumer_connect(int port) {
110110
return ret;
111111
}
112112

113-
int run_consumer(int port, umf_memory_provider_ops_t *provider_ops,
114-
void *provider_params, memcopy_callback_t memcopy_callback,
115-
void *memcopy_ctx) {
113+
int run_consumer(int port, umf_memory_pool_ops_t *pool_ops, void *pool_params,
114+
umf_memory_provider_ops_t *provider_ops, void *provider_params,
115+
memcopy_callback_t memcopy_callback, void *memcopy_ctx) {
116116
char consumer_message[MSG_SIZE];
117117
int producer_socket = -1;
118118
int ret = -1;
@@ -131,16 +131,23 @@ int run_consumer(int port, umf_memory_provider_ops_t *provider_ops,
131131
return -1;
132132
}
133133

134+
umf_memory_pool_handle_t pool;
135+
umf_result = umfPoolCreate(pool_ops, provider, pool_params, 0, &pool);
136+
if (umf_result != UMF_RESULT_SUCCESS) {
137+
fprintf(stderr, "[consumer] ERROR: creating memory pool failed\n");
138+
goto err_umfMemoryProviderDestroy;
139+
}
140+
134141
producer_socket = consumer_connect(port);
135142
if (producer_socket < 0) {
136-
goto err_umfMemoryProviderDestroy;
143+
goto err_umfMemoryPoolDestroy;
137144
}
138145

139146
// allocate the zeroed receive buffer
140147
char *recv_buffer = calloc(1, MSG_SIZE);
141148
if (!recv_buffer) {
142149
fprintf(stderr, "[consumer] ERROR: out of memory\n");
143-
goto err_umfMemoryProviderDestroy;
150+
goto err_umfMemoryPoolDestroy;
144151
}
145152

146153
// get the size of the IPC handle from the producer
@@ -183,7 +190,7 @@ int run_consumer(int port, umf_memory_provider_ops_t *provider_ops,
183190
len);
184191

185192
void *SHM_ptr;
186-
umf_result = umfMemoryProviderOpenIPCHandle(provider, IPC_handle, &SHM_ptr);
193+
umf_result = umfOpenIPCHandle(pool, IPC_handle, &SHM_ptr);
187194
if (umf_result == UMF_RESULT_ERROR_NOT_SUPPORTED) {
188195
fprintf(stderr,
189196
"[consumer] SKIP: opening the IPC handle is not supported\n");
@@ -240,8 +247,7 @@ int run_consumer(int port, umf_memory_provider_ops_t *provider_ops,
240247

241248
err_closeIPCHandle:
242249
// we do not know the exact size of the remote shared memory
243-
umf_result = umfMemoryProviderCloseIPCHandle(provider, SHM_ptr,
244-
sizeof(unsigned long long));
250+
umf_result = umfCloseIPCHandle(SHM_ptr);
245251
if (umf_result != UMF_RESULT_SUCCESS) {
246252
fprintf(stderr, "[consumer] ERROR: closing the IPC handle failed\n");
247253
}
@@ -252,6 +258,9 @@ int run_consumer(int port, umf_memory_provider_ops_t *provider_ops,
252258
err_close_producer_socket:
253259
close(producer_socket);
254260

261+
err_umfMemoryPoolDestroy:
262+
umfPoolDestroy(pool);
263+
255264
err_umfMemoryProviderDestroy:
256265
umfMemoryProviderDestroy(provider);
257266

@@ -303,9 +312,9 @@ int producer_connect(int port) {
303312
return -1;
304313
}
305314

306-
int run_producer(int port, umf_memory_provider_ops_t *provider_ops,
307-
void *provider_params, memcopy_callback_t memcopy_callback,
308-
void *memcopy_ctx) {
315+
int run_producer(int port, umf_memory_pool_ops_t *pool_ops, void *pool_params,
316+
umf_memory_provider_ops_t *provider_ops, void *provider_params,
317+
memcopy_callback_t memcopy_callback, void *memcopy_ctx) {
309318
int ret = -1;
310319
umf_memory_provider_handle_t provider = NULL;
311320
umf_result_t umf_result = UMF_RESULT_ERROR_UNKNOWN;
@@ -321,12 +330,19 @@ int run_producer(int port, umf_memory_provider_ops_t *provider_ops,
321330
return -1;
322331
}
323332

333+
umf_memory_pool_handle_t pool;
334+
umf_result = umfPoolCreate(pool_ops, provider, pool_params, 0, &pool);
335+
if (umf_result != UMF_RESULT_SUCCESS) {
336+
fprintf(stderr, "[producer] ERROR: creating memory pool failed\n");
337+
goto err_umfMemoryProviderDestroy;
338+
}
339+
324340
size_t page_size;
325341
umf_result = umfMemoryProviderGetMinPageSize(provider, NULL, &page_size);
326342
if (umf_result != UMF_RESULT_SUCCESS) {
327343
fprintf(stderr,
328344
"[producer] ERROR: getting the minimum page size failed\n");
329-
goto err_umfMemoryProviderDestroy;
345+
goto err_umfMemoryPoolDestroy;
330346
}
331347

332348
// Make 3 allocations of size: 1 page, 2 pages and 3 pages
@@ -335,45 +351,36 @@ int run_producer(int port, umf_memory_provider_ops_t *provider_ops,
335351
size_t ptr2_size = 2 * page_size;
336352
size_t size_IPC_shared_memory = 3 * page_size;
337353

338-
umf_result = umfMemoryProviderAlloc(provider, ptr1_size, 0, &ptr1);
339-
if (umf_result != UMF_RESULT_SUCCESS) {
354+
ptr1 = umfPoolMalloc(pool, ptr1_size);
355+
if (ptr1 == NULL) {
340356
fprintf(stderr, "[producer] ERROR: allocating 1 page failed\n");
341-
goto err_umfMemoryProviderDestroy;
357+
goto err_umfMemoryPoolDestroy;
342358
}
343359

344-
umf_result = umfMemoryProviderAlloc(provider, ptr2_size, 0, &ptr2);
345-
if (umf_result != UMF_RESULT_SUCCESS) {
360+
ptr2 = umfPoolMalloc(pool, ptr2_size);
361+
if (ptr2 == NULL) {
346362
fprintf(stderr, "[producer] ERROR: allocating 2 pages failed\n");
347363
goto err_free_ptr1;
348364
}
349365

350-
umf_result = umfMemoryProviderAlloc(provider, size_IPC_shared_memory, 0,
351-
&IPC_shared_memory);
352-
if (umf_result != UMF_RESULT_SUCCESS) {
366+
IPC_shared_memory = umfPoolMalloc(pool, size_IPC_shared_memory);
367+
if (IPC_shared_memory == NULL) {
353368
fprintf(stderr, "[producer] ERROR: allocating 3 pages failed\n");
354369
goto err_free_ptr2;
355370
}
356371

357372
// get size of the IPC handle
358373
size_t IPC_handle_size;
359-
umf_result = umfMemoryProviderGetIPCHandleSize(provider, &IPC_handle_size);
360-
if (umf_result != UMF_RESULT_SUCCESS) {
361-
fprintf(stderr,
362-
"[producer] ERROR: getting size of the IPC handle failed\n");
363-
goto err_free_IPC_shared_memory;
364-
}
374+
umf_ipc_handle_t IPC_handle = NULL;
365375

366-
// allocate data for IPC provider
367-
void *IPC_handle = malloc(IPC_handle_size);
368-
if (IPC_handle == NULL) {
369-
fprintf(stderr,
370-
"[producer] ERROR: allocating memory for IPC handle failed\n");
376+
// get the IPC handle
377+
umf_result =
378+
umfGetIPCHandle(IPC_shared_memory, &IPC_handle, &IPC_handle_size);
379+
if (umf_result != UMF_RESULT_SUCCESS) {
380+
fprintf(stderr, "[producer] ERROR: getting the IPC handle failed\n");
371381
goto err_free_IPC_shared_memory;
372382
}
373383

374-
// zero the IPC handle and the shared memory
375-
memset(IPC_handle, 0, IPC_handle_size);
376-
377384
// save a random number (&provider) in the shared memory
378385
unsigned long long SHM_number_1 = (unsigned long long)&provider;
379386
memcopy_callback(IPC_shared_memory, &SHM_number_1, sizeof(SHM_number_1),
@@ -382,16 +389,6 @@ int run_producer(int port, umf_memory_provider_ops_t *provider_ops,
382389
fprintf(stderr, "[producer] My shared memory contains a number: %llu\n",
383390
SHM_number_1);
384391

385-
// get the IPC handle from the OS memory provider
386-
umf_result = umfMemoryProviderGetIPCHandle(
387-
provider, IPC_shared_memory, size_IPC_shared_memory, IPC_handle);
388-
if (umf_result != UMF_RESULT_SUCCESS) {
389-
fprintf(stderr,
390-
"[producer] ERROR: getting the IPC handle from the OS memory "
391-
"provider failed\n");
392-
goto err_free_IPC_handle;
393-
}
394-
395392
fprintf(stderr, "[producer] Got the IPC handle\n");
396393

397394
producer_socket = producer_connect(port);
@@ -494,22 +491,25 @@ int run_producer(int port, umf_memory_provider_ops_t *provider_ops,
494491
close(producer_socket);
495492

496493
err_PutIPCHandle:
497-
umf_result = umfMemoryProviderPutIPCHandle(provider, IPC_handle);
494+
umf_result = umfPutIPCHandle(IPC_handle);
498495
if (umf_result != UMF_RESULT_SUCCESS) {
499496
fprintf(stderr, "[producer] ERROR: putting the IPC handle failed\n");
500497
}
501498

502499
fprintf(stderr, "[producer] Put the IPC handle\n");
503500

504-
err_free_IPC_handle:
505-
free(IPC_handle);
506501
err_free_IPC_shared_memory:
507-
(void)umfMemoryProviderFree(provider, IPC_shared_memory,
508-
size_IPC_shared_memory);
502+
(void)umfFree(IPC_shared_memory);
503+
509504
err_free_ptr2:
510-
(void)umfMemoryProviderFree(provider, ptr2, ptr2_size);
505+
(void)umfFree(ptr2);
506+
511507
err_free_ptr1:
512-
(void)umfMemoryProviderFree(provider, ptr1, ptr1_size);
508+
(void)umfFree(ptr1);
509+
510+
err_umfMemoryPoolDestroy:
511+
umfPoolDestroy(pool);
512+
513513
err_umfMemoryProviderDestroy:
514514
umfMemoryProviderDestroy(provider);
515515

test/common/ipc_common.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
#ifndef UMF_TEST_IPC_COMMON_H
99
#define UMF_TEST_IPC_COMMON_H
1010

11+
#include <umf/ipc.h>
12+
#include <umf/memory_pool.h>
1113
#include <umf/memory_provider.h>
14+
#include <umf/pools/pool_scalable.h>
1215

1316
// pointer to the function that returns void and accept two int values
1417
typedef void (*memcopy_callback_t)(void *dst, const void *src, size_t size,
@@ -17,11 +20,12 @@ typedef void (*memcopy_callback_t)(void *dst, const void *src, size_t size,
1720
int producer_connect(int port);
1821
int consumer_connect(int port);
1922

20-
int run_producer(int port, umf_memory_provider_ops_t *provider_ops,
21-
void *provider_params, memcopy_callback_t memcopy_callback,
22-
void *memcopy_ctx);
23-
int run_consumer(int port, umf_memory_provider_ops_t *provider_ops,
24-
void *provider_params, memcopy_callback_t memcopy_callback,
25-
void *memcopy_ctx);
23+
int run_producer(int port, umf_memory_pool_ops_t *pool_ops, void *pool_params,
24+
umf_memory_provider_ops_t *provider_ops, void *provider_params,
25+
memcopy_callback_t memcopy_callback, void *memcopy_ctx);
26+
27+
int run_consumer(int port, umf_memory_pool_ops_t *pool_ops, void *pool_params,
28+
umf_memory_provider_ops_t *provider_ops, void *provider_params,
29+
memcopy_callback_t memcopy_callback, void *memcopy_ctx);
2630

2731
#endif // UMF_TEST_IPC_COMMON_H

test/ipc_devdax_prov_consumer.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ int main(int argc, char *argv[]) {
3636
umf_devdax_memory_provider_params_t devdax_params =
3737
umfDevDaxMemoryProviderParamsDefault(path, atol(size));
3838

39-
return run_consumer(port, umfDevDaxMemoryProviderOps(), &devdax_params,
40-
memcopy, NULL);
39+
void *pool_params = NULL;
40+
41+
return run_consumer(port, umfScalablePoolOps(), pool_params,
42+
umfDevDaxMemoryProviderOps(), &devdax_params, memcopy,
43+
NULL);
4144
}

test/ipc_devdax_prov_producer.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ int main(int argc, char *argv[]) {
3636
umf_devdax_memory_provider_params_t devdax_params =
3737
umfDevDaxMemoryProviderParamsDefault(path, atol(size));
3838

39-
return run_producer(port, umfDevDaxMemoryProviderOps(), &devdax_params,
40-
memcopy, NULL);
39+
void *pool_params = NULL;
40+
41+
return run_producer(port, umfScalablePoolOps(), pool_params,
42+
umfDevDaxMemoryProviderOps(), &devdax_params, memcopy,
43+
NULL);
4144
}

test/ipc_file_prov_consumer.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ int main(int argc, char *argv[]) {
4343
file_params.visibility = UMF_MEM_MAP_SHARED;
4444
}
4545

46-
return run_consumer(port, umfFileMemoryProviderOps(), &file_params, memcopy,
46+
void *pool_params = NULL;
47+
48+
return run_consumer(port, umfScalablePoolOps(), pool_params,
49+
umfFileMemoryProviderOps(), &file_params, memcopy,
4750
NULL);
4851
}

test/ipc_file_prov_producer.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ int main(int argc, char *argv[]) {
4343
file_params.visibility = UMF_MEM_MAP_SHARED;
4444
}
4545

46-
return run_producer(port, umfFileMemoryProviderOps(), &file_params, memcopy,
46+
void *pool_params = NULL;
47+
48+
return run_producer(port, umfScalablePoolOps(), pool_params,
49+
umfFileMemoryProviderOps(), &file_params, memcopy,
4750
NULL);
4851
}

test/ipc_os_prov_consumer.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ int main(int argc, char *argv[]) {
2929
os_params.shm_name = argv[2];
3030
}
3131

32-
return run_consumer(port, umfOsMemoryProviderOps(), &os_params, memcopy,
33-
NULL);
32+
void *pool_params = NULL;
33+
34+
return run_consumer(port, umfScalablePoolOps(), pool_params,
35+
umfOsMemoryProviderOps(), &os_params, memcopy, NULL);
3436
}

test/ipc_os_prov_producer.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ int main(int argc, char *argv[]) {
2929
os_params.shm_name = argv[2];
3030
}
3131

32-
return run_producer(port, umfOsMemoryProviderOps(), &os_params, memcopy,
33-
NULL);
32+
void *pool_params = NULL;
33+
34+
return run_producer(port, umfScalablePoolOps(), pool_params,
35+
umfOsMemoryProviderOps(), &os_params, memcopy, NULL);
3436
}

test/providers/ipc_level_zero_prov_consumer.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <stdio.h>
99
#include <stdlib.h>
1010

11+
#include <umf/pools/pool_disjoint.h>
1112
#include <umf/providers/provider_level_zero.h>
1213

1314
#include "ipc_common.h"
@@ -25,6 +26,9 @@ int main(int argc, char *argv[]) {
2526
level_zero_memory_provider_params_t l0_params =
2627
create_level_zero_prov_params(UMF_MEMORY_TYPE_DEVICE);
2728

28-
return run_consumer(port, umfLevelZeroMemoryProviderOps(), &l0_params,
29-
memcopy, &l0_params);
29+
umf_disjoint_pool_params_t pool_params = umfDisjointPoolParamsDefault();
30+
31+
return run_consumer(port, umfDisjointPoolOps(), &pool_params,
32+
umfLevelZeroMemoryProviderOps(), &l0_params, memcopy,
33+
&l0_params);
3034
}

0 commit comments

Comments
 (0)