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));
68template<
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);
87 Kokkos::deep_copy (execution_space(), devView, hostView);
88 dv = dual_view_type (devView, hostView);
92template<
class ElementType,
class DeviceType>
94makeDualViewFromArrayView (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);
108 Kokkos::deep_copy (execution_space(), hostView, inView);
113template<
class ElementType,
class DeviceType>
115makeDualViewFromVector (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);
129 Kokkos::deep_copy (execution_space(), hostView, inView);
134template<
class ElementType,
class DeviceType>
136printDualView (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) {
Implementation details of Tpetra.
auto view_alloc_no_init(const std::string &label) -> decltype(Kokkos::view_alloc(label, Kokkos::WithoutInitializing))
Use in place of the string label as the first argument of Kokkos::View's constructor,...
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.
Namespace Tpetra contains the class and methods constituting the Tpetra library.