diff --git a/benchmark/benchmark.cpp b/benchmark/benchmark.cpp index 60636a559f..c6b954ea4d 100644 --- a/benchmark/benchmark.cpp +++ b/benchmark/benchmark.cpp @@ -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>); + +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); +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>); +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>); +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>); +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>); +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>); + +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>); + +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()) { diff --git a/benchmark/benchmark_umf.hpp b/benchmark/benchmark_umf.hpp index 5c3b160c7c..cfc9982d2c 100644 --- a/benchmark/benchmark_umf.hpp +++ b/benchmark/benchmark_umf.hpp @@ -19,6 +19,7 @@ #ifdef UMF_POOL_SCALABLE_ENABLED #include #endif +#include #include #ifdef UMF_POOL_JEMALLOC_ENABLED @@ -145,7 +146,9 @@ struct os_provider : public provider_interface { umfOsMemoryProviderParamsDestroy(handle); }; - return {static_cast(raw_params), deleter}; + return {static_cast( + raw_params), + deleter}; } umf_memory_provider_ops_t * @@ -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(p); + umfFixedMemoryProviderParamsDestroy(handle); + }; + + return {static_cast( + 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 struct proxy_pool : public pool_interface { umf_memory_pool_ops_t *