42 #ifndef TPETRA_DETAILS_CREATEMIRRORVIEW_HPP
43 #define TPETRA_DETAILS_CREATEMIRRORVIEW_HPP
45 #include "TpetraCore_config.h"
46 #include "Teuchos_Array.hpp"
47 #include "Teuchos_ArrayView.hpp"
50 #include "Kokkos_Core.hpp"
69 template<
class ValueType,
70 class OutputDeviceType,
71 const bool constInput = std::is_const<ValueType>::value,
72 const bool sameAsHost =
73 std::is_same<Kokkos::HostSpace,
74 typename OutputDeviceType::memory_space>::value>
75 class CreateMirrorViewFromUnmanagedHostArray {
77 typedef Kokkos::View<ValueType*, OutputDeviceType> output_view_type;
78 typedef Kokkos::View<ValueType*,
79 typename output_view_type::array_layout,
80 Kokkos::HostSpace> input_view_type;
81 static output_view_type
82 doIt (ValueType* inPtr,
84 const bool copy =
true,
85 const char label[] =
"");
90 template<
class ValueType,
91 class OutputDeviceType,
92 const bool constInput>
93 class CreateMirrorViewFromUnmanagedHostArray<ValueType, OutputDeviceType, constInput, true> {
95 typedef Kokkos::View<ValueType*, OutputDeviceType> output_view_type;
96 typedef Kokkos::View<ValueType*,
typename output_view_type::array_layout,
97 Kokkos::HostSpace> input_view_type;
98 static output_view_type
99 doIt (ValueType* inPtr,
104 static_assert (std::is_same<
typename OutputDeviceType::memory_space,
105 Kokkos::HostSpace>::value,
106 "OutputDeviceType::memory_space must be the same as "
107 "Kokkos::HostSpace in order to use this specialization. "
108 "Please report this bug to the Tpetra developers.");
109 return output_view_type (inPtr, inSize);
115 template<
class ValueType,
116 class OutputDeviceType>
117 class CreateMirrorViewFromUnmanagedHostArray<ValueType, OutputDeviceType, true, false> {
119 typedef Kokkos::View<ValueType*, OutputDeviceType> output_view_type;
120 typedef Kokkos::View<ValueType*,
typename output_view_type::array_layout,
121 Kokkos::HostSpace> input_view_type;
122 static output_view_type
123 doIt (ValueType* inPtr,
125 const bool copy =
true,
126 const char label[] =
"")
128 using Kokkos::view_alloc;
129 using Kokkos::WithoutInitializing;
130 static_assert (std::is_const<ValueType>::value,
"ValueType must be const "
131 "in order to use this specialization. Please report this "
132 "bug to the Tpetra developers.");
133 static_assert (! std::is_same<typename OutputDeviceType::memory_space, Kokkos::HostSpace>::value,
134 "OutputDeviceType::memory_space must not be the same as "
135 "Kokkos::HostSpace in order to use this specialization. "
136 "Please report this bug to the Tpetra developers.");
137 input_view_type inView (inPtr, inSize);
139 typedef typename output_view_type::non_const_type nc_output_view_type;
140 nc_output_view_type outView_nc;
146 outView_nc = nc_output_view_type (view_alloc (std::string (label)), inSize);
150 outView_nc = nc_output_view_type (view_alloc (std::string (label), WithoutInitializing), inSize);
159 template<
class ValueType,
160 class OutputDeviceType>
161 class CreateMirrorViewFromUnmanagedHostArray<ValueType, OutputDeviceType, false, false> {
163 typedef Kokkos::View<ValueType*, OutputDeviceType> output_view_type;
164 typedef Kokkos::View<ValueType*,
typename output_view_type::array_layout,
165 Kokkos::HostSpace> input_view_type;
166 static output_view_type
167 doIt (ValueType* inPtr,
169 const bool copy =
true,
170 const char label[] =
"")
172 typedef typename OutputDeviceType::memory_space out_mem_space;
173 static_assert (! std::is_const<ValueType>::value,
"ValueType must not be "
174 "const in order to use this specialization. Please report "
175 "this bug to the Tpetra developers.");
176 static_assert (! std::is_same<out_mem_space, Kokkos::HostSpace>::value,
177 "OutputDeviceType::memory_space must not be the same as "
178 "Kokkos::HostSpace in order to use this specialization. "
179 "Please report this bug to the Tpetra developers.");
180 input_view_type inView (inPtr, inSize);
181 output_view_type outView =
182 Kokkos::create_mirror_view (out_mem_space (), inView);
199 template<
class ValueType,
class OutputDeviceType>
200 typename Impl::CreateMirrorViewFromUnmanagedHostArray<ValueType, OutputDeviceType>::output_view_type
204 const bool copy =
true,
205 const char label[] =
"")
207 typedef Impl::CreateMirrorViewFromUnmanagedHostArray<ValueType, OutputDeviceType> impl_type;
208 return impl_type::doIt (inPtr, inSize, copy, label);
214 #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 function Tpetra::Details::computeOffsetsFromCounts, an implementation detail o...