Skip to content

add fixedprovider based benchmarks #1153

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 1 commit into from
Mar 5, 2025
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
75 changes: 75 additions & 0 deletions benchmark/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,81 @@ UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark, scalable_pool_uniform)

#endif

UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark,
proxy_pool_fixedprovider, fixed_alloc_size,
pool_allocator<proxy_pool<fixed_provider>>);

UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark,
proxy_pool_fixedprovider)
->Apply(&default_multiple_alloc_fix_size)
->Apply(&singlethreaded);

UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark, fixed_provider,
fixed_alloc_size,
provider_allocator<fixed_provider>);
UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark, fixed_provider)
->Apply(&default_multiple_alloc_fix_size)
->Apply(&singlethreaded);

UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark,
disjoint_pool_fix_fixedprovider, fixed_alloc_size,
pool_allocator<disjoint_pool<fixed_provider>>);
UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark,
disjoint_pool_fix_fixedprovider)
->Apply(&default_multiple_alloc_fix_size)
->Apply(&multithreaded);

UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark,
disjoint_pool_uniform_fixedprovider,
uniform_alloc_size,
pool_allocator<disjoint_pool<fixed_provider>>);
UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark,
disjoint_pool_uniform_fixedprovider)
->Apply(&default_multiple_alloc_uniform_size)
->Apply(&singlethreaded);
// TODO: change to multithreaded
//->Apply(&multithreaded);

#ifdef UMF_POOL_JEMALLOC_ENABLED
UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark,
jemalloc_pool_fixedprovider, fixed_alloc_size,
pool_allocator<jemalloc_pool<fixed_provider>>);
UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark, jemalloc_pool_fix)
->Apply(&default_multiple_alloc_fix_size)
->Apply(&multithreaded);

UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark,
jemalloc_pool_uniform_fixedprovider,
uniform_alloc_size,
pool_allocator<jemalloc_pool<fixed_provider>>);
UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark, jemalloc_pool_uniform)
->Apply(&default_multiple_alloc_uniform_size)
->Apply(&multithreaded);

#endif

#ifdef UMF_POOL_SCALABLE_ENABLED
UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark,
scalable_pool_fix_fixedprovider, fixed_alloc_size,
pool_allocator<scalable_pool<fixed_provider>>);

UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark,
scalable_pool_fix_fixedprovider)
->Apply(&default_multiple_alloc_fix_size)
->Apply(&multithreaded);

UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark,
scalable_pool_uniform_fixedprovider,
uniform_alloc_size,
pool_allocator<scalable_pool<fixed_provider>>);

UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark,
scalable_pool_uniform_fixedprovider)
->Apply(&default_multiple_alloc_uniform_size)
->Apply(&multithreaded);

#endif

//BENCHMARK_MAIN();
int main(int argc, char **argv) {
if (initAffinityMask()) {
Expand Down
61 changes: 60 additions & 1 deletion benchmark/benchmark_umf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifdef UMF_POOL_SCALABLE_ENABLED
#include <umf/pools/pool_scalable.h>
#endif
#include <umf/providers/provider_fixed_memory.h>
#include <umf/providers/provider_os_memory.h>

#ifdef UMF_POOL_JEMALLOC_ENABLED
Expand Down Expand Up @@ -145,7 +146,9 @@ struct os_provider : public provider_interface {
umfOsMemoryProviderParamsDestroy(handle);
};

return {static_cast<void *>(raw_params), deleter};
return {static_cast<provider_interface::params_ptr::element_type *>(
raw_params),
deleter};
}

umf_memory_provider_ops_t *
Expand All @@ -155,6 +158,62 @@ struct os_provider : public provider_interface {
static std::string name() { return "os_provider"; }
};

struct fixed_provider : public provider_interface {
private:
char *mem = NULL;
const size_t size = 1024 * 1024 * 1024; // 1GB
public:
virtual void SetUp(::benchmark::State &state) override {
if (state.thread_index() != 0) {
return;
}

if (!mem) {
mem = new char[size];
}

provider_interface::SetUp(state);
}

virtual void TearDown(::benchmark::State &state) override {
if (state.thread_index() != 0) {
return;
}

delete[] mem;
mem = nullptr;

provider_interface::TearDown(state);
}

provider_interface::params_ptr
getParams(::benchmark::State &state) override {
umf_fixed_memory_provider_params_handle_t raw_params = nullptr;
umfFixedMemoryProviderParamsCreate(&raw_params, mem, size);
if (!raw_params) {
state.SkipWithError("Failed to create fixed provider params");
return {nullptr, [](void *) {}};
}

// Use a lambda as the custom deleter
auto deleter = [](void *p) {
auto handle =
static_cast<umf_fixed_memory_provider_params_handle_t>(p);
umfFixedMemoryProviderParamsDestroy(handle);
};

return {static_cast<provider_interface::params_ptr::element_type *>(
raw_params),
deleter};
}

umf_memory_provider_ops_t *
getOps([[maybe_unused]] ::benchmark::State &state) override {
return umfFixedMemoryProviderOps();
}
static std::string name() { return "fixed_provider"; }
};

template <typename Provider>
struct proxy_pool : public pool_interface<Provider> {
umf_memory_pool_ops_t *
Expand Down