Skip to content

Commit

Permalink
implementation and tests
Browse files Browse the repository at this point in the history
Co-authored-by: Cezary Skrzyński
Co-authored-by: Jakub Strzebonski
  • Loading branch information
fnrizzi committed Jun 12, 2023
1 parent 63d695c commit 61839dc
Show file tree
Hide file tree
Showing 34 changed files with 4,572 additions and 549 deletions.
138 changes: 116 additions & 22 deletions algorithms/src/std_algorithms/Kokkos_AdjacentDifference.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@
namespace Kokkos {
namespace Experimental {

//
// overload set accepting execution space
//
template <class ExecutionSpace, class InputIteratorType,
class OutputIteratorType>
std::enable_if_t<!::Kokkos::is_view<InputIteratorType>::value,
std::enable_if_t<!::Kokkos::is_view<InputIteratorType>::value &&
::Kokkos::is_execution_space<ExecutionSpace>::value,
OutputIteratorType>
adjacent_difference(const ExecutionSpace& ex, InputIteratorType first_from,
InputIteratorType last_from,
Expand All @@ -35,26 +39,28 @@ adjacent_difference(const ExecutionSpace& ex, InputIteratorType first_from,
using binary_op =
Impl::StdAdjacentDifferenceDefaultBinaryOpFunctor<value_type1,
value_type2>;
return Impl::adjacent_difference_impl(
return Impl::adjacent_difference_exespace_impl(
"Kokkos::adjacent_difference_iterator_api", ex, first_from, last_from,
first_dest, binary_op());
}

template <class ExecutionSpace, class InputIteratorType,
class OutputIteratorType, class BinaryOp>
std::enable_if_t<!::Kokkos::is_view<InputIteratorType>::value,
std::enable_if_t<!::Kokkos::is_view<InputIteratorType>::value &&
::Kokkos::is_execution_space<ExecutionSpace>::value,
OutputIteratorType>
adjacent_difference(const ExecutionSpace& ex, InputIteratorType first_from,
InputIteratorType last_from, OutputIteratorType first_dest,
BinaryOp bin_op) {
return Impl::adjacent_difference_impl(
return Impl::adjacent_difference_exespace_impl(
"Kokkos::adjacent_difference_iterator_api", ex, first_from, last_from,
first_dest, bin_op);
}

template <class ExecutionSpace, class InputIteratorType,
class OutputIteratorType>
std::enable_if_t<!::Kokkos::is_view<InputIteratorType>::value,
std::enable_if_t<!::Kokkos::is_view<InputIteratorType>::value &&
::Kokkos::is_execution_space<ExecutionSpace>::value,
OutputIteratorType>
adjacent_difference(const std::string& label, const ExecutionSpace& ex,
InputIteratorType first_from, InputIteratorType last_from,
Expand All @@ -64,23 +70,26 @@ adjacent_difference(const std::string& label, const ExecutionSpace& ex,
using binary_op =
Impl::StdAdjacentDifferenceDefaultBinaryOpFunctor<value_type1,
value_type2>;
return Impl::adjacent_difference_impl(label, ex, first_from, last_from,
first_dest, binary_op());
return Impl::adjacent_difference_exespace_impl(
label, ex, first_from, last_from, first_dest, binary_op());
}

template <class ExecutionSpace, class InputIteratorType,
class OutputIteratorType, class BinaryOp>
std::enable_if_t<!::Kokkos::is_view<InputIteratorType>::value,
std::enable_if_t<!::Kokkos::is_view<InputIteratorType>::value &&
::Kokkos::is_execution_space<ExecutionSpace>::value,
OutputIteratorType>
adjacent_difference(const std::string& label, const ExecutionSpace& ex,
InputIteratorType first_from, InputIteratorType last_from,
OutputIteratorType first_dest, BinaryOp bin_op) {
return Impl::adjacent_difference_impl(label, ex, first_from, last_from,
first_dest, bin_op);
return Impl::adjacent_difference_exespace_impl(label, ex, first_from,
last_from, first_dest, bin_op);
}

template <class ExecutionSpace, class DataType1, class... Properties1,
class DataType2, class... Properties2>
class DataType2, class... Properties2,
std::enable_if_t<::Kokkos::is_execution_space<ExecutionSpace>::value,
int> = 0>
auto adjacent_difference(
const ExecutionSpace& ex,
const ::Kokkos::View<DataType1, Properties1...>& view_from,
Expand All @@ -96,13 +105,15 @@ auto adjacent_difference(
using binary_op =
Impl::StdAdjacentDifferenceDefaultBinaryOpFunctor<value_type1,
value_type2>;
return Impl::adjacent_difference_impl(
return Impl::adjacent_difference_exespace_impl(
"Kokkos::adjacent_difference_view_api", ex, KE::cbegin(view_from),
KE::cend(view_from), KE::begin(view_dest), binary_op());
}

template <class ExecutionSpace, class DataType1, class... Properties1,
class DataType2, class... Properties2, class BinaryOp>
class DataType2, class... Properties2, class BinaryOp,
std::enable_if_t<::Kokkos::is_execution_space<ExecutionSpace>::value,
int> = 0>
auto adjacent_difference(
const ExecutionSpace& ex,
const ::Kokkos::View<DataType1, Properties1...>& view_from,
Expand All @@ -111,13 +122,15 @@ auto adjacent_difference(
namespace KE = ::Kokkos::Experimental;
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
return Impl::adjacent_difference_impl(
return Impl::adjacent_difference_exespace_impl(
"Kokkos::adjacent_difference_view_api", ex, KE::cbegin(view_from),
KE::cend(view_from), KE::begin(view_dest), bin_op);
}

template <class ExecutionSpace, class DataType1, class... Properties1,
class DataType2, class... Properties2>
class DataType2, class... Properties2,
std::enable_if_t<::Kokkos::is_execution_space<ExecutionSpace>::value,
int> = 0>
auto adjacent_difference(
const std::string& label, const ExecutionSpace& ex,
const ::Kokkos::View<DataType1, Properties1...>& view_from,
Expand All @@ -134,13 +147,15 @@ auto adjacent_difference(
Impl::StdAdjacentDifferenceDefaultBinaryOpFunctor<value_type1,
value_type2>;

return Impl::adjacent_difference_impl(label, ex, KE::cbegin(view_from),
KE::cend(view_from),
KE::begin(view_dest), binary_op());
return Impl::adjacent_difference_exespace_impl(
label, ex, KE::cbegin(view_from), KE::cend(view_from),
KE::begin(view_dest), binary_op());
}

template <class ExecutionSpace, class DataType1, class... Properties1,
class DataType2, class... Properties2, class BinaryOp>
class DataType2, class... Properties2, class BinaryOp,
std::enable_if_t<::Kokkos::is_execution_space<ExecutionSpace>::value,
int> = 0>
auto adjacent_difference(
const std::string& label, const ExecutionSpace& ex,
const ::Kokkos::View<DataType1, Properties1...>& view_from,
Expand All @@ -149,9 +164,88 @@ auto adjacent_difference(
namespace KE = ::Kokkos::Experimental;
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
return Impl::adjacent_difference_impl(label, ex, KE::cbegin(view_from),
KE::cend(view_from),
KE::begin(view_dest), bin_op);
return Impl::adjacent_difference_exespace_impl(
label, ex, KE::cbegin(view_from), KE::cend(view_from),
KE::begin(view_dest), bin_op);
}

//
// 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 <class TeamHandleType, class InputIteratorType,
class OutputIteratorType>
KOKKOS_FUNCTION
std::enable_if_t<!::Kokkos::is_view<InputIteratorType>::value &&
::Kokkos::is_team_handle<TeamHandleType>::value,
OutputIteratorType>
adjacent_difference(const TeamHandleType& teamHandle,
InputIteratorType first_from,
InputIteratorType last_from,
OutputIteratorType first_dest) {
using value_type1 = typename InputIteratorType::value_type;
using value_type2 = typename OutputIteratorType::value_type;
using binary_op =
Impl::StdAdjacentDifferenceDefaultBinaryOpFunctor<value_type1,
value_type2>;
return Impl::adjacent_difference_team_impl(teamHandle, first_from, last_from,
first_dest, binary_op());
}

template <class TeamHandleType, class InputIteratorType,
class OutputIteratorType, class BinaryOp>
KOKKOS_FUNCTION
std::enable_if_t<!::Kokkos::is_view<InputIteratorType>::value &&
::Kokkos::is_team_handle<TeamHandleType>::value,
OutputIteratorType>
adjacent_difference(const TeamHandleType& teamHandle,
InputIteratorType first_from,
InputIteratorType last_from,
OutputIteratorType first_dest, BinaryOp bin_op) {
return Impl::adjacent_difference_team_impl(teamHandle, first_from, last_from,
first_dest, bin_op);
}

template <
class TeamHandleType, class DataType1, class... Properties1,
class DataType2, class... Properties2,
std::enable_if_t<::Kokkos::is_team_handle<TeamHandleType>::value, int> = 0>
KOKKOS_FUNCTION auto adjacent_difference(
const TeamHandleType& teamHandle,
const ::Kokkos::View<DataType1, Properties1...>& view_from,
const ::Kokkos::View<DataType2, Properties2...>& view_dest) {
namespace KE = ::Kokkos::Experimental;
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);

using view_type1 = ::Kokkos::View<DataType1, Properties1...>;
using view_type2 = ::Kokkos::View<DataType2, Properties2...>;
using value_type1 = typename view_type1::value_type;
using value_type2 = typename view_type2::value_type;
using binary_op =
Impl::StdAdjacentDifferenceDefaultBinaryOpFunctor<value_type1,
value_type2>;
return Impl::adjacent_difference_team_impl(teamHandle, KE::cbegin(view_from),
KE::cend(view_from),
KE::begin(view_dest), binary_op());
}

template <
class TeamHandleType, class DataType1, class... Properties1,
class DataType2, class... Properties2, class BinaryOp,
std::enable_if_t<::Kokkos::is_team_handle<TeamHandleType>::value, int> = 0>
KOKKOS_FUNCTION auto adjacent_difference(
const TeamHandleType& teamHandle,
const ::Kokkos::View<DataType1, Properties1...>& view_from,
const ::Kokkos::View<DataType2, Properties2...>& view_dest,
BinaryOp bin_op) {
namespace KE = ::Kokkos::Experimental;
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_from);
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(view_dest);
return Impl::adjacent_difference_team_impl(teamHandle, KE::cbegin(view_from),
KE::cend(view_from),
KE::begin(view_dest), bin_op);
}

} // namespace Experimental
Expand Down

0 comments on commit 61839dc

Please sign in to comment.