Skip to content

Commit

Permalink
refactor: Tidy up benchmarks (#1927) (#1944)
Browse files Browse the repository at this point in the history
  • Loading branch information
trisyoungs authored Jun 26, 2024
1 parent 9dbbd76 commit 064af34
Show file tree
Hide file tree
Showing 34 changed files with 724 additions and 97,571 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,23 @@ jobs:
run: |
set -ex
export LD_LIBRARY_PATH=`pwd`/build/onetbb/lib
./build/benchmarks --benchmark_format=json | tee benchmark_result.json
cd build
# Run individual benchmarks
for bm in benchmark_*
do
./${bm} --benchmark_format=json > ${bm}_result.json
done
# Combine benchmark results
jq -s '[.[] | to_entries] | flatten | reduce .[] as $dot ({}; .[$dot.key] += $dot.value)' benchmark_*.json > all_benchmark_results.json
cat all_benchmark_results.json
- name: Store benchmark result
uses: rhysd/github-action-benchmark@v1
if: ${{ github.ref_name == 'develop' }}
with:
tool: 'googlecpp'
output-file-path: benchmark_result.json
output-file-path: all_benchmark_results.json
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
comment-on-alert: true
Expand Down
14 changes: 5 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ if(CONAN)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})

if(BUILD_BENCHMARKS)
list(APPEND EXTRA_CONAN_REQUIRES benchmark/1.8.4)
endif(BUILD_BENCHMARKS)

include(conan-dissolve)
endif(CONAN)

Expand Down Expand Up @@ -320,16 +324,8 @@ if(BUILD_TESTS)
endif(BUILD_TESTS)

if(BUILD_BENCHMARKS)
# The conan package of goooglebenchmark segfaults - so lets use fetch content
include(FetchContent)
find_package(benchmark REQUIRED)
set(BENCHMARK_ENABLE_TESTING "OFF")
fetchcontent_declare(
googlebenchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.5.4
)

fetchcontent_makeavailable(googlebenchmark)
add_subdirectory(benchmark)
endif(BUILD_BENCHMARKS)

Expand Down
87 changes: 45 additions & 42 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
macro(DISSOLVE_BENCHMARK NAME)
set(benchmark_files ${benchmark_files} ${CMAKE_CURRENT_SOURCE_DIR}/${NAME}/${NAME}_benchmark.cpp)
endmacro(DISSOLVE_BENCHMARK)

dissolve_benchmark(calculate_gr)
dissolve_benchmark(box)
dissolve_benchmark(histogram)
dissolve_benchmark(array)
dissolve_benchmark(energy)
dissolve_benchmark(forces)
dissolve_benchmark(region)
dissolve_benchmark(math)
dissolve_benchmark(siterdf)

# create a single benchmark executable
add_executable(benchmarks benchmarks.cpp ${benchmark_files})

target_include_directories(benchmarks PRIVATE ${PROJECT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})

target_link_libraries(
benchmarks
PRIVATE benchmark::benchmark
PUBLIC ${WHOLE_ARCHIVE_FLAG} ${BASIC_LINK_LIBS} ${MODULENOGUI_LINK_LIBS} ${NO_WHOLE_ARCHIVE_FLAG}
PRIVATE ${CORE_LINK_LIBS} ${THREADING_LINK_LIBS}
)

target_compile_options(benchmarks PRIVATE -O3)

# Find all the input files
file(
GLOB benchmarkFiles
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/benchmark_files/*.txt"
)

# configure the input header to point to the directory containing the benchmark
set(BENCHMARK_PATH \"${CMAKE_CURRENT_BINARY_DIR}/\")
configure_file(benchmark_config.h.in benchmark_config.h @ONLY)

foreach(benchmarkFile ${benchmarkFiles})
file(COPY ${benchmarkFile} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
endforeach(benchmarkFile)
# CMakeLists.txt for Dissolve Benchmarks

function(dissolve_add_benchmark)

# Parse arguments
set(options "")
set(oneValueArgs SRC "")
cmake_parse_arguments(DISSOLVE_BENCHMARK "${options}" "${oneValueArgs}" "" ${ARGN})

# Check args
if(NOT DEFINED DISSOLVE_BENCHMARK_SRC)
message(FATAL_ERROR "Benchmark registered from directory '${CMAKE_CURRENT_LIST_DIR}' did not set a SRC file.")
endif(NOT DEFINED DISSOLVE_BENCHMARK_SRC)

# Strip path and extension from source file to get benchmark name
get_filename_component(benchmark_file ${DISSOLVE_BENCHMARK_SRC} NAME_WE)
get_filename_component(benchmark_file_dir "${CMAKE_CURRENT_LIST_DIR}" NAME)
set(BENCHMARK_NAME "benchmark_${benchmark_file_dir}_${benchmark_file}")
message(STATUS "... Benchmark '${BENCHMARK_NAME}' from ${DISSOLVE_BENCHMARK_SRC} in directory '${CMAKE_CURRENT_LIST_DIR}'")
message(STATUS " ... working directory = ${DISSOLVE_BENCHMARK_USE_TEST_DIRECTORY}")

# Register executable target
add_executable(${BENCHMARK_NAME} ${DISSOLVE_BENCHMARK_SRC})
target_compile_options(${BENCHMARK_NAME} PRIVATE -O3)

# Configure target
target_include_directories(
${BENCHMARK_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/benchmark ${PROJECT_BINARY_DIR}/benchmark ${CONAN_INCLUDE_DIRS_PUGIXML}
)
target_link_libraries(
${BENCHMARK_NAME}
PUBLIC ${WHOLE_ARCHIVE_FLAG} ${BASIC_LINK_LIBS} ${MODULENOGUI_LINK_LIBS} ${NO_WHOLE_ARCHIVE_FLAG}
PRIVATE ${CORE_LINK_LIBS} benchmark::benchmark
)

endfunction()

set(DISSOLVE_BENCHMARK_INPUT_FILE_PATH \"${PROJECT_SOURCE_DIR}/benchmark/common/\")
configure_file(benchmarkConfig.h.in benchmarkConfig.h @ONLY)

# Add benchmark subdirectories
add_subdirectory(classes)
add_subdirectory(math)
add_subdirectory(modules)
103 changes: 0 additions & 103 deletions benchmark/array/array_benchmark.cpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
*/
#pragma once

inline const char *benchmark_path = @BENCHMARK_PATH@;
inline const char *benchmarkInputFilePath = @DISSOLVE_BENCHMARK_INPUT_FILE_PATH@;
33 changes: 0 additions & 33 deletions benchmark/benchmark_files/argon10k.txt

This file was deleted.

33 changes: 0 additions & 33 deletions benchmark/benchmark_files/argon5k.txt

This file was deleted.

Loading

0 comments on commit 064af34

Please sign in to comment.