|
SpECTRE
v2026.11.17
|
A minimal output stream that can be used in device code. More...
#include <DeviceMessage.hpp>
Public Member Functions | |
| KOKKOS_FUNCTION const char * | c_str () const |
| The message as a null-terminated string. | |
| KOKKOS_FUNCTION size_t | size () const |
| The number of characters in the message. | |
| template<typename T> | |
| KOKKOS_FUNCTION DeviceMessage & | operator<< (const T &value) |
| KOKKOS_FUNCTION DeviceMessage & | operator<< (std::ios_base &(*)(std::ios_base &)) |
| Manipulators such as std::scientific are ignored. | |
Static Public Attributes | |
| static constexpr size_t | capacity = 1024 |
| The size of the buffer, including the null terminator. | |
A minimal output stream that can be used in device code.
Because the standard library streams can't be used on GPUs, ASSERT and ERROR stream their message into a DeviceMessage when they fail in device code, i.e. in a KOKKOS_FUNCTION or Kokkos kernel running on a GPU. The message is collected in a fixed-size buffer and printed all at once, because GPUs print the output of separate printf calls in no guaranteed order. See SPECTRE_ABORT_ON_DEVICE.
Common types are supported:
Manipulators such as std::scientific are ignored. Manipulators that take an argument, such as std::setprecision, are host functions and can't be used on the device; do not use them with this stream.
Values of other types are printed as <?>. Add an overload KOKKOS_FUNCTION DeviceMessage& operator<<(DeviceMessage&, const T&) to print them on the device. Messages longer than capacity characters are truncated, which is marked by ... at the end.
|
staticconstexpr |
The size of the buffer, including the null terminator.
ASSERT and ERROR use a single static buffer on the device (see SPECTRE_ABORT_ON_DEVICE), so the capacity doesn't cost memory per GPU thread. Each message is printed with a single printf, which must fit in the device's printf buffer (1 MB by default on CUDA, see cudaLimitPrintfFifoSize).