10 #ifndef TPETRA_DETAILS_CREATEMIRRORVIEW_HPP
11 #define TPETRA_DETAILS_CREATEMIRRORVIEW_HPP
13 #include "TpetraCore_config.h"
14 #include "Teuchos_Array.hpp"
15 #include "Teuchos_ArrayView.hpp"
18 #include "Kokkos_Core.hpp"
37 template <
class ValueType,
38 class OutputDeviceType,
39 const bool constInput = std::is_const<ValueType>::value,
40 const bool sameAsHost =
41 std::is_same<Kokkos::HostSpace,
42 typename OutputDeviceType::memory_space>::value>
43 class CreateMirrorViewFromUnmanagedHostArray {
45 typedef Kokkos::View<ValueType*, OutputDeviceType> output_view_type;
46 typedef Kokkos::View<ValueType*,
47 typename output_view_type::array_layout,
50 static output_view_type
51 doIt(ValueType* inPtr,
53 const bool copy =
true,
54 const char label[] =
"");
59 template <
class ValueType,
60 class OutputDeviceType,
61 const bool constInput>
62 class CreateMirrorViewFromUnmanagedHostArray<ValueType, OutputDeviceType, constInput, true> {
64 typedef Kokkos::View<ValueType*, OutputDeviceType> output_view_type;
65 typedef Kokkos::View<ValueType*,
typename output_view_type::array_layout,
68 static output_view_type
69 doIt(ValueType* inPtr,
73 static_assert(std::is_same<
typename OutputDeviceType::memory_space,
74 Kokkos::HostSpace>::value,
75 "OutputDeviceType::memory_space must be the same as "
76 "Kokkos::HostSpace in order to use this specialization. "
77 "Please report this bug to the Tpetra developers.");
78 return output_view_type(inPtr, inSize);
84 template <
class ValueType,
85 class OutputDeviceType>
86 class CreateMirrorViewFromUnmanagedHostArray<ValueType, OutputDeviceType, true, false> {
88 typedef Kokkos::View<ValueType*, OutputDeviceType> output_view_type;
89 typedef Kokkos::View<ValueType*,
typename output_view_type::array_layout,
92 static output_view_type
93 doIt(ValueType* inPtr,
95 const bool copy =
true,
96 const char label[] =
"") {
97 using Kokkos::view_alloc;
98 using Kokkos::WithoutInitializing;
99 static_assert(std::is_const<ValueType>::value,
100 "ValueType must be const "
101 "in order to use this specialization. Please report this "
102 "bug to the Tpetra developers.");
103 static_assert(!std::is_same<typename OutputDeviceType::memory_space, Kokkos::HostSpace>::value,
104 "OutputDeviceType::memory_space must not be the same as "
105 "Kokkos::HostSpace in order to use this specialization. "
106 "Please report this bug to the Tpetra developers.");
107 input_view_type inView(inPtr, inSize);
109 typedef typename output_view_type::non_const_type nc_output_view_type;
110 nc_output_view_type outView_nc;
116 outView_nc = nc_output_view_type(view_alloc(std::string(label)), inSize);
119 outView_nc = nc_output_view_type(view_alloc(std::string(label), WithoutInitializing), inSize);
121 using execution_space =
typename nc_output_view_type::execution_space;
130 template <
class ValueType,
131 class OutputDeviceType>
132 class CreateMirrorViewFromUnmanagedHostArray<ValueType, OutputDeviceType, false, false> {
134 typedef Kokkos::View<ValueType*, OutputDeviceType> output_view_type;
135 typedef Kokkos::View<ValueType*,
typename output_view_type::array_layout,
138 static output_view_type
139 doIt(ValueType* inPtr,
141 const bool copy =
true,
142 const char label[] =
"") {
143 typedef typename OutputDeviceType::memory_space out_mem_space;
144 typedef typename OutputDeviceType::execution_space out_exec_space;
145 static_assert(!std::is_const<ValueType>::value,
146 "ValueType must not be "
147 "const in order to use this specialization. Please report "
148 "this bug to the Tpetra developers.");
149 static_assert(!std::is_same<out_mem_space, Kokkos::HostSpace>::value,
150 "OutputDeviceType::memory_space must not be the same as "
151 "Kokkos::HostSpace in order to use this specialization. "
152 "Please report this bug to the Tpetra developers.");
153 input_view_type inView(inPtr, inSize);
154 output_view_type outView =
155 Kokkos::create_mirror_view(out_mem_space(), inView);
173 template <
class ValueType,
class OutputDeviceType>
174 typename Impl::CreateMirrorViewFromUnmanagedHostArray<ValueType, OutputDeviceType>::output_view_type
178 const bool copy =
true,
179 const char label[] =
"") {
180 typedef Impl::CreateMirrorViewFromUnmanagedHostArray<ValueType, OutputDeviceType> impl_type;
181 return impl_type::doIt(inPtr, inSize, copy, label);
187 #endif // TPETRA_DETAILS_CREATEMIRRORVIEW_HPP
Impl::CreateMirrorViewFromUnmanagedHostArray< ValueType, OutputDeviceType >::output_view_type create_mirror_view_from_raw_host_array(const OutputDeviceType &, ValueType *inPtr, const size_t inSize, const bool copy=true, const char label[]="")
Variant of Kokkos::create_mirror_view that takes a raw host 1-d array as input.
Import KokkosSparse::OrdinalTraits, a traits class for "invalid" (flag) values of integer types...
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.
Declare and define the functions Tpetra::Details::computeOffsetsFromCounts and Tpetra::computeOffsets...