|
7 | 7 | *
|
8 | 8 | */
|
9 | 9 |
|
| 10 | +#include <umf/ipc.h> |
10 | 11 | #include <umf/memory_pool.h>
|
11 | 12 | #include <umf/pools/pool_proxy.h>
|
12 | 13 | #include <umf/pools/pool_scalable.h>
|
| 14 | +#include <umf/providers/provider_level_zero.h> |
13 | 15 | #include <umf/providers/provider_os_memory.h>
|
14 | 16 |
|
15 | 17 | #ifdef UMF_BUILD_LIBUMF_POOL_DISJOINT
|
|
29 | 31 | #include "ubench.h"
|
30 | 32 | #include "utils_common.h"
|
31 | 33 |
|
| 34 | +#if (defined UMF_BUILD_GPU_TESTS) |
| 35 | +#include "utils_level_zero.h" |
| 36 | +#endif |
| 37 | + |
32 | 38 | // BENCHMARK CONFIG
|
33 | 39 | #define N_ITERATIONS 1000
|
34 | 40 | #define ALLOC_SIZE (util_get_page_size())
|
@@ -339,4 +345,145 @@ UBENCH_EX(simple, scalable_pool_with_os_memory_provider) {
|
339 | 345 | }
|
340 | 346 | #endif /* (defined UMF_POOL_SCALABLE_ENABLED) */
|
341 | 347 |
|
| 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 | + |
342 | 489 | UBENCH_MAIN()
|
0 commit comments