Skip to content

Commit 5d8fd5f

Browse files
authored
Merge pull request #521 from vinser52/svinogra_ipc_bench
Add benchmarks for IPC API
2 parents f05befc + 081dfdf commit 5d8fd5f

File tree

3 files changed

+163
-1
lines changed

3 files changed

+163
-1
lines changed

.github/workflows/gpu.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,7 @@ jobs:
8888
- name: Run examples
8989
working-directory: ${{github.workspace}}/build
9090
run: ctest --output-on-failure --test-dir examples -C ${{env.BUILD_TYPE}}
91+
92+
- name: Run benchmarks
93+
working-directory: ${{github.workspace}}/build
94+
run: ctest --output-on-failure --test-dir benchmark -C ${{env.BUILD_TYPE}} --exclude-regex umf-bench-multithreaded

benchmark/CMakeLists.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ function(add_umf_benchmark)
4545
${BENCH_NAME}
4646
PRIVATE ${UMF_CMAKE_SOURCE_DIR}/include
4747
${UMF_CMAKE_SOURCE_DIR}/src/utils
48-
${UMF_CMAKE_SOURCE_DIR}/test/common)
48+
${UMF_CMAKE_SOURCE_DIR}/test/common
49+
${UMF_CMAKE_SOURCE_DIR}/examples/basic)
4950

5051
target_link_directories(${BENCH_NAME} PRIVATE ${ARG_LIBDIRS})
5152

@@ -80,6 +81,13 @@ function(add_umf_benchmark)
8081
target_compile_definitions(${BENCH_NAME}
8182
PRIVATE UMF_POOL_SCALABLE_ENABLED=1)
8283
endif()
84+
if(UMF_BUILD_LEVEL_ZERO_PROVIDER)
85+
target_compile_definitions(${BENCH_NAME}
86+
PRIVATE UMF_BUILD_LEVEL_ZERO_PROVIDER=1)
87+
endif()
88+
if(UMF_BUILD_GPU_TESTS)
89+
target_compile_definitions(${BENCH_NAME} PRIVATE UMF_BUILD_GPU_TESTS=1)
90+
endif()
8391
endfunction()
8492

8593
set(LIB_DIRS ${LIBHWLOC_LIBRARY_DIRS})
@@ -95,6 +103,9 @@ endif()
95103
if(LINUX)
96104
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} m)
97105
endif()
106+
if(UMF_BUILD_GPU_TESTS)
107+
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} ze_loader)
108+
endif()
98109

99110
# BENCHMARKS
100111

benchmark/ubench.c

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
*
88
*/
99

10+
#include <umf/ipc.h>
1011
#include <umf/memory_pool.h>
1112
#include <umf/pools/pool_proxy.h>
1213
#include <umf/pools/pool_scalable.h>
14+
#include <umf/providers/provider_level_zero.h>
1315
#include <umf/providers/provider_os_memory.h>
1416

1517
#ifdef UMF_BUILD_LIBUMF_POOL_DISJOINT
@@ -29,6 +31,10 @@
2931
#include "ubench.h"
3032
#include "utils_common.h"
3133

34+
#if (defined UMF_BUILD_GPU_TESTS)
35+
#include "utils_level_zero.h"
36+
#endif
37+
3238
// BENCHMARK CONFIG
3339
#define N_ITERATIONS 1000
3440
#define ALLOC_SIZE (util_get_page_size())
@@ -339,4 +345,145 @@ UBENCH_EX(simple, scalable_pool_with_os_memory_provider) {
339345
}
340346
#endif /* (defined UMF_POOL_SCALABLE_ENABLED) */
341347

348+
#if (defined UMF_BUILD_LIBUMF_POOL_DISJOINT && \
349+
defined UMF_BUILD_LEVEL_ZERO_PROVIDER && defined UMF_BUILD_GPU_TESTS)
350+
static void do_ipc_get_put_benchmark(alloc_t *allocs, size_t num_allocs,
351+
size_t repeats,
352+
umf_ipc_handle_t *ipc_handles) {
353+
for (size_t r = 0; r < repeats; ++r) {
354+
for (size_t i = 0; i < num_allocs; ++i) {
355+
size_t handle_size = 0;
356+
umf_result_t res =
357+
umfGetIPCHandle(allocs[i].ptr, &(ipc_handles[i]), &handle_size);
358+
if (res != UMF_RESULT_SUCCESS) {
359+
fprintf(stderr, "umfGetIPCHandle() failed\n");
360+
}
361+
}
362+
363+
for (size_t i = 0; i < num_allocs; ++i) {
364+
umf_result_t res = umfPutIPCHandle(ipc_handles[i]);
365+
if (res != UMF_RESULT_SUCCESS) {
366+
fprintf(stderr, "umfPutIPCHandle() failed\n");
367+
}
368+
}
369+
}
370+
}
371+
372+
int create_level_zero_params(level_zero_memory_provider_params_t *params) {
373+
uint32_t driver_idx = 0;
374+
ze_driver_handle_t driver = NULL;
375+
ze_context_handle_t context = NULL;
376+
ze_device_handle_t device = NULL;
377+
378+
int ret = init_level_zero();
379+
if (ret != 0) {
380+
fprintf(stderr, "Failed to init Level 0!\n");
381+
return ret;
382+
}
383+
384+
ret = find_driver_with_gpu(&driver_idx, &driver);
385+
if (ret || driver == NULL) {
386+
fprintf(stderr, "Cannot find L0 driver with GPU device!\n");
387+
return ret;
388+
}
389+
390+
ret = create_context(driver, &context);
391+
if (ret != 0) {
392+
fprintf(stderr, "Failed to create L0 context!\n");
393+
return ret;
394+
}
395+
396+
ret = find_gpu_device(driver, &device);
397+
if (ret || device == NULL) {
398+
fprintf(stderr, "Cannot find GPU device!\n");
399+
destroy_context(context);
400+
return ret;
401+
}
402+
403+
params->level_zero_context_handle = context;
404+
params->level_zero_device_handle = device;
405+
params->memory_type = UMF_MEMORY_TYPE_DEVICE;
406+
407+
return ret;
408+
}
409+
410+
UBENCH_EX(ipc, disjoint_pool_with_level_zero_provider) {
411+
const size_t BUFFER_SIZE = 100;
412+
const size_t N_BUFFERS = 1000;
413+
level_zero_memory_provider_params_t level_zero_params;
414+
415+
int ret = create_level_zero_params(&level_zero_params);
416+
if (ret != 0) {
417+
exit(-1);
418+
}
419+
420+
alloc_t *allocs = alloc_array(N_BUFFERS);
421+
if (allocs == NULL) {
422+
fprintf(stderr, "error: alloc_array() failed\n");
423+
goto err_destroy_context;
424+
}
425+
426+
umf_ipc_handle_t *ipc_handles = calloc(N_BUFFERS, sizeof(umf_ipc_handle_t));
427+
if (ipc_handles == NULL) {
428+
fprintf(stderr, "error: calloc() failed\n");
429+
goto err_free_allocs;
430+
}
431+
432+
umf_result_t umf_result;
433+
umf_memory_provider_handle_t provider = NULL;
434+
umf_result = umfMemoryProviderCreate(umfLevelZeroMemoryProviderOps(),
435+
&level_zero_params, &provider);
436+
if (umf_result != UMF_RESULT_SUCCESS) {
437+
fprintf(stderr, "error: umfMemoryProviderCreate() failed\n");
438+
goto err_free_ipc_handles;
439+
}
440+
441+
umf_disjoint_pool_params_t disjoint_params = {0};
442+
disjoint_params.SlabMinSize = BUFFER_SIZE * 10;
443+
disjoint_params.MaxPoolableSize = 4ull * 1024ull * 1024ull;
444+
disjoint_params.Capacity = 64ull * 1024ull;
445+
disjoint_params.MinBucketSize = 64;
446+
umf_pool_create_flags_t flags = UMF_POOL_CREATE_FLAG_OWN_PROVIDER;
447+
umf_memory_pool_handle_t pool;
448+
umf_result = umfPoolCreate(umfDisjointPoolOps(), provider, &disjoint_params,
449+
flags, &pool);
450+
if (umf_result != UMF_RESULT_SUCCESS) {
451+
fprintf(stderr, "error: umfPoolCreate() failed\n");
452+
umfMemoryProviderDestroy(provider);
453+
goto err_free_ipc_handles;
454+
}
455+
456+
for (size_t i = 0; i < N_BUFFERS; ++i) {
457+
allocs[i].ptr = umfPoolMalloc(pool, BUFFER_SIZE);
458+
if (allocs[i].ptr == NULL) {
459+
goto err_buffer_destroy;
460+
}
461+
allocs[i].size = BUFFER_SIZE;
462+
}
463+
464+
do_ipc_get_put_benchmark(allocs, N_BUFFERS, N_ITERATIONS,
465+
ipc_handles); // WARMUP
466+
467+
UBENCH_DO_BENCHMARK() {
468+
do_ipc_get_put_benchmark(allocs, N_BUFFERS, N_ITERATIONS, ipc_handles);
469+
}
470+
471+
err_buffer_destroy:
472+
for (size_t i = 0; i < N_BUFFERS; ++i) {
473+
umfPoolFree(pool, allocs[i].ptr);
474+
}
475+
476+
umfPoolDestroy(pool);
477+
478+
err_free_ipc_handles:
479+
free(ipc_handles);
480+
481+
err_free_allocs:
482+
free(allocs);
483+
484+
err_destroy_context:
485+
destroy_context(level_zero_params.level_zero_context_handle);
486+
}
487+
#endif /* (defined UMF_BUILD_LIBUMF_POOL_DISJOINT && defined UMF_BUILD_LEVEL_ZERO_PROVIDER && defined UMF_BUILD_GPU_TESTS) */
488+
342489
UBENCH_MAIN()

0 commit comments

Comments
 (0)