42 #ifndef STOKHOS_TPETRA_UQ_PCE_HPP
43 #define STOKHOS_TPETRA_UQ_PCE_HPP
52 #include "Tpetra_ConfigDefs.hpp"
53 #include "Tpetra_MultiVector_fwd.hpp"
54 #include "Tpetra_Vector_fwd.hpp"
55 #include "Kokkos_Core.hpp"
56 #include "Kokkos_BufferMacros.hpp"
57 #include "KokkosCompat_ClassicNodeAPI_Wrapper.hpp"
58 #include "KokkosCompat_View.hpp"
59 #include "KokkosCompat_View_def.hpp"
66 template <
typename D,
typename S>
67 Kokkos::View<Sacado::UQ::PCE<S>*,
D>
70 typedef typename Kokkos::Impl::if_c<
71 ::Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< D, Kokkos::HostSpace>::value,
74 typedef Kokkos::View<T*,D> view_type;
75 typedef Kokkos::View<T*,typename view_type::array_layout,HostDevice,Kokkos::MemoryUnmanaged> unmanaged_host_view_type;
78 view_type v(
"", a.size(), a[0].size());
79 unmanaged_host_view_type hv(a.getRawPtr(), a.size(), a[0].size());
84 template <
typename D,
typename S>
85 Kokkos::View<const Sacado::UQ::PCE<S>*,
D>
88 typedef typename Kokkos::Impl::if_c<
89 ::Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< D, Kokkos::HostSpace>::value,
92 typedef Kokkos::View<T*,D> view_type;
93 typedef Kokkos::View<const T*,typename view_type::array_layout,HostDevice,Kokkos::MemoryUnmanaged> unmanaged_host_view_type;
96 view_type v(
"", a.size(), a[0].size());
97 unmanaged_host_view_type hv(a.getRawPtr(), a.size(), a[0].size());
119 template <
typename Node>
123 #if defined(KOKKOS_ENABLE_SERIAL)
124 typedef Kokkos::Serial
type;
127 #endif // defined(KOKKOS_ENABLE_SERIAL)
130 template <
typename Device>
137 #include "Tpetra_Details_PackTraits.hpp"
146 template<
typename S,
typename D>
147 struct PackTraits< Sacado::UQ::PCE<S>,
D > {
155 static const bool compileTimeSize =
false;
159 typedef Kokkos::View<const value_type*, device_type, Kokkos::MemoryUnmanaged>
input_array_type;
163 typedef PackTraits< scalar_value_type, device_type >
SPT;
167 KOKKOS_INLINE_FUNCTION
172 static Kokkos::View<value_type*, device_type>
175 typedef Kokkos::View<value_type*, device_type> view_type;
177 const size_type numVals = numValuesPerScalar (x);
178 return view_type (label, static_cast<size_type> (numEnt), numVals);
181 KOKKOS_INLINE_FUNCTION
182 static Kokkos::pair<int, size_t>
187 typedef Kokkos::pair<int, size_t> return_type;
192 return return_type (errorCode, numBytes);
199 const size_t scalar_size = numValuesPerScalar (inBuf[0]);
202 inBuf[0].coeff () + (numEnt - 1)*scalar_size;
203 const bool is_contiguous = (last_coeff == last_coeff_expected);
204 if (! is_contiguous) {
208 return return_type (errorCode, numBytes);
217 if (scalar_size != 1) {
221 return return_type (errorCode, numBytes);
224 const size_t flat_numEnt = numEnt * scalar_size;
225 return SPT::packArray (outBuf, inBuf[0].coeff (), flat_numEnt);
229 KOKKOS_INLINE_FUNCTION
230 static Kokkos::pair<int, size_t>
235 typedef Kokkos::pair<int, size_t> return_type;
240 return return_type (errorCode, numBytes);
245 const size_type scalar_size = numValuesPerScalar (outBuf[0]);
248 outBuf[0].coeff () + (numEnt - 1) * scalar_size;
249 const bool is_contiguous = (last_coeff == last_coeff_expected);
253 const size_t flat_numEnt = numEnt * scalar_size;
254 return SPT::unpackArray (outBuf[0].coeff (), inBuf, flat_numEnt);
261 size_t numBytesTotal = 0;
262 for (
size_t i = 0; i < numEnt; ++i) {
263 const char* inBufVal = inBuf + numBytesTotal;
264 const size_t numBytes = unpackValue (outBuf[i], inBufVal);
265 numBytesTotal += numBytes;
267 return return_type (errorCode, numBytesTotal);
272 KOKKOS_INLINE_FUNCTION
276 return inVal.size () * SPT::packValueCount (inVal.val ());
279 KOKKOS_INLINE_FUNCTION
284 const size_t numBytes = packValueCount (inVal);
285 memcpy (outBuf, inVal.coeff (), numBytes);
289 KOKKOS_INLINE_FUNCTION
292 const size_t outBufIndex,
295 const size_t numBytes = packValueCount (inVal);
296 const size_t offset = outBufIndex * numBytes;
297 memcpy (outBuf + offset, inVal.coeff (), numBytes);
301 KOKKOS_INLINE_FUNCTION
305 const size_t numBytes = packValueCount (outVal);
306 memcpy (outVal.coeff (), inBuf, numBytes);
315 template <
class S,
class L,
class G,
class N>
317 if ( mv.need_sync_device() ) {
328 template <
class S,
class L,
class G,
class N>
330 if ( v.need_sync_device() ) {
342 #endif // STOKHOS_TPETRA_UQ_PCE_HPP
Kokkos::View< const char *, device_type, Kokkos::MemoryUnmanaged > input_buffer_type
execution_space::size_type size_type
PackTraits< scalar_value_type, device_type > SPT
Kokkos::DefaultExecutionSpace execution_space
Kokkos::View< Sacado::UQ::PCE< S > *, D > getKokkosViewDeepCopy(const Teuchos::ArrayView< Sacado::UQ::PCE< S > > &a)
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< View< T, P...> >::value, unsigned >::type dimension_scalar(const View< T, P...> &view)
Kokkos::HostSpace::execution_space type
Kokkos::View< const value_type *, device_type, Kokkos::MemoryUnmanaged > input_array_type
SPT::output_array_type scalar_output_array_type
static KOKKOS_INLINE_FUNCTION size_t numValuesPerScalar(const value_type &x)
SPT::input_array_type scalar_input_array_type
void deep_copy(const Stokhos::CrsMatrix< ValueType, DstDevice, Layout > &dst, const Stokhos::CrsMatrix< ValueType, SrcDevice, Layout > &src)
Sacado::UQ::PCE< S > value_type
static KOKKOS_INLINE_FUNCTION size_t packValueCount(const value_type &inVal)
static KOKKOS_INLINE_FUNCTION Kokkos::pair< int, size_t > unpackArray(value_type outBuf[], const char inBuf[], const size_t numEnt)
static Kokkos::View< value_type *, device_type > allocateArray(const value_type &x, const size_t numEnt, const std::string &label="")
static KOKKOS_INLINE_FUNCTION size_t packValue(char outBuf[], const value_type &inVal)
static KOKKOS_INLINE_FUNCTION size_t packValue(char outBuf[], const size_t outBufIndex, const value_type &inVal)
Kokkos::View< char *, device_type, Kokkos::MemoryUnmanaged > output_buffer_type
static KOKKOS_INLINE_FUNCTION size_t unpackValue(value_type &outVal, const char inBuf[])
Kokkos::View< value_type *, device_type, Kokkos::MemoryUnmanaged > output_array_type
value_type::value_type scalar_value_type
D::execution_space execution_space
static KOKKOS_INLINE_FUNCTION Kokkos::pair< int, size_t > packArray(char outBuf[], const value_type inBuf[], const size_t numEnt)