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"
138 #include "Tpetra_Details_ScalarViewTraits.hpp"
147 struct PackTraits<Sacado::UQ::PCE<S>> {
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);
304 template<
typename S,
typename D>
305 struct 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() ) {
351 #endif // STOKHOS_TPETRA_UQ_PCE_HPP
Kokkos::View< value_type *, Kokkos::AnonymousSpace > output_array_type
typename value_type::value_type scalar_value_type
static KOKKOS_INLINE_FUNCTION Kokkos::pair< int, size_t > packArray(char outBuf[], const value_type inBuf[], const size_t numEnt)
Kokkos::DefaultExecutionSpace execution_space
static KOKKOS_INLINE_FUNCTION size_t packValue(char outBuf[], const size_t outBufIndex, const value_type &inVal)
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)
static Kokkos::View< value_type *, device_type > allocateArray(const value_type &x, const size_t numEnt, const std::string &label="")
Kokkos::HostSpace::execution_space type
static KOKKOS_INLINE_FUNCTION size_t unpackValue(value_type &outVal, const char inBuf[])
static KOKKOS_INLINE_FUNCTION size_t numValuesPerScalar(const value_type &x)
static KOKKOS_INLINE_FUNCTION size_t packValue(char outBuf[], const value_type &inVal)
typename SPT::output_array_type scalar_output_array_type
void deep_copy(const Stokhos::CrsMatrix< ValueType, DstDevice, Layout > &dst, const Stokhos::CrsMatrix< ValueType, SrcDevice, Layout > &src)
typename SPT::input_array_type scalar_input_array_type
Kokkos::View< const value_type *, Kokkos::AnonymousSpace > input_array_type
static KOKKOS_INLINE_FUNCTION size_t packValueCount(const value_type &inVal)
PackTraits< scalar_value_type > SPT
static KOKKOS_INLINE_FUNCTION Kokkos::pair< int, size_t > unpackArray(value_type outBuf[], const char inBuf[], const size_t numEnt)
Kokkos::View< char *, Kokkos::AnonymousSpace > output_buffer_type
Kokkos::View< const char *, Kokkos::AnonymousSpace > input_buffer_type