Skip to content

Commit

Permalink
team-level std algos: part 10 (kokkos#6256)
Browse files Browse the repository at this point in the history
Add Team Level Sorted and Partitioned algorithms

Co-authored-by: Cezary Skrzyński
Co-authored-by: Jakub Strzebonski
Co-authored-by: antoinemeyer5 <antoine.meyer54@gmail.com>
  • Loading branch information
fnrizzi and antoinemeyer5 committed Sep 26, 2023
1 parent 6e2ca15 commit d458fda
Show file tree
Hide file tree
Showing 16 changed files with 1,970 additions and 127 deletions.
61 changes: 50 additions & 11 deletions algorithms/src/std_algorithms/Kokkos_IsPartitioned.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,78 @@
namespace Kokkos {
namespace Experimental {

template <class ExecutionSpace, class IteratorType, class PredicateType>
//
// overload set accepting execution space
//
template <
typename ExecutionSpace, typename IteratorType, typename PredicateType,
std::enable_if_t<::Kokkos::is_execution_space_v<ExecutionSpace>, int> = 0>
bool is_partitioned(const ExecutionSpace& ex, IteratorType first,
IteratorType last, PredicateType p) {
return Impl::is_partitioned_impl(
return Impl::is_partitioned_exespace_impl(
"Kokkos::is_partitioned_iterator_api_default", ex, first, last,
std::move(p));
}

template <class ExecutionSpace, class IteratorType, class PredicateType>
template <
typename ExecutionSpace, typename IteratorType, typename PredicateType,
std::enable_if_t<::Kokkos::is_execution_space_v<ExecutionSpace>, int> = 0>
bool is_partitioned(const std::string& label, const ExecutionSpace& ex,
IteratorType first, IteratorType last, PredicateType p) {
return Impl::is_partitioned_impl(label, ex, first, last, std::move(p));
return Impl::is_partitioned_exespace_impl(label, ex, first, last,
std::move(p));
}

template <class ExecutionSpace, class PredicateType, class DataType,
class... Properties>
template <
typename ExecutionSpace, typename PredicateType, typename DataType,
typename... Properties,
std::enable_if_t<::Kokkos::is_execution_space_v<ExecutionSpace>, int> = 0>
bool is_partitioned(const ExecutionSpace& ex,
const ::Kokkos::View<DataType, Properties...>& v,
PredicateType p) {
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);

return Impl::is_partitioned_impl("Kokkos::is_partitioned_view_api_default",
ex, cbegin(v), cend(v), std::move(p));
return Impl::is_partitioned_exespace_impl(
"Kokkos::is_partitioned_view_api_default", ex, cbegin(v), cend(v),
std::move(p));
}

template <class ExecutionSpace, class PredicateType, class DataType,
class... Properties>
template <
typename ExecutionSpace, typename PredicateType, typename DataType,
typename... Properties,
std::enable_if_t<::Kokkos::is_execution_space_v<ExecutionSpace>, int> = 0>
bool is_partitioned(const std::string& label, const ExecutionSpace& ex,
const ::Kokkos::View<DataType, Properties...>& v,
PredicateType p) {
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);

return Impl::is_partitioned_impl(label, ex, cbegin(v), cend(v), std::move(p));
return Impl::is_partitioned_exespace_impl(label, ex, cbegin(v), cend(v),
std::move(p));
}

//
// overload set accepting a team handle
// Note: for now omit the overloads accepting a label
// since they cause issues on device because of the string allocation.
//
template <typename TeamHandleType, typename IteratorType,
typename PredicateType,
std::enable_if_t<::Kokkos::is_team_handle_v<TeamHandleType>, int> = 0>
KOKKOS_FUNCTION bool is_partitioned(const TeamHandleType& teamHandle,
IteratorType first, IteratorType last,
PredicateType p) {
return Impl::is_partitioned_team_impl(teamHandle, first, last, std::move(p));
}

template <typename TeamHandleType, typename PredicateType, typename DataType,
typename... Properties,
std::enable_if_t<::Kokkos::is_team_handle_v<TeamHandleType>, int> = 0>
KOKKOS_FUNCTION bool is_partitioned(
const TeamHandleType& teamHandle,
const ::Kokkos::View<DataType, Properties...>& v, PredicateType p) {
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(v);
return Impl::is_partitioned_team_impl(teamHandle, cbegin(v), cend(v),
std::move(p));
}

} // namespace Experimental
Expand Down
116 changes: 92 additions & 24 deletions algorithms/src/std_algorithms/Kokkos_IsSorted.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,78 +23,146 @@
namespace Kokkos {
namespace Experimental {

template <class ExecutionSpace, class IteratorType>
//
// overload set accepting execution space
//
template <
typename ExecutionSpace, typename IteratorType,
std::enable_if_t<::Kokkos::is_execution_space_v<ExecutionSpace>, int> = 0>
bool is_sorted(const ExecutionSpace& ex, IteratorType first,
IteratorType last) {
return Impl::is_sorted_impl("Kokkos::is_sorted_iterator_api_default", ex,
first, last);
return Impl::is_sorted_exespace_impl("Kokkos::is_sorted_iterator_api_default",
ex, first, last);
}

template <class ExecutionSpace, class IteratorType>
template <
typename ExecutionSpace, typename IteratorType,
std::enable_if_t<::Kokkos::is_execution_space_v<ExecutionSpace>, int> = 0>
bool is_sorted(const std::string& label, const ExecutionSpace& ex,
IteratorType first, IteratorType last) {
return Impl::is_sorted_impl(label, ex, first, last);
return Impl::is_sorted_exespace_impl(label, ex, first, last);
}

template <class ExecutionSpace, class DataType, class... Properties>
template <
typename ExecutionSpace, typename DataType, typename... Properties,
std::enable_if_t<::Kokkos::is_execution_space_v<ExecutionSpace>, int> = 0>
bool is_sorted(const ExecutionSpace& ex,
const ::Kokkos::View<DataType, Properties...>& view) {
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);

namespace KE = ::Kokkos::Experimental;
return Impl::is_sorted_impl("Kokkos::is_sorted_view_api_default", ex,
KE::cbegin(view), KE::cend(view));
return Impl::is_sorted_exespace_impl("Kokkos::is_sorted_view_api_default", ex,
KE::cbegin(view), KE::cend(view));
}

template <class ExecutionSpace, class DataType, class... Properties>
template <
typename ExecutionSpace, typename DataType, typename... Properties,
std::enable_if_t<::Kokkos::is_execution_space_v<ExecutionSpace>, int> = 0>
bool is_sorted(const std::string& label, const ExecutionSpace& ex,
const ::Kokkos::View<DataType, Properties...>& view) {
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);

namespace KE = ::Kokkos::Experimental;
return Impl::is_sorted_impl(label, ex, KE::cbegin(view), KE::cend(view));
return Impl::is_sorted_exespace_impl(label, ex, KE::cbegin(view),
KE::cend(view));
}

template <class ExecutionSpace, class IteratorType, class ComparatorType>
template <
typename ExecutionSpace, typename IteratorType, typename ComparatorType,
std::enable_if_t<::Kokkos::is_execution_space_v<ExecutionSpace>, int> = 0>
bool is_sorted(const ExecutionSpace& ex, IteratorType first, IteratorType last,
ComparatorType comp) {
Impl::static_assert_is_not_openmptarget(ex);
return Impl::is_sorted_impl("Kokkos::is_sorted_iterator_api_default", ex,
first, last, std::move(comp));
return Impl::is_sorted_exespace_impl("Kokkos::is_sorted_iterator_api_default",
ex, first, last, std::move(comp));
}

template <class ExecutionSpace, class IteratorType, class ComparatorType>
template <
typename ExecutionSpace, typename IteratorType, typename ComparatorType,
std::enable_if_t<::Kokkos::is_execution_space_v<ExecutionSpace>, int> = 0>
bool is_sorted(const std::string& label, const ExecutionSpace& ex,
IteratorType first, IteratorType last, ComparatorType comp) {
Impl::static_assert_is_not_openmptarget(ex);
return Impl::is_sorted_impl(label, ex, first, last, std::move(comp));
return Impl::is_sorted_exespace_impl(label, ex, first, last, std::move(comp));
}

template <class ExecutionSpace, class DataType, class... Properties,
class ComparatorType>
template <
typename ExecutionSpace, typename DataType, typename... Properties,
typename ComparatorType,
std::enable_if_t<::Kokkos::is_execution_space_v<ExecutionSpace>, int> = 0>
bool is_sorted(const ExecutionSpace& ex,
const ::Kokkos::View<DataType, Properties...>& view,
ComparatorType comp) {
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
Impl::static_assert_is_not_openmptarget(ex);

namespace KE = ::Kokkos::Experimental;
return Impl::is_sorted_impl("Kokkos::is_sorted_view_api_default", ex,
KE::cbegin(view), KE::cend(view),
std::move(comp));
return Impl::is_sorted_exespace_impl("Kokkos::is_sorted_view_api_default", ex,
KE::cbegin(view), KE::cend(view),
std::move(comp));
}

template <class ExecutionSpace, class DataType, class... Properties,
class ComparatorType>
template <
typename ExecutionSpace, typename DataType, typename... Properties,
typename ComparatorType,
std::enable_if_t<::Kokkos::is_execution_space_v<ExecutionSpace>, int> = 0>
bool is_sorted(const std::string& label, const ExecutionSpace& ex,
const ::Kokkos::View<DataType, Properties...>& view,
ComparatorType comp) {
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
Impl::static_assert_is_not_openmptarget(ex);

namespace KE = ::Kokkos::Experimental;
return Impl::is_sorted_impl(label, ex, KE::cbegin(view), KE::cend(view),
std::move(comp));
return Impl::is_sorted_exespace_impl(label, ex, KE::cbegin(view),
KE::cend(view), std::move(comp));
}

//
// overload set accepting a team handle
// Note: for now omit the overloads accepting a label
// since they cause issues on device because of the string allocation.
//
template <typename TeamHandleType, typename IteratorType,
std::enable_if_t<::Kokkos::is_team_handle_v<TeamHandleType>, int> = 0>
KOKKOS_FUNCTION bool is_sorted(const TeamHandleType& teamHandle,
IteratorType first, IteratorType last) {
return Impl::is_sorted_team_impl(teamHandle, first, last);
}

template <typename TeamHandleType, typename DataType, typename... Properties,
std::enable_if_t<::Kokkos::is_team_handle_v<TeamHandleType>, int> = 0>
KOKKOS_FUNCTION bool is_sorted(
const TeamHandleType& teamHandle,
const ::Kokkos::View<DataType, Properties...>& view) {
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);

namespace KE = ::Kokkos::Experimental;
return Impl::is_sorted_team_impl(teamHandle, KE::cbegin(view),
KE::cend(view));
}

template <typename TeamHandleType, typename IteratorType,
typename ComparatorType,
std::enable_if_t<::Kokkos::is_team_handle_v<TeamHandleType>, int> = 0>
KOKKOS_FUNCTION bool is_sorted(const TeamHandleType& teamHandle,
IteratorType first, IteratorType last,
ComparatorType comp) {
Impl::static_assert_is_not_openmptarget(teamHandle);
return Impl::is_sorted_team_impl(teamHandle, first, last, std::move(comp));
}

template <typename TeamHandleType, typename DataType, typename... Properties,
typename ComparatorType,
std::enable_if_t<::Kokkos::is_team_handle_v<TeamHandleType>, int> = 0>
KOKKOS_FUNCTION bool is_sorted(
const TeamHandleType& teamHandle,
const ::Kokkos::View<DataType, Properties...>& view, ComparatorType comp) {
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
Impl::static_assert_is_not_openmptarget(teamHandle);

namespace KE = ::Kokkos::Experimental;
return Impl::is_sorted_team_impl(teamHandle, KE::cbegin(view), KE::cend(view),
std::move(comp));
}

} // namespace Experimental
Expand Down

0 comments on commit d458fda

Please sign in to comment.