Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First cut at adding printf, help builds. #40

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading