Skip to content

Commit

Permalink
Add miniapps as tests
Browse files Browse the repository at this point in the history
  • Loading branch information
msimberg committed Mar 20, 2024
1 parent e564e88 commit 9900e70
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 41 deletions.
87 changes: 56 additions & 31 deletions cmake/DLAF_AddTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,72 +57,68 @@ function(_set_element_to_fallback_value LIST_NAME ELEMENT_REGEX FALLBACK)
endif()
endfunction()

function(DLAF_addTest test_target_name)
function(DLAF_addTargetTest test_target_name)
set(options "")
set(oneValueArgs MPIRANKS USE_MAIN)
set(multiValueArgs SOURCES COMPILE_DEFINITIONS INCLUDE_DIRS LIBRARIES ARGUMENTS)
cmake_parse_arguments(DLAF_AT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set(multiValueArgs ARGUMENTS)
cmake_parse_arguments(DLAF_ATT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

### Checks
if(DLAF_AT_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Unknown arguments ${DLAF_AT_UNPARSED_ARGUMENTS}")
endif()

if(NOT DLAF_AT_SOURCES)
message(FATAL_ERROR "No sources specified for this test")
if(DLAF_ATT_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Unknown arguments ${DLAF_ATT_UNPARSED_ARGUMENTS}")
endif()

set(IS_AN_MPI_TEST FALSE)
set(IS_AN_PIKA_TEST FALSE)
if(NOT DLAF_AT_USE_MAIN)
if(NOT DLAF_ATT_USE_MAIN)
set(_gtest_tgt gtest)
elseif(DLAF_AT_USE_MAIN STREQUAL PLAIN)
elseif(DLAF_ATT_USE_MAIN STREQUAL PLAIN)
set(_gtest_tgt gtest_main)
elseif(DLAF_AT_USE_MAIN STREQUAL PIKA)
elseif(DLAF_ATT_USE_MAIN STREQUAL PIKA)
set(_gtest_tgt DLAF_gtest_pika_main)
set(IS_AN_PIKA_TEST TRUE)
elseif(DLAF_AT_USE_MAIN STREQUAL MPI)
elseif(DLAF_ATT_USE_MAIN STREQUAL MPI)
set(_gtest_tgt DLAF_gtest_mpi_main)
set(IS_AN_MPI_TEST TRUE)
elseif(DLAF_AT_USE_MAIN STREQUAL MPIPIKA)
elseif(DLAF_ATT_USE_MAIN STREQUAL MPIPIKA)
set(_gtest_tgt DLAF_gtest_mpipika_main)
set(IS_AN_MPI_TEST TRUE)
set(IS_AN_PIKA_TEST TRUE)
elseif(DLAF_AT_USE_MAIN STREQUAL CAPI)
elseif(DLAF_ATT_USE_MAIN STREQUAL CAPI)
set(_gtest_tgt DLAF_gtest_mpi_main)
set(IS_AN_MPI_TEST TRUE)
else()
message(FATAL_ERROR "USE_MAIN=${DLAF_AT_USE_MAIN} is not a supported option")
message(FATAL_ERROR "USE_MAIN=${DLAF_ATT_USE_MAIN} is not a supported option")
endif()

if(IS_AN_MPI_TEST)
if(NOT DLAF_AT_MPIRANKS)
if(NOT DLAF_ATT_MPIRANKS)
message(FATAL_ERROR "You are asking for an MPI external main without specifying MPIRANKS")
endif()
if(NOT DLAF_AT_MPIRANKS GREATER 0)
message(FATAL_ERROR "Wrong MPIRANKS number ${DLAF_AT_MPIRANKS}")
if(NOT DLAF_ATT_MPIRANKS GREATER 0)
message(FATAL_ERROR "Wrong MPIRANKS number ${DLAF_ATT_MPIRANKS}")
endif()
if(DLAF_AT_MPIRANKS GREATER MPIEXEC_MAX_NUMPROCS)
if(DLAF_ATT_MPIRANKS GREATER MPIEXEC_MAX_NUMPROCS)
message(
WARNING
"\
YOU ARE ASKING FOR ${DLAF_AT_MPIRANKS} RANKS, BUT THERE ARE JUST ${MPIEXEC_MAX_NUMPROCS} CORES.
YOU ARE ASKING FOR ${DLAF_ATT_MPIRANKS} RANKS, BUT THERE ARE JUST ${MPIEXEC_MAX_NUMPROCS} CORES.
You can adjust MPIEXEC_MAX_NUMPROCS value to suppress this warning.
Using OpenMPI may require to set the environment variable OMPI_MCA_rmaps_base_oversubscribe=1."
)
endif()
else()
if(DLAF_AT_MPIRANKS)
if(DLAF_ATT_MPIRANKS)
message(FATAL_ERROR "You specified MPIRANKS and asked for an external main without MPI")
else()
set(DLAF_AT_MPIRANKS 1)
set(DLAF_ATT_MPIRANKS 1)
endif()
endif()

### Test target
set(DLAF_TEST_RUNALL_WITH_MPIEXEC OFF CACHE BOOL "Run all tests using the workload manager.")

set(_TEST_ARGUMENTS ${DLAF_AT_ARGUMENTS})
set(_TEST_ARGUMENTS ${DLAF_ATT_ARGUMENTS})

if(DLAF_TEST_RUNALL_WITH_MPIEXEC OR IS_AN_MPI_TEST)
if(MPIEXEC_NUMCORE_FLAG)
Expand All @@ -132,7 +128,7 @@ function(DLAF_addTest test_target_name)
set(_CORES_PER_RANK 1)
endif()

math(EXPR DLAF_CORE_PER_RANK "${_CORES_PER_RANK}/${DLAF_AT_MPIRANKS}")
math(EXPR DLAF_CORE_PER_RANK "${_CORES_PER_RANK}/${DLAF_ATT_MPIRANKS}")

if(NOT DLAF_CORE_PER_RANK)
set(DLAF_CORE_PER_RANK 1)
Expand All @@ -148,12 +144,12 @@ function(DLAF_addTest test_target_name)
else()
separate_arguments(MPIEXEC_PREFLAGS)
set(_TEST_COMMAND
${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${DLAF_AT_MPIRANKS} ${_MPI_CORE_ARGS}
${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${DLAF_ATT_MPIRANKS} ${_MPI_CORE_ARGS}
${MPIEXEC_PREFLAGS} ${DLAF_TEST_PREFLAGS} $<TARGET_FILE:${test_target_name}>
${DLAF_TEST_POSTFLAGS} ${MPIEXEC_POSTFLAGS}
)
endif()
set(_TEST_LABEL "RANK_${DLAF_AT_MPIRANKS}")
set(_TEST_LABEL "RANK_${DLAF_ATT_MPIRANKS}")

else()
# ----- Classic test
Expand All @@ -165,12 +161,12 @@ function(DLAF_addTest test_target_name)
separate_arguments(_PIKA_EXTRA_ARGS_LIST UNIX_COMMAND ${DLAF_PIKATEST_EXTRA_ARGS})

# --pika:bind=none is useful just in case more ranks are going to be allocated on the same node.
if(IS_AN_MPI_TEST AND (DLAF_AT_MPIRANKS GREATER 1) AND (NOT DLAF_TEST_THREAD_BINDING_ENABLED))
if(IS_AN_MPI_TEST AND (DLAF_ATT_MPIRANKS GREATER 1) AND (NOT DLAF_TEST_THREAD_BINDING_ENABLED))
_set_element_to_fallback_value(_PIKA_EXTRA_ARGS_LIST "--pika:bind" "--pika:bind=none")
endif()

if(IS_AN_MPI_TEST AND DLAF_MPI_PRESET STREQUAL "plain-mpi")
math(EXPR _DLAF_PIKA_THREADS "${MPIEXEC_MAX_NUMPROCS}/${DLAF_AT_MPIRANKS}")
math(EXPR _DLAF_PIKA_THREADS "${MPIEXEC_MAX_NUMPROCS}/${DLAF_ATT_MPIRANKS}")

if(_DLAF_PIKA_THREADS LESS 2)
set(_DLAF_PIKA_THREADS 2)
Expand Down Expand Up @@ -214,11 +210,34 @@ function(DLAF_addTest test_target_name)

endif()

add_test(NAME ${test_target_name} COMMAND ${_TEST_COMMAND} ${_TEST_ARGUMENTS})
set_tests_properties(${test_target_name} PROPERTIES LABELS "${_TEST_LABEL}")
endfunction()

function(DLAF_addTest test_target_name)
set(options "")
set(oneValueArgs MPIRANKS USE_MAIN)
set(multiValueArgs SOURCES COMPILE_DEFINITIONS INCLUDE_DIRS LIBRARIES ARGUMENTS)
cmake_parse_arguments(DLAF_AT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

### Checks
if(DLAF_AT_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Unknown arguments ${DLAF_AT_UNPARSED_ARGUMENTS}")
endif()

if(NOT DLAF_AT_SOURCES)
message(FATAL_ERROR "No sources specified for this test")
endif()

### Test executable target
add_executable(${test_target_name} ${DLAF_AT_SOURCES})
target_link_libraries(
${test_target_name} PRIVATE ${_gtest_tgt} DLAF_test ${DLAF_AT_LIBRARIES} dlaf.prop_private
)
set(IS_AN_MPI_TEST FALSE)
if(DLAF_AT_USE_MAIN MATCHES MPI OR DLAF_AT_USE_MAIN STREQUAL CAPI)
set(IS_AN_MPI_TEST TRUE)
endif()
target_compile_definitions(
${test_target_name} PRIVATE ${DLAF_AT_COMPILE_DEFINITIONS} $<$<BOOL:${IS_AN_MPI_TEST}>:
NUM_MPI_RANKS=${DLAF_AT_MPIRANKS}>
Expand All @@ -228,8 +247,6 @@ function(DLAF_addTest test_target_name)
)
target_add_warnings(${test_target_name})
DLAF_addPrecompiledHeaders(${test_target_name})
add_test(NAME ${test_target_name} COMMAND ${_TEST_COMMAND} ${_TEST_ARGUMENTS})
set_tests_properties(${test_target_name} PROPERTIES LABELS "${_TEST_LABEL}")

### DEPLOY
include(GNUInstallDirs)
Expand All @@ -241,4 +258,12 @@ function(DLAF_addTest test_target_name)
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endif()

### Test
DLAF_addTargetTest(
${test_target_name}
MPIRANKS ${DLAF_AT_MPIRANKS}
USE_MAIN ${DLAF_AT_USE_MAIN}
ARGUMENTS ${DLAF_AT_ARGUMENTS}
)
endfunction()
34 changes: 24 additions & 10 deletions miniapp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,39 @@ target_link_libraries(DLAF_miniapp INTERFACE DLAF::DLAF pika::pika)
target_include_directories(DLAF_miniapp INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)

DLAF_addMiniapp(miniapp_cholesky SOURCES miniapp_cholesky.cpp)

DLAF_addMiniapp(miniapp_gen_to_std SOURCES miniapp_gen_to_std.cpp)

DLAF_addMiniapp(miniapp_reduction_to_band SOURCES miniapp_reduction_to_band.cpp)

DLAF_addMiniapp(miniapp_band_to_tridiag SOURCES miniapp_band_to_tridiag.cpp)

DLAF_addMiniapp(miniapp_tridiag_solver SOURCES miniapp_tridiag_solver.cpp)

DLAF_addMiniapp(miniapp_bt_band_to_tridiag SOURCES miniapp_bt_band_to_tridiag.cpp)

DLAF_addMiniapp(miniapp_bt_reduction_to_band SOURCES miniapp_bt_reduction_to_band.cpp)

DLAF_addMiniapp(miniapp_triangular_solver SOURCES miniapp_triangular_solver.cpp)

DLAF_addMiniapp(miniapp_triangular_multiplication SOURCES miniapp_triangular_multiplication.cpp)

DLAF_addMiniapp(miniapp_eigensolver SOURCES miniapp_eigensolver.cpp)

DLAF_addMiniapp(miniapp_gen_eigensolver SOURCES miniapp_gen_eigensolver.cpp)

if(DLAF_BUILD_TESTING)
set(miniapp_test_args
USE_MAIN
MPIPIKA
MPIRANKS
6
ARGUMENTS
--grid-rows=3
--grid-cols=2
--check=all
)
DLAF_addTargetTest(miniapp_cholesky ${miniapp_test_args})
DLAF_addTargetTest(miniapp_gen_to_std ${miniapp_test_args})
DLAF_addTargetTest(miniapp_reduction_to_band ${miniapp_test_args})
DLAF_addTargetTest(miniapp_band_to_tridiag ${miniapp_test_args})
DLAF_addTargetTest(miniapp_tridiag_solver ${miniapp_test_args})
DLAF_addTargetTest(miniapp_bt_band_to_tridiag ${miniapp_test_args})
DLAF_addTargetTest(miniapp_bt_reduction_to_band ${miniapp_test_args})
DLAF_addTargetTest(miniapp_triangular_solver ${miniapp_test_args})
DLAF_addTargetTest(miniapp_triangular_multiplication ${miniapp_test_args})
DLAF_addTargetTest(miniapp_eigensolver ${miniapp_test_args})
DLAF_addTargetTest(miniapp_gen_eigensolver ${miniapp_test_args})
endif()

add_subdirectory(kernel)
1 change: 1 addition & 0 deletions miniapp/kernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
if(DLAF_BUILD_TESTING)
# TODO they depends on DLAF_TEST exclusively for the createTile method.
DLAF_addMiniapp(miniapp_laset SOURCES miniapp_laset.cpp LIBRARIES dlaf.core DLAF_test)
DLAF_addTargetTest(miniapp_laset USE_MAIN PIKA)
endif()

0 comments on commit 9900e70

Please sign in to comment.