42 #ifndef TPETRA_DETAILS_DUALVIEWUTIL_HPP
43 #define TPETRA_DETAILS_DUALVIEWUTIL_HPP
45 #include "TpetraCore_config.h"
46 #include "Kokkos_DualView.hpp"
47 #include "Teuchos_ArrayView.hpp"
62 decltype (Kokkos::view_alloc (label, Kokkos::WithoutInitializing));
68 template<
class ElementType,
class DeviceType>
71 (Kokkos::DualView<ElementType*, DeviceType>& dv,
72 const typename Kokkos::DualView<ElementType*, DeviceType>::t_host& hostView)
74 using execution_space =
typename DeviceType::execution_space;
75 using dual_view_type = Kokkos::DualView<ElementType*, DeviceType>;
77 if (dv.extent (0) == hostView.extent (0)) {
79 dv.clear_sync_state ();
85 auto devView = Kokkos::create_mirror_view (DeviceType (), hostView);
88 dv = dual_view_type (devView, hostView);
92 template<
class ElementType,
class DeviceType>
94 makeDualViewFromArrayView (Kokkos::DualView<ElementType*, DeviceType>& dv,
95 const Teuchos::ArrayView<const ElementType>& av,
96 const std::string& label)
98 using execution_space =
typename DeviceType::execution_space;
99 using dual_view_type = Kokkos::DualView<ElementType*, DeviceType>;
100 using host_view_type =
typename dual_view_type::t_host;
101 using const_host_view_type =
typename host_view_type::const_type;
103 const auto size = av.size ();
104 const ElementType* ptr = (size == 0) ?
nullptr : av.getRawPtr ();
105 const_host_view_type inView (ptr, size);
113 template<
class ElementType,
class DeviceType>
115 makeDualViewFromVector (Kokkos::DualView<ElementType*, DeviceType>& dv,
116 const std::vector<ElementType>& vec,
117 const std::string& label)
119 using dual_view_type = Kokkos::DualView<ElementType*, DeviceType>;
120 using execution_space =
typename DeviceType::execution_space;
121 using host_view_type =
typename dual_view_type::t_host;
122 using const_host_view_type =
typename host_view_type::const_type;
124 const auto size = vec.size ();
125 const ElementType* ptr = (size == 0) ?
nullptr : vec.data ();
126 const_host_view_type inView (ptr, size);
134 template<
class ElementType,
class DeviceType>
136 printDualView (std::ostream& out,
137 const Kokkos::DualView<ElementType*, DeviceType>& dv,
138 const std::string& name)
141 const size_t size = size_t (dv.extent (0));
142 const auto hostView = dv.view_host ();
145 for (
size_t k = 0; k < size; ++k) {
147 if (k +
size_t (1) < size) {
158 #endif // TPETRA_DETAILS_DUALVIEWUTIL_HPP
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.
auto view_alloc_no_init(const std::string &label) ->
Use in place of the string label as the first argument of Kokkos::View's constructor, in case you want to allocate without initializing.
void makeDualViewFromOwningHostView(Kokkos::DualView< ElementType *, DeviceType > &dv, const typename Kokkos::DualView< ElementType *, DeviceType >::t_host &hostView)
Initialize dv such that its host View is hostView.