42 #ifndef TPETRA_DETAILS_TEMPVIEWUTILS_HPP
43 #define TPETRA_DETAILS_TEMPVIEWUTILS_HPP
45 #include "Kokkos_Core.hpp"
55 template<
typename MemorySpace>
58 enum :
bool {value =
false};
62 struct AlwaysMPISafe<Kokkos::HostSpace>
64 enum :
bool {value =
true};
67 #ifdef KOKKOS_ENABLE_CUDA
69 struct AlwaysMPISafe<Kokkos::CudaHostPinnedSpace>
71 enum :
bool {value =
true};
75 #ifdef KOKKOS_ENABLE_HIP
77 struct AlwaysMPISafe<Kokkos::HIPHostPinnedSpace>
79 enum :
bool {value =
true};
84 template<
typename View1,
typename View2>
87 using L1 =
typename View1::array_layout;
88 using L2 =
typename View2::array_layout;
89 enum :
bool {EitherLeft = std::is_same<L1, Kokkos::LayoutLeft>::value || std::is_same<L2, Kokkos::LayoutLeft>::value};
90 enum :
bool {BothStride = std::is_same<L1, Kokkos::LayoutStride>::value && std::is_same<L2, Kokkos::LayoutStride>::value};
91 using type =
typename std::conditional<EitherLeft || BothStride, Kokkos::LayoutLeft, Kokkos::LayoutRight>::type;
95 template<typename SrcView, typename Layout, typename std::enable_if<!std::is_same<typename SrcView::array_layout, Layout>::value>::type* =
nullptr>
96 Kokkos::View<typename SrcView::data_type, Layout, typename SrcView::device_type>
97 toLayout(
const SrcView& src)
99 static_assert(!std::is_same<Kokkos::LayoutStride, Layout>::value,
100 "TempView::toLayout: Layout must be contiguous (not LayoutStride)");
101 Layout layout(src.extent(0), src.extent(1));
102 Kokkos::View<typename SrcView::non_const_data_type, Layout, typename SrcView::device_type> dst(Kokkos::ViewAllocateWithoutInitializing(src.label()), layout);
107 template<typename SrcView, typename Layout, typename std::enable_if<std::is_same<typename SrcView::array_layout, Layout>::value>::type* =
nullptr>
108 Kokkos::View<typename SrcView::data_type, Layout, typename SrcView::device_type>
109 toLayout(
const SrcView& src)
111 if(src.span_is_contiguous())
118 Layout layout(src.extent(0), src.extent(1));
119 Kokkos::View<typename SrcView::non_const_data_type, Layout, typename SrcView::device_type>
120 result(Kokkos::ViewAllocateWithoutInitializing(src.label()), layout);
129 template<typename SrcView, bool AssumeGPUAware, typename = typename std::enable_if<AssumeGPUAware || AlwaysMPISafe<typename SrcView::memory_space>::value>::type>
131 toMPISafe(
const SrcView& src)
133 using SrcLayout =
typename SrcView::array_layout;
134 static_assert(!std::is_same<SrcLayout, Kokkos::LayoutStride>::value,
"toMPISafe requires that SrcView is contiguous");
135 return toLayout<SrcView, SrcLayout>(src);
138 template<typename SrcView, bool AssumeGPUAware, typename = typename std::enable_if<!(AssumeGPUAware || AlwaysMPISafe<typename SrcView::memory_space>::value)>::type>
139 decltype(Kokkos::create_mirror_view_and_copy(std::declval<Kokkos::HostSpace>(), std::declval<SrcView>()))
140 toMPISafe(
const SrcView& src)
142 using SrcLayout =
typename SrcView::array_layout;
143 static_assert(!std::is_same<SrcLayout, Kokkos::LayoutStride>::value,
"toMPISafe requires that SrcView is contiguous");
144 auto srcContig = toLayout<SrcView, SrcLayout>(src);
145 return Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), srcContig);
void deep_copy(MultiVector< DS, DL, DG, DN > &dst, const MultiVector< SS, SL, SG, SN > &src)
Copy the contents of the MultiVector src into dst.
Declaration of Tpetra::Details::isInterComm.
Get the contiguous layout that matches as many of the given views as possible. If neither or both arg...