diff --git a/unittests/Kokkos/ParallelAdd.h b/unittests/Kokkos/ParallelAdd.h deleted file mode 100644 index 6d8b3d039..000000000 --- a/unittests/Kokkos/ParallelAdd.h +++ /dev/null @@ -1,338 +0,0 @@ -// source: -// https://github.com/kliegeois/clad/blob/kokkos-PR/unittests/Kokkos/parallel_sum.hpp - -#ifndef KOKKOS_UNITTEST_PARALLELSUM -#define KOKKOS_UNITTEST_PARALLELSUM - -#include - -namespace kokkos_builtin_derivative { - -// Parallel sum: - -template -struct ViewSum; - -template -struct ViewSum { - - template - static void execute(ResultT& result, const Viewtype& v, - const ExecSpace space = ExecSpace()) { - - using policy_type = - Kokkos::RangePolicy>; - using value_type = typename Viewtype::value_type; - - value_type sum; - - Kokkos::parallel_reduce( - "ViewSum-1D", policy_type(space, 0, v.extent(0)), - KOKKOS_LAMBDA(const iType& i0, value_type& update) { update += v(i0); }, - sum); - - result += sum; - } -}; - -template -struct ViewSum { - - template - static void execute(ResultT& result, const Viewtype& v, - const ExecSpace space = ExecSpace()) { - - static const Kokkos::Iterate outer_iteration_pattern = - Kokkos::layout_iterate_type_selector::outer_iteration_pattern; - static const Kokkos::Iterate inner_iteration_pattern = - Kokkos::layout_iterate_type_selector::inner_iteration_pattern; - using iterate_type = - Kokkos::Rank<2, outer_iteration_pattern, inner_iteration_pattern>; - using policy_type = Kokkos::MDRangePolicy>; - using value_type = typename Viewtype::value_type; - - value_type sum; - - Kokkos::parallel_reduce( - "ViewSum-2D", policy_type(space, {0, 0}, {v.extent(0), v.extent(1)}), - KOKKOS_LAMBDA(const iType& i0, const iType& i1, value_type& update) { - update += v(i0, i1); - }, - sum); - - result += sum; - } -}; - -template -struct ViewSum { - - template - static void execute(ResultT& result, const Viewtype& v, - const ExecSpace space = ExecSpace()) { - - static const Kokkos::Iterate outer_iteration_pattern = - Kokkos::layout_iterate_type_selector::outer_iteration_pattern; - static const Kokkos::Iterate inner_iteration_pattern = - Kokkos::layout_iterate_type_selector::inner_iteration_pattern; - using iterate_type = - Kokkos::Rank<3, outer_iteration_pattern, inner_iteration_pattern>; - using policy_type = Kokkos::MDRangePolicy>; - using value_type = typename Viewtype::value_type; - - value_type sum; - - Kokkos::parallel_reduce( - "ViewSum-3D", - policy_type(space, {0, 0}, {v.extent(0), v.extent(1), v.extent(2)}), - KOKKOS_LAMBDA(const iType& i0, const iType& i1, const iType& i2, - value_type& update) { update += v(i0, i1, i2); }, - sum); - - result += sum; - } -}; - -// Parallel add - -template -struct ViewAdd; - -template -struct ViewAdd { - - template - static void execute(const Viewtype& v, ResultT& update, - const ExecSpace space = ExecSpace()) { - - using policy_type = - Kokkos::RangePolicy>; - - Kokkos::parallel_for( - "ViewAdd-1D", policy_type(space, 0, v.extent(0)), - KOKKOS_LAMBDA(const iType& i0) { v(i0) += update; }); - } - - template - static void executeView(const Viewtype& v, ResultT& update, - const ExecSpace space = ExecSpace()) { - - using policy_type = - Kokkos::RangePolicy>; - - Kokkos::parallel_for( - "ViewAdd-1D", policy_type(space, 0, v.extent(0)), - KOKKOS_LAMBDA(const iType& i0) { v(i0) += update(i0); }); - } -}; - -template -struct ViewAdd { - - template - static void execute(const Viewtype& v, ResultT& update, - const ExecSpace space = ExecSpace()) { - - static const Kokkos::Iterate outer_iteration_pattern = - Kokkos::layout_iterate_type_selector::outer_iteration_pattern; - static const Kokkos::Iterate inner_iteration_pattern = - Kokkos::layout_iterate_type_selector::inner_iteration_pattern; - using iterate_type = - Kokkos::Rank<2, outer_iteration_pattern, inner_iteration_pattern>; - using policy_type = Kokkos::MDRangePolicy>; - - Kokkos::parallel_for( - "ViewAdd-2D", policy_type(space, {0, 0}, {v.extent(0), v.extent(1)}), - KOKKOS_LAMBDA(const iType& i0, const iType& i1) { - v(i0, i1) += update; - }); - } - - template - static void executeView(const Viewtype& v, ResultT& update, - const ExecSpace space = ExecSpace()) { - - static const Kokkos::Iterate outer_iteration_pattern = - Kokkos::layout_iterate_type_selector::outer_iteration_pattern; - static const Kokkos::Iterate inner_iteration_pattern = - Kokkos::layout_iterate_type_selector::inner_iteration_pattern; - using iterate_type = - Kokkos::Rank<2, outer_iteration_pattern, inner_iteration_pattern>; - using policy_type = Kokkos::MDRangePolicy>; - - Kokkos::parallel_for( - "ViewAdd-2D", policy_type(space, {0, 0}, {v.extent(0), v.extent(1)}), - KOKKOS_LAMBDA(const iType& i0, const iType& i1) { - v(i0, i1) += update(i0, i1); - }); - } -}; - -template -struct ViewAdd { - - template - static void execute(const Viewtype& v, ResultT& update, - const ExecSpace space = ExecSpace()) { - - static const Kokkos::Iterate outer_iteration_pattern = - Kokkos::layout_iterate_type_selector::outer_iteration_pattern; - static const Kokkos::Iterate inner_iteration_pattern = - Kokkos::layout_iterate_type_selector::inner_iteration_pattern; - using iterate_type = - Kokkos::Rank<3, outer_iteration_pattern, inner_iteration_pattern>; - using policy_type = Kokkos::MDRangePolicy>; - - Kokkos::parallel_for( - "ViewAdd-3D", - policy_type(space, {0, 0}, {v.extent(0), v.extent(1), v.extent(2)}), - KOKKOS_LAMBDA(const iType& i0, const iType& i1, const iType& i2) { - v(i0, i1, i2) += update; - }); - } - - template - static void executeView(const Viewtype& v, ResultT& update, - const ExecSpace space = ExecSpace()) { - - static const Kokkos::Iterate outer_iteration_pattern = - Kokkos::layout_iterate_type_selector::outer_iteration_pattern; - static const Kokkos::Iterate inner_iteration_pattern = - Kokkos::layout_iterate_type_selector::inner_iteration_pattern; - using iterate_type = - Kokkos::Rank<3, outer_iteration_pattern, inner_iteration_pattern>; - using policy_type = Kokkos::MDRangePolicy>; - - Kokkos::parallel_for( - "ViewAdd-3D", - policy_type(space, {0, 0}, {v.extent(0), v.extent(1), v.extent(2)}), - KOKKOS_LAMBDA(const iType& i0, const iType& i1, const iType& i2) { - v(i0, i1, i2) += update(i0, i1, i2); - }); - } -}; - -template -void parallel_sum(typename Kokkos::ViewTraits::value_type& sum, - const Kokkos::View A) { - using ViewtypeA = Kokkos::View; - Kokkos::fence(); - if (A.span_is_contiguous()) { - - using ViewTypeFlat = Kokkos::View< - typename ViewtypeA::value_type*, Kokkos::LayoutRight, - Kokkos::Device>, - Kokkos::MemoryTraits<0>>; - - ViewTypeFlat A_flat(A.data(), A.size()); - ViewSum::template execute< - typename ViewTypeFlat::execution_space>(sum, A_flat); - } else { - ViewSum::template execute(sum, A); - } - Kokkos::fence(); -} - -template -void parallel_sum(const ExecSpace& space, - typename Kokkos::ViewTraits::value_type& sum, - const Kokkos::View A) { - using ViewtypeA = Kokkos::View; - space.fence(); - if (A.span_is_contiguous()) { - - using ViewTypeFlat = Kokkos::View< - typename ViewtypeA::value_type*, Kokkos::LayoutRight, - Kokkos::Device>, - Kokkos::MemoryTraits<0>>; - - ViewTypeFlat A_flat(A.data(), A.size()); - ViewSum::template execute< - typename ViewTypeFlat::execution_space>(sum, A_flat, space); - } else { - ViewSum::template execute(sum, A, space); - } - space.fence(); -} - -template -void parallel_add(Kokkos::View A, - typename Kokkos::ViewTraits::const_value_type b) { - using ViewtypeA = Kokkos::View; - Kokkos::fence(); - if (A.span_is_contiguous()) { - - using ViewTypeFlat = Kokkos::View< - typename ViewtypeA::value_type*, Kokkos::LayoutRight, - Kokkos::Device>, - Kokkos::MemoryTraits<0>>; - - ViewTypeFlat A_flat(A.data(), A.size()); - ViewAdd::template execute< - typename ViewTypeFlat::execution_space>(A_flat, b); - } else { - ViewAdd::template execute(A, b); - } - Kokkos::fence(); -} - -template -void parallel_add(const ExecSpace& space, Kokkos::View A, - typename Kokkos::ViewTraits::const_value_type b) { - using ViewtypeA = Kokkos::View; - space.fence(); - if (A.span_is_contiguous()) { - - using ViewTypeFlat = Kokkos::View< - typename ViewtypeA::value_type*, Kokkos::LayoutRight, - Kokkos::Device>, - Kokkos::MemoryTraits<0>>; - - ViewTypeFlat A_flat(A.data(), A.size()); - ViewAdd::template execute< - typename ViewTypeFlat::execution_space>(A_flat, b, space); - } else { - ViewAdd::template execute(A, b, space); - } - space.fence(); -} - -template -void parallel_add(Kokkos::View A, const Kokkos::View B) { - using ViewtypeA = Kokkos::View; - using ViewtypeA = Kokkos::View; - Kokkos::fence(); - - ViewAdd::template executeView(A, B); - - Kokkos::fence(); -} - -} // namespace kokkos_builtin_derivative - -#endif \ No newline at end of file