11#ifndef EBGEOMETRY_MACROS_HPP
12#define EBGEOMETRY_MACROS_HPP
22#if defined(EBGEOMETRY_HIP)
26#include <hip/hip_runtime.h>
28#if defined(EBGEOMETRY_DEVICE_COMPILE)
32#if defined(EBGEOMETRY_CUDA)
33#define EBGEOMETRY_DEVICE_TRAP() __trap()
35#define EBGEOMETRY_DEVICE_TRAP() __builtin_trap()
38namespace MacrosDetail {
41__device__ __noinline__
inline void
42deviceAssertionFailed(
const char* a_cond,
const char* a_file,
const int a_line)
44 printf(
"EBGeometry device assertion failed: (%s)\n file: %s\n line: %d\n", a_cond, a_file, a_line);
45 EBGEOMETRY_DEVICE_TRAP();
60 using std::runtime_error::runtime_error;
63namespace MacrosDetail {
72 static thread_local int scopes = 0;
90__attribute__((format(printf, 4, 5)))
93requireFailed(
const char* a_cond,
const char* a_file,
const int a_line,
const char* a_format, ...)
99 va_start(arguments, a_format);
100 va_copy(again, arguments);
102 const int length = std::vsnprintf(
nullptr, 0, a_format, arguments);
105 std::string message(
length > 0 ?
static_cast<size_t>(
length) : 0U,
'\0');
108 std::vsnprintf(&message[0], message.size() + 1, a_format, again);
121 std::fprintf(stderr,
"%s\n check: (%s)\n file: %s\n line: %d\n", message.c_str(), a_cond, a_file, a_line);
145 ++MacrosDetail::throwingScopes();
153 --MacrosDetail::throwingScopes();
192#if defined(EBGEOMETRY_DEVICE_COMPILE)
193#define EBGEOMETRY_REQUIRE(cond, ...) \
196 ::EBGeometry::MacrosDetail::deviceAssertionFailed(#cond, __FILE__, __LINE__); \
200#define EBGEOMETRY_REQUIRE(cond, ...) \
203 ::EBGeometry::MacrosDetail::requireFailed(#cond, __FILE__, __LINE__, "EBGeometry::" __VA_ARGS__); \
243#if defined(EBGEOMETRY_ENABLE_ASSERTIONS)
244#if defined(EBGEOMETRY_DEVICE_COMPILE)
245#define EBGEOMETRY_EXPECT(cond) \
248 ::EBGeometry::MacrosDetail::deviceAssertionFailed(#cond, __FILE__, __LINE__); \
252#define EBGEOMETRY_EXPECT(cond) \
255 std::fprintf(stderr, \
256 "EBGeometry assertion failed: (%s)\n file: %s\n line: %d\n function: %s\n", \
260 static_cast<const char*>(__func__)); \
269#define EBGEOMETRY_EXPECT(cond) ((void)0)
GPU portability layer: host/device decoration macros and backend detection.
void requireFailed(const char *a_cond, const char *a_file, const int a_line, const char *a_format,...)
A failed EBGEOMETRY_REQUIRE on the host: throws RequireError inside a ThrowOnRequire scope,...
Definition EBGeometry_Macros.hpp:93
int & throwingScopes() noexcept
How many ThrowOnRequire scopes are open on this thread.
Definition EBGeometry_Macros.hpp:70
What a failed EBGEOMETRY_REQUIRE throws on the host inside a ThrowOnRequire scope: its message,...
Definition EBGeometry_Macros.hpp:58
While an object of this class lives, a failed EBGEOMETRY_REQUIRE on this thread throws RequireError i...
Definition EBGeometry_Macros.hpp:138
ThrowOnRequire() noexcept
Open the scope.
Definition EBGeometry_Macros.hpp:143
~ThrowOnRequire() noexcept
Close the scope.
Definition EBGeometry_Macros.hpp:151
Namespace containing all of EBGeometry's functionality.
Definition EBGeometry_Affine.hpp:26
T length(const Vec2T< T > &v) noexcept
Euclidean length of a 2D vector.