-
Notifications
You must be signed in to change notification settings - Fork 407
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
Implement Kokkos::printf #6083
Implement Kokkos::printf #6083
Conversation
82e8086
to
97c2c21
Compare
Retest this please. |
477ef77
to
8f67e27
Compare
NVHPC seems to error out when we are not using a string literal for the formatting string. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
4bd9a5e
to
4537fee
Compare
58eea6c
to
1b71a4f
Compare
core/unit_test/TestPrintf.hpp
Outdated
#endif | ||
|
||
int backup_no, new_no; | ||
fflush(stdout); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason why you are not using ::testing::internal::CaptureStdout()
It is not part of the GTest API but we already use it elsewhere and if/when we get into trouble for it we can encapsulate and replace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't quite realize that we are already reaching into someone else's internal
namespace. Sure, we can try that instead. It's just for testing anyway.
core/src/impl/Kokkos_Printf.hpp
Outdated
#elif defined(KOKKOS_COMPILER_NVHPC) // FIXME_NVHPC | ||
template <typename... Args> | ||
KOKKOS_FUNCTION int printf(const char* format, Args... args) { | ||
::printf(format, args...); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning a value here doesn't work with NVHPC
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we discuss whether we should be providing a checked version or return anything at all?
By that I mean, should we attempt to cause program termination when we detect than an error occurred?
Should we return void instead of "passing through" the return value of printf
as currently proposed?
I don't necessarily have an issue with what is proposed but I do want to make sure we considered alternatives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's good to stay close to what printf
does since that's what people are used to (even though I doubt many people use the return value anyway).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we discuss whether that should be a private or public header?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, my intuition was to do the same as for core/src/impl/Kokko_Error.hpp
(and it's easier to go from "private" to "public" than the other way around).
core/src/impl/Kokkos_Printf.hpp
Outdated
template <typename... Args> | ||
KOKKOS_FUNCTION int printf(const char* format, Args... args) { | ||
::printf(format, args...); | ||
return 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case anyone is using the return value of printf
for some diagnostic, I think this should return some other value than 1
to avoid confusion. But since negative value is reserved to indicate errors for standard ::printf
, perhaps 0
is the neutral option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was choosing 1
because that is what I get for most GPU
backends and it's fairly difficult to make printf
fail anyway.
3cb8f35
to
55948b4
Compare
core/src/impl/Kokkos_Printf.hpp
Outdated
// We are forwarding the format string to printf but gcc and clang warn about | ||
// the format string not being a literal. | ||
#if defined(__GNUC__) | ||
#pragma GCC diagnostic push | ||
#pragma GCC diagnostic ignored "-Wformat-security" | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get this one. Can you share a godbolt link?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed commit to remove these lines and you can see the CI failing with these warnings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, see https://godbolt.org/z/bdM4ozM9r where I found a different workaround when there are no arguments for the format string.
Failures in
are unrelated. |
Do these show on other builds? |
I have seen that in a couple of other builds. |
c3a0409
to
4474e8e
Compare
Co-authored-by: Damien L-G <dalg24+github@gmail.com>
Supersedes #6061. This pull request implements
Kokkos::printf
as discussed.After trying a bunch of implementations (just wrap
KOKKOS_IMPL_DO_NOT_USE_PRINTF
, define a separate function that callsprintf
), it seems that importingprintf
into theKokkos
namespace is the only option that works.In my opinion, it's a good idea to keep the
KOKKOS_IMPL_DO_NOT_USE_PRINTF
macro around a little longer to allow some users to transition.