Skip to content

Commit 8d7ad62

Browse files
committed
add fixedprovider based benchmarks
1 parent eae8d63 commit 8d7ad62

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed

benchmark/benchmark.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,84 @@ UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark, scalable_pool_uniform)
136136

137137
#endif
138138

139+
UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark,
140+
proxy_pool_fixedprovider, fixed_alloc_size,
141+
pool_allocator<proxy_pool<fixed_provider>>);
142+
143+
UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark,
144+
proxy_pool_fixedprovider)
145+
->Apply(&default_multiple_alloc_fix_size)
146+
// reduce iterations, as this benchmark is slower than others
147+
->Iterations(50000)
148+
->Apply(&singlethreaded);
149+
150+
UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark, fixed_provider,
151+
fixed_alloc_size,
152+
provider_allocator<fixed_provider>);
153+
UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark, fixed_provider)
154+
->Apply(&default_multiple_alloc_fix_size)
155+
// reduce iterations, as this benchmark is slower than others
156+
->Iterations(50000)
157+
->Apply(&singlethreaded);
158+
159+
UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark,
160+
disjoint_pool_fix_fixedprovider, fixed_alloc_size,
161+
pool_allocator<disjoint_pool<fixed_provider>>);
162+
UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark,
163+
disjoint_pool_fix_fixedprovider)
164+
->Apply(&default_multiple_alloc_fix_size)
165+
->Apply(&multithreaded);
166+
167+
UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark,
168+
disjoint_pool_uniform_fixedprovider,
169+
uniform_alloc_size,
170+
pool_allocator<disjoint_pool<fixed_provider>>);
171+
UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark,
172+
disjoint_pool_uniform_fixedprovider)
173+
->Apply(&default_multiple_alloc_uniform_size)
174+
->Apply(&singlethreaded);
175+
// TODO: change to multithreaded
176+
//->Apply(&multithreaded);
177+
178+
#ifdef UMF_POOL_JEMALLOC_ENABLED
179+
UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark, jemalloc_pool_fix,
180+
fixed_alloc_size,
181+
pool_allocator<jemalloc_pool<fixed_provider>>);
182+
UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark, jemalloc_pool_fix)
183+
->Apply(&default_multiple_alloc_fix_size)
184+
->Apply(&multithreaded);
185+
186+
UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark,
187+
jemalloc_pool_uniform, uniform_alloc_size,
188+
pool_allocator<jemalloc_pool<fixed_provider>>);
189+
UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark, jemalloc_pool_uniform)
190+
->Apply(&default_multiple_alloc_uniform_size)
191+
->Apply(&multithreaded);
192+
193+
#endif
194+
195+
#ifdef UMF_POOL_SCALABLE_ENABLED
196+
UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark,
197+
scalable_pool_fix_fixedprovider, fixed_alloc_size,
198+
pool_allocator<scalable_pool<fixed_provider>>);
199+
200+
UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark,
201+
scalable_pool_fix_fixedprovider)
202+
->Apply(&default_multiple_alloc_fix_size)
203+
->Apply(&multithreaded);
204+
205+
UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark,
206+
scalable_pool_uniform_fixedprovider,
207+
uniform_alloc_size,
208+
pool_allocator<scalable_pool<fixed_provider>>);
209+
210+
UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark,
211+
scalable_pool_uniform_fixedprovider)
212+
->Apply(&default_multiple_alloc_uniform_size)
213+
->Apply(&multithreaded);
214+
215+
#endif
216+
139217
//BENCHMARK_MAIN();
140218
int main(int argc, char **argv) {
141219
if (initAffinityMask()) {

benchmark/benchmark_umf.hpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#ifdef UMF_POOL_SCALABLE_ENABLED
2020
#include <umf/pools/pool_scalable.h>
2121
#endif
22+
#include <umf/providers/provider_fixed_memory.h>
2223
#include <umf/providers/provider_os_memory.h>
2324

2425
#ifdef UMF_POOL_JEMALLOC_ENABLED
@@ -155,6 +156,60 @@ struct os_provider : public provider_interface {
155156
static std::string name() { return "os_provider"; }
156157
};
157158

159+
struct fixed_provider : public provider_interface {
160+
void *mem = NULL;
161+
const size_t size = 1024 * 1024 * 1024; // 1GB
162+
virtual void SetUp([[maybe_unused]] ::benchmark::State &state) override {
163+
if (state.thread_index() != 0) {
164+
return;
165+
}
166+
167+
if (!mem) {
168+
mem = new char[size];
169+
}
170+
171+
provider_interface::SetUp(state);
172+
}
173+
174+
virtual void TearDown([[maybe_unused]] ::benchmark::State &state) override {
175+
if (state.thread_index() != 0) {
176+
return;
177+
}
178+
179+
if (mem) {
180+
delete[] static_cast<char *>(mem);
181+
mem = NULL;
182+
}
183+
184+
provider_interface::TearDown(state);
185+
}
186+
187+
provider_interface::params_ptr
188+
getParams(::benchmark::State &state) override {
189+
umf_fixed_memory_provider_params_handle_t raw_params = nullptr;
190+
umfFixedMemoryProviderParamsCreate(&raw_params, mem, size);
191+
if (!raw_params) {
192+
state.SkipWithError("Failed to create fixed provider params");
193+
return {nullptr, [](void *) {}};
194+
}
195+
196+
// Use a lambda as the custom deleter
197+
auto deleter = [](void *p) {
198+
auto handle =
199+
static_cast<umf_fixed_memory_provider_params_handle_t>(p);
200+
umfFixedMemoryProviderParamsDestroy(handle);
201+
};
202+
203+
return {static_cast<void *>(raw_params), deleter};
204+
}
205+
206+
umf_memory_provider_ops_t *
207+
getOps([[maybe_unused]] ::benchmark::State &state) override {
208+
return umfFixedMemoryProviderOps();
209+
}
210+
static std::string name() { return "fixed_provider"; }
211+
};
212+
158213
template <typename Provider>
159214
struct proxy_pool : public pool_interface<Provider> {
160215
umf_memory_pool_ops_t *

0 commit comments

Comments
 (0)