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

New Reducer ValOp Interface #1732

Merged
merged 62 commits into from
Oct 8, 2024
Merged

New Reducer ValOp Interface #1732

merged 62 commits into from
Oct 8, 2024

Conversation

rchen20
Copy link
Member

@rchen20 rchen20 commented Sep 6, 2024

Summary

  • This PR is a refactoring:
  • It does the following:
    • Refactors new reduction interface to have consistent min/max/loc operator semantics.
    • Introduces type safety to reduction operators.
    • Interface will be changed to require passing in ValOp objects, as opposed to the old interface which used raw data types. Changes will be highlighted with a comparison chart soon.
    • ValLoc now requires IndexType, and must be used within a ValOp, e.g. ValOp<ValLoc<T,IndexType>, Op>.
    • Satisfies this request Add Val class similar to ValLoc #1582.

Original interface:

int sum = 0;
int min = large_num;
RAJA::expt::ValLoc<T, RAJA::Index_type> minloc(large_num, -1);

RAJA::forall<seqpol>(host_res, range,

  RAJA::expt::Reduce<RAJA::operators::plus>(&sum),
  RAJA::expt::Reduce<RAJA::operators::minimum>(&min),
  RAJA::expt::Reduce<RAJA::operators::minimum>(&minloc),

  [=] (int i,
    int & _sum,
    int & _min,
    RAJA::expt::ValLoc<T,RAJA::Index_type> & _minloc) {

            _sum += a[i];
            _min = RAJA_MIN(a[i], _min);
            _minloc = RAJA_MIN(RAJA::expt::ValLoc<T,RAJA::Index_type>(a[i], i), _minloc);
});

Changes in this PR:

int sum(0);
int min(large_num);
RAJA::expt::ValLoc<T, RAJA::Index_type> minloc(large_num, -1);

RAJA::expt::ValLoc<T, RAJA::Index_type> temploc(large_num, -1);

int max = small_num;
RAJA::Index_type loc(-1);

RAJA::forall<seqpol>(host_res, range,

  RAJA::expt::Reduce<RAJA::operators::plus>(&sum),
  RAJA::expt::Reduce<RAJA::operators::minimum>(&min),
  RAJA::expt::Reduce<RAJA::operators::minimum>(&minloc),
  RAJA::expt::ReduceLoc<RAJA::operators::maximum>(&max, &loc),

  [=] (int i,
    RAJA::expt::ValOp<T, RAJA::operators::plus> & _sum,
    RAJA::expt::ValOp<T, RAJA::operators::minimum> & _min,
    RAJA::expt::ValOp<RAJA::expt::ValLoc<T, RAJA::Index_type>, RAJA::operators::minimum> & _minloc,
    RAJA::expt::ValOp<RAJA::expt::ValLoc<T, RAJA::Index_type>, RAJA::operators::maximum> & _maxloc) {

            _sum += a[i];
            _min.min(a[i]);
            _minloc.minloc(a[i], i);

            _minloc.min(temploc);

            _maxloc.maxloc(a[i], i);
});

minloc.set(large_num, -1);

Todo's:

  • Clean up accessors to val
  • Documentation
  • Modify tests to use ValOp
  • Launch
  • SYCL
  • OpenMP Target

Enhancements for later:

  • Reset function. Like set(), but puts max/min and -1 for locs.
  • Default init to min/max values and -1 for loc.
  • Expand launch/reduce-param tests (BitOr, Max, locs).

@rchen20
Copy link
Member Author

rchen20 commented Oct 3, 2024

@rhornung67 I think the documentation issues have been addressed, please take another look when you can.
@MrBurmark The templating has been simplified according to your suggestions, please take another look.

@rchen20
Copy link
Member Author

rchen20 commented Oct 5, 2024

@MrBurmark Everything should be addressed now, please take another look.

@rchen20 rchen20 merged commit 5443545 into develop Oct 8, 2024
26 checks passed
@rchen20 rchen20 deleted the task/chen59/valopinterface branch October 8, 2024 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants