Skip to content

Commit 0e824fb

Browse files
Merge pull request #1153 from lplewa/fixed_benchmark
add fixedprovider based benchmarks
2 parents badb7de + 89db625 commit 0e824fb

File tree

2 files changed

+135
-1
lines changed

2 files changed

+135
-1
lines changed

benchmark/benchmark.cpp

+75
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,81 @@ UMF_BENCHMARK_REGISTER_F(multiple_malloc_free_benchmark, scalable_pool_uniform)
134134

135135
#endif
136136

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

benchmark/benchmark_umf.hpp

+60-1
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
@@ -145,7 +146,9 @@ struct os_provider : public provider_interface {
145146
umfOsMemoryProviderParamsDestroy(handle);
146147
};
147148

148-
return {static_cast<void *>(raw_params), deleter};
149+
return {static_cast<provider_interface::params_ptr::element_type *>(
150+
raw_params),
151+
deleter};
149152
}
150153

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

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

0 commit comments

Comments
 (0)