forked from AMICI-dev/AMICI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
270 additions
and
0 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
ThirdParty/sundials/cmake/macros/SundialsAddBenchmark.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# --------------------------------------------------------------- | ||
# Programmer(s): Yu Pan @ LLNL | ||
# --------------------------------------------------------------- | ||
# SUNDIALS Copyright Start | ||
# Copyright (c) 2002-2024, Lawrence Livermore National Security | ||
# and Southern Methodist University. | ||
# All rights reserved. | ||
# | ||
# See the top-level LICENSE and NOTICE files for details. | ||
# | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# SUNDIALS Copyright End | ||
# --------------------------------------------------------------- | ||
# CMake macro for adding benchmarks to `make benchmark`. | ||
# --------------------------------------------------------------- | ||
|
||
macro(sundials_add_benchmark NAME EXECUTABLE BASE_BENCHMARK_NAME) | ||
|
||
# Define single value parameters the macro takes in to set up the test runner | ||
# | ||
# NUM_CORES = number of cores (GPU count or CPU count) to run on/number of resource sets | ||
# BENCHMARK_ARGS = arguments to pass to the executable | ||
# IDENTIFIER = suffix to append to end of benchmark name | ||
set(oneValueArgs NUM_CORES BENCHMARK_ARGS IDENTIFIER) | ||
|
||
# TEST_RUNNER_ARGS = command line arguments to pass to the test executable | ||
set(multiValueArgs TEST_RUNNER_ARGS ) | ||
|
||
# ENABLE_GPU = indicate this benchmark should be run with GPUs | ||
set(options ENABLE_GPU) | ||
|
||
cmake_parse_arguments(sundials_add_benchmark | ||
"${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | ||
|
||
# set the target name | ||
if(sundials_add_benchmark_IDENTIFIER) | ||
set(TARGET_NAME ${NAME}_${sundials_add_benchmark_IDENTIFIER}) | ||
else() | ||
if(sundials_add_benchmark_BENCHMARK_ARGS) | ||
string(REPLACE " " "_" TEST_SUFFIX "${sundials_add_benchmark_BENCHMARK_ARGS}") | ||
set(TARGET_NAME ${NAME}_${TEST_SUFFIX}) | ||
else() | ||
set(TARGET_NAME ${NAME}_run) | ||
endif() | ||
endif() | ||
|
||
# Create default benchmark caliper output directory if custom directory is not defined | ||
if(SUNDIALS_CALIPER_OUTPUT_DIR) | ||
set(SUNDIALS_BENCHMARK_OUTPUT_DIR ${SUNDIALS_CALIPER_OUTPUT_DIR}/Benchmarking/${BASE_BENCHMARK_NAME}) | ||
else() | ||
set(SUNDIALS_BENCHMARK_OUTPUT_DIR ${PROJECT_BINARY_DIR}/Benchmarking/${BASE_BENCHMARK_NAME}) | ||
endif() | ||
|
||
# make the caliper output directory if it doesn't exist | ||
if(NOT EXISTS ${SUNDIALS_BENCHMARK_OUTPUT_DIR}/${TARGET_NAME}) | ||
file(MAKE_DIRECTORY ${SUNDIALS_BENCHMARK_OUTPUT_DIR}/${TARGET_NAME}) | ||
endif() | ||
|
||
# make the the output directory if it doesn't exist | ||
if(NOT EXISTS ${SUNDIALS_BENCHMARK_OUTPUT_DIR}/output) | ||
file(MAKE_DIRECTORY ${SUNDIALS_BENCHMARK_OUTPUT_DIR}/output) | ||
endif() | ||
|
||
# command line arguments for the test runner script | ||
set(TEST_RUNNER_ARGS | ||
"--profile" | ||
"--verbose" | ||
"--executablename=$<TARGET_FILE:${EXECUTABLE}>" | ||
"--outputdir=${SUNDIALS_BENCHMARK_OUTPUT_DIR}/output" | ||
"--calidir=${SUNDIALS_BENCHMARK_OUTPUT_DIR}/${TARGET_NAME}" | ||
"--nodiff") | ||
|
||
# incorporate scheduler arguments into test_runner | ||
if(SUNDIALS_SCHEDULER_COMMAND STREQUAL "flux run") | ||
set(SCHEDULER_STRING " -n${sundials_add_benchmark_NUM_CORES}") | ||
elseif(SUNDIALS_SCHEDULER_COMMAND STREQUAL "jsrun" AND ${sundials_add_benchmark_ENABLE_GPU}) | ||
set(SCHEDULER_STRING " --smpiargs=\\\"-gpu\\\" -n${sundials_add_benchmark_NUM_CORES} -a1 -c1 -g1") | ||
elseif(SUNDIALS_SCHEDULER_COMMAND STREQUAL "jsrun") | ||
set(SCHEDULER_STRING " -n${sundials_add_benchmark_NUM_CORES} -a1 -c1") | ||
elseif(SUNDIALS_SCHEDULER_COMMAND STREQUAL "srun") | ||
set(SCHEDULER_STRING " -n${sundials_add_benchmark_NUM_CORES} --cpus-per-task=1 --ntasks-per-node=1") | ||
endif() | ||
string(REPLACE " " ";" SCHEDULER_ARGS "${SCHEDULER_STRING}") | ||
string(REPLACE " " ";" SCHEDULER_COMMAND_ARGS "${SUNDIALS_SCHEDULER_COMMAND}") | ||
|
||
string(STRIP "${RUN_COMMAND}" RUN_COMMAND) | ||
set(RUN_COMMAND ${SCHEDULER_COMMAND_ARGS} ${SCHEDULER_ARGS}) | ||
list(APPEND TEST_RUNNER_ARGS "--runcommand=\"${RUN_COMMAND}\"") | ||
|
||
list(APPEND TEST_RUNNER_ARGS "--runargs=${sundials_add_benchmark_BENCHMARK_ARGS}" "--testname=${TARGET_NAME}") | ||
add_custom_target(${TARGET_NAME} | ||
COMMENT "Running ${TARGET_NAME}" | ||
COMMAND ${PYTHON_EXECUTABLE} ${TESTRUNNER} ${TEST_RUNNER_ARGS}) | ||
add_dependencies(benchmark ${TARGET_NAME}) | ||
|
||
endmacro() |
129 changes: 129 additions & 0 deletions
129
ThirdParty/sundials/cmake/macros/SundialsAddExamplesGinkgo.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
# ------------------------------------------------------------------------------ | ||
# Programmer(s): David J. Gardner @ LLNL | ||
# ------------------------------------------------------------------------------ | ||
# SUNDIALS Copyright Start | ||
# Copyright (c) 2002-2024, Lawrence Livermore National Security | ||
# and Southern Methodist University. | ||
# All rights reserved. | ||
# | ||
# See the top-level LICENSE and NOTICE files for details. | ||
# | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# SUNDIALS Copyright End | ||
# ------------------------------------------------------------------------------ | ||
# The macro: | ||
# | ||
# sundials_install_examples_ginkgo(EXAMPLES_VAR | ||
# [TARGETS targets] | ||
# [BACKENDS backends] | ||
# [UNIT_TEST] | ||
# ) | ||
# | ||
# adds a build target for each example tuple in EXAMPLES_VAR. | ||
# | ||
# The TARGETS option is a list of CMake targets provided to | ||
# target_link_libraries. | ||
# | ||
# The BACKENDS is a list of Ginkgo backends compatible with the examples in | ||
# EXAMPLES_VAR. | ||
# | ||
# When the UNIT_TEST option is provided sundials_add_test is called with NODIFF | ||
# so the example return value determines pass/fail. Otherwise, the ANSWER_DIR | ||
# and ANSWER_FILE are used to set an output file for comparison. | ||
# ------------------------------------------------------------------------------ | ||
|
||
# Add the build targets for each CVODE example | ||
macro(sundials_add_examples_ginkgo EXAMPLES_VAR) | ||
|
||
set(options UNIT_TEST) | ||
set(oneValueArgs) | ||
set(multiValueArgs TARGETS BACKENDS) | ||
|
||
# Parse keyword arguments and options | ||
cmake_parse_arguments(arg | ||
"${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | ||
|
||
foreach(example_tuple ${${EXAMPLES_VAR}}) | ||
foreach(backend ${arg_BACKENDS}) | ||
|
||
# parse the example tuple | ||
list(GET example_tuple 0 example) | ||
list(GET example_tuple 1 example_args) | ||
list(GET example_tuple 2 example_type) | ||
|
||
if(NOT (SUNDIALS_GINKGO_BACKENDS MATCHES "${backend}")) | ||
continue() | ||
endif() | ||
|
||
set(float_precision "default") | ||
if(backend MATCHES "CUDA") | ||
set_source_files_properties(${example} PROPERTIES LANGUAGE CUDA) | ||
set(vector nveccuda) | ||
set(float_precision "4") | ||
elseif(backend MATCHES "HIP") | ||
set_source_files_properties(${example} PROPERTIES LANGUAGE CXX) | ||
set(vector nvechip) | ||
elseif(backend MATCHES "SYCL") | ||
set(vector nvecsycl) | ||
elseif(backend MATCHES "OMP") | ||
set(vector nvecopenmp) | ||
elseif(backend MATCHES "REF") | ||
set(vector nvecserial) | ||
endif() | ||
|
||
# extract the file name without extension | ||
get_filename_component(example_target ${example} NAME_WE) | ||
set(example_target "${example_target}.${backend}") | ||
|
||
if(NOT TARGET ${example_target}) | ||
|
||
# create target | ||
add_executable(${example_target} ${example}) | ||
|
||
# folder for IDEs | ||
set_target_properties(${example_target} PROPERTIES FOLDER "Examples") | ||
|
||
# which backend to use | ||
target_compile_definitions(${example_target} PRIVATE USE_${backend}) | ||
|
||
# directories to include | ||
target_include_directories(${example_target} | ||
PRIVATE | ||
"${PROJECT_SOURCE_DIR}/examples/utilities") | ||
|
||
# libraries to link against | ||
target_link_libraries(${example_target} | ||
PRIVATE | ||
${arg_TARGETS} | ||
sundials_${vector} | ||
Ginkgo::ginkgo | ||
${EXTRA_LINK_LIBS}) | ||
|
||
endif() | ||
|
||
# check if example args are provided and set the test name | ||
if("${example_args}" STREQUAL "") | ||
set(test_name ${example_target}) | ||
else() | ||
string(REGEX REPLACE " " "_" test_name ${example_target}_${example_args}) | ||
endif() | ||
|
||
# add example to regression tests | ||
if(${arg_UNIT_TEST}) | ||
sundials_add_test(${test_name} ${example_target} | ||
EXAMPLE_TYPE ${example_type} | ||
TEST_ARGS ${example_args} | ||
NODIFF) | ||
else() | ||
sundials_add_test(${test_name} ${example_target} | ||
EXAMPLE_TYPE ${example_type} | ||
TEST_ARGS ${example_args} | ||
ANSWER_DIR ${CMAKE_CURRENT_SOURCE_DIR} | ||
ANSWER_FILE ${test_name}.out | ||
FLOAT_PRECISION ${float_precision}) | ||
endif() | ||
|
||
endforeach() | ||
endforeach() | ||
|
||
endmacro() |
45 changes: 45 additions & 0 deletions
45
ThirdParty/sundials/cmake/macros/SundialsAddExecutable.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# --------------------------------------------------------------- | ||
# Programmer(s): Cody J. Balos @ LLNL | ||
# --------------------------------------------------------------- | ||
# SUNDIALS Copyright Start | ||
# Copyright (c) 2002-2024, Lawrence Livermore National Security | ||
# and Southern Methodist University. | ||
# All rights reserved. | ||
# | ||
# See the top-level LICENSE and NOTICE files for details. | ||
# | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# SUNDIALS Copyright End | ||
# --------------------------------------------------------------- | ||
# CMake macro for adding executables. | ||
# --------------------------------------------------------------- | ||
|
||
macro(sundials_add_nvector_benchmark NAME) | ||
|
||
set(options ) | ||
set(singleValueArgs ) | ||
set(multiValueArgs SOURCES SUNDIALS_TARGETS LINK_LIBRARIES | ||
INSTALL_SUBDIR) | ||
|
||
cmake_parse_arguments(arg | ||
"${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN}) | ||
|
||
set(BENCHMARKS_DIR ${PROJECT_SOURCE_DIR}/benchmarks) | ||
|
||
add_executable(${NAME} | ||
${BENCHMARKS_DIR}/nvector/test_nvector_performance.c | ||
${arg_SOURCES}) | ||
|
||
set_target_properties(${NAME} PROPERTIES FOLDER "Benchmarks") | ||
|
||
target_include_directories(${NAME} PRIVATE | ||
${BENCHMARKS_DIR}/nvector) | ||
|
||
target_link_libraries(${NAME} PRIVATE | ||
${arg_SUNDIALS_TARGETS} ${arg_LINK_LIBRARIES} -lm) | ||
|
||
install(TARGETS ${NAME} | ||
DESTINATION "${BENCHMARKS_INSTALL_PATH}/${arg_INSTALL_SUBDIR}") | ||
|
||
endmacro(sundials_add_nvector_benchmark) | ||
|