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

AMREX_DEVICE_PRINTF: Host #4116

Merged
merged 2 commits into from
Sep 2, 2024

Conversation

ax3l
Copy link
Member

@ax3l ax3l commented Aug 28, 2024

Summary

In AMReX, device means host if compiled for CPUs.
Add support for printf debugging on CPUs for AMREX_DEVICE_PRINTF.

Currently, the macro was undefined, unless for the special case of SYCL compilation for host code paths where it worked.

Additional background

Checklist

The proposed changes:

  • fix a bug or incorrect behavior in AMReX
  • add new capabilities to AMReX
  • changes answers in the test suite to more than roundoff level
  • are likely to significantly affect the results of downstream AMReX users
  • include documentation in the code and/or rst files, if appropriate

In AMReX, device means host if compiled for CPUs.
Add support for printf debugging on CPUs for `AMREX_DEVICE_PRINTF`.
@ax3l ax3l added the bug label Aug 28, 2024
@ax3l ax3l requested a review from WeiqunZhang August 28, 2024 16:20
@WeiqunZhang
Copy link
Member

It was intentional, because AMREX_DEVICE_PRINTF really should be for debugging only.

@WeiqunZhang
Copy link
Member

WeiqunZhang commented Aug 28, 2024

It was intended as a feature, not a bug.

@ax3l
Copy link
Member Author

ax3l commented Aug 28, 2024

Yes, but both on host as well as on device this is breaking compiler optimizations and bloating registers.

I want to use it exclusively inside a

#if defined(AMREX_DEBUG) || defined(DEBUG)
#endif

block.

@ax3l
Copy link
Member Author

ax3l commented Aug 28, 2024

A common construct where this macro is used that I saw is this:

#if defined(AMREX_DEBUG)
    AMREX_IF_ON_DEVICE((
        AMREX_DEVICE_PRINTF("Message %d\n", n);
    ))
    AMREX_IF_ON_HOST((
        std::stringstream ss;
        ss << "Message " << n << "\n";
        amrex::Abort(ss.str());
    ))
#endif

Maybe we could provide a macro for this?
The difference is:

  • only defined in debug
  • will abort on the host, too
#define AMREX_DEBUG_DEVICE_PRINTF(Format,...) ...

Enable host-side apple prints
@WeiqunZhang WeiqunZhang merged commit a589638 into AMReX-Codes:development Sep 2, 2024
71 of 72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants