Skip to content

Commit a045006

Browse files
Merge pull request #300 from ldorau/Unify_benchmarks_CI_workflows_for_Linux_and_Windows
Unify benchmarks' CI workflows for Linux and Windows
2 parents 91a3a74 + d67f2f6 commit a045006

File tree

5 files changed

+132
-165
lines changed

5 files changed

+132
-165
lines changed

.github/workflows/basic.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ jobs:
158158

159159
- name: Run tests
160160
working-directory: ${{env.BUILD_DIR}}
161-
run: ctest --output-on-failure
161+
run: ctest --output-on-failure --test-dir test
162162

163163
- name: Test make install
164164
# Run only when the example is built
@@ -246,7 +246,7 @@ jobs:
246246

247247
- name: Run tests
248248
working-directory: ${{env.BUILD_DIR}}
249-
run: ctest -C ${{matrix.build_type}} --output-on-failure
249+
run: ctest -C ${{matrix.build_type}} --output-on-failure --test-dir test
250250

251251
macos-build:
252252
name: MacOS

.github/workflows/benchmarks.yml

Lines changed: 40 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -7,126 +7,72 @@ permissions:
77
contents: read
88

99
jobs:
10-
benchmarks-ubuntu:
11-
name: Ubuntu
10+
benchmarks:
11+
name: Benchmarks
12+
env:
13+
BUILD_DIR : "${{github.workspace}}/build/"
14+
VCPKG_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows;${{github.workspace}}/build/vcpkg/packages/tbb_x64-windows"
1215
strategy:
1316
matrix:
14-
os: ['ubuntu-22.04']
15-
build_type: [Release]
16-
compiler: [{c: gcc, cxx: g++}]
17-
shared_library: ['ON', 'OFF']
17+
include:
18+
- os: ubuntu-latest
19+
pool_jemalloc: 'ON'
20+
21+
- os: windows-latest
22+
pool_jemalloc: 'OFF'
23+
1824
runs-on: ${{matrix.os}}
1925

2026
steps:
2127
- name: Checkout
2228
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
2329

2430
- name: Install apt packages
31+
if: matrix.os == 'ubuntu-latest'
2532
run: |
2633
sudo apt-get update
2734
sudo apt-get install -y cmake libhwloc-dev libnuma-dev libjemalloc-dev libtbb-dev
2835
36+
- name: Initialize vcpkg
37+
if: matrix.os == 'windows-latest'
38+
uses: lukka/run-vcpkg@5e0cab206a5ea620130caf672fce3e4a6b5666a1 # v11.5
39+
with:
40+
vcpkgGitCommitId: 3dd44b931481d7a8e9ba412621fa810232b66289
41+
vcpkgDirectory: ${{env.BUILD_DIR}}/vcpkg
42+
vcpkgJsonGlob: '**/vcpkg.json'
43+
44+
- name: Install vcpkg packages
45+
if: matrix.os == 'windows-latest'
46+
run: vcpkg install
47+
shell: pwsh # Specifies PowerShell as the shell for running the script.
48+
2949
- name: Configure build
3050
run: >
3151
cmake
32-
-B ${{github.workspace}}/build
33-
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
34-
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
35-
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
36-
-DUMF_BUILD_SHARED_LIBRARY=${{matrix.shared_library}}
52+
-B ${{env.BUILD_DIR}}
53+
-DCMAKE_BUILD_TYPE=Release
54+
-DCMAKE_PREFIX_PATH="${{env.VCPKG_PATH}}"
55+
-DUMF_BUILD_SHARED_LIBRARY=ON
3756
-DUMF_BUILD_BENCHMARKS=ON
3857
-DUMF_BUILD_BENCHMARKS_MT=ON
3958
-DUMF_BUILD_TESTS=OFF
4059
-DUMF_FORMAT_CODE_STYLE=OFF
4160
-DUMF_DEVELOPER_MODE=OFF
4261
-DUMF_BUILD_OS_MEMORY_PROVIDER=ON
43-
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=ON
4462
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
63+
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=${{matrix.pool_jemalloc}}
4564
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=ON
4665
-DUMF_ENABLE_POOL_TRACKING=OFF
4766
-DUMF_BUILD_LEVEL_ZERO_PROVIDER=OFF
4867
49-
- name: Build UMF
50-
run: cmake --build ${{github.workspace}}/build -j $(nproc)
51-
52-
- name: Run benchmarks
53-
working-directory: ${{github.workspace}}/build
54-
# The benchmark of TBB pool manager fails very often with the
55-
# "confidence interval exceeds maximum permitted 2.5%" error.
56-
# Do not treat that as a failure in CI.
57-
run: |
58-
export LOG=/tmp/ubench.log
59-
if ! ./benchmark/ubench 2>/dev/null > $LOG; then \
60-
cat $LOG; \
61-
if ! grep -q -e "exceeds maximum permitted 2.5" $LOG; then \
62-
echo "[ FAILED ] The CI benchmark job FAILED."; \
63-
exit 1; \
64-
fi; \
65-
fi
66-
cat $LOG
67-
echo "[ PASSED ] The CI benchmark job PASSED."
68+
- name: Build UMF on Linux
69+
if: matrix.os == 'ubuntu-latest'
70+
run: cmake --build ${{env.BUILD_DIR}} -j $(nproc)
6871

69-
- name: Run MT benchmarks
70-
working-directory: ${{github.workspace}}/build
71-
run: ./benchmark/multithread_bench
72+
- name: Build UMF on Windows
73+
if: matrix.os == 'windows-latest'
74+
run: cmake --build ${{env.BUILD_DIR}} --config Release -j $Env:NUMBER_OF_PROCESSORS
7275

73-
benchmarks-windows:
74-
name: Windows
75-
env:
76-
BUILD_DIR : "${{github.workspace}}/build/"
77-
VCPKG_PATH: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows;${{github.workspace}}/build/vcpkg/packages/tbb_x64-windows"
78-
VCPKG_PATH_BIN: "${{github.workspace}}/build/vcpkg/packages/hwloc_x64-windows/bin;${{github.workspace}}/build/vcpkg/packages/tbb_x64-windows/bin"
79-
strategy:
80-
fail-fast: false
81-
matrix:
82-
build_type: [Release]
83-
compiler: [{c: cl, cxx: cl}]
84-
shared_library: ['ON', 'OFF']
85-
runs-on: 'windows-2022'
86-
87-
steps:
88-
- name: Checkout
89-
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
90-
91-
- name: Initialize vcpkg
92-
uses: lukka/run-vcpkg@5e0cab206a5ea620130caf672fce3e4a6b5666a1 # v11.5
93-
with:
94-
vcpkgGitCommitId: 3dd44b931481d7a8e9ba412621fa810232b66289
95-
vcpkgDirectory: ${{github.workspace}}/build/vcpkg
96-
vcpkgJsonGlob: '**/vcpkg.json'
97-
98-
- name: Install dependencies
99-
run: vcpkg install
100-
shell: pwsh # Specifies PowerShell as the shell for running the script.
101-
102-
- name: Configure build
103-
run: >
104-
cmake
105-
-B ${{env.BUILD_DIR}}
106-
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
107-
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
108-
-DCMAKE_PREFIX_PATH="${{env.VCPKG_PATH}}"
109-
-DUMF_BUILD_SHARED_LIBRARY=${{matrix.shared_library}}
110-
-DUMF_BUILD_BENCHMARKS=ON
111-
-DUMF_BUILD_BENCHMARKS_MT=OFF
112-
-DUMF_BUILD_TESTS=OFF
113-
-DUMF_FORMAT_CODE_STYLE=OFF
114-
-DUMF_DEVELOPER_MODE=OFF
115-
-DUMF_BUILD_OS_MEMORY_PROVIDER=ON
116-
-DUMF_BUILD_LIBUMF_POOL_DISJOINT=ON
117-
-DUMF_BUILD_LIBUMF_POOL_JEMALLOC=OFF
118-
-DUMF_BUILD_LIBUMF_POOL_SCALABLE=OFF
119-
-DUMF_ENABLE_POOL_TRACKING=OFF
120-
121-
- name: Build UMF
122-
run: cmake --build ${{env.BUILD_DIR}} --config ${{matrix.build_type}} -j $Env:NUMBER_OF_PROCESSORS
123-
124-
- name: Run benchmarks
125-
working-directory: ${{env.BUILD_DIR}}
126-
shell: pwsh # Specifies PowerShell as the shell for running the script.
127-
run: |
128-
# add path to umf.dll
129-
$env:PATH += ";${{env.BUILD_DIR}}\bin\${{matrix.build_type}}"
130-
# add path to DLL directories
131-
$env:PATH += ";${{env.VCPKG_PATH_BIN}}"
132-
.\benchmark\${{matrix.build_type}}\ubench.exe
76+
- name: Run benchmarks
77+
working-directory: ${{env.BUILD_DIR}}
78+
run: ctest -V --test-dir benchmark -C Release

benchmark/CMakeLists.txt

Lines changed: 75 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,92 +2,102 @@
22
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
33
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

5-
include(FindThreads)
6-
75
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
86
message(WARNING "The benchmarks SHOULD NOT be run in the Debug build type!")
97
endif()
108

9+
if (UMF_BUILD_BENCHMARKS_MT)
10+
include(FindThreads)
11+
endif()
12+
13+
function(add_umf_benchmark)
14+
# NAME - a name of the benchmark
15+
# SRCS - source files
16+
# LIBS - libraries to be linked with
17+
# LIBDIRS - directories of libraries to be linked with
18+
set(oneValueArgs NAME)
19+
set(multiValueArgs SRCS LIBS LIBDIRS)
20+
cmake_parse_arguments(ARG "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
21+
22+
set(BENCH_NAME umf-bench-${ARG_NAME})
23+
24+
set(BENCH_LIBS umf ${ARG_LIBS})
25+
26+
add_umf_executable(NAME ${BENCH_NAME} SRCS ${ARG_SRCS} LIBS ${BENCH_LIBS})
27+
28+
target_include_directories(${BENCH_NAME} PRIVATE
29+
${UMF_CMAKE_SOURCE_DIR}/include
30+
${UMF_CMAKE_SOURCE_DIR}/src/utils)
31+
32+
target_link_directories(${BENCH_NAME} PRIVATE ${ARG_LIBDIRS})
33+
34+
add_test(NAME ${BENCH_NAME}
35+
COMMAND ${BENCH_NAME}
36+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
37+
38+
# Benchmark passes if it prints "PASSED" in the output,
39+
# because ubench of scalable pool fails if the confidence interval
40+
# exceeds maximum permitted 2.5%.
41+
set_tests_properties(${BENCH_NAME} PROPERTIES
42+
LABELS "benchmark"
43+
PASS_REGULAR_EXPRESSION "PASSED")
44+
45+
if(WINDOWS)
46+
# append PATH to DLLs
47+
set(DLL_PATH_LIST "PATH=path_list_append:../bin/$<CONFIG>")
48+
if(LIBHWLOC_LIBRARY_DIRS)
49+
set(DLL_PATH_LIST "${DLL_PATH_LIST};PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS}/../bin")
50+
endif()
51+
if(TBB_LIBRARY_DIRS)
52+
set(DLL_PATH_LIST "${DLL_PATH_LIST};PATH=path_list_append:${TBB_LIBRARY_DIRS}/../bin")
53+
endif()
54+
set_property(TEST ${BENCH_NAME} PROPERTY ENVIRONMENT_MODIFICATION "${DLL_PATH_LIST}")
55+
endif()
56+
57+
if (UMF_BUILD_OS_MEMORY_PROVIDER)
58+
target_compile_definitions(${BENCH_NAME} PRIVATE UMF_BUILD_OS_MEMORY_PROVIDER=1)
59+
endif()
60+
if (UMF_BUILD_LIBUMF_POOL_DISJOINT)
61+
target_compile_definitions(${BENCH_NAME} PRIVATE UMF_BUILD_LIBUMF_POOL_DISJOINT=1)
62+
endif()
63+
if (UMF_BUILD_LIBUMF_POOL_JEMALLOC)
64+
target_compile_definitions(${BENCH_NAME} PRIVATE UMF_BUILD_LIBUMF_POOL_JEMALLOC=1)
65+
endif()
66+
if (UMF_BUILD_LIBUMF_POOL_SCALABLE)
67+
target_compile_definitions(${BENCH_NAME} PRIVATE UMF_BUILD_LIBUMF_POOL_SCALABLE=1)
68+
endif()
69+
endfunction()
70+
71+
# optional libraries
1172
if(UMF_BUILD_LIBUMF_POOL_DISJOINT)
1273
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} disjoint_pool)
1374
endif()
14-
1575
if(UMF_BUILD_LIBUMF_POOL_JEMALLOC)
1676
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} jemalloc_pool)
1777
endif()
18-
1978
if(UMF_BUILD_LIBUMF_POOL_SCALABLE)
2079
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} scalable_pool)
2180
endif()
22-
23-
add_executable(ubench ubench.c)
24-
2581
if(LINUX)
26-
set(LIBS_LINUX m)
82+
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} m)
2783
endif()
28-
29-
add_dependencies(ubench
30-
umf
31-
${LIBS_OPTIONAL})
32-
3384
if(UMF_BUILD_OS_MEMORY_PROVIDER)
3485
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} ${LIBHWLOC_LIBRARIES})
3586
set(LIB_DIRS_OPTIONAL ${LIB_DIRS_OPTIONAL} ${LIBHWLOC_LIBRARY_DIRS})
3687
endif()
3788

38-
target_include_directories(ubench PRIVATE ${UMF_CMAKE_SOURCE_DIR}/include/ ${UMF_CMAKE_SOURCE_DIR}/src/utils/)
89+
# BENCHMARKS
3990

40-
target_link_directories(ubench PRIVATE ${LIB_DIRS_OPTIONAL})
41-
42-
target_link_libraries(ubench
43-
umf
44-
${LIBS_OPTIONAL}
45-
${CMAKE_THREAD_LIBS_INIT}
46-
${LIBS_LINUX})
91+
add_umf_benchmark(
92+
NAME ubench
93+
SRCS ubench.c
94+
LIBS ${LIBS_OPTIONAL}
95+
LIBDIRS ${LIB_DIRS_OPTIONAL})
4796

4897
if (UMF_BUILD_BENCHMARKS_MT)
49-
add_executable(multithread_bench multithread.cpp)
50-
target_link_directories(multithread_bench PRIVATE ${LIB_DIRS_OPTIONAL})
51-
target_link_libraries(multithread_bench
52-
umf
53-
${LIBS_OPTIONAL}
54-
${CMAKE_THREAD_LIBS_INIT}
55-
${LIBS_LINUX})
56-
target_include_directories(multithread_bench PRIVATE ${UMF_CMAKE_SOURCE_DIR}/include/)
57-
endif()
58-
59-
if (UMF_BUILD_OS_MEMORY_PROVIDER)
60-
target_compile_definitions(ubench PRIVATE UMF_BUILD_OS_MEMORY_PROVIDER=1)
61-
62-
if (UMF_BUILD_BENCHMARKS_MT)
63-
target_compile_definitions(multithread_bench PRIVATE UMF_BUILD_OS_MEMORY_PROVIDER=1)
64-
endif()
65-
endif()
66-
67-
if (UMF_BUILD_OS_MEMORY_PROVIDER)
68-
target_compile_definitions(ubench PRIVATE UMF_BUILD_OS_MEMORY_PROVIDER=1)
69-
endif()
70-
71-
if (UMF_BUILD_LIBUMF_POOL_DISJOINT)
72-
target_compile_definitions(ubench PRIVATE UMF_BUILD_LIBUMF_POOL_DISJOINT=1)
73-
74-
if (UMF_BUILD_BENCHMARKS_MT)
75-
target_compile_definitions(multithread_bench PRIVATE UMF_BUILD_LIBUMF_POOL_DISJOINT=1)
76-
endif()
77-
endif()
78-
79-
if (UMF_BUILD_LIBUMF_POOL_JEMALLOC)
80-
target_compile_definitions(ubench PRIVATE UMF_BUILD_LIBUMF_POOL_JEMALLOC=1)
81-
82-
if (UMF_BUILD_BENCHMARKS_MT)
83-
target_compile_definitions(multithread_bench PRIVATE UMF_BUILD_LIBUMF_POOL_JEMALLOC=1)
84-
endif()
85-
endif()
86-
87-
if (UMF_BUILD_LIBUMF_POOL_SCALABLE)
88-
target_compile_definitions(ubench PRIVATE UMF_BUILD_LIBUMF_POOL_SCALABLE=1)
89-
90-
if (UMF_BUILD_BENCHMARKS_MT)
91-
target_compile_definitions(multithread_bench PRIVATE UMF_BUILD_LIBUMF_POOL_SCALABLE=1)
92-
endif()
98+
add_umf_benchmark(
99+
NAME multithreaded
100+
SRCS multithread.cpp
101+
LIBS ${LIBS_OPTIONAL} ${CMAKE_THREAD_LIBS_INIT}
102+
LIBDIRS ${LIB_DIRS_OPTIONAL})
93103
endif()

benchmark/multithread.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ static void mt_alloc_free(poolCreateExtParams params,
6565
auto values = umf_bench::measure<std::chrono::milliseconds>(
6666
bench.n_repeats, bench.n_threads,
6767
[&, pool = pool.get()](auto thread_id) {
68-
for (int i = 0; i < bench.n_iterations; i++) {
68+
for (size_t i = 0; i < bench.n_iterations; i++) {
6969
allocs[thread_id].push_back(
7070
umfPoolMalloc(pool, bench.alloc_size));
7171
if (!allocs[thread_id].back()) {
7272
numFailures[thread_id]++;
7373
}
7474
}
7575

76-
for (int i = 0; i < bench.n_iterations; i++) {
76+
for (size_t i = 0; i < bench.n_iterations; i++) {
7777
umfPoolFree(pool, allocs[thread_id][i]);
7878
}
7979

@@ -131,5 +131,8 @@ int main() {
131131
std::cout << "skipping disjoint_pool mt_alloc_free" << std::endl;
132132
#endif
133133

134+
// ctest looks for "PASSED" in the output
135+
std::cout << "PASSED" << std::endl;
136+
134137
return 0;
135138
}

0 commit comments

Comments
 (0)