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 "Tpetra_Access.hpp"
56#include "Kokkos_Core.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 std::conditional<
71 ::Kokkos::SpaceAccessibility< D, Kokkos::HostSpace>::accessible,
72 typename D::execution_space, Kokkos::HostSpace>::type
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 std::conditional<
89 ::Kokkos::SpaceAccessibility< D, Kokkos::HostSpace>::accessible,
90 typename D::execution_space, Kokkos::HostSpace>::type
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());
119template <
typename Node>
123#if defined(KOKKOS_ENABLE_SERIAL)
124 typedef Kokkos::Serial
type;
126 typedef Kokkos::HostSpace::execution_space
type;
130template <
typename Device>
137#include "Tpetra_Details_PackTraits.hpp"
138#include "Tpetra_Details_ScalarViewTraits.hpp"
152 static const bool compileTimeSize =
false;
160 using SPT = PackTraits<scalar_value_type>;
164 KOKKOS_INLINE_FUNCTION
169 KOKKOS_INLINE_FUNCTION
170 static Kokkos::pair<int, size_t>
175 using return_type = Kokkos::pair<int, size_t>;
180 return return_type (errorCode, numBytes);
187 const size_t scalar_size = numValuesPerScalar (inBuf[0]);
190 inBuf[0].coeff () + (numEnt - 1)*scalar_size;
191 const bool is_contiguous = (last_coeff == last_coeff_expected);
192 if (! is_contiguous) {
196 return return_type (errorCode, numBytes);
205 if (scalar_size != 1) {
209 return return_type (errorCode, numBytes);
212 const size_t flat_numEnt = numEnt * scalar_size;
213 return SPT::packArray (outBuf, inBuf[0].coeff (), flat_numEnt);
217 KOKKOS_INLINE_FUNCTION
218 static Kokkos::pair<int, size_t>
223 using return_type = Kokkos::pair<int, size_t>;
228 return return_type (errorCode, numBytes);
233 const size_t scalar_size = numValuesPerScalar (outBuf[0]);
236 outBuf[0].coeff () + (numEnt - 1) * scalar_size;
237 const bool is_contiguous = (last_coeff == last_coeff_expected);
241 const size_t flat_numEnt = numEnt * scalar_size;
242 return SPT::unpackArray (outBuf[0].coeff (), inBuf, flat_numEnt);
249 size_t numBytesTotal = 0;
250 for (
size_t i = 0; i < numEnt; ++i) {
251 const char* inBufVal = inBuf + numBytesTotal;
252 const size_t numBytes = unpackValue (outBuf[i], inBufVal);
253 numBytesTotal += numBytes;
255 return return_type (errorCode, numBytesTotal);
260 KOKKOS_INLINE_FUNCTION
264 return inVal.size () * SPT::packValueCount (inVal.val ());
267 KOKKOS_INLINE_FUNCTION
272 const size_t numBytes = packValueCount (inVal);
273 memcpy (outBuf, inVal.coeff (), numBytes);
277 KOKKOS_INLINE_FUNCTION
280 const size_t outBufIndex,
283 const size_t numBytes = packValueCount (inVal);
284 const size_t offset = outBufIndex * numBytes;
285 memcpy (outBuf + offset, inVal.coeff (), numBytes);
289 KOKKOS_INLINE_FUNCTION
293 const size_t numBytes = packValueCount (outVal);
294 memcpy (outVal.coeff (), inBuf, numBytes);
304template<
typename S,
typename D>
305struct ScalarViewTraits<
Sacado::UQ::PCE<S>, D> {
309 static Kokkos::View<value_type*, device_type>
312 const std::string& label =
"")
314 const size_t numVals = PackTraits<value_type>::numValuesPerScalar (x);
315 using view_type = Kokkos::View<value_type*, device_type>;
316 return view_type (label, numEnt, numVals);
324 template <
class S,
class L,
class G,
class N>
326 if ( mv.need_sync_device() ) {
337 template <
class S,
class L,
class G,
class N>
339 if ( v.need_sync_device() ) {
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)
void deep_copy(const Stokhos::CrsMatrix< ValueType, DstDevice, Layout > &dst, const Stokhos::CrsMatrix< ValueType, SrcDevice, Layout > &src)
Top-level namespace for Stokhos classes and functions.
Kokkos::HostSpace::execution_space type
Kokkos::View< char *, Kokkos::AnonymousSpace > output_buffer_type
Kokkos::View< const value_type *, Kokkos::AnonymousSpace > input_array_type
static KOKKOS_INLINE_FUNCTION size_t packValue(char outBuf[], const size_t outBufIndex, const value_type &inVal)
typename SPT::output_array_type scalar_output_array_type
static KOKKOS_INLINE_FUNCTION size_t packValueCount(const value_type &inVal)
static KOKKOS_INLINE_FUNCTION Kokkos::pair< int, size_t > packArray(char outBuf[], const value_type inBuf[], const size_t numEnt)
typename value_type::value_type scalar_value_type
static KOKKOS_INLINE_FUNCTION size_t packValue(char outBuf[], 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_INLINE_FUNCTION size_t numValuesPerScalar(const value_type &x)
typename SPT::input_array_type scalar_input_array_type
PackTraits< scalar_value_type > SPT
Kokkos::View< value_type *, Kokkos::AnonymousSpace > output_array_type
Kokkos::View< const char *, Kokkos::AnonymousSpace > input_buffer_type
static KOKKOS_INLINE_FUNCTION size_t unpackValue(value_type &outVal, const char inBuf[])
static Kokkos::View< value_type *, device_type > allocateArray(const value_type &x, const size_t numEnt, const std::string &label="")