10 #ifndef STOKHOS_TPETRA_UQ_PCE_HPP
11 #define STOKHOS_TPETRA_UQ_PCE_HPP
20 #include "Tpetra_ConfigDefs.hpp"
21 #include "Tpetra_MultiVector_fwd.hpp"
22 #include "Tpetra_Vector_fwd.hpp"
23 #include "Tpetra_Access.hpp"
24 #include "Kokkos_Core.hpp"
25 #include <Tpetra_KokkosCompat_ClassicNodeAPI_Wrapper.hpp>
26 #include "KokkosCompat_View.hpp"
27 #include "KokkosCompat_View_def.hpp"
34 template <
typename D,
typename S>
35 Kokkos::View<Sacado::UQ::PCE<S>*,
D>
38 typedef typename std::conditional<
39 ::Kokkos::SpaceAccessibility< D, Kokkos::HostSpace>::accessible,
42 typedef Kokkos::View<T*,D> view_type;
43 typedef Kokkos::View<T*,typename view_type::array_layout,HostDevice,Kokkos::MemoryUnmanaged> unmanaged_host_view_type;
46 view_type v(
"", a.size(), a[0].size());
47 unmanaged_host_view_type hv(a.getRawPtr(), a.size(), a[0].size());
52 template <
typename D,
typename S>
53 Kokkos::View<const Sacado::UQ::PCE<S>*,
D>
56 typedef typename std::conditional<
57 ::Kokkos::SpaceAccessibility< D, Kokkos::HostSpace>::accessible,
60 typedef Kokkos::View<T*,D> view_type;
61 typedef Kokkos::View<const T*,typename view_type::array_layout,HostDevice,Kokkos::MemoryUnmanaged> unmanaged_host_view_type;
64 view_type v(
"", a.size(), a[0].size());
65 unmanaged_host_view_type hv(a.getRawPtr(), a.size(), a[0].size());
87 template <
typename Node>
91 #if defined(KOKKOS_ENABLE_SERIAL)
92 typedef Kokkos::Serial
type;
95 #endif // defined(KOKKOS_ENABLE_SERIAL)
98 template <
typename ExecSpace,
typename MemSpace>
99 struct DeviceForNode2< Tpetra::KokkosCompat::KokkosDeviceWrapperNode<ExecSpace, MemSpace> > {
100 typedef typename Tpetra::KokkosCompat::KokkosDeviceWrapperNode<ExecSpace, MemSpace>::device_type
type;
105 #include "Tpetra_Details_PackTraits.hpp"
106 #include "Tpetra_Details_ScalarViewTraits.hpp"
115 struct PackTraits<Sacado::UQ::PCE<S>> {
120 static const bool compileTimeSize =
false;
128 using SPT = PackTraits<scalar_value_type>;
132 KOKKOS_INLINE_FUNCTION
137 KOKKOS_INLINE_FUNCTION
138 static Kokkos::pair<int, size_t>
143 using return_type = Kokkos::pair<int, size_t>;
148 return return_type (errorCode, numBytes);
155 const size_t scalar_size = numValuesPerScalar (inBuf[0]);
158 inBuf[0].coeff () + (numEnt - 1)*scalar_size;
159 const bool is_contiguous = (last_coeff == last_coeff_expected);
160 if (! is_contiguous) {
164 return return_type (errorCode, numBytes);
173 if (scalar_size != 1) {
177 return return_type (errorCode, numBytes);
180 const size_t flat_numEnt = numEnt * scalar_size;
181 return SPT::packArray (outBuf, inBuf[0].coeff (), flat_numEnt);
185 KOKKOS_INLINE_FUNCTION
186 static Kokkos::pair<int, size_t>
191 using return_type = Kokkos::pair<int, size_t>;
196 return return_type (errorCode, numBytes);
201 const size_t scalar_size = numValuesPerScalar (outBuf[0]);
204 outBuf[0].coeff () + (numEnt - 1) * scalar_size;
205 const bool is_contiguous = (last_coeff == last_coeff_expected);
209 const size_t flat_numEnt = numEnt * scalar_size;
210 return SPT::unpackArray (outBuf[0].coeff (), inBuf, flat_numEnt);
217 size_t numBytesTotal = 0;
218 for (
size_t i = 0; i < numEnt; ++i) {
219 const char* inBufVal = inBuf + numBytesTotal;
220 const size_t numBytes = unpackValue (outBuf[i], inBufVal);
221 numBytesTotal += numBytes;
223 return return_type (errorCode, numBytesTotal);
228 KOKKOS_INLINE_FUNCTION
232 return inVal.size () * SPT::packValueCount (inVal.val ());
235 KOKKOS_INLINE_FUNCTION
240 const size_t numBytes = packValueCount (inVal);
241 memcpy (outBuf, inVal.coeff (), numBytes);
245 KOKKOS_INLINE_FUNCTION
248 const size_t outBufIndex,
251 const size_t numBytes = packValueCount (inVal);
252 const size_t offset = outBufIndex * numBytes;
253 memcpy (outBuf + offset, inVal.coeff (), numBytes);
257 KOKKOS_INLINE_FUNCTION
261 const size_t numBytes = packValueCount (outVal);
262 memcpy (outVal.coeff (), inBuf, numBytes);
272 template<
typename S,
typename D>
273 struct ScalarViewTraits<Sacado::UQ::PCE<S>,
D> {
277 static Kokkos::View<value_type*, device_type>
280 const std::string& label =
"")
282 const size_t numVals = PackTraits<value_type>::numValuesPerScalar (x);
283 using view_type = Kokkos::View<value_type*, device_type>;
284 return view_type (label, numEnt, numVals);
292 template <
class S,
class L,
class G,
class N>
294 if ( mv.need_sync_device() ) {
305 template <
class S,
class L,
class G,
class N>
307 if ( v.need_sync_device() ) {
319 #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="")
Tpetra::KokkosCompat::KokkosDeviceWrapperNode< ExecSpace, MemSpace >::device_type type
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