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 Apr 24, 2022
1 parent bbe9f2c commit 3fb7ee2
Showing 1 changed file with 54 additions and 5 deletions.
59 changes: 54 additions & 5 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,16 +44,27 @@ 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()
{
using Vec_t = VectorizedArray<Number, width>;
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;
}
}
Expand Down Expand Up @@ -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 <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()
{
using namespace std;
using Vec_t = VectorizedArray<Number, width>;
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<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 3fb7ee2

Please sign in to comment.