Skip to content

Commit

Permalink
handle precondition error printing for multiple archs
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverlee committed May 7, 2024
1 parent b3d0e06 commit 6a4e011
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions include/experimental/__p0009_bits/macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,17 @@
namespace MDSPAN_IMPL_STANDARD_NAMESPACE {
namespace detail {

#ifdef __CUDA_ARCH__
#define eprintf printf
#elif __SYCL_ARCH__
#define eprintf sycl::ext::oneapi::experimental::printf
#else
const auto eprintf = [](auto... args) { (void)std::fprintf(::stderr, args...); };
#endif

inline void default_precondition_violation_handler(const char* cond, const char* file, unsigned line)
{
(void)std::fprintf(::stderr, "%s:%u: precondition failure: `%s`\n", file, line, cond);
eprintf("%s:%u: precondition failure: `%s`\n", file, line, cond);
std::abort();
}

Expand All @@ -132,7 +140,7 @@ namespace MDSPAN_IMPL_STANDARD_NAMESPACE {
namespace detail {

template <bool check = MDSPAN_IMPL_CHECK_PRECONDITION>
constexpr void precondition(const char* cond, const char* file, unsigned line)
MDSPAN_FUNCTION constexpr void precondition(const char* cond, const char* file, unsigned line)
{
if (not check) { return; }

Expand Down

0 comments on commit 6a4e011

Please sign in to comment.