10#ifndef TPETRA_DETAILS_TEMPVIEWUTILS_HPP
11#define TPETRA_DETAILS_TEMPVIEWUTILS_HPP
13#include "Kokkos_Core.hpp"
20template <
typename MemorySpace>
22 enum :
bool { value =
false };
26struct AlwaysMPISafe<Kokkos::HostSpace> {
27 enum :
bool { value =
true };
30#ifdef KOKKOS_ENABLE_CUDA
32struct AlwaysMPISafe<Kokkos::CudaHostPinnedSpace> {
33 enum :
bool { value =
true };
37#ifdef KOKKOS_ENABLE_HIP
39struct AlwaysMPISafe<Kokkos::HIPHostPinnedSpace> {
40 enum :
bool { value =
true };
45template <
typename View1,
typename View2>
47 using L1 =
typename View1::array_layout;
48 using L2 =
typename View2::array_layout;
49 enum :
bool { EitherLeft = std::is_same<L1, Kokkos::LayoutLeft>::value || std::is_same<L2, Kokkos::LayoutLeft>::value };
50 enum :
bool { BothStride = std::is_same<L1, Kokkos::LayoutStride>::value && std::is_same<L2, Kokkos::LayoutStride>::value };
51 using type =
typename std::conditional<EitherLeft || BothStride, Kokkos::LayoutLeft, Kokkos::LayoutRight>::type;
55template <typename SrcView, typename Layout, typename std::enable_if<!std::is_same<typename SrcView::array_layout, Layout>::value>::type* =
nullptr>
56Kokkos::View<typename SrcView::data_type, Layout, typename SrcView::device_type>
57toLayout(
const SrcView& src) {
58 static_assert(!std::is_same<Kokkos::LayoutStride, Layout>::value,
59 "TempView::toLayout: Layout must be contiguous (not LayoutStride)");
60 Layout layout(src.extent(0), src.extent(1));
61 Kokkos::View<typename SrcView::non_const_data_type, Layout, typename SrcView::device_type> dst(Kokkos::ViewAllocateWithoutInitializing(src.label()), layout);
62 Kokkos::deep_copy(dst, src);
66template <typename SrcView, typename Layout, typename std::enable_if<std::is_same<typename SrcView::array_layout, Layout>::value>::type* =
nullptr>
67Kokkos::View<typename SrcView::data_type, Layout, typename SrcView::device_type>
68toLayout(
const SrcView& src) {
69 if (src.span_is_contiguous()) {
73 Layout layout(src.extent(0), src.extent(1));
74 Kokkos::View<typename SrcView::non_const_data_type, Layout, typename SrcView::device_type>
75 result(Kokkos::ViewAllocateWithoutInitializing(src.label()), layout);
76 Kokkos::deep_copy(result, src);
84template <typename SrcView, bool AssumeGPUAware, typename = typename std::enable_if<AssumeGPUAware || AlwaysMPISafe<typename SrcView::memory_space>::value>::type>
86toMPISafe(
const SrcView& src) {
87 using SrcLayout =
typename SrcView::array_layout;
88 static_assert(!std::is_same<SrcLayout, Kokkos::LayoutStride>::value,
"toMPISafe requires that SrcView is contiguous");
89 return toLayout<SrcView, SrcLayout>(src);
92template <
typename SrcView,
bool AssumeGPUAware,
typename =
typename std::enable_if<!(AssumeGPUAware || AlwaysMPISafe<
typename SrcView::memory_space>::value)>::type>
93decltype(Kokkos::create_mirror_view_and_copy(std::declval<Kokkos::HostSpace>(), std::declval<SrcView>()))
94toMPISafe(
const SrcView& src) {
95 using SrcLayout =
typename SrcView::array_layout;
96 static_assert(!std::is_same<SrcLayout, Kokkos::LayoutStride>::value,
"toMPISafe requires that SrcView is contiguous");
97 auto srcContig = toLayout<SrcView, SrcLayout>(src);
98 return Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), srcContig);
Declaration of Tpetra::Details::isInterComm.
Nonmember function that computes a residual Computes R = B - A * X.
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...