* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
* Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
*/
int gmx_fedisableexcept();
+/*! \brief Return true if the current build should enable floating-point exceptions by default.
+ *
+ * Currently, it returns true unless any of the following conditions are met:
+ * - release build,
+ * - SYCL build (Intel IGC, at least 1.0.5964, raises FP exceptions in JIT compilation),
+ * - - See https://github.com/intel/intel-graphics-compiler/issues/164
+ * - compilers with known buggy FP exception support (clang with any optimization)
+ * or suspected buggy FP exception support (gcc 7.* with optimization).
+ *
+ * Note that this function does not check whether the build/OS supports FP exceptions.
+ *
+ * \returns true if we should enable FP exceptions by default.
+ */
+bool gmxShouldEnableFPExceptions();
+
#endif
regression tests
+floating-point exceptions
+ In debug builds, floating-point exceptions (FPEs) are generated whenever one of the
+ following operations is encountered: division by zero, floating-point overflow,
+ invalid operation (e.g., taking sqrt of a negative number).
+ Such checks are *not* performed in the following configurations:
+
+ - release build,
+ - any build by GCC 7.x or Clang with optimizations,
+ - build with SYCL support.
+
+ In these configurations, FPEs can be enabled by adding ``-fpexcept`` flag to ``gmx``
+ invocation. However, FPEs are not supported on Windows and non-x86 Apple hardware.
+ See ``api/legacy/include/gromacs/math/utilities.h`` for more details.
+
.. _dev-formatting-tools:
Code formatting and style
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
* Copyright (c) 2013,2014,2015,2016,2018 by the GROMACS development team.
- * Copyright (c) 2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2019,2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
return -1;
#endif
}
+
+bool gmxShouldEnableFPExceptions()
+{
+#if defined(NDEBUG)
+ return false; // Release build
+#elif ((defined __clang__ || (defined(__GNUC__) && __GNUC__ == 7)) && defined __OPTIMIZE__)
+ return false; // Buggy compiler
+#elif GMX_GPU_SYCL
+ return false; // avoid spurious FPE during SYCL JIT
+#else
+ return true;
+#endif
+}
hw_opt.nthreads_omp_pme,
!thisRankHasDuty(cr, DUTY_PP));
-// Enable FP exception detection, but not in
-// Release mode and not for compilers with known buggy FP
-// exception support (clang with any optimization) or suspected
-// buggy FP exception support (gcc 7.* with optimization).
-#if !defined NDEBUG \
- && !((defined __clang__ || (defined(__GNUC__) && __GNUC__ == 7)) && defined __OPTIMIZE__)
- const bool bEnableFPE = true;
-#else
- const bool bEnableFPE = false;
-#endif
+ const bool bEnableFPE = gmxShouldEnableFPExceptions();
// FIXME - reconcile with gmx_feenableexcept() call from CommandLineModuleManager::run()
if (bEnableFPE)
{
int* argc,
char*** argv)
{
-#if !defined NDEBUG \
- && !((defined __clang__ || (defined(__GNUC__) && __GNUC__ == 7)) && defined __OPTIMIZE__)
- gmx_feenableexcept();
-#endif
+ if (gmxShouldEnableFPExceptions())
+ {
+ gmx_feenableexcept();
+ }
const CommandLineProgramContext& context = initForCommandLine(argc, argv);
try
{