10 #ifndef TPETRA_DETAILS_CREATEMIRRORVIEW_HPP
11 #define TPETRA_DETAILS_CREATEMIRRORVIEW_HPP
13 #include "TpetraCore_config.h"
14 #include "Teuchos_Array.hpp"
15 #include "Teuchos_ArrayView.hpp"
18 #include "Kokkos_Core.hpp"
37 template<
class ValueType,
38 class OutputDeviceType,
39 const bool constInput = std::is_const<ValueType>::value,
40 const bool sameAsHost =
41 std::is_same<Kokkos::HostSpace,
42 typename OutputDeviceType::memory_space>::value>
43 class CreateMirrorViewFromUnmanagedHostArray {
45 typedef Kokkos::View<ValueType*, OutputDeviceType> output_view_type;
46 typedef Kokkos::View<ValueType*,
47 typename output_view_type::array_layout,
48 Kokkos::HostSpace> input_view_type;
49 static output_view_type
50 doIt (ValueType* inPtr,
52 const bool copy =
true,
53 const char label[] =
"");
58 template<
class ValueType,
59 class OutputDeviceType,
60 const bool constInput>
61 class CreateMirrorViewFromUnmanagedHostArray<ValueType, OutputDeviceType, constInput, true> {
63 typedef Kokkos::View<ValueType*, OutputDeviceType> output_view_type;
64 typedef Kokkos::View<ValueType*,
typename output_view_type::array_layout,
65 Kokkos::HostSpace> input_view_type;
66 static output_view_type
67 doIt (ValueType* inPtr,
72 static_assert (std::is_same<
typename OutputDeviceType::memory_space,
73 Kokkos::HostSpace>::value,
74 "OutputDeviceType::memory_space must be the same as "
75 "Kokkos::HostSpace in order to use this specialization. "
76 "Please report this bug to the Tpetra developers.");
77 return output_view_type (inPtr, inSize);
83 template<
class ValueType,
84 class OutputDeviceType>
85 class CreateMirrorViewFromUnmanagedHostArray<ValueType, OutputDeviceType, true, false> {
87 typedef Kokkos::View<ValueType*, OutputDeviceType> output_view_type;
88 typedef Kokkos::View<ValueType*,
typename output_view_type::array_layout,
89 Kokkos::HostSpace> input_view_type;
90 static output_view_type
91 doIt (ValueType* inPtr,
93 const bool copy =
true,
94 const char label[] =
"")
96 using Kokkos::view_alloc;
97 using Kokkos::WithoutInitializing;
98 static_assert (std::is_const<ValueType>::value,
"ValueType must be const "
99 "in order to use this specialization. Please report this "
100 "bug to the Tpetra developers.");
101 static_assert (! std::is_same<typename OutputDeviceType::memory_space, Kokkos::HostSpace>::value,
102 "OutputDeviceType::memory_space must not be the same as "
103 "Kokkos::HostSpace in order to use this specialization. "
104 "Please report this bug to the Tpetra developers.");
105 input_view_type inView (inPtr, inSize);
107 typedef typename output_view_type::non_const_type nc_output_view_type;
108 nc_output_view_type outView_nc;
114 outView_nc = nc_output_view_type (view_alloc (std::string (label)), inSize);
118 outView_nc = nc_output_view_type (view_alloc (std::string (label), WithoutInitializing), inSize);
120 using execution_space =
typename nc_output_view_type::execution_space;
129 template<
class ValueType,
130 class OutputDeviceType>
131 class CreateMirrorViewFromUnmanagedHostArray<ValueType, OutputDeviceType, false, false> {
133 typedef Kokkos::View<ValueType*, OutputDeviceType> output_view_type;
134 typedef Kokkos::View<ValueType*,
typename output_view_type::array_layout,
135 Kokkos::HostSpace> input_view_type;
136 static output_view_type
137 doIt (ValueType* inPtr,
139 const bool copy =
true,
140 const char label[] =
"")
142 typedef typename OutputDeviceType::memory_space out_mem_space;
143 typedef typename OutputDeviceType::execution_space out_exec_space;
144 static_assert (! std::is_const<ValueType>::value,
"ValueType must not be "
145 "const in order to use this specialization. Please report "
146 "this bug to the Tpetra developers.");
147 static_assert (! std::is_same<out_mem_space, Kokkos::HostSpace>::value,
148 "OutputDeviceType::memory_space must not be the same as "
149 "Kokkos::HostSpace in order to use this specialization. "
150 "Please report this bug to the Tpetra developers.");
151 input_view_type inView (inPtr, inSize);
152 output_view_type outView =
153 Kokkos::create_mirror_view (out_mem_space (), inView);
171 template<
class ValueType,
class OutputDeviceType>
172 typename Impl::CreateMirrorViewFromUnmanagedHostArray<ValueType, OutputDeviceType>::output_view_type
176 const bool copy =
true,
177 const char label[] =
"")
179 typedef Impl::CreateMirrorViewFromUnmanagedHostArray<ValueType, OutputDeviceType> impl_type;
180 return impl_type::doIt (inPtr, inSize, copy, label);
186 #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 functions Tpetra::Details::computeOffsetsFromCounts and Tpetra::computeOffsets...