SpECTRE  v2026.11.17
Loading...
Searching...
No Matches
DeviceMessage Class Reference

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.

Detailed Description

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:

  • string literals and const char*
  • char (also signed char and unsigned char) as a character
  • bool as 1 or 0, like std::ostream without std::boolalpha
  • integers
  • floating-point numbers in scientific notation with 17 significant digits. The last digit can differ from the exact decimal representation.
  • enums as their underlying integer
  • std::arrays of supported types, as (a,b,c) like on the host

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.

Member Data Documentation

◆ capacity

size_t DeviceMessage::capacity = 1024
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).


The documentation for this class was generated from the following file:
  • src/Utilities/ErrorHandling/DeviceMessage.hpp