-
Notifications
You must be signed in to change notification settings - Fork 61
Adding Mxx*FirstLoc reducers #692
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
Open
nliber
wants to merge
12
commits into
kokkos:main
Choose a base branch
from
nliber:MxxFirstLoc-reducers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4a1f29c
WIP: First added MaxFirstLoc
nliber 1f7b49c
WIP: Some cleanup of MaxFirstLoc
nliber 15963c0
Fixed up MaxFirstLoc
nliber 856be1d
Added MinFirstLoc
nliber 749407a
For MinFirstLoc and MaxFirstLoc:
nliber d16476b
Added a note to M??Loc when the user wants to guarantee to get
nliber 73d2991
Changed the note to include a hyperlink
nliber 39825db
Fixed copy/paste errors with MinFirstLoc
nliber aad700c
Changed prose from "first index position" to "smallest index position".
nliber 4eca8b9
Aded MinMaxFirstLastLoc
nliber 4adeaa0
Change MaxFirstLoc and MinFirstLoc join description to match
nliber 58a18a4
Fix MinFirstLoc::join description
nliber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| ``MaxFirstLoc`` | ||
| =============== | ||
|
|
||
| .. role:: cpp(code) | ||
| :language: cpp | ||
|
|
||
| Specific implementation of `ReducerConcept <ReducerConcept.html>`_ storing the maximum value. | ||
| If there are equivalent values, stores the smallest index. | ||
|
|
||
| Header File: ``<Kokkos_Core.hpp>`` | ||
|
|
||
| Usage | ||
| ----- | ||
|
|
||
| .. code-block:: cpp | ||
| MaxFirstLoc<T, I, S>::value_type result; | ||
| parallel_reduce(N, Functor, MaxFirstLoc<T, I, S>(result)); | ||
| Synopsis | ||
| -------- | ||
|
|
||
| .. code-block:: cpp | ||
| template<typename Scalar, typename Index, typename Space = HostSpace> | ||
| struct MaxFirstLoc{ | ||
| using reducer = MaxFirstLoc; | ||
| using value_type = ValLocScalar<std::remove_cv_t<Scalar>, std::remove_cv_t<Index>>; | ||
| using result_view_type = View<value_type, Space>; | ||
| MaxFirstLoc(value_type& value_); | ||
| MaxFirstLoc(const result_view_type& value_); | ||
| void join(value_type& dest, const value_type& src) const; | ||
| void init(value_type& val) const; | ||
| value_type& reference() const; | ||
| result_view_type view() const; | ||
| bool references_scalar() const; | ||
| }; | ||
| template<typename T, typename I, typename... Ps> | ||
| MaxFirstLoc(View<ValLocScalar<T, I>, Ps...> const&) | ||
| -> MaxFirstLoc<T, I, View<ValLocScalar<T, I>, Ps...>::memory_space>; | ||
| Interface | ||
| --------- | ||
|
|
||
| .. cpp:class:: template<class Scalar, class Index, class Space> MaxFirstLoc | ||
|
|
||
| .. rubric:: Public Types: | ||
|
|
||
| .. cpp:type:: reducer | ||
|
|
||
| The self type. | ||
|
|
||
| .. cpp:type:: value_type | ||
|
|
||
| The reduction scalar type (specialization of `ValLocScalar <ValLocScalar.html>`_). | ||
|
|
||
| .. cpp:type:: result_view_type | ||
|
|
||
| A ``View`` referencing the reduction result. | ||
|
|
||
| .. rubric:: Constructors: | ||
|
|
||
| .. cpp:function:: MaxFirstLoc(value_type& value_); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. KOKKOS_FUNCTION annotations are missing |
||
|
|
||
| Constructs a reducer which references a local variable as its result location. | ||
|
|
||
| .. cpp:function:: MaxFirstLoc(const result_view_type& value_); | ||
|
|
||
| Constructs a reducer which references a specific view as its result location. | ||
|
|
||
| .. rubric:: Public Member Functions: | ||
|
|
||
| .. cpp:function:: void join(value_type& dest, const value_type& src) const; | ||
|
|
||
| If ``dest.val == src.val && src.loc < dest.loc`` then ``dest.loc = src.loc``; | ||
| otherwise if ``dest.val < src.val`` then ``dest.val = src.val`` & ``dest.loc = src.loc``. | ||
|
|
||
| .. cpp:function:: void init(value_type& val) const; | ||
|
|
||
| Initialize ``val.val`` using the ``reduction_identity<Scalar>::max()`` method. The default implementation sets ``val=<TYPE>_MIN``. | ||
| Initialize ``val.loc`` using the ``reduction_identity<Index>::min()`` method. The default implementation sets ``val=<TYPE>_MAX``. | ||
|
|
||
| .. cpp:function:: value_type& reference() const; | ||
|
|
||
| :return: A reference to the result provided in class constructor. | ||
|
|
||
| .. cpp:function:: result_view_type view() const; | ||
|
|
||
| :return: A ``View`` of the result place provided in class constructor. | ||
|
|
||
| .. cpp:function:: bool references_scalar() const; | ||
|
|
||
| :return: ``true`` if the reducer was constructed with a scalar; ``false`` if the reducer was constructed with a ``View``. | ||
|
|
||
| .. rubric:: Explicit Deduction Guides (CTAD): | ||
|
|
||
| .. cpp:function:: template<typename T, typename I, typename... Ps> MaxFirstLoc(View<ValLocScalar<T, I>, Ps...> const&) -> MaxFirstLoc<T, I, View<ValLocScalar<T, I>, Ps...>::memory_space>; | ||
|
|
||
| Additional Information | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| * ``MaxFirstLoc<T, I, S>::value_type`` is specialization of ``ValLocScalar`` on non-``const`` ``T`` and non-``const`` ``I``. | ||
|
|
||
| * ``MaxFirstLoc<T, I, S>::result_view_type`` is ``View<T, S, MemoryTraits<Unmanaged>>``. Note that the ``S`` (memory space) must be the same as the space where the result resides. | ||
|
|
||
| * Requires: ``Scalar`` has ``operator=`` and ``operator>`` defined. ``reduction_identity<Scalar>::max()`` is a valid expression. | ||
|
|
||
| * Requires: ``Index`` has ``operator=`` defined. ``reduction_identity<Index>::min()`` is a valid expression. | ||
|
|
||
| * In order to use ``MaxFirstLoc`` with a custom type of either ``Scalar`` or ``Index``, a template specialization of ``reduction_identity<CustomType>`` must be defined. See `Built-In Reducers with Custom Scalar Types <../../../ProgrammingGuide/Custom-Reductions-Built-In-Reducers-with-Custom-Scalar-Types.html>`_ for details. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| ``MinFirstLoc`` | ||
| =============== | ||
|
|
||
| .. role:: cpp(code) | ||
| :language: cpp | ||
|
|
||
| Specific implementation of `ReducerConcept <ReducerConcept.html>`_ storing the minimum value. | ||
| If there are equivalent values, stores the smallest index. | ||
|
|
||
| Header File: ``<Kokkos_Core.hpp>`` | ||
|
|
||
| Usage | ||
| ----- | ||
|
|
||
| .. code-block:: cpp | ||
|
|
||
| MinFirstLoc<T, I, S>::value_type result; | ||
| parallel_reduce(N, Functor, MinFirstLoc<T, I, S>(result)); | ||
|
|
||
| Synopsis | ||
| -------- | ||
|
|
||
| .. code-block:: cpp | ||
|
|
||
| template<typename Scalar, typename Index, typename Space = HostSpace> | ||
| struct MinFirstLoc{ | ||
| using reducer = MinFirstLoc; | ||
| using value_type = ValLocScalar<std::remove_cv_t<Scalar>, std::remove_cv_t<Index>>; | ||
| using result_view_type = View<value_type, Space>; | ||
|
|
||
| MinFirstLoc(value_type& value_); | ||
| MinFirstLoc(const result_view_type& value_); | ||
|
|
||
| void join(value_type& dest, const value_type& src) const; | ||
| void init(value_type& val) const; | ||
| value_type& reference() const; | ||
| result_view_type view() const; | ||
| bool references_scalar() const; | ||
| }; | ||
|
|
||
| template<typename T, typename I, typename... Ps> | ||
| MinFirstLoc(View<ValLocScalar<T, I>, Ps...> const&) | ||
| -> MinFirstLoc<T, I, View<ValLocScalar<T, I>, Ps...>::memory_space>; | ||
|
|
||
| Interface | ||
| --------- | ||
|
|
||
| .. cpp:class:: template<class Scalar, class Index, class Space> MinFirstLoc | ||
|
|
||
| .. rubric:: Public Types: | ||
|
|
||
| .. cpp:type:: reducer | ||
|
|
||
| The self type. | ||
|
|
||
| .. cpp:type:: value_type | ||
|
|
||
| The reduction scalar type (specialization of `ValLocScalar <ValLocScalar.html>`_). | ||
|
|
||
| .. cpp:type:: result_view_type | ||
|
|
||
| A ``View`` referencing the reduction result. | ||
|
|
||
| .. rubric:: Constructors: | ||
|
|
||
| .. cpp:function:: MinFirstLoc(value_type& value_); | ||
|
|
||
| Constructs a reducer which references a local variable as its result location. | ||
|
|
||
| .. cpp:function:: MinFirstLoc(const result_view_type& value_); | ||
|
|
||
| Constructs a reducer which references a specific view as its result location. | ||
|
|
||
| .. rubric:: Public Member Functions: | ||
|
|
||
| .. cpp:function:: void join(value_type& dest, const value_type& src) const; | ||
|
|
||
| If ``src.val == dest.val`` && ``src.loc < dest.loc`` then ``dest.loc = src.loc``; | ||
| otherwise if ``src.val < dest.val`` then ``dest.val = src.val`` && ``dest.loc = src.loc``. | ||
|
|
||
| .. cpp:function:: void init(value_type& val) const; | ||
|
|
||
| Initialize ``val.val`` using the ``reduction_identity<Scalar>::min()`` method. The default implementation sets ``val=<TYPE>_MAX``. | ||
| Initialize ``val.loc`` using the ``reduction_identity<Index>::min()`` method. The default implementation sets ``val=<TYPE>_MAX``. | ||
|
|
||
| .. cpp:function:: value_type& reference() const; | ||
|
|
||
| :return: A reference to the result provided in class constructor. | ||
|
|
||
| .. cpp:function:: result_view_type view() const; | ||
|
|
||
| :return: A ``View`` of the result place provided in class constructor. | ||
|
|
||
| .. cpp:function:: bool references_scalar() const; | ||
|
|
||
| :return: ``true`` if the reducer was constructed with a scalar; ``false`` if the reducer was constructed with a ``View``. | ||
|
|
||
| .. rubric:: Explicit Deduction Guides (CTAD): | ||
|
|
||
| .. cpp:function:: template<typename T, typename I, typename... Ps> MinFirstLoc(View<ValLocScalar<T, I>, Ps...> const&) -> MinFirstLoc<T, I, View<ValLocScalar<T, I>, Ps...>::memory_space>; | ||
|
|
||
| Additional Information | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| * ``MinFirstLoc<T, I, S>::value_type`` is specialization of ``ValLocScalar`` on non-``const`` ``T`` and non-``const`` ``I``. | ||
|
|
||
| * ``MinFirstLoc<T, I, S>::result_view_type`` is ``View<T,S,MemoryTraits<Unmanaged>>``. Note that the ``S`` (memory space) must be the same as the space where the result resides. | ||
|
|
||
| * Requires: ``Scalar`` has ``operator=`` and ``operator>`` defined. ``reduction_identity<Scalar>::max()`` is a valid expression. | ||
|
|
||
| * Requires: ``Index`` has ``operator=`` defined. ``reduction_identity<Index>::min()`` is a valid expression. | ||
|
|
||
| * In order to use ``MinFirstLoc`` with a custom type of either ``Scalar`` or ``Index``, a template specialization of ``reduction_identity<CustomType>`` must be defined. See `Built-In Reducers with Custom Scalar Types <../../../ProgrammingGuide/Custom-Reductions-Built-In-Reducers-with-Custom-Scalar-Types.html>`_ for details. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.