Skip to content

Commit

Permalink
Make vectorization FPE tests more closely match implementation that f…
Browse files Browse the repository at this point in the history
…ails, and use values from debug logs.
  • Loading branch information
jppelteret committed Jun 12, 2022
1 parent 2a9b88c commit 391dd74
Showing 1 changed file with 52 additions and 3 deletions.
55 changes: 52 additions & 3 deletions cmake/checks/check_02_compiler_features.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -29,6 +44,16 @@ WF_CHECK_CXX_SOURCE_RUNS(
"
#include <deal.II/base/vectorization.h>
using namespace dealii;
class BinaryOp
{
public:
template <typename T>
T
operator()(const T &num, const T &den) const
{
return num/den;
}
};
template <typename Number, std::size_t width>
void
do_test()
Expand All @@ -38,7 +63,8 @@ WF_CHECK_CXX_SOURCE_RUNS(
{
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;
}
}
Expand Down Expand Up @@ -73,13 +99,25 @@ 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 <deal.II/base/vectorization.h>
#include <limits>
using namespace dealii;
class UnaryOp
{
public:
template <typename T>
T
operator()(const T &value) const
{
using namespace std;
return sqrt(value);
}
};
template <typename Number, std::size_t width>
void
do_test()
Expand All @@ -90,8 +128,13 @@ WF_CHECK_CXX_SOURCE_RUNS(
{
Vec_t val = 0.0;
auto result = sqrt(val);
result = UnaryOp()(val);
val = std::numeric_limits<Number>::epsilon();
result = sqrt(val);
result = UnaryOp()(val);
val = 6.9161116785120245e-310;
result = sqrt(val);
result = UnaryOp()(val);
(void)result;
}
}
Expand All @@ -118,4 +161,10 @@ WF_CHECK_CXX_SOURCE_RUNS(
return 0;
}
"
WEAK_FORMS_VECTORIZATION_FPE_SQRT_OF_ZERO)
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})

0 comments on commit 391dd74

Please sign in to comment.