[Mirror] MueLu: Enable floating point exceptions in Automatic_Test_ETI#70
Open
[Mirror] MueLu: Enable floating point exceptions in Automatic_Test_ETI#70
Conversation
Signed-off-by: malphil <malphil@sandia.gov>
|
CDash for AT1 results [Only accessible from Sandia networks] |
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to enable floating-point exceptions (Divide-by-Zero, Overflow, and Invalid) for Linux and macOS platforms within the MueLu unit tests. The enableFPE function is added to the MueLu_Test namespace and invoked during test initialization. Feedback suggests marking the function as inline to prevent linker errors, fixing a state-tracking bug in the macOS implementation, and adopting a stateless approach for toggling exception bits.
Comment on lines
+51
to
+71
| void enableFPE(bool enableFPE) { | ||
| #if defined(__APPLE__) && defined(__GNUC__) && defined(__SSE__) | ||
| static int eMask = _MM_GET_EXCEPTION_MASK(); | ||
| #endif | ||
|
|
||
| if (enableFPE) { | ||
| #if defined(__linux__) && defined(__GNUC__) && !defined(__INTEL_COMPILER) | ||
| feenableexcept(FE_DIVBYZERO | FE_OVERFLOW | FE_INVALID); | ||
| #elif defined(__APPLE__) && defined(__GNUC__) && defined(__SSE__) | ||
| eMask = _MM_GET_EXCEPTION_MASK(); // Save current eMask so we can disable. | ||
| _MM_SET_EXCEPTION_MASK(eMask & ~_MM_MASK_DIV_ZERO & ~_MM_MASK_OVERFLOW & | ||
| ~_MM_MASK_INVALID); | ||
| #endif | ||
| } else { | ||
| #if defined(__linux__) && defined(__GNUC__) && !defined(__INTEL_COMPILER) | ||
| fedisableexcept(FE_DIVBYZERO | FE_OVERFLOW | FE_INVALID); | ||
| #elif defined(__APPLE__) && defined(__GNUC__) && defined(__SSE__) | ||
| _MM_SET_EXCEPTION_MASK(eMask); | ||
| #endif | ||
| } | ||
| } |
There was a problem hiding this comment.
The enableFPE function has a few issues that should be addressed:
- Multiple Definition Risk: Since the function is defined in a header file, it should be marked
inlineto prevent linker errors if the header is included in multiple translation units. - Logic Bug on Apple/SSE: The use of a
staticvariable with an assignment (eMask = _MM_GET_EXCEPTION_MASK()) inside theif (enableFPE)block is problematic. IfenableFPE(true)is called twice, thestaticvariable will store the "enabled" state, causing a subsequent call toenableFPE(false)to fail to restore the original disabled state. - Stateless Implementation: It is cleaner and more robust to implement this in a stateless manner by toggling only the specific exception bits, which also makes the Apple implementation consistent with the Linux/glibc behavior.
inline void enableFPE(bool enableFPE) {
#if defined(__linux__) && defined(__GNUC__) && !defined(__INTEL_COMPILER)
if (enableFPE) {
feenableexcept(FE_DIVBYZERO | FE_OVERFLOW | FE_INVALID);
} else {
fedisableexcept(FE_DIVBYZERO | FE_OVERFLOW | FE_INVALID);
}
#elif defined(__APPLE__) && defined(__GNUC__) && defined(__SSE__)
if (enableFPE) {
_MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~(_MM_MASK_DIV_ZERO | _MM_MASK_OVERFLOW | _MM_MASK_INVALID));
} else {
_MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() | (_MM_MASK_DIV_ZERO | _MM_MASK_OVERFLOW | _MM_MASK_INVALID));
}
#endif
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Automated mirror of upstream PR trilinos#14733 @trilinos/muelu