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 dual_view_type = Kokkos::DualView<ElementType*, DeviceType>;
76 if (dv.extent (0) == hostView.extent (0)) {
78 dv.clear_sync_state ();
84 auto devView = Kokkos::create_mirror_view (DeviceType (), hostView);
86 dv = dual_view_type (devView, hostView);
90 template<
class ElementType,
class DeviceType>
92 makeDualViewFromArrayView (Kokkos::DualView<ElementType*, DeviceType>& dv,
93 const Teuchos::ArrayView<const ElementType>& av,
94 const std::string& label)
96 using dual_view_type = Kokkos::DualView<ElementType*, DeviceType>;
97 using host_view_type =
typename dual_view_type::t_host;
98 using const_host_view_type =
typename host_view_type::const_type;
100 const auto size = av.size ();
101 const ElementType* ptr = (size == 0) ?
nullptr : av.getRawPtr ();
102 const_host_view_type inView (ptr, size);
109 template<
class ElementType,
class DeviceType>
111 makeDualViewFromVector (Kokkos::DualView<ElementType*, DeviceType>& dv,
112 const std::vector<ElementType>& vec,
113 const std::string& label)
115 using dual_view_type = Kokkos::DualView<ElementType*, DeviceType>;
116 using host_view_type =
typename dual_view_type::t_host;
117 using const_host_view_type =
typename host_view_type::const_type;
119 const auto size = vec.size ();
120 const ElementType* ptr = (size == 0) ?
nullptr : vec.data ();
121 const_host_view_type inView (ptr, size);
128 template<
class ElementType,
class DeviceType>
130 printDualView (std::ostream& out,
131 const Kokkos::DualView<ElementType*, DeviceType>& dv,
132 const std::string& name)
135 const size_t size = size_t (dv.extent (0));
136 const auto hostView = dv.view_host ();
139 for (
size_t k = 0; k < size; ++k) {
141 if (k +
size_t (1) < size) {
152 #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.