|
SpECTRE
v2026.11.17
|
Classes | |
| class | DeviceMessage |
| A minimal output stream that can be used in device code. More... | |
| class | SpectreAssert |
| Exception indicating an ASSERT failed. More... | |
| class | SpectreError |
| Exception indicating an ERROR was triggered. More... | |
| class | SpectreFpe |
| Exception indicating an ERROR was triggered because of an FPE. More... | |
| class | convergence_error |
| Exception indicating convergence failure. More... | |
| class | ScopedFpeState |
| An RAII object to temporarily modify the handling of floating point exceptions. More... | |
Macros | |
| #define | SPECTRE_ASSERT_ON_HOST(a, m) |
| Assert that an expression should be true. | |
| #define | SPECTRE_ABORT_ON_DEVICE(HEADING, DESCRIPTION, MESSAGE) |
| Prints a failure message in device code and aborts the program. | |
| #define | SPECTRE_ERROR_ON_HOST(EXCEPTION_TYPE, m) |
| prints an error message to the standard error stream and aborts the program. | |
| #define | ERROR_AS(m, EXCEPTION_TYPE) |
| Same as ERROR but will throw EXCEPTION_TYPE instead of SpectreError. | |
| #define | SPECTRE_ERROR_NO_TRACE_ON_HOST(m) |
| Same as ERROR but does not print a backtrace. Intended to be used for user errors, such as incorrect values in an input file. | |
| #define | Expects(cond) |
| check expectation of pre-conditions of a function | |
| #define | Ensures(cond) |
| Check that a post-condition of a function is true. | |
| #define | DEBUG_STATIC_ASSERT(...) |
| A static_assert that is only checked in Debug builds. | |
Functions | |
| void | abort_with_error_message (const char *expression, const char *file, int line, const char *pretty_function, const std::string &message) |
| Compose an error message with an expression and a backtrace, then abort the program. | |
| template<typename ExceptionTypeToThrow> | |
| void | abort_with_error_message (const char *file, int line, const char *pretty_function, const std::string &message) |
| Compose an error message including a backtrace and abort the program. | |
| void | abort_with_error_message_no_trace (const char *file, int line, const char *pretty_function, const std::string &message) |
| Compose an error message without a backtrace and abort the program. | |
| void | enable_floating_point_exceptions () |
| After a call to this function, the code will terminate with a floating point exception on overflow, divide-by-zero, and invalid operations. | |
| void | disable_floating_point_exceptions () |
| After a call to this function, the code will NOT terminate with a floating point exception on overflow, divide-by-zero, and invalid operations. | |
| void | enable_segfault_handler () |
| After a call to this function, the code will handle SIGSEGV segmentation faults by printing an error with a stacktrace. | |
| void | sys::abort (const std::string &message) |
| Abort the program with an error message. | |
Macros and functions used for handling errors
| #define DEBUG_STATIC_ASSERT | ( | ... | ) |
A static_assert that is only checked in Debug builds.
| #define Ensures | ( | cond | ) |
Check that a post-condition of a function is true.
The Ensures macro sets the postconditions of function, it is a contract (C++20) that must be satisfied. See the CppCoreGuidelines for details.
| cond | the expression that is expected to be true |
| #define ERROR_AS | ( | m, | |
| EXCEPTION_TYPE ) |
Same as ERROR but will throw EXCEPTION_TYPE instead of SpectreError.
| #define Expects | ( | cond | ) |
check expectation of pre-conditions of a function
The Expects macro sets the preconditions to a function's arguments, it is a contract (C++20) that must be satisfied. See the CppCoreGuidelines for details.
| cond | the expression that is expected to be true |
| #define SPECTRE_ABORT_ON_DEVICE | ( | HEADING, | |
| DESCRIPTION, | |||
| MESSAGE ) |
Prints a failure message in device code and aborts the program.
Used by ASSERT and ERROR in device code. HEADING and DESCRIPTION must be string literals, where the DESCRIPTION (e.g. the failed expression) can be empty. MESSAGE is an expression that can be streamed into a DeviceMessage.
Often many GPU threads fail at the same time. Only the first of them formats its message, in a single static buffer, and passes it to Kokkos::abort, which prints it with the indices of the GPU block and thread. Printing it at once keeps it from interleaving with other output, because GPUs print the output of separate printf calls in no guaranteed order. The message starts with the heading, file, line and description, and ends with the function name, so truncating a long message cuts the function name first.
On CUDA devices the other failing threads end right away without printing anything (with the PTX instruction exit, which ends only the calling thread), so the kernel keeps running until the first thread has printed its message. On HIP devices a single thread can't end by itself, so the others wait until the abort of the first thread ends the kernel. If that doesn't happen in time, e.g. because the GPU can't run the first thread while the others wait, they abort with a short message that contains the heading, file, line and description.
| #define SPECTRE_ASSERT_ON_HOST | ( | a, | |
| m ) |
Assert that an expression should be true.
If the preprocessor macro SPECTRE_DEBUG is defined and the expression is false, an error message is printed to the standard error stream, and the program aborts. ASSERT should be used to catch coding errors as it does nothing in production code.
ASSERT can also be used in functions that run on a GPU (KOKKOS_FUNCTIONs). On the GPU the message is streamed into a DeviceMessage, which supports fewer types than std::ostream.
| a | the expression that must be true |
| m | the error message as an ostream |
| #define SPECTRE_ERROR_NO_TRACE_ON_HOST | ( | m | ) |
Same as ERROR but does not print a backtrace. Intended to be used for user errors, such as incorrect values in an input file.
| #define SPECTRE_ERROR_ON_HOST | ( | EXCEPTION_TYPE, | |
| m ) |
prints an error message to the standard error stream and aborts the program.
ERROR should not be used for coding errors, but instead for user errors or failure modes of numerical algorithms. An acceptable use for error is also in the default case of a switch statement.
The implementation is specialized so that in compile time contexts, a short error message will be thrown, but in runtime contexts, a more verbose error will be printed. This specialization of throwing a short error at compile time greatly reduces the compile time and memory consumption during debug builds of deep and heavily inlined TensorExpression tree traversals.
To accomplish this, __builtin_is_constant_evaluated() is used directly instead of calling a wrapper function because calling a wrapper was found to slightly increase the compile time and memory usage of large TensorExpressions when compiling in debug mode.
ERROR can also be used in functions that run on a GPU (KOKKOS_FUNCTIONs). On the GPU the message is streamed into a DeviceMessage, which supports fewer types than std::ostream, and the program aborts with Kokkos::abort.
| m | an arbitrary output stream. |
| void sys::abort | ( | const std::string & | message | ) |
Abort the program with an error message.
This function calls CkExit with a non-zero argument to indicate a failure, unless the SPECTRE_TRAP_ON_ERROR environmental variable is set, in which case it raises SIGTRAP.
| void abort_with_error_message | ( | const char * | expression, |
| const char * | file, | ||
| int | line, | ||
| const char * | pretty_function, | ||
| const std::string & | message ) |
Compose an error message with an expression and a backtrace, then abort the program.
We try to demangle and format the backtrace. Long symbol names are abbreviated, unless you set the SPECTRE_SHOW_FULL_BACKTRACE_SYMBOLS environment variable to a non-empty value (e.g. "1").
| void abort_with_error_message | ( | const char * | file, |
| int | line, | ||
| const char * | pretty_function, | ||
| const std::string & | message ) |
Compose an error message including a backtrace and abort the program.
We try to demangle and format the backtrace. Long symbol names are abbreviated, unless you set the SPECTRE_SHOW_FULL_BACKTRACE_SYMBOLS environment variable to a non-empty value (e.g. "1").
| void abort_with_error_message_no_trace | ( | const char * | file, |
| int | line, | ||
| const char * | pretty_function, | ||
| const std::string & | message ) |
Compose an error message without a backtrace and abort the program.
| void disable_floating_point_exceptions | ( | ) |
After a call to this function, the code will NOT terminate with a floating point exception on overflow, divide-by-zero, and invalid operations.