From 3fb7ee22240f159fe112240ef0b165a5d0f40eda Mon Sep 17 00:00:00 2001 From: Jean-Paul Pelteret Date: Sat, 23 Apr 2022 22:18:51 +0200 Subject: [PATCH] Make vectorization FPE tests more closely match implementation that fails, and use values from debug logs. --- cmake/checks/check_02_compiler_features.cmake | 59 +++++++++++++++++-- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/cmake/checks/check_02_compiler_features.cmake b/cmake/checks/check_02_compiler_features.cmake index 4dec8040..761e57a9 100644 --- a/cmake/checks/check_02_compiler_features.cmake +++ b/cmake/checks/check_02_compiler_features.cmake @@ -14,10 +14,25 @@ ## --------------------------------------------------------------------- +# Save the current flags +SET(CMAKE_REQUIRED_LIBRARIES_SAVED ${CMAKE_REQUIRED_LIBRARIES}) +SET(CMAKE_REQUIRED_INCLUDES_SAVED ${CMAKE_REQUIRED_INCLUDES}) +SET(CMAKE_REQUIRED_FLAGS_SAVED ${CMAKE_REQUIRED_FLAGS}) + +# Add deal.II's flags to the current project's +# (which should be empty unless the user specifies otherwise) LIST(APPEND CMAKE_REQUIRED_LIBRARIES ${DEAL_II_LIBRARIES}) LIST(APPEND CMAKE_REQUIRED_INCLUDES ${DEAL_II_INCLUDE_DIRS}) LIST(APPEND CMAKE_REQUIRED_FLAGS ${DEAL_II_CXX_FLAGS}) +IF("${CMAKE_BUILD_TYPE}" STREQUAL "Release") + LIST(APPEND CMAKE_REQUIRED_FLAGS ${DEAL_II_CXX_FLAGS_RELEASE}) +ELSEIF("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") + LIST(APPEND CMAKE_REQUIRED_FLAGS ${DEAL_II_CXX_FLAGS_DEBUG}) +ELSE() + MESSAGE(FATAL_ERROR "CMAKE_BUILD_TYPE doesn't match either Release or Debug!") +ENDIF() + # # Check whether division by zero in a vectorized array results in # a floating point exception. @@ -29,16 +44,27 @@ WF_CHECK_CXX_SOURCE_RUNS( " #include using namespace dealii; + class BinaryOp + { + public: + template + T + operator()(const T &num, const T &den) const + { + return num/den; + } + }; template void do_test() { using Vec_t = VectorizedArray; - for (unsigned int i=0; i<10000; ++i) + for (unsigned int i=0; i<100000; ++i) { const Vec_t num = 1.0; const Vec_t den = 0.0; - const auto result = num / den; + auto result = num / den; + result = BinaryOp()(num, den); (void)result; } } @@ -73,25 +99,42 @@ WF_CHECK_CXX_SOURCE_RUNS( # results in a floating point exception. # # The test is multiple times to ensure that the failure is not in -# any way sporadic. +# any way sporadic. The tested value 6.916...e-310 comes from some +# backtraced output of a test failure on a Docker image. # WF_CHECK_CXX_SOURCE_RUNS( " #include #include using namespace dealii; + class UnaryOp + { + public: + template + T + operator()(const T &value) const + { + using namespace std; + return sqrt(value); + } + }; template void do_test() { using namespace std; using Vec_t = VectorizedArray; - for (unsigned int i=0; i<10000; ++i) + for (unsigned int i=0; i<100000; ++i) { Vec_t val = 0.0; auto result = sqrt(val); + result = UnaryOp()(val); val = std::numeric_limits::epsilon(); result = sqrt(val); + result = UnaryOp()(val); + val = 6.9161116785120245e-310; + result = sqrt(val); + result = UnaryOp()(val); (void)result; } } @@ -118,4 +161,10 @@ WF_CHECK_CXX_SOURCE_RUNS( return 0; } " - WEAK_FORMS_VECTORIZATION_FPE_SQRT_OF_ZERO) \ No newline at end of file + WEAK_FORMS_VECTORIZATION_FPE_SQRT_OF_ZERO) + + +# Restore all flags +SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_SAVED}) +SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_SAVED}) +SET(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVED})