Skip to content

Commit

Permalink
First cut at adding printf, help builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Holladay committed Jan 23, 2024
1 parent 993d820 commit 6f3e8fa
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions ports-of-call/portable_errors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
// TODO(JMM): Is relative path right here?
#include "portability.hpp"

// use kokkos printf if available
//#ifdef PORTABILITY_STRATEGY_KOKKOS
//#include <Kokkos_Printf.hpp>
//#endif // PORTABILITY_STRATEGY_KOKKOS

// Use these macros for error handling. A macro is required, as
// opposed to a function, so that the file name and line number can be
// pulled from the call site.
Expand Down Expand Up @@ -101,6 +106,18 @@ namespace impl {
std::abort();
#endif // PORTABILITY_STRATEGY_KOKKOS
}

template <typename ... Ts>
PORTABLE_INLINE_FUNCTION void printf(char const * const format, Ts ... ts) {
//#ifdef PORTABILITY_STRATEGY_KOKKOS
// Kokkos::printf(format, ts...);
//#else
#ifndef __HIPCC__
std::printf(format, ts...);
#endif // __HIPCC__
//#endif // PORTABILITY_STRATEGY_KOKKOS
return;
}
} // namespace impl

// Prints an error message describing the failed condition in an
Expand All @@ -112,7 +129,7 @@ PORTABLE_INLINE_FUNCTION void require(bool condition_bool,
const char *const filename,
int const linenumber) {
if (!condition_bool) {
std::printf(
impl::printf(
"### ERROR\n Condition: %s\n Message: %s\n File: "
"%s\n Line number: %i\n",
condition, message, filename, linenumber);
Expand All @@ -134,7 +151,7 @@ inline void require(bool condition_bool, const char *const condition,
[[noreturn]] PORTABLE_INLINE_FUNCTION void abort(const char *const message,
const char *const filename,
int const linenumber) {
std::printf(
impl::printf(
"### ERROR\n Message: %s\n File: %s\n Line number: %i\n",
message, filename, linenumber);
impl::abort();
Expand Down Expand Up @@ -177,7 +194,7 @@ inline void require(bool condition_bool, const char *const condition,
PORTABLE_INLINE_FUNCTION
void warn(const char *const message, const char *const filename,
int const linenumber) {
std::printf(
impl::printf(
"### WARNING\n Message: %s\n File: %s\n Line number: "
"%i\n",
message, filename, linenumber);
Expand Down

0 comments on commit 6f3e8fa

Please sign in to comment.