Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set(OCB_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(OCB_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
set(OCB_CHECKS_DIR "${OCB_SOURCE_DIR}/../Checks")
# Each check may contain a directory for benchmark-specific codes
set(OCB_CHECKS_BENCH_CODES_DIR "benchmark/")
set(OCB_CHECKS_BENCH_CODES_DIR "benchmark")

# Configure the project
include(Config)
Expand Down
41 changes: 25 additions & 16 deletions Benchmark/cmake/modules/Benchmark.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@ add_custom_target(run
COMMENT "Running all the available benchmarks"
)

# Utility function to automatically create the build target for the given check
# Helper function to scan the files in the check directories
function(scan_check_files VAR CHECKID EXPR)
file(GLOB files "${OCB_CHECKS_DIR}/${CHECKID}/${OCB_CHECKS_BENCH_CODES_DIR}/${EXPR}")
if(NOT files)
file(GLOB files "${OCB_CHECKS_DIR}/${CHECKID}/${EXPR}")
endif()
# Propagate the result to the calling function
set(${VAR} "${files}" PARENT_SCOPE)
endfunction()

# Utility function to automatically create the build target for the given check
function(add_benchmark CHECKID)
set(files)

Expand All @@ -12,17 +22,11 @@ function(add_benchmark CHECKID)
# - Prioritize benchmark-specific codes for the check, if available
# - Otherwise, compile the usual code examples created for the README
if (OCB_ENABLE_C)
file(GLOB c_files "${OCB_CHECKS_DIR}/${CHECKID}/${OCB_CHECKS_BENCH_CODES_DIR}/*.c")
if(NOT c_files)
file(GLOB c_files "${OCB_CHECKS_DIR}/${CHECKID}/*.c")
endif()
scan_check_files(c_files "${CHECKID}" "*.c")
list(APPEND files ${c_files})
endif()
if (OCB_ENABLE_Fortran)
file(GLOB fortran_files "${OCB_CHECKS_DIR}/${CHECKID}/${OCB_CHECKS_BENCH_CODES_DIR}/*.f90")
if(NOT fortran_files)
file(GLOB fortran_files "${OCB_CHECKS_DIR}/${CHECKID}/*.f90")
endif()
scan_check_files(fortran_files "${CHECKID}" "*.f90")
list(APPEND files ${fortran_files})
endif()

Expand All @@ -43,6 +47,11 @@ function(add_benchmark CHECKID)
benchmark::benchmark
)

# Setup separated dirs to avoid output files clashing between checks
set_target_properties(${CHECKID} PROPERTIES
Fortran_MODULE_DIRECTORY "${CHECKID}"
)

Comment on lines +50 to +54

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come this workflow didn't catch this error earlier?? Is GNU Make silently ignoring the conflict? 😨

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my computer (without the fix) the Unix Makefiles generation "just works", but all the Fortran modules are in build/src, so I guess they get overwritten in the build.

Nice catch by ninja, I guess.

find_library(MATH_LIBRARY m)
if(MATH_LIBRARY)
target_link_libraries(${CHECKID}
Expand Down Expand Up @@ -70,14 +79,14 @@ function(add_benchmark CHECKID)
add_dependencies(run run-${CHECKID})
endfunction()

# Find a systems google benchmark library or build it from source
# We require version 1.5.3 or above because we change the name of the benchmarks
# through the `::Name()` method
find_package(benchmark 1.5.3 QUIET)
if (NOT benchmark_FOUND)
note("No compatible Benchmark library was found. Building it from source...")

option(OCB_USE_SYSTEM_GBENCH "Prefer using the system installed google benchmark library, rather than compiling it from source" OFF)
if (NOT OCB_USE_SYSTEM_GBENCH)
# Disable benchmark testing to avoid depending on GTest
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "")
add_subdirectory("${OCB_SOURCE_DIR}/external/google_benchmark")
else()
# Find a systems google benchmark library or build it from source
# We require version 1.5.3 or above because we change the name of the benchmarks
# through the `::Name()` method
find_package(benchmark 1.5.3 REQUIRED)
endif()
12 changes: 9 additions & 3 deletions Benchmark/run-benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,12 @@ def main():
args = parse_args()
if not args.build.exists():
args.build.mkdir()
# CMake 3.10 doesn't support the -B flag
echorun(["cmake", f"{SCRIPT_DIR}", *args.cmake_args], cwd=args.build, check=True)
echorun(["cmake", "--build", f"{args.build}", "--", "all"], check=True)
try:
# CMake 3.10 doesn't support the -B flag
echorun(["cmake", f"{SCRIPT_DIR}", *args.cmake_args], cwd=args.build, check=True)
echorun(["cmake", "--build", f"{args.build}", "--", "all"], check=True)
except subprocess.CalledProcessError as e:
exit("Build command failed")

benchmarks_to_run = list((args.build / Path("bin")).iterdir())
if args.check:
Expand Down Expand Up @@ -212,4 +215,7 @@ def main():


if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
sys.exit("Aborted by the user")
Loading