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 6837868
Show file tree
Hide file tree
Showing 32 changed files with 3,012 additions and 300 deletions.
66 changes: 52 additions & 14 deletions algorithms/src/std_algorithms/Kokkos_Copy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,44 +23,82 @@
namespace Kokkos {
namespace Experimental {

//
// overload set accepting execution space
//
template <class ExecutionSpace, class InputIterator, class OutputIterator>
OutputIterator copy(const ExecutionSpace& ex, InputIterator first,
InputIterator last, OutputIterator d_first) {
return Impl::copy_impl("Kokkos::copy_iterator_api_default", ex, first, last,
d_first);
std::enable_if_t<::Kokkos::is_execution_space<ExecutionSpace>::value,
OutputIterator>
copy(const ExecutionSpace& ex, InputIterator first, InputIterator last,
OutputIterator d_first) {
return Impl::copy_exespace_impl("Kokkos::copy_iterator_api_default", ex,
first, last, d_first);
}

template <class ExecutionSpace, class InputIterator, class OutputIterator>
OutputIterator copy(const std::string& label, const ExecutionSpace& ex,
InputIterator first, InputIterator last,
OutputIterator d_first) {
return Impl::copy_impl(label, ex, first, last, d_first);
std::enable_if_t<::Kokkos::is_execution_space<ExecutionSpace>::value,
OutputIterator>
copy(const std::string& label, const ExecutionSpace& ex, InputIterator first,
InputIterator last, OutputIterator d_first) {
return Impl::copy_exespace_impl(label, ex, first, last, d_first);
}

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 copy(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);

namespace KE = ::Kokkos::Experimental;
return Impl::copy_impl("Kokkos::copy_view_api_default", ex,
KE::cbegin(source), KE::cend(source), KE::begin(dest));
return Impl::copy_exespace_impl("Kokkos::copy_view_api_default", ex,
KE::cbegin(source), KE::cend(source),
KE::begin(dest));
}

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 copy(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);

namespace KE = ::Kokkos::Experimental;
return Impl::copy_impl(label, ex, KE::cbegin(source), KE::cend(source),
KE::begin(dest));
return Impl::copy_exespace_impl(label, ex, KE::cbegin(source),
KE::cend(source), KE::begin(dest));
}

//
// overload set accepting team handle
//
template <class TeamHandleType, class InputIterator, class OutputIterator>
KOKKOS_FUNCTION std::enable_if_t<
::Kokkos::is_team_handle<TeamHandleType>::value, OutputIterator>
copy(const TeamHandleType& teamHandle, InputIterator first, InputIterator last,
OutputIterator d_first) {
return Impl::copy_team_impl(teamHandle, first, last, d_first);
}

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 copy(
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);

namespace KE = ::Kokkos::Experimental;
return Impl::copy_team_impl(teamHandle, KE::cbegin(source), KE::cend(source),
KE::begin(dest));
}

} // namespace Experimental
Expand Down
65 changes: 51 additions & 14 deletions algorithms/src/std_algorithms/Kokkos_CopyBackward.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,79 @@
namespace Kokkos {
namespace Experimental {

//
// overload set accepting execution space
//
template <class ExecutionSpace, class IteratorType1, class IteratorType2>
IteratorType2 copy_backward(const ExecutionSpace& ex, IteratorType1 first,
IteratorType1 last, IteratorType2 d_last) {
return Impl::copy_backward_impl("Kokkos::copy_backward_iterator_api_default",
ex, first, last, d_last);
std::enable_if_t<::Kokkos::is_execution_space<ExecutionSpace>::value,
IteratorType2>
copy_backward(const ExecutionSpace& ex, IteratorType1 first, IteratorType1 last,
IteratorType2 d_last) {
return Impl::copy_backward_exespace_impl(
"Kokkos::copy_backward_iterator_api_default", ex, first, last, d_last);
}

template <class ExecutionSpace, class IteratorType1, class IteratorType2>
IteratorType2 copy_backward(const std::string& label, const ExecutionSpace& ex,
IteratorType1 first, IteratorType1 last,
IteratorType2 d_last) {
return Impl::copy_backward_impl(label, ex, first, last, d_last);
std::enable_if_t<::Kokkos::is_execution_space<ExecutionSpace>::value,
IteratorType2>
copy_backward(const std::string& label, const ExecutionSpace& ex,
IteratorType1 first, IteratorType1 last, IteratorType2 d_last) {
return Impl::copy_backward_exespace_impl(label, ex, first, last, d_last);
}

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 copy_backward(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);

return Impl::copy_backward_impl("Kokkos::copy_backward_view_api_default", ex,
cbegin(source), cend(source), end(dest));
return Impl::copy_backward_exespace_impl(
"Kokkos::copy_backward_view_api_default", ex, cbegin(source),
cend(source), end(dest));
}

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 copy_backward(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);

return Impl::copy_backward_impl(label, ex, cbegin(source), cend(source),
end(dest));
return Impl::copy_backward_exespace_impl(label, ex, cbegin(source),
cend(source), end(dest));
}

//
// overload set accepting team handle
//
template <class TeamHandleType, class IteratorType1, class IteratorType2>
KOKKOS_FUNCTION std::enable_if_t<
::Kokkos::is_team_handle<TeamHandleType>::value, IteratorType2>
copy_backward(const TeamHandleType& teamHandle, IteratorType1 first,
IteratorType1 last, IteratorType2 d_last) {
return Impl::copy_backward_team_impl(teamHandle, first, last, d_last);
}

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 copy_backward(
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);

return Impl::copy_backward_team_impl(teamHandle, cbegin(source), cend(source),
end(dest));
}

} // namespace Experimental
Expand Down
70 changes: 54 additions & 16 deletions algorithms/src/std_algorithms/Kokkos_CopyIf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,46 +23,84 @@
namespace Kokkos {
namespace Experimental {

//
// overload set accepting execution space
//
template <class ExecutionSpace, class InputIterator, class OutputIterator,
class Predicate>
OutputIterator copy_if(const ExecutionSpace& ex, InputIterator first,
InputIterator last, OutputIterator d_first,
Predicate pred) {
return Impl::copy_if_impl("Kokkos::copy_if_iterator_api_default", ex, first,
last, d_first, std::move(pred));
std::enable_if_t<::Kokkos::is_execution_space<ExecutionSpace>::value,
OutputIterator>
copy_if(const ExecutionSpace& ex, InputIterator first, InputIterator last,
OutputIterator d_first, Predicate pred) {
return Impl::copy_if_exespace_impl("Kokkos::copy_if_iterator_api_default", ex,
first, last, d_first, std::move(pred));
}

template <class ExecutionSpace, class InputIterator, class OutputIterator,
class Predicate>
OutputIterator copy_if(const std::string& label, const ExecutionSpace& ex,
InputIterator first, InputIterator last,
OutputIterator d_first, Predicate pred) {
return Impl::copy_if_impl(label, ex, first, last, d_first, std::move(pred));
std::enable_if_t<::Kokkos::is_execution_space<ExecutionSpace>::value,
OutputIterator>
copy_if(const std::string& label, const ExecutionSpace& ex, InputIterator first,
InputIterator last, OutputIterator d_first, Predicate pred) {
return Impl::copy_if_exespace_impl(label, ex, first, last, d_first,
std::move(pred));
}

template <class ExecutionSpace, class DataType1, class... Properties1,
class DataType2, class... Properties2, class Predicate>
class DataType2, class... Properties2, class Predicate,
std::enable_if_t<::Kokkos::is_execution_space<ExecutionSpace>::value,
int> = 0>
auto copy_if(const ExecutionSpace& ex,
const ::Kokkos::View<DataType1, Properties1...>& source,
::Kokkos::View<DataType2, Properties2...>& dest, Predicate pred) {
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);

return Impl::copy_if_impl("Kokkos::copy_if_view_api_default", ex,
cbegin(source), cend(source), begin(dest),
std::move(pred));
return Impl::copy_if_exespace_impl("Kokkos::copy_if_view_api_default", ex,
cbegin(source), cend(source), begin(dest),
std::move(pred));
}

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

return Impl::copy_if_impl(label, ex, cbegin(source), cend(source),
begin(dest), std::move(pred));
return Impl::copy_if_exespace_impl(label, ex, cbegin(source), cend(source),
begin(dest), std::move(pred));
}

//
// overload set accepting team handle
//
template <class TeamHandleType, class InputIterator, class OutputIterator,
class Predicate>
KOKKOS_FUNCTION std::enable_if_t<
::Kokkos::is_team_handle<TeamHandleType>::value, OutputIterator>
copy_if(const TeamHandleType& teamHandle, InputIterator first,
InputIterator last, OutputIterator d_first, Predicate pred) {
return Impl::copy_if_team_impl(teamHandle, first, last, d_first,
std::move(pred));
}

template <
class TeamHandleType, class DataType1, class... Properties1,
class DataType2, class... Properties2, class Predicate,
std::enable_if_t<::Kokkos::is_team_handle<TeamHandleType>::value, int> = 0>
KOKKOS_FUNCTION auto copy_if(
const TeamHandleType& teamHandle,
const ::Kokkos::View<DataType1, Properties1...>& source,
::Kokkos::View<DataType2, Properties2...>& dest, Predicate pred) {
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(source);
Impl::static_assert_is_admissible_to_kokkos_std_algorithms(dest);

return Impl::copy_if_team_impl(teamHandle, cbegin(source), cend(source),
begin(dest), std::move(pred));
}

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

//
// overload set accepting execution space
//
template <class ExecutionSpace, class InputIterator, class Size,
class OutputIterator>
OutputIterator copy_n(const ExecutionSpace& ex, InputIterator first, Size count,
OutputIterator result) {
return Impl::copy_n_impl("Kokkos::copy_n_iterator_api_default", ex, first,
count, result);
std::enable_if_t<::Kokkos::is_execution_space<ExecutionSpace>::value,
OutputIterator>
copy_n(const ExecutionSpace& ex, InputIterator first, Size count,
OutputIterator result) {
return Impl::copy_n_exespace_impl("Kokkos::copy_n_iterator_api_default", ex,
first, count, result);
}

template <class ExecutionSpace, class InputIterator, class Size,
class OutputIterator>
OutputIterator copy_n(const std::string& label, const ExecutionSpace& ex,
InputIterator first, Size count, OutputIterator result) {
return Impl::copy_n_impl(label, ex, first, count, result);
std::enable_if_t<::Kokkos::is_execution_space<ExecutionSpace>::value,
OutputIterator>
copy_n(const std::string& label, const ExecutionSpace& ex, InputIterator first,
Size count, OutputIterator result) {
return Impl::copy_n_exespace_impl(label, ex, first, count, result);
}

template <class ExecutionSpace, class DataType1, class... Properties1,
class Size, class DataType2, class... Properties2>
class Size, class DataType2, class... Properties2,
std::enable_if_t<::Kokkos::is_execution_space<ExecutionSpace>::value,
int> = 0>
auto copy_n(const ExecutionSpace& ex,
const ::Kokkos::View<DataType1, Properties1...>& source, Size count,
::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);

namespace KE = ::Kokkos::Experimental;
return Impl::copy_n_impl("Kokkos::copy_n_view_api_default", ex,
KE::cbegin(source), count, KE::begin(dest));
return Impl::copy_n_exespace_impl("Kokkos::copy_n_view_api_default", ex,
KE::cbegin(source), count, KE::begin(dest));
}

template <class ExecutionSpace, class DataType1, class... Properties1,
class Size, class DataType2, class... Properties2>
class Size, class DataType2, class... Properties2,
std::enable_if_t<::Kokkos::is_execution_space<ExecutionSpace>::value,
int> = 0>
auto copy_n(const std::string& label, const ExecutionSpace& ex,
const ::Kokkos::View<DataType1, Properties1...>& source, Size count,
::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);

namespace KE = ::Kokkos::Experimental;
return Impl::copy_n_impl(label, ex, KE::cbegin(source), count,
KE::begin(dest));
return Impl::copy_n_exespace_impl(label, ex, KE::cbegin(source), count,
KE::begin(dest));
}

//
// overload set accepting team handle
//
template <class TeamHandleType, class InputIterator, class Size,
class OutputIterator>
KOKKOS_FUNCTION std::enable_if_t<
::Kokkos::is_team_handle<TeamHandleType>::value, OutputIterator>
copy_n(const TeamHandleType& teamHandle, InputIterator first, Size count,
OutputIterator result) {
return Impl::copy_n_team_impl(teamHandle, first, count, result);
}

template <
class TeamHandleType, class DataType1, class... Properties1, class Size,
class DataType2, class... Properties2,
std::enable_if_t<::Kokkos::is_team_handle<TeamHandleType>::value, int> = 0>
KOKKOS_FUNCTION auto copy_n(
const TeamHandleType& teamHandle,
const ::Kokkos::View<DataType1, Properties1...>& source, Size count,
::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);

namespace KE = ::Kokkos::Experimental;
return Impl::copy_n_team_impl(teamHandle, KE::cbegin(source), count,
KE::begin(dest));
}

} // namespace Experimental
Expand Down

0 comments on commit 6837868

Please sign in to comment.