Skip to content

Commit

Permalink
team-level std algos: part 11 (kokkos#6258)
Browse files Browse the repository at this point in the history
Team-level std-algorithms: transform, generate, swap_ranges

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 9250328 commit 9db1ea4
Show file tree
Hide file tree
Showing 13 changed files with 1,268 additions and 158 deletions.
54 changes: 42 additions & 12 deletions algorithms/src/std_algorithms/Kokkos_Generate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,68 @@
namespace Kokkos {
namespace Experimental {

template <class ExecutionSpace, class IteratorType, class Generator>
//
// overload set accepting execution space
//
template <typename ExecutionSpace, typename IteratorType, typename Generator,
std::enable_if_t<is_execution_space_v<ExecutionSpace>, int> = 0>
void generate(const ExecutionSpace& ex, IteratorType first, IteratorType last,
Generator g) {
Impl::generate_impl("Kokkos::generate_iterator_api_default", ex, first, last,
std::move(g));
Impl::generate_exespace_impl("Kokkos::generate_iterator_api_default", ex,
first, last, std::move(g));
}

template <class ExecutionSpace, class IteratorType, class Generator>
template <typename ExecutionSpace, typename IteratorType, typename Generator,
std::enable_if_t<is_execution_space_v<ExecutionSpace>, int> = 0>
void generate(const std::string& label, const ExecutionSpace& ex,
IteratorType first, IteratorType last, Generator g) {
Impl::generate_impl(label, ex, first, last, std::move(g));
Impl::generate_exespace_impl(label, ex, first, last, std::move(g));
}

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

Impl::generate_impl("Kokkos::generate_view_api_default", ex, begin(view),
end(view), std::move(g));
Impl::generate_exespace_impl("Kokkos::generate_view_api_default", ex,
begin(view), end(view), std::move(g));
}

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

Impl::generate_impl(label, ex, begin(view), end(view), std::move(g));
Impl::generate_exespace_impl(label, ex, begin(view), end(view), std::move(g));
}

//
// 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 Generator,
std::enable_if_t<is_team_handle_v<TeamHandleType>, int> = 0>
KOKKOS_FUNCTION void generate(const TeamHandleType& teamHandle,
IteratorType first, IteratorType last,
Generator g) {
Impl::generate_team_impl(teamHandle, first, last, std::move(g));
}

template <typename TeamHandleType, typename DataType, typename... Properties,
typename Generator,
std::enable_if_t<is_team_handle_v<TeamHandleType>, int> = 0>
KOKKOS_FUNCTION void generate(
const TeamHandleType& teamHandle,
const ::Kokkos::View<DataType, Properties...>& view, Generator g) {
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
Impl::generate_team_impl(teamHandle, begin(view), end(view), std::move(g));
}

} // namespace Experimental
Expand Down
63 changes: 49 additions & 14 deletions algorithms/src/std_algorithms/Kokkos_GenerateN.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,75 @@
namespace Kokkos {
namespace Experimental {

template <class ExecutionSpace, class IteratorType, class Size, class Generator>
//
// overload set accepting execution space
//
template <typename ExecutionSpace, typename IteratorType, typename Size,
typename Generator,
std::enable_if_t<is_execution_space_v<ExecutionSpace>, int> = 0>
IteratorType generate_n(const ExecutionSpace& ex, IteratorType first,
Size count, Generator g) {
Impl::generate_n_impl("Kokkos::generate_n_iterator_api_default", ex, first,
count, std::move(g));
return first + count;
return Impl::generate_n_exespace_impl(
"Kokkos::generate_n_iterator_api_default", ex, first, count,
std::move(g));
}

template <class ExecutionSpace, class IteratorType, class Size, class Generator>
template <typename ExecutionSpace, typename IteratorType, typename Size,
typename Generator,
std::enable_if_t<is_execution_space_v<ExecutionSpace>, int> = 0>
IteratorType generate_n(const std::string& label, const ExecutionSpace& ex,
IteratorType first, Size count, Generator g) {
Impl::generate_n_impl(label, ex, first, count, std::move(g));
return first + count;
return Impl::generate_n_exespace_impl(label, ex, first, count, std::move(g));
}

template <class ExecutionSpace, class DataType, class... Properties, class Size,
class Generator>
template <typename ExecutionSpace, typename DataType, typename... Properties,
typename Size, typename Generator,
std::enable_if_t<is_execution_space_v<ExecutionSpace>, int> = 0>
auto generate_n(const ExecutionSpace& ex,
const ::Kokkos::View<DataType, Properties...>& view, Size count,
Generator g) {
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);

return Impl::generate_n_impl("Kokkos::generate_n_view_api_default", ex,
begin(view), count, std::move(g));
return Impl::generate_n_exespace_impl("Kokkos::generate_n_view_api_default",
ex, begin(view), count, std::move(g));
}

template <class ExecutionSpace, class DataType, class... Properties, class Size,
class Generator>
template <typename ExecutionSpace, typename DataType, typename... Properties,
typename Size, typename Generator,
std::enable_if_t<is_execution_space_v<ExecutionSpace>, int> = 0>
auto generate_n(const std::string& label, const ExecutionSpace& ex,
const ::Kokkos::View<DataType, Properties...>& view, Size count,
Generator g) {
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);

return Impl::generate_n_impl(label, ex, begin(view), count, std::move(g));
return Impl::generate_n_exespace_impl(label, ex, begin(view), count,
std::move(g));
}

//
// 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 Size,
typename Generator,
std::enable_if_t<is_team_handle_v<TeamHandleType>, int> = 0>
KOKKOS_FUNCTION IteratorType generate_n(const TeamHandleType& teamHandle,
IteratorType first, Size count,
Generator g) {
return Impl::generate_n_team_impl(teamHandle, first, count, std::move(g));
}

template <typename TeamHandleType, typename DataType, typename... Properties,
typename Size, typename Generator,
std::enable_if_t<is_team_handle_v<TeamHandleType>, int> = 0>
KOKKOS_FUNCTION auto generate_n(
const TeamHandleType& teamHandle,
const ::Kokkos::View<DataType, Properties...>& view, Size count,
Generator g) {
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view);
return Impl::generate_n_team_impl(teamHandle, begin(view), count,
std::move(g));
}

} // namespace Experimental
Expand Down
66 changes: 53 additions & 13 deletions algorithms/src/std_algorithms/Kokkos_SwapRanges.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,44 +23,84 @@
namespace Kokkos {
namespace Experimental {

template <class ExecutionSpace, class IteratorType1, class IteratorType2>
//
// overload set accepting execution space
//
template <typename ExecutionSpace, typename IteratorType1,
typename IteratorType2,
std::enable_if_t<is_execution_space_v<ExecutionSpace>, int> = 0>
IteratorType2 swap_ranges(const ExecutionSpace& ex, IteratorType1 first1,
IteratorType1 last1, IteratorType2 first2) {
return Impl::swap_ranges_impl("Kokkos::swap_ranges_iterator_api_default", ex,
first1, last1, first2);
return Impl::swap_ranges_exespace_impl(
"Kokkos::swap_ranges_iterator_api_default", ex, first1, last1, first2);
}

template <class ExecutionSpace, class DataType1, class... Properties1,
class DataType2, class... Properties2>
template <typename ExecutionSpace, typename DataType1, typename... Properties1,
typename DataType2, typename... Properties2,
std::enable_if_t<is_execution_space_v<ExecutionSpace>, int> = 0>
auto swap_ranges(const ExecutionSpace& ex,
const ::Kokkos::View<DataType1, Properties1...>& source,
::Kokkos::View<DataType2, Properties2...>& dest) {
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);

assert(source.extent(0) == dest.extent(0));
return Impl::swap_ranges_impl("Kokkos::swap_ranges_view_api_default", ex,
begin(source), end(source), begin(dest));
return Impl::swap_ranges_exespace_impl("Kokkos::swap_ranges_view_api_default",
ex, begin(source), end(source),
begin(dest));
}

template <class ExecutionSpace, class IteratorType1, class IteratorType2>
template <typename ExecutionSpace, typename IteratorType1,
typename IteratorType2,
std::enable_if_t<is_execution_space_v<ExecutionSpace>, int> = 0>
IteratorType2 swap_ranges(const std::string& label, const ExecutionSpace& ex,
IteratorType1 first1, IteratorType1 last1,
IteratorType2 first2) {
return Impl::swap_ranges_impl(label, ex, first1, last1, first2);
return Impl::swap_ranges_exespace_impl(label, ex, first1, last1, first2);
}

template <class ExecutionSpace, class DataType1, class... Properties1,
class DataType2, class... Properties2>
template <typename ExecutionSpace, typename DataType1, typename... Properties1,
typename DataType2, typename... Properties2,
std::enable_if_t<is_execution_space_v<ExecutionSpace>, int> = 0>
auto swap_ranges(const std::string& label, const ExecutionSpace& ex,
const ::Kokkos::View<DataType1, Properties1...>& source,
::Kokkos::View<DataType2, Properties2...>& dest) {
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);

assert(source.extent(0) == dest.extent(0));
return Impl::swap_ranges_impl(label, ex, begin(source), end(source),
begin(dest));
return Impl::swap_ranges_exespace_impl(label, ex, begin(source), end(source),
begin(dest));
}

//
// 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 IteratorType1,
typename IteratorType2,
std::enable_if_t<is_team_handle_v<TeamHandleType>, int> = 0>
KOKKOS_FUNCTION IteratorType2 swap_ranges(const TeamHandleType& teamHandle,
IteratorType1 first1,
IteratorType1 last1,
IteratorType2 first2) {
return Impl::swap_ranges_team_impl(teamHandle, first1, last1, first2);
}

template <typename TeamHandleType, typename DataType1, typename... Properties1,
typename DataType2, typename... Properties2,
std::enable_if_t<is_team_handle_v<TeamHandleType>, int> = 0>
KOKKOS_FUNCTION auto swap_ranges(
const TeamHandleType& teamHandle,
const ::Kokkos::View<DataType1, Properties1...>& source,
::Kokkos::View<DataType2, Properties2...>& dest) {
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);

assert(source.extent(0) == dest.extent(0));
return Impl::swap_ranges_team_impl(teamHandle, begin(source), end(source),
begin(dest));
}

} // namespace Experimental
Expand Down

0 comments on commit 9db1ea4

Please sign in to comment.