Skip to content

Commit

Permalink
Add new benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
lplewa committed Nov 14, 2024
1 parent 508162e commit 57edb2d
Show file tree
Hide file tree
Showing 3 changed files with 413 additions and 10 deletions.
31 changes: 21 additions & 10 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
# Copyright (C) 2023 Intel Corporation
# Copyright (C) 2023-2024 Intel Corporation
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# In MSVC builds, there is no way to determine the actual build type during the
# CMake configuration step. Therefore, this message is printed in all MSVC
# builds.

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)

include(FetchContent)
FetchContent_Declare(
googlebenchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.9.0
EXCLUDE_FROM_ALL)
FetchContent_MakeAvailable(googlebenchmark)

if(WINDOWS OR NOT CMAKE_BUILD_TYPE STREQUAL "Release")
message(
STATUS
Expand Down Expand Up @@ -32,7 +44,7 @@ function(add_umf_benchmark)
"${multiValueArgs}"
${ARGN})

set(BENCH_NAME umf-bench-${ARG_NAME})
set(BENCH_NAME umf-${ARG_NAME})

set(BENCH_LIBS ${ARG_LIBS} umf)

Expand All @@ -55,13 +67,7 @@ function(add_umf_benchmark)
COMMAND ${BENCH_NAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

# Benchmark passes if it prints "PASSED" in the output, because ubench of
# scalable pool fails if the confidence interval exceeds maximum permitted
# 2.5%.
set_tests_properties(
${BENCH_NAME} PROPERTIES
LABELS "benchmark"
PASS_REGULAR_EXPRESSION "PASSED")
set_tests_properties(${BENCH_NAME} PROPERTIES LABELS "benchmark")

if(WINDOWS)
# append PATH to DLLs
Expand Down Expand Up @@ -117,7 +123,12 @@ endif()
add_umf_benchmark(
NAME ubench
SRCS ubench.c
LIBS ${LIBS_OPTIONAL}
LIBDIRS ${LIB_DIRS})

add_umf_benchmark(
NAME benchmark
SRCS benchmark.cpp
LIBS ${LIBS_OPTIONAL} benchmark::benchmark
LIBDIRS ${LIB_DIRS})

if(UMF_BUILD_BENCHMARKS_MT)
Expand Down
132 changes: 132 additions & 0 deletions benchmark/benchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* Copyright (C) 2024 Intel Corporation
*
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*/

#include <benchmark/benchmark.h>
#include <umf/pools/pool_proxy.h>
#include <umf/pools/pool_scalable.h>
#include <umf/providers/provider_level_zero.h>
#include <umf/providers/provider_os_memory.h>

#ifdef UMF_BUILD_LIBUMF_POOL_DISJOINT
#include <umf/pools/pool_disjoint.h>
#endif

#ifdef UMF_BUILD_LIBUMF_POOL_JEMALLOC
#include <umf/pools/pool_jemalloc.h>
#endif

#include "benchmark.hpp"

struct os_provider : public provider_interface {
umf_os_memory_provider_params_t params = umfOsMemoryProviderParamsDefault();
virtual void *getParams() override { return &params; }
virtual umf_memory_provider_ops_t *getOps() override {
return umfOsMemoryProviderOps();
}
};

template <typename T> class proxy_pool : public pool_interface<T> {
private:
virtual umf_memory_pool_ops_t *
getOps([[maybe_unused]] ::benchmark::State &state) override {
return umfProxyPoolOps();
}
virtual void *
getParams([[maybe_unused]] ::benchmark::State &state) override {
return nullptr;
}
};

#if (defined UMF_BUILD_LIBUMF_POOL_DISJOINT)

template <typename T> class disjoint_pool : public pool_interface<T> {
umf_disjoint_pool_params_t disjoint_memory_pool_params;
virtual umf_memory_pool_ops_t *
getOps([[maybe_unused]] ::benchmark::State &state) override {
return umfDisjointPoolOps();
}
virtual void *
getParams([[maybe_unused]] ::benchmark::State &state) override {
size_t page_size;
if (umfMemoryProviderGetMinPageSize(
pool_interface<T>::provider.provider, NULL, &page_size) !=
UMF_RESULT_SUCCESS) {
return NULL;
}
disjoint_memory_pool_params.SlabMinSize = page_size;
disjoint_memory_pool_params.MaxPoolableSize = page_size * 2;
disjoint_memory_pool_params.Capacity = state.range(0);

disjoint_memory_pool_params.MinBucketSize = page_size;
return &disjoint_memory_pool_params;
}
};

#endif

#if (defined UMF_BUILD_LIBUMF_POOL_JEMALLOC)
template <typename T> class jemalloc_pool : public pool_interface<T> {
private:
virtual umf_memory_pool_ops_t *
getOps([[maybe_unused]] ::benchmark::State &state) {
return umfJemallocPoolOps();
}
virtual void *getParams([[maybe_unused]] ::benchmark::State &state) {
return NULL;
}
};
#endif

template <typename T> class scalable_pool : public pool_interface<T> {
private:
virtual umf_memory_pool_ops_t *
getOps([[maybe_unused]] ::benchmark::State &state) {
return umfScalablePoolOps();
}
virtual void *getParams([[maybe_unused]] ::benchmark::State &state) {
return NULL;
}
};

ALLOC_BENCHMARK_TEMPLATE_DEFINE(alloc_benchmark, stdmalloc, fix_alloc_size);
BENCHMARK_REGISTER_F(alloc_benchmark, stdmalloc)->Args({1000, 4096});
BENCHMARK_REGISTER_F(alloc_benchmark, stdmalloc)->Args({1000, 10 * 4096});

ALLOC_BENCHMARK_TEMPLATE_DEFINE(provider_benchmark, bench, os_provider,
fix_alloc_size);
BENCHMARK_REGISTER_F(provider_benchmark, bench)
->Args({1000, 4096})
->Args({1000, 100 * 4096});

ALLOC_BENCHMARK_TEMPLATE_DEFINE(pool_benchmark, bench, proxy_pool<os_provider>,
fix_alloc_size);

BENCHMARK_REGISTER_F(pool_benchmark, bench)->Args({1000, 4096});

ALLOC_BENCHMARK_TEMPLATE_DEFINE(pool_benchmark, disjoint_pool,
disjoint_pool<os_provider>, fix_alloc_size);
BENCHMARK_REGISTER_F(pool_benchmark, disjoint_pool)->Args({1000, 4096});

ALLOC_BENCHMARK_TEMPLATE_DEFINE(pool_benchmark, jemalloc_pool,
jemalloc_pool<os_provider>, fix_alloc_size);
BENCHMARK_REGISTER_F(pool_benchmark, jemalloc_pool)->Args({1000, 4096});

ALLOC_BENCHMARK_TEMPLATE_DEFINE(pool_benchmark, jemalloc_pool_size,
jemalloc_pool<os_provider>, uniform_alloc_size);

BENCHMARK_REGISTER_F(pool_benchmark, jemalloc_pool_size)
->Args({1000, 1, 5, 4096});

ALLOC_BENCHMARK_TEMPLATE_DEFINE(pool_benchmark, scalable_pool_size,
scalable_pool<os_provider>, uniform_alloc_size);

BENCHMARK_REGISTER_F(pool_benchmark, scalable_pool_size)
->Args({1000, 1, 5, 4096})
->Name("scalable_pool<os_provider>");

BENCHMARK_MAIN();
Loading

0 comments on commit 57edb2d

Please sign in to comment.