10 #ifndef TPETRA_DETAILS_TEMPVIEWUTILS_HPP
11 #define TPETRA_DETAILS_TEMPVIEWUTILS_HPP
13 #include "Kokkos_Core.hpp"
23 template<
typename MemorySpace>
26 enum :
bool {value =
false};
30 struct AlwaysMPISafe<Kokkos::HostSpace>
32 enum :
bool {value =
true};
35 #ifdef KOKKOS_ENABLE_CUDA
37 struct AlwaysMPISafe<Kokkos::CudaHostPinnedSpace>
39 enum :
bool {value =
true};
43 #ifdef KOKKOS_ENABLE_HIP
45 struct AlwaysMPISafe<Kokkos::HIPHostPinnedSpace>
47 enum :
bool {value =
true};
52 template<
typename View1,
typename View2>
55 using L1 =
typename View1::array_layout;
56 using L2 =
typename View2::array_layout;
57 enum :
bool {EitherLeft = std::is_same<L1, Kokkos::LayoutLeft>::value || std::is_same<L2, Kokkos::LayoutLeft>::value};
58 enum :
bool {BothStride = std::is_same<L1, Kokkos::LayoutStride>::value && std::is_same<L2, Kokkos::LayoutStride>::value};
59 using type =
typename std::conditional<EitherLeft || BothStride, Kokkos::LayoutLeft, Kokkos::LayoutRight>::type;
63 template<typename SrcView, typename Layout, typename std::enable_if<!std::is_same<typename SrcView::array_layout, Layout>::value>::type* =
nullptr>
64 Kokkos::View<typename SrcView::data_type, Layout, typename SrcView::device_type>
65 toLayout(
const SrcView& src)
67 static_assert(!std::is_same<Kokkos::LayoutStride, Layout>::value,
68 "TempView::toLayout: Layout must be contiguous (not LayoutStride)");
69 Layout layout(src.extent(0), src.extent(1));
70 Kokkos::View<typename SrcView::non_const_data_type, Layout, typename SrcView::device_type> dst(Kokkos::ViewAllocateWithoutInitializing(src.label()), layout);
75 template<typename SrcView, typename Layout, typename std::enable_if<std::is_same<typename SrcView::array_layout, Layout>::value>::type* =
nullptr>
76 Kokkos::View<typename SrcView::data_type, Layout, typename SrcView::device_type>
77 toLayout(
const SrcView& src)
79 if(src.span_is_contiguous())
86 Layout layout(src.extent(0), src.extent(1));
87 Kokkos::View<typename SrcView::non_const_data_type, Layout, typename SrcView::device_type>
88 result(Kokkos::ViewAllocateWithoutInitializing(src.label()), layout);
97 template<typename SrcView, bool AssumeGPUAware, typename = typename std::enable_if<AssumeGPUAware || AlwaysMPISafe<typename SrcView::memory_space>::value>::type>
99 toMPISafe(
const SrcView& src)
101 using SrcLayout =
typename SrcView::array_layout;
102 static_assert(!std::is_same<SrcLayout, Kokkos::LayoutStride>::value,
"toMPISafe requires that SrcView is contiguous");
103 return toLayout<SrcView, SrcLayout>(src);
106 template<typename SrcView, bool AssumeGPUAware, typename = typename std::enable_if<!(AssumeGPUAware || AlwaysMPISafe<typename SrcView::memory_space>::value)>::type>
107 decltype(Kokkos::create_mirror_view_and_copy(std::declval<Kokkos::HostSpace>(), std::declval<SrcView>()))
108 toMPISafe(
const SrcView& src)
110 using SrcLayout =
typename SrcView::array_layout;
111 static_assert(!std::is_same<SrcLayout, Kokkos::LayoutStride>::value,
"toMPISafe requires that SrcView is contiguous");
112 auto srcContig = toLayout<SrcView, SrcLayout>(src);
113 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...