Skip to content

Update params implementation #901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions benchmark/multithread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,15 @@ int main() {
#endif

#if defined(UMF_BUILD_LIBUMF_POOL_DISJOINT)
auto disjointParams = umfDisjointPoolParamsDefault();
umf_disjoint_pool_params_handle_t hDisjointParams = nullptr;
umf_result_t ret = umfDisjointPoolParamsCreate(&hDisjointParams);
if (ret != UMF_RESULT_SUCCESS) {
std::cerr << "disjoint pool params create failed" << std::endl;
return -1;
}

std::cout << "disjoint_pool mt_alloc_free: ";
mt_alloc_free(poolCreateExtParams{umfDisjointPoolOps(), &disjointParams,
mt_alloc_free(poolCreateExtParams{umfDisjointPoolOps(), hDisjointParams,
umfOsMemoryProviderOps(), &osParams});
#else
std::cout << "skipping disjoint_pool mt_alloc_free" << std::endl;
Expand All @@ -129,5 +134,11 @@ int main() {
// ctest looks for "PASSED" in the output
std::cout << "PASSED" << std::endl;

ret = umfDisjointPoolParamsDestroy(hDisjointParams);
if (ret != UMF_RESULT_SUCCESS) {
std::cerr << "disjoint pool params destroy failed" << std::endl;
return -1;
}

return 0;
}
101 changes: 85 additions & 16 deletions benchmark/ubench.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,47 @@ UBENCH_EX(simple, disjoint_pool_with_os_memory_provider) {
exit(-1);
}

umf_disjoint_pool_params_t disjoint_memory_pool_params = {0};
disjoint_memory_pool_params.SlabMinSize = DISJOINT_POOL_SLAB_MIN_SIZE;
disjoint_memory_pool_params.MaxPoolableSize =
DISJOINT_POOL_MAX_POOLABLE_SIZE;
disjoint_memory_pool_params.Capacity = DISJOINT_POOL_CAPACITY;
disjoint_memory_pool_params.MinBucketSize = DISJOINT_POOL_MIN_BUCKET_SIZE;
umf_disjoint_pool_params_handle_t disjoint_memory_pool_params = NULL;
umf_result = umfDisjointPoolParamsCreate(&disjoint_memory_pool_params);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "ERROR: umfDisjointPoolParamsCreate failed\n");
exit(-1);
}

umf_result = umfDisjointPoolParamsSetSlabMinSize(
disjoint_memory_pool_params, DISJOINT_POOL_SLAB_MIN_SIZE);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr,
"error: umfDisjointPoolParamsSetSlabMinSize() failed\n");
exit(-1);
}

umf_result = umfDisjointPoolParamsSetMaxPoolableSize(
disjoint_memory_pool_params, DISJOINT_POOL_MAX_POOLABLE_SIZE);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr,
"error: umfDisjointPoolParamsSetMaxPoolableSize() failed\n");
exit(-1);
}

umf_result = umfDisjointPoolParamsSetCapacity(disjoint_memory_pool_params,
DISJOINT_POOL_CAPACITY);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "error: umfDisjointPoolParamsSetCapacity() failed\n");
exit(-1);
}

umf_result = umfDisjointPoolParamsSetMinBucketSize(
disjoint_memory_pool_params, DISJOINT_POOL_MIN_BUCKET_SIZE);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr,
"error: umfDisjointPoolParamsSetMinBucketSize() failed\n");
exit(-1);
}

umf_memory_pool_handle_t disjoint_pool;
umf_result = umfPoolCreate(umfDisjointPoolOps(), os_memory_provider,
&disjoint_memory_pool_params, 0, &disjoint_pool);
disjoint_memory_pool_params, 0, &disjoint_pool);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "error: umfPoolCreate() failed\n");
exit(-1);
Expand All @@ -284,6 +315,7 @@ UBENCH_EX(simple, disjoint_pool_with_os_memory_provider) {
}

umfPoolDestroy(disjoint_pool);
umfDisjointPoolParamsDestroy(disjoint_memory_pool_params);
umfMemoryProviderDestroy(os_memory_provider);
free(array);
}
Expand Down Expand Up @@ -458,19 +490,50 @@ UBENCH_EX(ipc, disjoint_pool_with_level_zero_provider) {
goto err_free_ipc_handles;
}

umf_disjoint_pool_params_t disjoint_params = {0};
disjoint_params.SlabMinSize = BUFFER_SIZE * 10;
disjoint_params.MaxPoolableSize = 4ull * 1024ull * 1024ull;
disjoint_params.Capacity = 64ull * 1024ull;
disjoint_params.MinBucketSize = 64;
umf_pool_create_flags_t flags = UMF_POOL_CREATE_FLAG_OWN_PROVIDER;
umf_disjoint_pool_params_handle_t disjoint_params = NULL;
umf_result = umfDisjointPoolParamsCreate(&disjoint_params);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "ERROR: umfDisjointPoolParamsCreate failed\n");
goto err_provider_destroy;
}

umf_result =
umfDisjointPoolParamsSetSlabMinSize(disjoint_params, BUFFER_SIZE * 10);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr,
"error: umfDisjointPoolParamsSetSlabMinSize() failed\n");
goto err_params_destroy;
}

umf_result = umfDisjointPoolParamsSetMaxPoolableSize(
disjoint_params, 4ull * 1024ull * 1024ull);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr,
"error: umfDisjointPoolParamsSetMaxPoolableSize() failed\n");
goto err_params_destroy;
}

umf_result =
umfDisjointPoolParamsSetCapacity(disjoint_params, 64ull * 1024ull);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "error: umfDisjointPoolParamsSetCapacity() failed\n");
goto err_params_destroy;
}

umf_result = umfDisjointPoolParamsSetMinBucketSize(disjoint_params, 64);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr,
"error: umfDisjointPoolParamsSetMinBucketSize() failed\n");
goto err_params_destroy;
}

umf_pool_create_flags_t flags = UMF_POOL_CREATE_FLAG_NONE;
umf_memory_pool_handle_t pool;
umf_result = umfPoolCreate(umfDisjointPoolOps(), provider, &disjoint_params,
umf_result = umfPoolCreate(umfDisjointPoolOps(), provider, disjoint_params,
flags, &pool);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "error: umfPoolCreate() failed\n");
umfMemoryProviderDestroy(provider);
goto err_free_ipc_handles;
goto err_params_destroy;
}

for (size_t i = 0; i < N_BUFFERS; ++i) {
Expand All @@ -495,6 +558,12 @@ UBENCH_EX(ipc, disjoint_pool_with_level_zero_provider) {

umfPoolDestroy(pool);

err_params_destroy:
umfDisjointPoolParamsDestroy(disjoint_params);

err_provider_destroy:
umfMemoryProviderDestroy(provider);

err_free_ipc_handles:
free(ipc_handles);

Expand Down
46 changes: 37 additions & 9 deletions examples/cuda_shared_memory/cuda_shared_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,48 @@ int main(void) {

// Setup parameters for the Disjoint Pool. It will be used for managing the
// memory allocated using memory provider.
umf_disjoint_pool_params_t disjoint_memory_pool_params =
umfDisjointPoolParamsDefault();
umf_disjoint_pool_params_handle_t hDisjointParams = NULL;
res = umfDisjointPoolParamsCreate(&hDisjointParams);
if (res != UMF_RESULT_SUCCESS) {
fprintf(stderr, "disjoint pool params create failed\n");
ret = -1;
goto memory_provider_destroy;
}
// Set the Slab Min Size to 64KB - the page size for GPU allocations
disjoint_memory_pool_params.SlabMinSize = 64 * 1024L;
res = umfDisjointPoolParamsSetSlabMinSize(hDisjointParams, 64 * 1024L);
if (res != UMF_RESULT_SUCCESS) {
fprintf(stderr, "Failed to set the slab min size!\n");
ret = -1;
goto pool_params_destroy;
}
// We would keep only single slab per each allocation bucket
disjoint_memory_pool_params.Capacity = 1;
res = umfDisjointPoolParamsSetCapacity(hDisjointParams, 1);
if (res != UMF_RESULT_SUCCESS) {
fprintf(stderr, "Failed to set the capacity!\n");
ret = -1;
goto pool_params_destroy;
}
// Set the maximum poolable size to 64KB - objects with size above this
// limit will not be stored/allocated from the pool.
disjoint_memory_pool_params.MaxPoolableSize = 64 * 1024L;
res = umfDisjointPoolParamsSetMaxPoolableSize(hDisjointParams, 64 * 1024L);
if (res != UMF_RESULT_SUCCESS) {
fprintf(stderr, "Failed to set the max poolable size!\n");
ret = -1;
goto pool_params_destroy;
}
// Enable tracing
disjoint_memory_pool_params.PoolTrace = 1;
res = umfDisjointPoolParamsSetTrace(hDisjointParams, 1);
if (res != UMF_RESULT_SUCCESS) {
fprintf(stderr, "Failed to set the pool trace!\n");
ret = -1;
goto pool_params_destroy;
}

// Create Disjoint Pool memory pool.
umf_memory_pool_handle_t cu_disjoint_memory_pool;
res = umfPoolCreate(umfDisjointPoolOps(), cu_memory_provider,
&disjoint_memory_pool_params, UMF_POOL_CREATE_FLAG_NONE,
&cu_disjoint_memory_pool);
res =
umfPoolCreate(umfDisjointPoolOps(), cu_memory_provider, hDisjointParams,
UMF_POOL_CREATE_FLAG_NONE, &cu_disjoint_memory_pool);
if (res != UMF_RESULT_SUCCESS) {
fprintf(stderr, "Failed to create a memory pool!\n");
ret = -1;
Expand Down Expand Up @@ -116,6 +141,9 @@ int main(void) {
memory_pool_destroy:
umfPoolDestroy(cu_disjoint_memory_pool);

pool_params_destroy:
umfDisjointPoolParamsDestroy(hDisjointParams);

memory_provider_destroy:
umfMemoryProviderDestroy(cu_memory_provider);

Expand Down
22 changes: 19 additions & 3 deletions examples/dram_and_fsdax/dram_and_fsdax.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,35 @@ static umf_memory_pool_handle_t create_fsdax_pool(const char *path) {
// so it should be used with a pool manager that will take over
// the managing of the provided memory - for example the jemalloc pool
// with the `disable_provider_free` parameter set to true.
umf_jemalloc_pool_params_t pool_params;
pool_params.disable_provider_free = true;
umf_jemalloc_pool_params_handle_t pool_params;
umf_result = umfJemallocPoolParamsCreate(&pool_params);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "Failed to create jemalloc params!\n");
umfMemoryProviderDestroy(provider_fsdax);
return NULL;
}
umf_result = umfJemallocPoolParamsSetKeepAllMemory(pool_params, true);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "Failed to set KeepAllMemory!\n");
umfMemoryProviderDestroy(provider_fsdax);
return NULL;
}

// Create an FSDAX memory pool
umf_result =
umfPoolCreate(umfJemallocPoolOps(), provider_fsdax, &pool_params,
umfPoolCreate(umfJemallocPoolOps(), provider_fsdax, pool_params,
UMF_POOL_CREATE_FLAG_OWN_PROVIDER, &pool_fsdax);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "Failed to create an FSDAX memory pool!\n");
umfMemoryProviderDestroy(provider_fsdax);
return NULL;
}

umf_result = umfJemallocPoolParamsDestroy(pool_params);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "Failed to destroy jemalloc params!\n");
}

return pool_fsdax;
}

Expand Down
18 changes: 15 additions & 3 deletions examples/ipc_level_zero/ipc_level_zero.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,29 @@ int create_level_zero_pool(ze_context_handle_t context,
return -1;
}

umf_disjoint_pool_params_handle_t disjoint_params = NULL;
umf_result = umfDisjointPoolParamsCreate(&disjoint_params);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "ERROR: Failed to create pool params!\n");
goto provider_destroy;
}

// create pool
umf_pool_create_flags_t flags = UMF_POOL_CREATE_FLAG_OWN_PROVIDER;
umf_disjoint_pool_params_t disjoint_params = umfDisjointPoolParamsDefault();
umf_result = umfPoolCreate(umfDisjointPoolOps(), provider, &disjoint_params,
umf_result = umfPoolCreate(umfDisjointPoolOps(), provider, disjoint_params,
flags, pool);
umfDisjointPoolParamsDestroy(disjoint_params);
if (umf_result != UMF_RESULT_SUCCESS) {
fprintf(stderr, "ERROR: Failed to create pool!\n");
return -1;
goto provider_destroy;
}

return 0;

provider_destroy:
umfMemoryProviderDestroy(provider);

return -1;
}

int main(void) {
Expand Down
46 changes: 38 additions & 8 deletions examples/level_zero_shared_memory/level_zero_shared_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,54 @@ int main(void) {

// Setup parameters for the Disjoint Pool. It will be used for managing the
// memory allocated using memory provider.
umf_disjoint_pool_params_t disjoint_memory_pool_params =
umfDisjointPoolParamsDefault();
umf_disjoint_pool_params_handle_t disjoint_memory_pool_params = NULL;
res = umfDisjointPoolParamsCreate(&disjoint_memory_pool_params);
if (res != UMF_RESULT_SUCCESS) {
fprintf(stderr, "Failed to create pool params!\n");
ret = -1;
goto memory_provider_destroy;
}
// Set the Slab Min Size to 64KB - the page size for GPU allocations
disjoint_memory_pool_params.SlabMinSize = 64 * 1024L;
res = umfDisjointPoolParamsSetSlabMinSize(disjoint_memory_pool_params,
64 * 1024L);
if (res != UMF_RESULT_SUCCESS) {
fprintf(stderr, "Failed to set Slab Min Size!\n");
ret = -1;
goto disjoint_params_destroy;
}
// We would keep only single slab per each allocation bucket
disjoint_memory_pool_params.Capacity = 1;
res = umfDisjointPoolParamsSetCapacity(disjoint_memory_pool_params, 1);
if (res != UMF_RESULT_SUCCESS) {
fprintf(stderr, "Failed to set Capacity!\n");
ret = -1;
goto disjoint_params_destroy;
}
// Set the maximum poolable size to 64KB - objects with size above this
// limit will not be stored/allocated from the pool.
disjoint_memory_pool_params.MaxPoolableSize = 64 * 1024L;
res = umfDisjointPoolParamsSetMaxPoolableSize(disjoint_memory_pool_params,
64 * 1024L);
if (res != UMF_RESULT_SUCCESS) {
fprintf(stderr, "Failed to set Max Poolable Size!\n");
ret = -1;
goto disjoint_params_destroy;
}
// Enable tracing
disjoint_memory_pool_params.PoolTrace = 1;
res = umfDisjointPoolParamsSetTrace(disjoint_memory_pool_params, 1);
if (res != UMF_RESULT_SUCCESS) {
fprintf(stderr, "Failed to set Trace!\n");
ret = -1;
goto disjoint_params_destroy;
}

// Create Disjoint Pool memory pool.
umf_memory_pool_handle_t ze_disjoint_memory_pool;
res = umfPoolCreate(umfDisjointPoolOps(), ze_memory_provider,
&disjoint_memory_pool_params, UMF_POOL_CREATE_FLAG_NONE,
disjoint_memory_pool_params, UMF_POOL_CREATE_FLAG_NONE,
&ze_disjoint_memory_pool);
if (res != UMF_RESULT_SUCCESS) {
fprintf(stderr, "Failed to create a memory pool!\n");
ret = -1;
goto memory_provider_destroy;
goto disjoint_params_destroy;
}

printf("Disjoint Pool created at %p\n", (void *)ze_disjoint_memory_pool);
Expand Down Expand Up @@ -121,6 +148,9 @@ int main(void) {
memory_pool_destroy:
umfPoolDestroy(ze_disjoint_memory_pool);

disjoint_params_destroy:
umfDisjointPoolParamsDestroy(disjoint_memory_pool_params);

memory_provider_destroy:
umfMemoryProviderDestroy(ze_memory_provider);

Expand Down
Loading
Loading