42#ifndef TPETRA_DETAILS_TEMPVIEWUTILS_HPP
43#define TPETRA_DETAILS_TEMPVIEWUTILS_HPP
45#include "Kokkos_Core.hpp"
55template<
typename MemorySpace>
58 enum :
bool {value =
false};
62struct AlwaysMPISafe<Kokkos::HostSpace>
64 enum :
bool {value =
true};
67#ifdef KOKKOS_ENABLE_CUDA
69struct AlwaysMPISafe<Kokkos::CudaHostPinnedSpace>
71 enum :
bool {value =
true};
75#ifdef KOKKOS_ENABLE_HIP
77struct AlwaysMPISafe<Kokkos::Experimental::HIPHostPinnedSpace>
79 enum :
bool {value =
true};
84template<
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};
90enum :
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;
95template<typename SrcView, typename Layout, typename std::enable_if<!std::is_same<typename SrcView::array_layout, Layout>::value>::type* =
nullptr>
96Kokkos::View<typename SrcView::data_type, Layout, typename SrcView::device_type>
97toLayout(
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);
103 Kokkos::deep_copy(dst, src);
107template<typename SrcView, typename Layout, typename std::enable_if<std::is_same<typename SrcView::array_layout, Layout>::value>::type* =
nullptr>
108Kokkos::View<typename SrcView::data_type, Layout, typename SrcView::device_type>
109toLayout(
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);
121 Kokkos::deep_copy(result, src);
129template<typename SrcView, bool AssumeGPUAware, typename = typename std::enable_if<AssumeGPUAware || AlwaysMPISafe<typename SrcView::memory_space>::value>::type>
131toMPISafe(
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);
138template<
typename SrcView,
bool AssumeGPUAware,
typename =
typename std::enable_if<!(AssumeGPUAware || AlwaysMPISafe<
typename SrcView::memory_space>::value)>::type>
139decltype(Kokkos::create_mirror_view_and_copy(std::declval<Kokkos::HostSpace>(), std::declval<SrcView>()))
140toMPISafe(
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);
Declaration of Tpetra::Details::isInterComm.
Implementation details of Tpetra.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Get the contiguous layout that matches as many of the given views as possible. If neither or both arg...