44 #ifndef TPETRA_DETAILS_COPYCONVERT_HPP 45 #define TPETRA_DETAILS_COPYCONVERT_HPP 52 #include "TpetraCore_config.h" 53 #include "Kokkos_Core.hpp" 56 #include <type_traits> 71 template<
class OutputViewType,
73 class CopyConvertFunctor {
79 typedef typename std::decay<decltype (dst_[0])>::type output_type;
80 typedef typename OutputViewType::size_type index_type;
82 CopyConvertFunctor (
const OutputViewType& dst,
const InputViewType& src) :
89 static_assert (Kokkos::Impl::VerifyExecutionCanAccessMemorySpace<
90 typename OutputViewType::memory_space,
91 typename InputViewType::memory_space>::value,
92 "CopyConvertFunctor (implements copyConvert): Output " 93 "View's space must be able to access the input View's " 95 static_assert (OutputViewType::Rank == 1 && InputViewType::Rank == 1,
96 "CopyConvertFunctor (implements copyConvert): " 97 "OutputViewType and InputViewType must be rank-1 " 98 "Kokkos::View specializations.");
101 KOKKOS_INLINE_FUNCTION
void 102 operator () (
const index_type& i)
const {
107 dst_(i) = output_type (src_(i));
132 template<
class OutputViewType,
134 const bool canUseKokkosDeepCopy =
135 std::is_same<
typename OutputViewType::array_layout,
136 typename InputViewType::array_layout>::value &&
137 std::is_same<
typename OutputViewType::non_const_value_type,
138 typename InputViewType::non_const_value_type>::value,
139 const bool outputExecSpaceCanAccessInputMemSpace =
140 Kokkos::Impl::VerifyExecutionCanAccessMemorySpace<
141 typename OutputViewType::memory_space,
142 typename InputViewType::memory_space>::value>
143 struct CopyConvertImpl {
144 static void run (
const OutputViewType& dst,
const InputViewType& src);
154 template<
class OutputViewType,
156 const bool outputExecSpaceCanAccessInputMemSpace>
157 struct CopyConvertImpl<OutputViewType, InputViewType,
158 true, outputExecSpaceCanAccessInputMemSpace> {
159 static void run (
const OutputViewType& dst,
const InputViewType& src) {
160 static_assert (std::is_same<
typename OutputViewType::non_const_value_type,
161 typename InputViewType::non_const_value_type>::value,
162 "CopyConvertImpl (implementation of copyConvert): In order" 163 " to call this specialization, the input and output must " 164 "use the same offset type.");
165 static_assert (OutputViewType::Rank == 1 && InputViewType::Rank == 1,
166 "CopyConvertImpl (implementation of copyConvert): " 167 "OutputViewType and InputViewType must be rank-1 " 168 "Kokkos::View specializations.");
169 static_assert (std::is_same<
typename OutputViewType::array_layout,
170 typename InputViewType::array_layout>::value,
171 "CopyConvertImpl (implementation of copyConvert): In order" 172 " to call this specialization, src and dst must have the " 173 "the same array_layout.");
183 template<
class OutputViewType,
185 struct CopyConvertImpl<OutputViewType,
189 static void run (
const OutputViewType& dst,
const InputViewType& src) {
190 static_assert (! std::is_same<
typename OutputViewType::non_const_value_type,
191 typename InputViewType::non_const_value_type>::value,
192 "CopyConvertImpl (implementation of copyConvert): We " 193 "should not be calling this specialization if the entries " 194 "of OutputViewType and InputViewType have the same type.");
195 static_assert (OutputViewType::Rank == 1 && InputViewType::Rank == 1,
196 "CopyConvertImpl (implementation of copyConvert): " 197 "OutputViewType and InputViewType must both be rank-1 " 198 "Kokkos::View types.");
202 static_assert (Kokkos::Impl::VerifyExecutionCanAccessMemorySpace<
203 typename OutputViewType::memory_space,
204 typename InputViewType::memory_space>::value,
205 "CopyConvertImpl (implements copyConvert): In order to " 206 "call this specialization, the output View's space must " 207 "be able to access the input View's memory space.");
209 typedef CopyConvertFunctor<OutputViewType, InputViewType> functor_type;
210 typedef typename OutputViewType::execution_space execution_space;
211 typedef typename OutputViewType::size_type index_type;
212 typedef Kokkos::RangePolicy<execution_space, index_type> range_type;
213 Kokkos::parallel_for (range_type (0, dst.dimension_0 ()),
214 functor_type (dst, src));
235 template<
class OutputViewType,
237 struct CopyConvertImpl<OutputViewType,
241 static void run (
const OutputViewType& dst,
const InputViewType& src) {
242 const bool canUseKokkosDeepCopy =
243 std::is_same<
typename OutputViewType::array_layout,
244 typename InputViewType::array_layout>::value &&
245 std::is_same<
typename OutputViewType::non_const_value_type,
246 typename InputViewType::non_const_value_type>::value;
247 static_assert (! canUseKokkosDeepCopy,
248 "CopyConvertImpl (implementation of copyConvert): We " 249 "should not be calling this specialization if we could " 250 "have used Kokkos::deep_copy instead.");
251 static_assert (OutputViewType::Rank == 1 && InputViewType::Rank == 1,
252 "CopyConvertImpl (implementation of copyConvert): " 253 "OutputViewType and InputViewType must both be rank-1 " 254 "Kokkos::View types.");
256 using Kokkos::ViewAllocateWithoutInitializing;
257 typedef Kokkos::View<
typename InputViewType::non_const_value_type*,
258 typename InputViewType::array_layout,
259 typename OutputViewType::device_type> output_space_copy_type;
260 output_space_copy_type
261 outputSpaceCopy (ViewAllocateWithoutInitializing (
"outputSpace"),
267 typedef CopyConvertFunctor<OutputViewType,
268 output_space_copy_type> functor_type;
269 typedef typename OutputViewType::execution_space execution_space;
270 typedef typename OutputViewType::size_type index_type;
271 typedef Kokkos::RangePolicy<execution_space, index_type> range_type;
272 Kokkos::parallel_for (range_type (0, dst.dimension_0 ()),
273 functor_type (dst, outputSpaceCopy));
286 template<
class OutputViewType,
290 const InputViewType& src)
292 static_assert (Kokkos::Impl::is_view<OutputViewType>::value,
293 "OutputViewType (the type of dst) must be a Kokkos::View.");
294 static_assert (Kokkos::Impl::is_view<InputViewType>::value,
295 "InputViewType (the type of src) must be a Kokkos::View.");
296 static_assert (std::is_same<
typename OutputViewType::value_type,
297 typename OutputViewType::non_const_value_type>::value,
298 "OutputViewType (the type of dst) must be a nonconst Kokkos::View.");
299 static_assert (static_cast<int> (OutputViewType::rank) == 1,
300 "OutputViewType (the type of dst) must be a rank-1 Kokkos::View.");
301 static_assert (static_cast<int> (InputViewType::rank) == 1,
302 "InputViewType (the type of src) must be a rank-1 Kokkos::View.");
303 if (dst.dimension_0 () != src.dimension_0 ()) {
304 std::ostringstream os;
305 os <<
"Tpetra::Details::copyConvert: " 306 <<
"dst.dimension_0() = " << dst.dimension_0 ()
307 <<
" != src.dimension_0() = " << src.dimension_0 ()
309 throw std::invalid_argument (os.str ());
312 typedef typename OutputViewType::non_const_type output_view_type;
313 typedef typename InputViewType::const_type input_view_type;
314 CopyConvertImpl<output_view_type, input_view_type>::run (dst, src);
320 #endif // TPETRA_DETAILS_COPYCONVERT_HPP Namespace Tpetra contains the class and methods constituting the Tpetra library.
void deep_copy(MultiVector< DS, DL, DG, DN, dstClassic > &dst, const MultiVector< SS, SL, SG, SN, srcClassic > &src)
Copy the contents of the MultiVector src into dst.
Implementation details of Tpetra.
void copyConvert(const OutputViewType &dst, const InputViewType &src)
Copy values from the 1-D Kokkos::View src, to the 1-D Kokkos::View dst, of the same length...