From 2ee95dd0fe86f4c986eb21a15a674ebb11f85be0 Mon Sep 17 00:00:00 2001 From: Andrea Franceschini Date: Wed, 16 Sep 2020 16:36:44 -0700 Subject: [PATCH 1/4] Setting a default set of fp exceptions --- src/system.cpp | 25 +++++++++++++++---------- src/system.hpp | 11 ++++++++--- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/system.cpp b/src/system.cpp index 7accf235..a6c30926 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -506,6 +506,11 @@ void resetSignalHandling() } } +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +int getDefaultFloatingPointExceptions() +{ + return ( FE_DIVBYZERO | FE_OVERFLOW | FE_INVALID ); +} /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int enableFloatingPointExceptions( int const exceptions ) @@ -551,7 +556,7 @@ int disableFloatingPointExceptions( int const exceptions ) { return -1; } - oldExcepts = fenv.__control & FE_ALL_EXCEPT; + oldExcepts = ~( fenv.__control & FE_ALL_EXCEPT ); // mask fenv.__control |= newExcepts; @@ -568,15 +573,15 @@ int disableFloatingPointExceptions( int const exceptions ) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void setFPE() { -#if defined(__APPLE__) && defined(__MACH__) - fesetenv( FE_DFL_DISABLE_SSE_DENORMS_ENV ); -#elif defined(__x86_64__) - _MM_SET_FLUSH_ZERO_MODE( _MM_FLUSH_ZERO_ON ); - _MM_SET_DENORMALS_ZERO_MODE( _MM_DENORMALS_ZERO_ON ); -#endif -#if defined(__x86_64__) - enableFloatingPointExceptions( FE_DIVBYZERO | FE_OVERFLOW | FE_INVALID ); -#endif +//#if defined(__APPLE__) && defined(__MACH__) +// fesetenv( FE_DFL_DISABLE_SSE_DENORMS_ENV ); +//#elif defined(__x86_64__) +// _MM_SET_FLUSH_ZERO_MODE( _MM_FLUSH_ZERO_ON ); +// _MM_SET_DENORMALS_ZERO_MODE( _MM_DENORMALS_ZERO_ON ); +//#endif +//#if defined(__x86_64__) + enableFloatingPointExceptions( getDefaultFloatingPointExceptions() ); +//#endif } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/system.hpp b/src/system.hpp index 80227024..bd81f7cc 100644 --- a/src/system.hpp +++ b/src/system.hpp @@ -82,19 +82,24 @@ void setSignalHandling( void (* handler)( int ) ); */ void resetSignalHandling(); +/** + * @brief Get the default set of exceptions to be checked. + */ +int getDefaultFloatingPointExceptions(); + /** * @brief A wrapper around @c feenableexcept that work on OSX. * @param exceptions The set of floating point exceptions to enable. * @return The old exception mask or -1 if there was an error. */ -int enableFloatingPointExceptions( int const exceptions ); +int enableFloatingPointExceptions( int const exceptions = getDefaultFloatingPointExceptions() ); /** * @brief A wrapper around @c fedisableexcept that work on OSX. * @param exceptions The set of floating point exceptions to disable. * @return The old exception mask or -1 if there was an error. */ -int disableFloatingPointExceptions( int const exceptions ); +int disableFloatingPointExceptions( int const exceptions = getDefaultFloatingPointExceptions() ); /** * @brief Sets the floating point environment. @@ -114,7 +119,7 @@ class FloatingPointExceptionGuard * @brief Disable the floating point exceptions given by @p exceptions. * @param exceptions The floating point exceptions to disable. */ - FloatingPointExceptionGuard( int const exceptions ): + FloatingPointExceptionGuard( int const exceptions = getDefaultFloatingPointExceptions() ): m_previousExceptions( disableFloatingPointExceptions( exceptions ) ) {} From 64baf51d85020dd752f339c8c82049caaf2ae5c9 Mon Sep 17 00:00:00 2001 From: Andrea Franceschini Date: Wed, 16 Sep 2020 19:31:22 -0700 Subject: [PATCH 2/4] Minor changes --- src/system.cpp | 30 ++++++++++++------------------ src/system.hpp | 3 ++- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/system.cpp b/src/system.cpp index a6c30926..6d41ca3c 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -520,14 +520,13 @@ int enableFloatingPointExceptions( int const exceptions ) // http://www-personal.umich.edu/~williams/archive/computation/fe-handling-example.c static fenv_t fenv; int const newExcepts = exceptions & FE_ALL_EXCEPT; - // previous masks - int oldExcepts; if( fegetenv( &fenv )) { return -1; } - oldExcepts = fenv.__control & FE_ALL_EXCEPT; + // all previous masks + int const oldExcepts = fenv.__control & FE_ALL_EXCEPT; // unmask fenv.__control &= ~newExcepts; @@ -549,14 +548,13 @@ int disableFloatingPointExceptions( int const exceptions ) // http://www-personal.umich.edu/~williams/archive/computation/fe-handling-example.c static fenv_t fenv; int const newExcepts = exceptions & FE_ALL_EXCEPT; - // all previous masks - int oldExcepts; if( fegetenv( &fenv )) { return -1; } - oldExcepts = ~( fenv.__control & FE_ALL_EXCEPT ); + // all previous masks + int const oldExcepts = ~( fenv.__control & FE_ALL_EXCEPT ); // mask fenv.__control |= newExcepts; @@ -573,20 +571,16 @@ int disableFloatingPointExceptions( int const exceptions ) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void setFPE() { -//#if defined(__APPLE__) && defined(__MACH__) -// fesetenv( FE_DFL_DISABLE_SSE_DENORMS_ENV ); -//#elif defined(__x86_64__) -// _MM_SET_FLUSH_ZERO_MODE( _MM_FLUSH_ZERO_ON ); -// _MM_SET_DENORMALS_ZERO_MODE( _MM_DENORMALS_ZERO_ON ); -//#endif -//#if defined(__x86_64__) +#if defined(__APPLE__) && defined(__MACH__) + fesetenv( FE_DFL_DISABLE_SSE_DENORMS_ENV ); +#elif defined(__x86_64__) + _MM_SET_FLUSH_ZERO_MODE( _MM_FLUSH_ZERO_ON ); + _MM_SET_DENORMALS_ZERO_MODE( _MM_DENORMALS_ZERO_ON ); +#endif +#if defined(__x86_64__) enableFloatingPointExceptions( getDefaultFloatingPointExceptions() ); -//#endif +#endif } -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -int getAllExceptionsMask() -{ return FE_ALL_EXCEPT; } - } // namespace system } // namespace LvArray diff --git a/src/system.hpp b/src/system.hpp index bd81f7cc..2940432e 100644 --- a/src/system.hpp +++ b/src/system.hpp @@ -83,7 +83,8 @@ void setSignalHandling( void (* handler)( int ) ); void resetSignalHandling(); /** - * @brief Get the default set of exceptions to be checked. + * @brief Get the default set of exceptions to check. + * @return The default set of exceptions. */ int getDefaultFloatingPointExceptions(); From 1faeb8cfd4ab1686b90ac0f3f1ecec0d7605db2e Mon Sep 17 00:00:00 2001 From: Andrea Franceschini Date: Thu, 17 Sep 2020 09:41:51 -0700 Subject: [PATCH 3/4] Avoid clang optimization in testFloatingPointExceptions --- unitTests/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/unitTests/CMakeLists.txt b/unitTests/CMakeLists.txt index cd61ef00..06838185 100644 --- a/unitTests/CMakeLists.txt +++ b/unitTests/CMakeLists.txt @@ -87,6 +87,11 @@ blt_add_executable( NAME testFloatingPointExceptions OUTPUT_DIR ${TEST_OUTPUT_DIRECTORY} DEPENDS_ON gtest lvarray ${lvarray_dependencies} ) +# Need to avoid optimization to catch invalid operations +if( APPLE AND ${CMAKE_CXX_COMPILER} MATCHES "clang" ) + set_source_files_properties( testFloatingPointExceptionsHelpers.cpp PROPERTIES COMPILE_FLAGS "-O0" ) +endif() + target_include_directories( testFloatingPointExceptions PUBLIC ${CMAKE_CURRENT_LIST_DIR}/../src ) blt_add_test( NAME testFloatingPointExceptions From 08a3b5b83fcf58f622192adcd4c965c51cf650ef Mon Sep 17 00:00:00 2001 From: Nicola Castelletto Date: Fri, 18 Sep 2020 14:57:57 -0700 Subject: [PATCH 4/4] Updating LC hostconfig tpl location to 2020-09-18 --- host-configs/LLNL/lassen-clang@upstream.cmake | 2 +- host-configs/LLNL/lassen-gcc@8.3.1.cmake | 2 +- host-configs/LLNL/quartz-base.cmake | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/host-configs/LLNL/lassen-clang@upstream.cmake b/host-configs/LLNL/lassen-clang@upstream.cmake index d76474db..1aa38e94 100644 --- a/host-configs/LLNL/lassen-clang@upstream.cmake +++ b/host-configs/LLNL/lassen-clang@upstream.cmake @@ -2,7 +2,7 @@ set(CONFIG_NAME "lassen-clang@upstream" CACHE PATH "") # Set up the tpls set(GEOSX_TPL_ROOT_DIR /usr/gapps/GEOSX/thirdPartyLibs CACHE PATH "") -set(GEOSX_TPL_DIR ${GEOSX_TPL_ROOT_DIR}/2020-08-05/install-${CONFIG_NAME}-release CACHE PATH "") +set(GEOSX_TPL_DIR ${GEOSX_TPL_ROOT_DIR}/2020-09-18/install-${CONFIG_NAME}-release CACHE PATH "") set(ENABLE_UMPIRE ON CACHE BOOL "") set(ENABLE_CHAI ON CACHE BOOL "") diff --git a/host-configs/LLNL/lassen-gcc@8.3.1.cmake b/host-configs/LLNL/lassen-gcc@8.3.1.cmake index e7b695e4..b20086a7 100644 --- a/host-configs/LLNL/lassen-gcc@8.3.1.cmake +++ b/host-configs/LLNL/lassen-gcc@8.3.1.cmake @@ -3,7 +3,7 @@ set(CONFIG_NAME "lassen-gcc@8.3.1" CACHE PATH "") # Set up the tpls # These were probably built with clang (no guarantee that they would work) set(GEOSX_TPL_ROOT_DIR /usr/gapps/GEOSX/thirdPartyLibs CACHE PATH "") -set(GEOSX_TPL_DIR ${GEOSX_TPL_ROOT_DIR}/2020-08-05/install-${CONFIG_NAME}-release CACHE PATH "") +set(GEOSX_TPL_DIR ${GEOSX_TPL_ROOT_DIR}/2020-09-18/install-${CONFIG_NAME}-release CACHE PATH "") set(ENABLE_UMPIRE ON CACHE BOOL "") set(ENABLE_CHAI ON CACHE BOOL "") diff --git a/host-configs/LLNL/quartz-base.cmake b/host-configs/LLNL/quartz-base.cmake index 4b3498aa..834c7ee9 100644 --- a/host-configs/LLNL/quartz-base.cmake +++ b/host-configs/LLNL/quartz-base.cmake @@ -23,7 +23,7 @@ set(MPIEXEC /usr/bin/srun CACHE PATH "") set(MPIEXEC_NUMPROC_FLAG "-n" CACHE STRING "") set(GEOSX_TPL_ROOT_DIR /usr/gapps/GEOSX/thirdPartyLibs CACHE PATH "") -set(GEOSX_TPL_DIR ${GEOSX_TPL_ROOT_DIR}/2020-08-05/install-${CONFIG_NAME}-release CACHE PATH "") +set(GEOSX_TPL_DIR ${GEOSX_TPL_ROOT_DIR}/2020-09-18/install-${CONFIG_NAME}-release CACHE PATH "") set(ENABLE_UMPIRE ON CACHE BOOL "") set(ENABLE_CHAI ON CACHE BOOL "")