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

Clean-up in-situ diagnostic #1052

Merged
merged 3 commits into from
Jan 10, 2024

Conversation

AlexanderSinn
Copy link
Member

@AlexanderSinn AlexanderSinn commented Dec 18, 2023

Previously it was relatively tedious to add new quantities to the in-situ diagnostic. This PR automates a few parts to reduce the number of places that need to change for a new quantity from about 11 to just 4 (InSituComputeDiags gpu kernel, InSituWriteToFile output format, m_insitu_nrp in header file and the documentation).

Old:

amrex::ReduceOps<amrex::ReduceOpSum, amrex::ReduceOpSum, amrex::ReduceOpSum,
                 amrex::ReduceOpSum, amrex::ReduceOpSum, amrex::ReduceOpSum,
                 amrex::ReduceOpSum, amrex::ReduceOpSum, amrex::ReduceOpSum,
                 amrex::ReduceOpSum, amrex::ReduceOpSum, amrex::ReduceOpSum,
                 amrex::ReduceOpSum, amrex::ReduceOpSum, amrex::ReduceOpSum,
                 amrex::ReduceOpSum, amrex::ReduceOpSum, amrex::ReduceOpSum,
                 amrex::ReduceOpSum> reduce_op;
amrex::ReduceData<amrex::Real, amrex::Real, amrex::Real, amrex::Real,
                  amrex::Real, amrex::Real, amrex::Real, amrex::Real,
                  amrex::Real, amrex::Real, amrex::Real, amrex::Real,
                  amrex::Real, amrex::Real, amrex::Real, amrex::Real,
                  amrex::Real, amrex::Real, int> reduce_data(reduce_op);

...

m_insitu_rdata[islice             ] = sum_w0;
m_insitu_rdata[islice+ 1*m_nslices] = amrex::get< 1>(a)*sum_w_inv;
m_insitu_rdata[islice+ 2*m_nslices] = amrex::get< 2>(a)*sum_w_inv;
m_insitu_rdata[islice+ 3*m_nslices] = amrex::get< 3>(a)*sum_w_inv;
m_insitu_rdata[islice+ 4*m_nslices] = amrex::get< 4>(a)*sum_w_inv;
m_insitu_rdata[islice+ 5*m_nslices] = amrex::get< 5>(a)*sum_w_inv;
m_insitu_rdata[islice+ 6*m_nslices] = amrex::get< 6>(a)*sum_w_inv;
m_insitu_rdata[islice+ 7*m_nslices] = amrex::get< 7>(a)*sum_w_inv;
m_insitu_rdata[islice+ 8*m_nslices] = amrex::get< 8>(a)*sum_w_inv;
m_insitu_rdata[islice+ 9*m_nslices] = amrex::get< 9>(a)*sum_w_inv;
m_insitu_rdata[islice+10*m_nslices] = amrex::get<10>(a)*sum_w_inv;
m_insitu_rdata[islice+11*m_nslices] = amrex::get<11>(a)*sum_w_inv;
m_insitu_rdata[islice+12*m_nslices] = amrex::get<12>(a)*sum_w_inv;
m_insitu_rdata[islice+13*m_nslices] = amrex::get<13>(a)*sum_w_inv;
m_insitu_rdata[islice+14*m_nslices] = amrex::get<14>(a)*sum_w_inv;
m_insitu_rdata[islice+15*m_nslices] = amrex::get<15>(a)*sum_w_inv;
m_insitu_rdata[islice+16*m_nslices] = amrex::get<16>(a)*sum_w_inv;
m_insitu_rdata[islice+17*m_nslices] = amrex::get<17>(a)*sum_w_inv;
m_insitu_idata[islice             ] = amrex::get<18>(a);

m_insitu_sum_rdata[ 0] += sum_w0;
m_insitu_sum_rdata[ 1] += amrex::get< 1>(a);
m_insitu_sum_rdata[ 2] += amrex::get< 2>(a);
m_insitu_sum_rdata[ 3] += amrex::get< 3>(a);
m_insitu_sum_rdata[ 4] += amrex::get< 4>(a);
m_insitu_sum_rdata[ 5] += amrex::get< 5>(a);
m_insitu_sum_rdata[ 6] += amrex::get< 6>(a);
m_insitu_sum_rdata[ 7] += amrex::get< 7>(a);
m_insitu_sum_rdata[ 8] += amrex::get< 8>(a);
m_insitu_sum_rdata[ 9] += amrex::get< 9>(a);
m_insitu_sum_rdata[10] += amrex::get<10>(a);
m_insitu_sum_rdata[11] += amrex::get<11>(a);
m_insitu_sum_rdata[12] += amrex::get<12>(a);
m_insitu_sum_rdata[13] += amrex::get<13>(a);
m_insitu_sum_rdata[14] += amrex::get<14>(a);
m_insitu_sum_rdata[15] += amrex::get<15>(a);
m_insitu_sum_rdata[16] += amrex::get<16>(a);
m_insitu_sum_rdata[17] += amrex::get<17>(a);
m_insitu_sum_idata[ 0] += amrex::get<18>(a);

New:

TypeMultiplier<amrex::ReduceOps, amrex::ReduceOpSum[19]> reduce_op;
TypeMultiplier<amrex::ReduceData, amrex::Real[18], int[1]> reduce_data(reduce_op);

...

amrex::constexpr_for<0, 18>(
    [&] (auto idx) {
        m_insitu_rdata[islice + idx.value * m_nslices] = amrex::get<idx.value>(a) *
            ( idx.value == 0 ? 1 : sum_w_inv );
        m_insitu_sum_rdata[idx.value] += amrex::get<idx.value>(a);
    }
);

amrex::constexpr_for<0, 1>(
    [&] (auto idx) {
        m_insitu_idata[islice + idx.value * m_nslices] = amrex::get<18+idx.value>(a);
        m_insitu_sum_idata[idx.value] += amrex::get<18+idx.value>(a);
    }
);
  • Small enough (< few 100s of lines), otherwise it should probably be split into smaller PRs
  • Tested (describe the tests in the PR description)
  • Runs on GPU (basic: the code compiles and run well with the new module)
  • Contains an automated test (checksum and/or comparison with theory)
  • Documented: all elements (classes and their members, functions, namespaces, etc.) are documented
  • Constified (All that can be const is const)
  • Code is clean (no unwanted comments, )
  • Style and code conventions are respected at the bottom of https://github.com/Hi-PACE/hipace
  • Proper label and GitHub project, if applicable

@AlexanderSinn AlexanderSinn added cleaning Code cleaning, avoid duplication, better naming, better style etc. component: diagnostics About any types of diagnostics labels Dec 18, 2023
Copy link
Member

@MaxThevenet MaxThevenet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for this PR! See minor comment below.

src/utils/TemplateUtil.H Show resolved Hide resolved
Copy link
Member

@MaxThevenet MaxThevenet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR!

@MaxThevenet MaxThevenet merged commit c41482d into Hi-PACE:development Jan 10, 2024
10 checks passed
WeiqunZhang pushed a commit to AMReX-Codes/amrex that referenced this pull request Jan 23, 2024
## Summary

This PR adds TypeMultiplier and MakeZeroTuple from
Hi-PACE/hipace#1052 to AMReX.

TypeMultiplier can be used to shorten ReduceOps and ReduceData
definitions where the same type is used many times.

MakeZeroTuple can be used to initialize a GpuTuple to zero (the default
constructor would leave the values uninitialized).

IdentityTuple can be used to initialize a GpuTuple to the identity
elements of each operation in a ReduceOps.

## Additional background

## Checklist

The proposed changes:
- [ ] fix a bug or incorrect behavior in AMReX
- [x] 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleaning Code cleaning, avoid duplication, better naming, better style etc. component: diagnostics About any types of diagnostics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants