|
2 | 2 | # Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
|
3 | 3 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
4 | 4 |
|
5 |
| -include(FindThreads) |
6 |
| - |
7 | 5 | if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
8 | 6 | message(WARNING "The benchmarks SHOULD NOT be run in the Debug build type!")
|
9 | 7 | endif()
|
10 | 8 |
|
11 |
| -if(UMF_BUILD_LIBUMF_POOL_DISJOINT) |
12 |
| - set(LIBS_OPTIONAL ${LIBS_OPTIONAL} disjoint_pool) |
13 |
| -endif() |
14 |
| - |
15 |
| -if(UMF_BUILD_LIBUMF_POOL_JEMALLOC) |
16 |
| - set(LIBS_OPTIONAL ${LIBS_OPTIONAL} jemalloc_pool) |
17 |
| -endif() |
18 |
| - |
19 |
| -if(UMF_BUILD_LIBUMF_POOL_SCALABLE) |
20 |
| - set(LIBS_OPTIONAL ${LIBS_OPTIONAL} scalable_pool) |
| 9 | +if (UMF_BUILD_BENCHMARKS_MT) |
| 10 | + include(FindThreads) |
21 | 11 | endif()
|
22 | 12 |
|
23 |
| -add_executable(ubench ubench.c) |
| 13 | +function(add_umf_benchmark) |
| 14 | + # NAME - a name of the benchmark |
| 15 | + # SRCS - source files |
| 16 | + # LIBS - libraries to be linked with |
| 17 | + set(oneValueArgs NAME) |
| 18 | + set(multiValueArgs SRCS LIBS) |
| 19 | + cmake_parse_arguments(ARG "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) |
24 | 20 |
|
25 |
| -if(LINUX) |
26 |
| - set(LIBS_LINUX m) |
27 |
| -endif() |
| 21 | + set(BENCH_NAME umf-bench-${ARG_NAME}) |
28 | 22 |
|
29 |
| -add_dependencies(ubench |
30 |
| - umf |
31 |
| - ${LIBS_OPTIONAL}) |
| 23 | + set(BENCH_LIBS umf ${ARG_LIBS}) |
32 | 24 |
|
33 |
| -target_include_directories(ubench PRIVATE ${UMF_CMAKE_SOURCE_DIR}/include/ ${UMF_CMAKE_SOURCE_DIR}/src/utils/) |
| 25 | + add_umf_executable(NAME ${BENCH_NAME} SRCS ${ARG_SRCS} LIBS ${BENCH_LIBS}) |
34 | 26 |
|
35 |
| -target_link_libraries(ubench |
36 |
| - umf |
37 |
| - ${LIBS_OPTIONAL} |
38 |
| - ${CMAKE_THREAD_LIBS_INIT} |
39 |
| - ${LIBS_LINUX}) |
| 27 | + target_include_directories(${BENCH_NAME} PRIVATE |
| 28 | + ${UMF_CMAKE_SOURCE_DIR}/include |
| 29 | + ${UMF_CMAKE_SOURCE_DIR}/src/utils) |
40 | 30 |
|
41 |
| -if (UMF_BUILD_BENCHMARKS_MT) |
42 |
| - add_executable(multithread_bench multithread.cpp) |
43 |
| - target_link_libraries(multithread_bench |
44 |
| - umf |
45 |
| - ${LIBS_OPTIONAL} |
46 |
| - pthread |
47 |
| - ${LIBS_LINUX}) |
48 |
| - target_include_directories(multithread_bench PRIVATE ${UMF_CMAKE_SOURCE_DIR}/include/) |
49 |
| -endif() |
| 31 | + add_test(NAME ${BENCH_NAME} |
| 32 | + COMMAND ${BENCH_NAME} |
| 33 | + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) |
50 | 34 |
|
51 |
| -if (UMF_BUILD_OS_MEMORY_PROVIDER) |
52 |
| - target_compile_definitions(ubench PRIVATE UMF_BUILD_OS_MEMORY_PROVIDER=1) |
| 35 | + # Benchmark passes if it prints "PASSED" in the output, |
| 36 | + # because ubench of scalable pool fails if the confidence interval |
| 37 | + # exceeds maximum permitted 2.5%. |
| 38 | + set_tests_properties(${BENCH_NAME} PROPERTIES |
| 39 | + LABELS "benchmark" |
| 40 | + PASS_REGULAR_EXPRESSION "PASSED") |
53 | 41 |
|
54 |
| - if (UMF_BUILD_BENCHMARKS_MT) |
55 |
| - target_compile_definitions(multithread_bench PRIVATE UMF_BUILD_OS_MEMORY_PROVIDER=1) |
| 42 | + if(WINDOWS) |
| 43 | + # append PATH to DLLs |
| 44 | + set(DLL_PATH_LIST "PATH=path_list_append:../bin/$<CONFIG>") |
| 45 | + if(LIBHWLOC_DLL_DIRS) |
| 46 | + set(DLL_PATH_LIST "${DLL_PATH_LIST};PATH=path_list_append:${LIBHWLOC_DLL_DIRS}") |
56 | 47 | endif()
|
| 48 | + set_property(TEST ${BENCH_NAME} PROPERTY ENVIRONMENT_MODIFICATION "${DLL_PATH_LIST}") |
| 49 | + endif() |
| 50 | + |
| 51 | + if (UMF_BUILD_OS_MEMORY_PROVIDER) |
| 52 | + target_compile_definitions(${BENCH_NAME} PRIVATE UMF_BUILD_OS_MEMORY_PROVIDER=1) |
| 53 | + endif() |
| 54 | + if (UMF_BUILD_LIBUMF_POOL_DISJOINT) |
| 55 | + target_compile_definitions(${BENCH_NAME} PRIVATE UMF_BUILD_LIBUMF_POOL_DISJOINT=1) |
| 56 | + endif() |
| 57 | + if (UMF_BUILD_LIBUMF_POOL_JEMALLOC) |
| 58 | + target_compile_definitions(${BENCH_NAME} PRIVATE UMF_BUILD_LIBUMF_POOL_JEMALLOC=1) |
| 59 | + endif() |
| 60 | + if (UMF_BUILD_LIBUMF_POOL_SCALABLE) |
| 61 | + target_compile_definitions(${BENCH_NAME} PRIVATE UMF_BUILD_LIBUMF_POOL_SCALABLE=1) |
| 62 | + endif() |
| 63 | +endfunction() |
| 64 | + |
| 65 | +# optional libraries |
| 66 | +if(UMF_BUILD_LIBUMF_POOL_DISJOINT) |
| 67 | + set(LIBS_OPTIONAL ${LIBS_OPTIONAL} disjoint_pool) |
57 | 68 | endif()
|
58 |
| - |
59 |
| -if (UMF_BUILD_OS_MEMORY_PROVIDER) |
60 |
| - target_compile_definitions(ubench PRIVATE UMF_BUILD_OS_MEMORY_PROVIDER=1) |
| 69 | +if(UMF_BUILD_LIBUMF_POOL_JEMALLOC) |
| 70 | + set(LIBS_OPTIONAL ${LIBS_OPTIONAL} jemalloc_pool) |
61 | 71 | endif()
|
62 |
| - |
63 |
| -if (UMF_BUILD_LIBUMF_POOL_DISJOINT) |
64 |
| - target_compile_definitions(ubench PRIVATE UMF_BUILD_LIBUMF_POOL_DISJOINT=1) |
65 |
| - |
66 |
| - if (UMF_BUILD_BENCHMARKS_MT) |
67 |
| - target_compile_definitions(multithread_bench PRIVATE UMF_BUILD_LIBUMF_POOL_DISJOINT=1) |
68 |
| - endif() |
| 72 | +if(UMF_BUILD_LIBUMF_POOL_SCALABLE) |
| 73 | + set(LIBS_OPTIONAL ${LIBS_OPTIONAL} scalable_pool) |
69 | 74 | endif()
|
70 |
| - |
71 |
| -if (UMF_BUILD_LIBUMF_POOL_JEMALLOC) |
72 |
| - target_compile_definitions(ubench PRIVATE UMF_BUILD_LIBUMF_POOL_JEMALLOC=1) |
73 |
| - |
74 |
| - if (UMF_BUILD_BENCHMARKS_MT) |
75 |
| - target_compile_definitions(multithread_bench PRIVATE UMF_BUILD_LIBUMF_POOL_JEMALLOC=1) |
76 |
| - endif() |
| 75 | +if(LINUX) |
| 76 | + set(LIBS_OPTIONAL ${LIBS_OPTIONAL} m) |
77 | 77 | endif()
|
78 | 78 |
|
79 |
| -if (UMF_BUILD_LIBUMF_POOL_SCALABLE) |
80 |
| - target_compile_definitions(ubench PRIVATE UMF_BUILD_LIBUMF_POOL_SCALABLE=1) |
| 79 | +# BENCHMARKS |
81 | 80 |
|
82 |
| - if (UMF_BUILD_BENCHMARKS_MT) |
83 |
| - target_compile_definitions(multithread_bench PRIVATE UMF_BUILD_LIBUMF_POOL_SCALABLE=1) |
84 |
| - endif() |
| 81 | +add_umf_benchmark(NAME ubench SRCS ubench.c LIBS ${LIBS_OPTIONAL}) |
| 82 | + |
| 83 | +if (UMF_BUILD_BENCHMARKS_MT) |
| 84 | + add_umf_benchmark(NAME multithreaded SRCS multithread.cpp LIBS ${LIBS_OPTIONAL} ${CMAKE_THREAD_LIBS_INIT}) |
85 | 85 | endif()
|
0 commit comments