Skip to content

Commit 811320d

Browse files
committed
add fixedprovider based benchmarks
1 parent eae8d63 commit 811320d

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed

benchmark/benchmark.cpp

+75
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,81 @@ 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+
->Apply(&singlethreaded);
147+
148+
UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark, fixed_provider,
149+
fixed_alloc_size,
150+
provider_allocator<fixed_provider>);
151+
UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark, fixed_provider)
152+
->Apply(&default_multiple_alloc_fix_size)
153+
->Apply(&singlethreaded);
154+
155+
UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark,
156+
disjoint_pool_fix_fixedprovider, fixed_alloc_size,
157+
pool_allocator<disjoint_pool<fixed_provider>>);
158+
UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark,
159+
disjoint_pool_fix_fixedprovider)
160+
->Apply(&default_multiple_alloc_fix_size)
161+
->Apply(&multithreaded);
162+
163+
UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark,
164+
disjoint_pool_uniform_fixedprovider,
165+
uniform_alloc_size,
166+
pool_allocator<disjoint_pool<fixed_provider>>);
167+
UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark,
168+
disjoint_pool_uniform_fixedprovider)
169+
->Apply(&default_multiple_alloc_uniform_size)
170+
->Apply(&singlethreaded);
171+
// TODO: change to multithreaded
172+
//->Apply(&multithreaded);
173+
174+
#ifdef UMF_POOL_JEMALLOC_ENABLED
175+
UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark,
176+
jemalloc_pool_fixedprovider, fixed_alloc_size,
177+
pool_allocator<jemalloc_pool<fixed_provider>>);
178+
UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark, jemalloc_pool_fix)
179+
->Apply(&default_multiple_alloc_fix_size)
180+
->Apply(&multithreaded);
181+
182+
UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark,
183+
jemalloc_pool_uniform_fixedprovider,
184+
uniform_alloc_size,
185+
pool_allocator<jemalloc_pool<fixed_provider>>);
186+
UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark, jemalloc_pool_uniform)
187+
->Apply(&default_multiple_alloc_uniform_size)
188+
->Apply(&multithreaded);
189+
190+
#endif
191+
192+
#ifdef UMF_POOL_SCALABLE_ENABLED
193+
UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark,
194+
scalable_pool_fix_fixedprovider, fixed_alloc_size,
195+
pool_allocator<scalable_pool<fixed_provider>>);
196+
197+
UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark,
198+
scalable_pool_fix_fixedprovider)
199+
->Apply(&default_multiple_alloc_fix_size)
200+
->Apply(&multithreaded);
201+
202+
UMF_BENCHMARK_TEMPLATE_DEFINE(multiple_malloc_free_benchmark,
203+
scalable_pool_uniform_fixedprovider,
204+
uniform_alloc_size,
205+
pool_allocator<scalable_pool<fixed_provider>>);
206+
207+
UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark,
208+
scalable_pool_uniform_fixedprovider)
209+
->Apply(&default_multiple_alloc_uniform_size)
210+
->Apply(&multithreaded);
211+
212+
#endif
213+
139214
//BENCHMARK_MAIN();
140215
int main(int argc, char **argv) {
141216
if (initAffinityMask()) {

benchmark/benchmark_umf.hpp

+55
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)