From 3a93ddd4a3a5f12693b99e5ffba58b8e602281cb Mon Sep 17 00:00:00 2001 From: Eric Phipps Date: Wed, 10 Nov 2021 14:22:39 -0700 Subject: [PATCH 1/3] Kokkos: Constrain local_deep_copy_contiguous impl to "normal" views The implementation of local_deep_copy_contiguous(view,value) does not work for special views like Sacado. Constrain the implementation here to only be valid for "normal" views, so it can be overloaded by Sacado. --- packages/kokkos/core/src/Kokkos_CopyViews.hpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/kokkos/core/src/Kokkos_CopyViews.hpp b/packages/kokkos/core/src/Kokkos_CopyViews.hpp index 16946dd602b5..3b7c7590e833 100644 --- a/packages/kokkos/core/src/Kokkos_CopyViews.hpp +++ b/packages/kokkos/core/src/Kokkos_CopyViews.hpp @@ -2118,7 +2118,11 @@ void KOKKOS_INLINE_FUNCTION local_deep_copy( template void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( const TeamType& team, const View& dst, - typename ViewTraits::const_value_type& value) { + typename ViewTraits::const_value_type& value, + typename std::enable_if< + std::is_same< typename ViewTraits::specialize, + void>::value + >::type* = nullptr) { Kokkos::parallel_for(Kokkos::TeamThreadRange(team, dst.span()), [&](const int& i) { dst.data()[i] = value; }); } @@ -2126,7 +2130,11 @@ void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( template void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( const View& dst, - typename ViewTraits::const_value_type& value) { + typename ViewTraits::const_value_type& value, + typename std::enable_if< + std::is_same< typename ViewTraits::specialize, + void>::value + >::type* = nullptr) { for (size_t i = 0; i < dst.span(); ++i) { dst.data()[i] = value; } From ea2be869ec751dc1064d2dfc1bf425277443f631 Mon Sep 17 00:00:00 2001 From: Eric Phipps Date: Wed, 10 Nov 2021 14:25:13 -0700 Subject: [PATCH 2/3] Sacado: Overload local_deep_copy_contiguous() for Fad types --- packages/sacado/src/KokkosExp_View_Fad.hpp | 548 ++++++++++++++++++ .../sacado/test/UnitTests/Fad_KokkosTests.hpp | 127 ++++ 2 files changed, 675 insertions(+) diff --git a/packages/sacado/src/KokkosExp_View_Fad.hpp b/packages/sacado/src/KokkosExp_View_Fad.hpp index beec02ad0fd7..bb7faa39cdc8 100644 --- a/packages/sacado/src/KokkosExp_View_Fad.hpp +++ b/packages/sacado/src/KokkosExp_View_Fad.hpp @@ -185,6 +185,180 @@ create_mirror( } // namespace Kokkos +namespace Kokkos { +namespace Experimental { + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 1))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 2))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 3))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 4))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 5))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 6))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 7))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const TeamType& team, const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 1))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const TeamType& team, const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 2))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const TeamType& team, const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 3))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const TeamType& team, const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 4))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const TeamType& team, const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 5))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const TeamType& team, const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 6))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const TeamType& team, const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 7))>::type* = nullptr); + +} // namespace Experimental +} // namespace Kokkos + #include "Sacado_Traits.hpp" #include "Kokkos_Core.hpp" #include "Kokkos_LayoutContiguous.hpp" @@ -566,6 +740,380 @@ create_mirror(const Space& , const Kokkos::View & src } // namespace Kokkos +namespace Kokkos { +namespace Experimental { + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 1))>::type*) +{ + if (dst.data() == nullptr) + return; + + for (size_t i0 = 0; i0 < dst.extent(0); ++i0) + dst(i0) = value; +} + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 2))>::type*) +{ + if (dst.data() == nullptr) + return; + + for (size_t i0 = 0; i0 < dst.extent(0); ++i0) + for (size_t i1 = 0; i1 < dst.extent(1); ++i1) + dst(i0,i1) = value; +} + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 3))>::type*) +{ + if (dst.data() == nullptr) + return; + + for (size_t i0 = 0; i0 < dst.extent(0); ++i0) + for (size_t i1 = 0; i1 < dst.extent(1); ++i1) + for (size_t i2 = 0; i2 < dst.extent(2); ++i2) + dst(i0,i1,i2) = value; +} + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 4))>::type*) +{ + if (dst.data() == nullptr) + return; + + for (size_t i0 = 0; i0 < dst.extent(0); ++i0) + for (size_t i1 = 0; i1 < dst.extent(1); ++i1) + for (size_t i2 = 0; i2 < dst.extent(2); ++i2) + for (size_t i3 = 0; i3 < dst.extent(3); ++i3) + dst(i0,i1,i2,i3) = value; +} + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 5))>::type*) +{ + if (dst.data() == nullptr) + return; + + for (size_t i0 = 0; i0 < dst.extent(0); ++i0) + for (size_t i1 = 0; i1 < dst.extent(1); ++i1) + for (size_t i2 = 0; i2 < dst.extent(2); ++i2) + for (size_t i3 = 0; i3 < dst.extent(3); ++i3) + for (size_t i4 = 0; i4 < dst.extent(4); ++i4) + dst(i0,i1,i2,i3,i4) = value; +} + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 6))>::type*) +{ + if (dst.data() == nullptr) + return; + + for (size_t i0 = 0; i0 < dst.extent(0); ++i0) + for (size_t i1 = 0; i1 < dst.extent(1); ++i1) + for (size_t i2 = 0; i2 < dst.extent(2); ++i2) + for (size_t i3 = 0; i3 < dst.extent(3); ++i3) + for (size_t i4 = 0; i4 < dst.extent(4); ++i4) + for (size_t i5 = 0; i5 < dst.extent(5); ++i5) + dst(i0,i1,i2,i3,i4,i5) = value; +} + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 7))>::type*) +{ + if (dst.data() == nullptr) + return; + + for (size_t i0 = 0; i0 < dst.extent(0); ++i0) + for (size_t i1 = 0; i1 < dst.extent(1); ++i1) + for (size_t i2 = 0; i2 < dst.extent(2); ++i2) + for (size_t i3 = 0; i3 < dst.extent(3); ++i3) + for (size_t i4 = 0; i4 < dst.extent(4); ++i4) + for (size_t i5 = 0; i5 < dst.extent(5); ++i5) + for (size_t i6 = 0; i6 < dst.extent(6); ++i6) + dst(i0,i1,i2,i3,i4,i5,i6) = value; +} + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const TeamType& team, const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 1))>::type*) +{ + if (dst.data() == nullptr) + return; + + const size_t N = dst.extent(0); + + team.team_barrier(); + Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), + [&](const int& i) { dst(i) = value; }); + team.team_barrier(); +} + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const TeamType& team, const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 2))>::type*) +{ + if (dst.data() == nullptr) + return; + + const size_t N = dst.extent(0) * dst.extent(1); + + team.team_barrier(); + Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](const int& i) { + int i0 = i % dst.extent(0); + int i1 = i / dst.extent(0); + dst(i0, i1) = value; + }); + team.team_barrier(); +} + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const TeamType& team, const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 3))>::type*) +{ + if (dst.data() == nullptr) + return; + + const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2); + + team.team_barrier(); + Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](const int& i) { + int i0 = i % dst.extent(0); + int itmp = i / dst.extent(0); + int i1 = itmp % dst.extent(1); + int i2 = itmp / dst.extent(1); + dst(i0, i1, i2) = value; + }); + team.team_barrier(); +} + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const TeamType& team, const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 4))>::type*) +{ + if (dst.data() == nullptr) + return; + + const size_t N = + dst.extent(0) * dst.extent(1) * dst.extent(2) * dst.extent(3); + + team.team_barrier(); + Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](const int& i) { + int i0 = i % dst.extent(0); + int itmp = i / dst.extent(0); + int i1 = itmp % dst.extent(1); + itmp = itmp / dst.extent(1); + int i2 = itmp % dst.extent(2); + int i3 = itmp / dst.extent(2); + dst(i0, i1, i2, i3) = value; + }); + team.team_barrier(); +} + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const TeamType& team, const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 5))>::type*) +{ + if (dst.data() == nullptr) + return; + + const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) * + dst.extent(3) * dst.extent(4); + + team.team_barrier(); + Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](const int& i) { + int i0 = i % dst.extent(0); + int itmp = i / dst.extent(0); + int i1 = itmp % dst.extent(1); + itmp = itmp / dst.extent(1); + int i2 = itmp % dst.extent(2); + itmp = itmp / dst.extent(2); + int i3 = itmp % dst.extent(3); + int i4 = itmp / dst.extent(3); + dst(i0, i1, i2, i3, i4) = value; + }); + team.team_barrier(); +} + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const TeamType& team, const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 6))>::type*) +{ + if (dst.data() == nullptr) + return; + + const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) * + dst.extent(3) * dst.extent(4) * dst.extent(5); + + team.team_barrier(); + Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](const int& i) { + int i0 = i % dst.extent(0); + int itmp = i / dst.extent(0); + int i1 = itmp % dst.extent(1); + itmp = itmp / dst.extent(1); + int i2 = itmp % dst.extent(2); + itmp = itmp / dst.extent(2); + int i3 = itmp % dst.extent(3); + itmp = itmp / dst.extent(3); + int i4 = itmp % dst.extent(4); + int i5 = itmp / dst.extent(4); + dst(i0, i1, i2, i3, i4, i5) = value; + }); + team.team_barrier(); +} + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const TeamType& team, const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 7))>::type*) +{ + if (dst.data() == nullptr) + return; + + const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) * + dst.extent(3) * dst.extent(4) * dst.extent(5) * + dst.extent(6); + + team.team_barrier(); + Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](const int& i) { + int i0 = i % dst.extent(0); + int itmp = i / dst.extent(0); + int i1 = itmp % dst.extent(1); + itmp = itmp / dst.extent(1); + int i2 = itmp % dst.extent(2); + itmp = itmp / dst.extent(2); + int i3 = itmp % dst.extent(3); + itmp = itmp / dst.extent(3); + int i4 = itmp % dst.extent(4); + itmp = itmp / dst.extent(4); + int i5 = itmp % dst.extent(5); + int i6 = itmp / dst.extent(5); + dst(i0, i1, i2, i3, i4, i5, i6) = value; + }); + team.team_barrier(); +} + +} // namespace Experimental +} // namespace Kokkos + //---------------------------------------------------------------------------- namespace Kokkos { diff --git a/packages/sacado/test/UnitTests/Fad_KokkosTests.hpp b/packages/sacado/test/UnitTests/Fad_KokkosTests.hpp index da9bb6ae4252..c11c9b04d0b4 100644 --- a/packages/sacado/test/UnitTests/Fad_KokkosTests.hpp +++ b/packages/sacado/test/UnitTests/Fad_KokkosTests.hpp @@ -668,6 +668,131 @@ TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( } } +TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( + Kokkos_View_Fad, LocalDeepCopy, FadType, Layout, Device ) +{ + typedef Kokkos::View ViewType; + typedef Kokkos::View ScalarViewType; + typedef typename ViewType::size_type size_type; + typedef typename ViewType::HostMirror host_view_type; + typedef typename ScalarViewType::HostMirror host_scalar_view_type; + + const size_type num_rows = global_num_rows; + const size_type num_cols = global_num_cols; + const size_type num_slices = 10; + const size_type fad_size = global_fad_size; + + // Create and fill view + ViewType v; +#if defined (SACADO_DISABLE_FAD_VIEW_SPEC) + v = ViewType ("view", num_rows, num_cols, num_slices); +#else + v = ViewType ("view", num_rows, num_cols, num_slices, fad_size+1); +#endif + typename ViewType::array_type va = v; + Kokkos::deep_copy( va, 1.0 ); + + // Deep copy a constant Fad to the device + // Can't deep_copy directly because that doesn't work with DFad + FadType a(fad_size, 2.3456); + for (size_type i=0; i(0,num_rows), + KOKKOS_LAMBDA(const int i) + { + auto s = Kokkos::subview(v,i,Kokkos::ALL,Kokkos::ALL); + Kokkos::Experimental::local_deep_copy(s,a_view()); + }); + + // Copy back to host + host_view_type hv = Kokkos::create_mirror_view(v); + Kokkos::deep_copy(hv, a); + + // Check + success = true; + for (size_type i=0; i ViewType; + typedef Kokkos::View ScalarViewType; + typedef typename ViewType::size_type size_type; + typedef typename ViewType::HostMirror host_view_type; + typedef typename ScalarViewType::HostMirror host_scalar_view_type; + + const size_type num_rows = global_num_rows; + const size_type num_cols = global_num_cols; + const size_type num_slices = 10; + const size_type fad_size = global_fad_size; + + // Create and fill view + ViewType v; +#if defined (SACADO_DISABLE_FAD_VIEW_SPEC) + v = ViewType ("view", num_rows, num_cols, num_slices); +#else + v = ViewType ("view", num_rows, num_cols, num_slices, fad_size+1); +#endif + typename ViewType::array_type va = v; + Kokkos::deep_copy( va, 1.0 ); + + // Deep copy a constant Fad to the device + // Can't deep_copy directly because that doesn't work with DFad + FadType a(fad_size, 2.3456); + for (size_type i=0; i Policy; + static const size_type stride = Kokkos::ViewScalarStride::stride; + Kokkos::parallel_for(Policy(num_rows,Kokkos::AUTO,stride), + KOKKOS_LAMBDA(const typename Policy::member_type& team) + { + int i = team.league_rank(); + auto s = Kokkos::subview(v,i,Kokkos::ALL,Kokkos::ALL); + Kokkos::Experimental::local_deep_copy(team,s,a_view()); + }); + + // Copy back to host + host_view_type hv = Kokkos::create_mirror_view(v); + Kokkos::deep_copy(hv, a); + + // Check + success = true; + for (size_type i=0; i Date: Mon, 13 Nov 2023 11:27:49 -0700 Subject: [PATCH 3/3] Sacado: Add forward declarations of local_deep_copy_contiguous overloads --- packages/sacado/src/Kokkos_View_Fad_Fwd.hpp | 172 ++++++++++++++++++++ 1 file changed, 172 insertions(+) diff --git a/packages/sacado/src/Kokkos_View_Fad_Fwd.hpp b/packages/sacado/src/Kokkos_View_Fad_Fwd.hpp index 7a73d2509dec..7063e2206acc 100644 --- a/packages/sacado/src/Kokkos_View_Fad_Fwd.hpp +++ b/packages/sacado/src/Kokkos_View_Fad_Fwd.hpp @@ -223,6 +223,178 @@ as_view_of_rank_n(View); } +namespace Experimental { + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 1))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 2))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 3))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 4))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 5))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 6))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 7))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const TeamType& team, const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 1))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const TeamType& team, const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 2))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const TeamType& team, const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 3))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const TeamType& team, const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 4))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const TeamType& team, const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 5))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const TeamType& team, const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 6))>::type* = nullptr); + +template +void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous( + const TeamType& team, const View& dst, + typename ViewTraits::const_value_type& value, + typename std::enable_if<( + ( std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFad >::value + || + std::is_same< typename ViewTraits::specialize, + Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) + && (unsigned(ViewTraits::rank) == 7))>::type* = nullptr); + +} + } // namespace Kokkos #endif // defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)