42 #ifndef STOKHOS_TPETRA_UQ_PCE_HPP 43 #define STOKHOS_TPETRA_UQ_PCE_HPP 52 #include "Tpetra_ConfigDefs.hpp" 53 #include "Kokkos_Core.hpp" 54 #include "Kokkos_BufferMacros.hpp" 55 #include "KokkosCompat_ClassicNodeAPI_Wrapper.hpp" 56 #include "KokkosCompat_View.hpp" 57 #include "KokkosCompat_View_def.hpp" 64 template <
typename D,
typename S>
65 Kokkos::View<Sacado::UQ::PCE<S>*,D>
68 typedef typename Kokkos::Impl::if_c<
69 ::Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< D, Kokkos::HostSpace>::value,
72 typedef Kokkos::View<T*,D> view_type;
73 typedef Kokkos::View<T*,typename view_type::array_layout,HostDevice,Kokkos::MemoryUnmanaged> unmanaged_host_view_type;
76 view_type v(
"", a.size(), a[0].size());
77 unmanaged_host_view_type hv(a.getRawPtr(), a.size(), a[0].size());
82 template <
typename D,
typename S>
83 Kokkos::View<const Sacado::UQ::PCE<S>*,D>
86 typedef typename Kokkos::Impl::if_c<
87 ::Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< D, Kokkos::HostSpace>::value,
90 typedef Kokkos::View<T*,D> view_type;
91 typedef Kokkos::View<const T*,typename view_type::array_layout,HostDevice,Kokkos::MemoryUnmanaged> unmanaged_host_view_type;
94 view_type v(
"", a.size(), a[0].size());
95 unmanaged_host_view_type hv(a.getRawPtr(), a.size(), a[0].size());
116 template <
typename Node>
120 #if defined(KOKKOS_HAVE_SERIAL) 121 typedef Kokkos::Serial
type;
124 #endif // defined(KOKKOS_HAVE_SERIAL) 127 template <
typename Device>
134 #include "Tpetra_Details_PackTraits.hpp" 143 template<
typename S,
typename D>
144 struct PackTraits<
Sacado::UQ::PCE<S>, D > {
152 static const bool compileTimeSize =
false;
156 typedef Kokkos::View<const value_type*, device_type, Kokkos::MemoryUnmanaged>
input_array_type;
160 typedef PackTraits< scalar_value_type, device_type >
SPT;
168 static Kokkos::View<value_type*, device_type>
171 typedef Kokkos::View<value_type*, device_type> view_type;
173 const size_type numVals = numValuesPerScalar (
x);
174 return view_type (label, static_cast<size_type> (numEnt), numVals);
182 #ifdef HAVE_TPETRA_DEBUG 183 TEUCHOS_TEST_FOR_EXCEPTION(
184 static_cast<size_t> (inBuf.dimension_0 ()) < numEnt,
185 std::invalid_argument,
"PackTraits::packArray: inBuf.dimension_0() = " 186 << inBuf.dimension_0 () <<
" < numEnt = " << numEnt <<
".");
187 #endif // HAVE_TPETRA_DEBUG 197 const size_t scalar_size = numValuesPerScalar(inBuf(0));
198 const size_t in_dim = inBuf.dimension_0();
201 inBuf(0).coeff() + (in_dim-1)*scalar_size;
202 const bool is_contiguous = (last_coeff == last_coeff_expected);
203 TEUCHOS_TEST_FOR_EXCEPTION(
204 !is_contiguous, std::logic_error,
205 "Cannot pack non-contiguous PCE array since buffer size calculation" <<
206 " is likely wrong.");
214 TEUCHOS_TEST_FOR_EXCEPTION(
215 scalar_size != 1, std::logic_error,
216 "Cannot pack PCE array with pce_size > 1 since unpack array" <<
217 " may not be allocated correctly.");
219 const size_t flat_numEnt = numEnt * scalar_size;
221 return SPT::packArray(outBuf, flat_inBuf, flat_numEnt);
230 #ifdef HAVE_TPETRA_DEBUG 231 TEUCHOS_TEST_FOR_EXCEPTION(
232 static_cast<size_t> (outBuf.dimension_0 ()) < numEnt,
233 std::invalid_argument,
234 "PackTraits::unpackArray: outBuf.dimension_0 () = " <<
235 outBuf.dimension_0 () <<
" < numEnt = " << numEnt <<
".");
236 #endif // HAVE_TPETRA_DEBUG 239 return static_cast<size_t> (0);
244 const size_type scalar_size = numValuesPerScalar(outBuf(0));
245 const size_type out_dim = outBuf.dimension_0();
248 outBuf(0).coeff() + (out_dim-1)*scalar_size;
249 const bool is_contiguous = (last_coeff == last_coeff_expected);
253 const size_t flat_numEnt = numEnt * scalar_size;
255 return SPT::unpackArray(flat_outBuf, inBuf, flat_numEnt);
262 size_t numBytesTotal = 0;
263 const size_type in_dim = inBuf.dimension_0();
264 for (
size_t i=0; i<numEnt; ++i) {
266 in_dim-numBytesTotal);
267 const size_t numBytes = unpackValue(outBuf(i), val_inBuf);
268 numBytesTotal += numBytes;
270 return numBytesTotal;
278 return inVal.size () * SPT::packValueCount (inVal.val ());
285 const size_t numBytes = packValueCount (inVal);
286 memcpy (outBuf.ptr_on_device (), inVal.coeff (), numBytes);
293 const size_t numBytes = packValueCount (outVal);
294 memcpy (outVal.coeff (), inBuf.ptr_on_device (), numBytes);
303 template <
class S,
class L,
class G,
class N,
bool>
class MultiVector;
304 template <
class S,
class L,
class G,
class N,
bool>
class Vector;
308 template <
class S,
class L,
class G,
class N,
bool c>
311 typedef typename MV::dual_view_type dual_view_type;
312 typedef typename dual_view_type::t_dev device_type;
313 typedef typename dual_view_type::t_host host_type;
314 dual_view_type dual_view = mv.getDualView();
315 if (dual_view.modified_host() > dual_view.modified_device())
320 template <
class S,
class L,
class G,
class N,
bool c>
323 typedef typename V::dual_view_type dual_view_type;
324 typedef typename dual_view_type::t_dev device_type;
325 typedef typename dual_view_type::t_host host_type;
326 dual_view_type dual_view = v.getDualView();
327 if (dual_view.modified_host() > dual_view.modified_device())
333 #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
static size_t unpackArray(const output_array_type &outBuf, const input_buffer_type &inBuf, const size_t numEnt)
Kokkos::DefaultExecutionSpace execution_space
static size_t unpackValue(value_type &outVal, const input_buffer_type &inBuf)
Kokkos::View< Sacado::UQ::PCE< S > *, D > getKokkosViewDeepCopy(const Teuchos::ArrayView< Sacado::UQ::PCE< S > > &a)
Kokkos::HostSpace::execution_space type
static size_t packValue(const output_buffer_type &outBuf, const value_type &inVal)
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x
Kokkos::View< const value_type *, device_type, Kokkos::MemoryUnmanaged > input_array_type
SPT::output_array_type scalar_output_array_type
Top-level namespace for Stokhos classes and functions.
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< View< T, P... > >::value, unsigned >::type dimension_scalar(const View< T, P... > &view)
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 size_t packValueCount(const value_type &inVal)
static size_t packArray(const output_buffer_type &outBuf, const input_array_type &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 size_t numValuesPerScalar(const value_type &x)
Kokkos::View< char *, device_type, Kokkos::MemoryUnmanaged > output_buffer_type
Kokkos::View< value_type *, device_type, Kokkos::MemoryUnmanaged > output_array_type
value_type::value_type scalar_value_type
D::execution_space execution_space