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

Support for C++ standard algorithms #4315

Merged
merged 137 commits into from
Oct 18, 2021
Merged

Support for C++ standard algorithms #4315

merged 137 commits into from
Oct 18, 2021

Conversation

cz4rs
Copy link
Contributor

@cz4rs cz4rs commented Sep 14, 2021

Add support for C++ standard algorithms

This adds support for C++ standard algorithms from categories A and B.
Note: replaces PR #4108.

Fixes #4075
Fixes #4076

Copy link
Contributor

@nliber nliber left a comment

Choose a reason for hiding this comment

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

Only got through the first could of headers (up to Kokkos_ModifyingOperations.hpp) so far.

algorithms/src/std_algorithms/Kokkos_Constraints.hpp Outdated Show resolved Hide resolved
algorithms/src/std_algorithms/Kokkos_HelperPredicates.hpp Outdated Show resolved Hide resolved
algorithms/src/std_algorithms/Kokkos_HelperPredicates.hpp Outdated Show resolved Hide resolved
algorithms/src/std_algorithms/Kokkos_HelperPredicates.hpp Outdated Show resolved Hide resolved

// swap
template <class T>
KOKKOS_INLINE_FUNCTION void swap(T& a, T& b) noexcept {
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: this noexcept specification differs from the one in the standard. At a minimum we should document that.

C++20 changes how swap is found. Users are no longer required to specialized std::swap; rather, they just have to put a non-member function in the same namespace as their type. Should we support that kind of lookup here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I added that to be consistent with std syntax - i have to read more about this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Because we need operations that cannot fail as building blocks, noexcept really matters for the following operations (as far as optimizations made in the standard library):

Move construction
Move assignment
Swap

For swap, noexcept is conditional based on the noexcept-ness of the underlying move operations until C++17, then uses the is_nothrow_swappable trait (with the change in how swap is called as I described in the note above).

Also, there is a subtle difference between noexcept and not throwing. noexcept has semantics: an exception will not escape a function marked noexcept; rather, if one is about to escape, std::terminate is called. In the above, I'm specifically talking about functions marked noexcept.

Copy link
Member

Choose a reason for hiding this comment

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

I am always unsure on this stuff. but we may just want to remove this. In particular the requirement for std::terminate if one tries to escape is kinda shitty, since it actually requires inserting a try/catch by the compiler or?

@fnrizzi fnrizzi added this to To do in Kokkos Release 3.6 Sep 15, 2021
@cz4rs cz4rs marked this pull request as ready for review September 29, 2021 19:25
@cz4rs cz4rs changed the title [WIP] Support for C++ standard algorithms Support for C++ standard algorithms Sep 29, 2021
Copy link
Contributor

@masterleinad masterleinad left a comment

Choose a reason for hiding this comment

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

Apart from critically examining #4315 (comment), SortingOperations, MinMaxElementOperations and PartitioningOperations look good to me.

Copy link
Contributor

@masterleinad masterleinad left a comment

Choose a reason for hiding this comment

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

Looks OK to me.

Copy link
Contributor

@nmm0 nmm0 left a 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!

- fix comparison between signed and unsigned integers in tests
- fix return type in std::count implementation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

C++ standard algorithms - implementation category B C++ standard algorithms - implementation category A
9 participants