Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
KokkosExp_View_UQ_PCE_Contiguous.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Stokhos Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef KOKKOS_EXPERIMENTAL_VIEW_UQ_PCE_CONTIGUOUS_HPP
43 #define KOKKOS_EXPERIMENTAL_VIEW_UQ_PCE_CONTIGUOUS_HPP
44 
45 // Only include forward declarations so any overloads appear before they
46 // might be used inside Kokkos
47 #include "Kokkos_Core_fwd.hpp"
48 #include "Kokkos_View.hpp"
49 #include "Kokkos_Layout.hpp"
50 
52 #include "Kokkos_View_Utils.hpp"
54 
55 
56 //----------------------------------------------------------------------------
57 
58 namespace Sacado {
59  namespace UQ {
60  template <typename Storage >
61  class PCE;
62  }
63 }
64 
65 namespace Kokkos {
66 
67  namespace Impl {
68  template<class Space, class T, class ... P>
69  struct MirrorType;
70  }
71 
72 }
73 
74 namespace Kokkos {
75 namespace Experimental {
76 namespace Impl {
77 
79 
80 template< class ... Args >
81 struct is_ViewPCEContiguous { enum { value = false }; };
82 
83 template< class D , class ... P , class ... Args >
84 struct is_ViewPCEContiguous< Kokkos::View<D,P...> , Args... > {
85  enum { value =
86  std::is_same< typename Kokkos::ViewTraits<D,P...>::specialize
88  &&
89  ( ( sizeof...(Args) == 0 ) ||
90  is_ViewPCEContiguous< Args... >::value ) };
91 };
92 
93 } // namespace Impl
94 } // namespace Experimental
95 } // namespace Kokkos
96 
97 namespace Kokkos {
98 
99 // Declare overloads of create_mirror() so they are in scope
100 // Kokkos_Core.hpp is included below
101 
102 template< class T , class ... P >
103 inline
104 typename Kokkos::View<T,P...>::HostMirror
106  const Kokkos::View<T,P...> & src,
107  typename std::enable_if<
108  std::is_same< typename ViewTraits<T,P...>::specialize ,
110  !std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout,
111  Kokkos::LayoutStride >::value >::type * = 0);
112 
113 template< class T , class ... P >
114 inline
115 typename Kokkos::View<T,P...>::HostMirror
117  const Kokkos::View<T,P...> & src,
118  typename std::enable_if<
119  std::is_same< typename ViewTraits<T,P...>::specialize ,
121  std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout,
122  Kokkos::LayoutStride >::value >::type * = 0);
123 
124 template<class Space, class T, class ... P>
125 typename Impl::MirrorType<Space,T,P ...>::view_type
127  const Space&,
128  const Kokkos::View<T,P...> & src,
129  typename std::enable_if<
130  std::is_same< typename ViewTraits<T,P...>::specialize ,
131  Kokkos::Experimental::Impl::ViewPCEContiguous >::value >::type * = 0);
132 
133 // Overload of deep_copy for UQ::PCE views intializing to a constant scalar
134 template< class DT, class ... DP >
135 void deep_copy(
136  const View<DT,DP...> & view ,
137  const typename View<DT,DP...>::array_type::value_type & value
138  , typename std::enable_if<(
139  std::is_same< typename ViewTraits<DT,DP...>::specialize
141  )>::type * = 0 );
142 
143 // Overload of deep_copy for UQ::PCE views intializing to a constant UQ::PCE
144 template< class DT, class ... DP >
145 void deep_copy(
146  const View<DT,DP...> & view ,
147  const typename View<DT,DP...>::value_type & value
148  , typename std::enable_if<(
149  std::is_same< typename ViewTraits<DT,DP...>::specialize
151  )>::type * = 0 );
152 
153 // Overload of deep_copy for UQ::PCE views intializing to a constant scalar
154 template< class ExecSpace , class DT, class ... DP >
155 void deep_copy(
156  const ExecSpace &,
157  const View<DT,DP...> & view ,
158  const typename View<DT,DP...>::array_type::value_type & value
159  , typename std::enable_if<(
160  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
161  std::is_same< typename ViewTraits<DT,DP...>::specialize
163  )>::type * = 0 );
164 
165 // Overload of deep_copy for UQ::PCE views intializing to a constant UQ::PCE
166 template< class ExecSpace , class DT, class ... DP >
167 void deep_copy(
168  const ExecSpace &,
169  const View<DT,DP...> & view ,
170  const typename View<DT,DP...>::value_type & value
171  , typename std::enable_if<(
172  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
173  std::is_same< typename ViewTraits<DT,DP...>::specialize
175  )>::type * = 0 );
176 
177 /* Specialize for deep copy of UQ::PCE */
178 template< class DT , class ... DP , class ST , class ... SP >
179 inline
180 void deep_copy( const View<DT,DP...> & dst ,
181  const View<ST,SP...> & src
182  , typename std::enable_if<(
183  std::is_same< typename ViewTraits<DT,DP...>::specialize
185  &&
186  std::is_same< typename ViewTraits<ST,SP...>::specialize
188  )>::type * = 0 );
189 
190 /* Specialize for deep copy of UQ::PCE */
191 template< class ExecSpace, class DT , class ... DP , class ST , class ... SP >
192 inline
193 void deep_copy( const ExecSpace &,
194  const View<DT,DP...> & dst ,
195  const View<ST,SP...> & src
196  , typename std::enable_if<(
197  std::is_same< typename ViewTraits<DT,DP...>::specialize
199  &&
200  std::is_same< typename ViewTraits<ST,SP...>::specialize
202  )>::type * = 0 );
203 
204 template <typename T, typename ... P>
205 struct is_view_uq_pce< View<T,P...> > {
206  typedef View<T,P...> view_type;
207  static const bool value =
208  std::is_same< typename view_type::specialize,
210 };
211 
212 template <typename ViewType>
213 struct CijkType< ViewType,
214  typename std::enable_if< is_view_uq_pce< ViewType >::value >::type > {
215  typedef typename ViewType::non_const_value_type::cijk_type type;
216 };
217 
218 template <typename T, typename ... P>
219 KOKKOS_INLINE_FUNCTION
220 constexpr typename
221 std::enable_if< is_view_uq_pce< View<T,P...> >::value, unsigned >::type
222 dimension_scalar(const View<T,P...>& view) {
223  return view.impl_map().dimension_scalar();
224 }
225 
226 template <typename view_type>
227 KOKKOS_INLINE_FUNCTION
228 constexpr typename
229 std::enable_if< is_view_uq_pce<view_type>::value,
230  typename CijkType<view_type>::type >::type
231 cijk(const view_type& view) {
232  return view.impl_map().cijk();
233 }
234 
235 template <typename view_type>
236 KOKKOS_INLINE_FUNCTION
237 constexpr typename
238 std::enable_if< is_view_uq_pce<view_type>::value, bool >::type
239 is_allocation_contiguous(const view_type& view) {
240  return view.impl_map().is_allocation_contiguous();
241 }
242 
243 template <typename ViewType>
244 ViewType
245 make_view(const std::string& label,
246  const typename CijkType<ViewType>::type& cijk,
247  size_t N0 = 0, size_t N1 = 0, size_t N2 = 0, size_t N3 = 0,
248  size_t N4 = 0, size_t N5 = 0, size_t N6 = 0, size_t N7 = 0)
249 {
250  return ViewType(view_alloc(label,cijk),
251  N0, N1, N2, N3, N4, N5, N6, N7);
252 }
253 
254 template <typename ViewType>
255 ViewType
256 make_view(const std::string& label,
257  const Impl::WithoutInitializing_t& init,
258  const typename CijkType<ViewType>::type& cijk,
259  size_t N0 = 0, size_t N1 = 0, size_t N2 = 0, size_t N3 = 0,
260  size_t N4 = 0, size_t N5 = 0, size_t N6 = 0, size_t N7 = 0)
261 {
262  return ViewType(view_alloc(label,init,cijk),
263  N0, N1, N2, N3, N4, N5, N6, N7);
264 }
265 
266 template <typename ViewType>
267 ViewType
268 make_view(const ViewAllocateWithoutInitializing& init,
269  const typename CijkType<ViewType>::type& cijk,
270  size_t N0 = 0, size_t N1 = 0, size_t N2 = 0, size_t N3 = 0,
271  size_t N4 = 0, size_t N5 = 0, size_t N6 = 0, size_t N7 = 0)
272 {
273  return ViewType(view_alloc(((Kokkos::Impl::ViewCtorProp<void, std::string>)init).value,
274  WithoutInitializing,
275  cijk),
276  N0, N1, N2, N3, N4, N5, N6, N7);
277 }
278 
279 template <typename ViewType>
280 typename std::enable_if< is_view_uq_pce<ViewType>::value, ViewType>::type
281 make_view(typename ViewType::pointer_type ptr,
282  const typename CijkType<ViewType>::type& cijk,
283  size_t N0 = 0, size_t N1 = 0, size_t N2 = 0, size_t N3 = 0,
284  size_t N4 = 0, size_t N5 = 0, size_t N6 = 0, size_t N7 = 0)
285 {
286  size_t N[8] = { N0, N1, N2, N3, N4, N5, N6, N7 };
287  N[ViewType::rank] = cijk.dimension();
288  ViewType v(view_wrap(ptr, cijk),
289  N[0], N[1], N[2], N[3], N[4], N[5], N[6], N[7]);
290  return v;
291 }
292 
293 } // namespace Kokkos
294 
295 #include "Sacado_Traits.hpp"
296 #include "Sacado_UQ_PCE.hpp"
297 #include "Sacado_UQ_PCE_Traits.hpp"
298 #include "Kokkos_Core.hpp"
299 
300 namespace Kokkos {
301 
302 template <typename D, typename ... P>
303 struct FlatArrayType< View<D,P...>,
304  typename std::enable_if< is_view_uq_pce< View<D,P...> >::value >::type > {
305  typedef View<D,P...> view_type;
306  typedef typename view_type::traits::dimension dimension;
308  typedef typename Kokkos::Impl::ViewDataType< flat_value_type , dimension >::type flat_data_type;
309  typedef View<flat_data_type,P...> type;
310 };
311 
312 template< class T , class ... P >
313 inline
314 typename Kokkos::View<T,P...>::HostMirror
315 create_mirror( const Kokkos::View<T,P...> & src
316  , typename std::enable_if<
317  std::is_same< typename ViewTraits<T,P...>::specialize ,
319  &&
320  ! std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
321  , Kokkos::LayoutStride >::value
322  >::type *
323  )
324 {
325  typedef View<T,P...> src_type ;
326  typedef typename src_type::HostMirror dst_type ;
327 
328  typename src_type::array_layout layout = src.layout();
329  layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
330 
331  return dst_type(view_alloc(std::string(src.label()).append("_mirror"),
332  src.impl_map().cijk()), layout);
333 }
334 
335 template< class T , class ... P >
336 inline
337 typename Kokkos::View<T,P...>::HostMirror
338 create_mirror( const Kokkos::View<T,P...> & src
339  , typename std::enable_if<
340  std::is_same< typename ViewTraits<T,P...>::specialize ,
342  &&
343  std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
344  , Kokkos::LayoutStride >::value
345  >::type *
346  )
347 {
348  typedef View<T,P...> src_type ;
349  typedef typename src_type::HostMirror dst_type ;
350 
351  Kokkos::LayoutStride layout ;
352 
353  layout.dimension[0] = src.extent(0);
354  layout.dimension[1] = src.extent(1);
355  layout.dimension[2] = src.extent(2);
356  layout.dimension[3] = src.extent(3);
357  layout.dimension[4] = src.extent(4);
358  layout.dimension[5] = src.extent(5);
359  layout.dimension[6] = src.extent(6);
360  layout.dimension[7] = src.extent(7);
361 
362  layout.stride[0] = src.stride_0();
363  layout.stride[1] = src.stride_1();
364  layout.stride[2] = src.stride_2();
365  layout.stride[3] = src.stride_3();
366  layout.stride[4] = src.stride_4();
367  layout.stride[5] = src.stride_5();
368  layout.stride[6] = src.stride_6();
369  layout.stride[7] = src.stride_7();
370 
371  layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
372 
373  return dst_type(view_alloc(std::string(src.label()).append("_mirror"),
374  src.impl_map().cijk()), layout);
375 }
376 
377 template<class Space, class T, class ... P>
378 typename Impl::MirrorType<Space,T,P ...>::view_type
379 create_mirror(const Space& , const Kokkos::View<T,P...> & src
380  , typename std::enable_if<
381  std::is_same< typename ViewTraits<T,P...>::specialize ,
383  >::type *) {
384  typedef View<T,P...> src_type ;
385  typename src_type::array_layout layout = src.layout();
386  layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
388  view_alloc(src.label(), src.impl_map().cijk()),layout);
389 }
390 
391 // Overload of deep_copy for UQ::PCE views intializing to a constant scalar
392 template< class DT, class ... DP >
394  const View<DT,DP...> & view ,
395  const typename View<DT,DP...>::array_type::value_type & value
396  , typename std::enable_if<(
397  std::is_same< typename ViewTraits<DT,DP...>::specialize
399  )>::type * )
400 {
401  static_assert(
402  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
403  typename ViewTraits<DT,DP...>::non_const_value_type >::value
404  , "Can only deep copy into non-const type" );
405 
406  typedef View<DT,DP...> view_type;
408  typedef typename FlatArrayType<view_type>::type flat_array_type;
409  if (value == scalar_type(0))
411  else
413 }
414 
415 // Overload of deep_copy for UQ::PCE views intializing to a constant UQ::PCE
416 template< class DT, class ... DP >
418  const View<DT,DP...> & view ,
419  const typename View<DT,DP...>::value_type & value
420  , typename std::enable_if<(
421  std::is_same< typename ViewTraits<DT,DP...>::specialize
423  )>::type * )
424 {
425  static_assert(
426  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
427  typename ViewTraits<DT,DP...>::non_const_value_type >::value
428  , "Can only deep copy into non-const type" );
429 
430  Kokkos::Impl::StokhosViewFill< View<DT,DP...> >( view , value );
431 }
432 
433 // Overload of deep_copy for UQ::PCE views intializing to a constant scalar
434 template< class ExecSpace , class DT, class ... DP >
436  const ExecSpace &,
437  const View<DT,DP...> & view ,
438  const typename View<DT,DP...>::array_type::value_type & value
439  , typename std::enable_if<(
440  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
441  std::is_same< typename ViewTraits<DT,DP...>::specialize
443  )>::type * )
444 {
445  static_assert(
446  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
447  typename ViewTraits<DT,DP...>::non_const_value_type >::value
448  , "Can only deep copy into non-const type" );
449 
450  typedef View<DT,DP...> view_type;
452  typedef typename FlatArrayType<view_type>::type flat_array_type;
453  if (value == scalar_type(0))
455  else
457 }
458 
459 // Overload of deep_copy for UQ::PCE views intializing to a constant UQ::PCE
460 template< class ExecSpace , class DT, class ... DP >
462  const ExecSpace &,
463  const View<DT,DP...> & view ,
464  const typename View<DT,DP...>::value_type & value
465  , typename std::enable_if<(
466  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
467  std::is_same< typename ViewTraits<DT,DP...>::specialize
469  )>::type * )
470 {
471  static_assert(
472  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
473  typename ViewTraits<DT,DP...>::non_const_value_type >::value
474  , "Can only deep copy into non-const type" );
475 
476  Kokkos::Impl::StokhosViewFill< View<DT,DP...> >( view , value );
477 }
478 
479 namespace Experimental {
480 namespace Impl {
481 
482 // Deep copy between views not assuming contiguous storage of arrays
483 // Need to use team interface for Cuda
484 template< class OutputView , class InputView >
486 {
488  typedef typename execution_space::size_type size_type ;
489 
490  const OutputView output ;
491  const InputView input ;
492 
493  DeepCopyNonContiguous( const OutputView & arg_out ,
494  const InputView & arg_in ) :
495  output( arg_out ), input( arg_in )
496  {
497  parallel_for( output.extent(0) , *this );
498  execution_space().fence();
499  }
500 
501  KOKKOS_INLINE_FUNCTION
502  void operator()( const size_type i0 ) const
503  {
504  for ( size_type i1 = 0 ; i1 < output.extent(1) ; ++i1 ) {
505  for ( size_type i2 = 0 ; i2 < output.extent(2) ; ++i2 ) {
506  for ( size_type i3 = 0 ; i3 < output.extent(3) ; ++i3 ) {
507  for ( size_type i4 = 0 ; i4 < output.extent(4) ; ++i4 ) {
508  for ( size_type i5 = 0 ; i5 < output.extent(5) ; ++i5 ) {
509  for ( size_type i6 = 0 ; i6 < output.extent(6) ; ++i6 ) {
510  for ( size_type i7 = 0 ; i7 < output.extent(7) ; ++i7 ) {
511  output.access(i0,i1,i2,i3,i4,i5,i6,i7) = input.access(i0,i1,i2,i3,i4,i5,i6,i7) ;
512  }}}}}}}
513  }
514 };
515 
516 } // namespace Impl
517 } // namespace Experimental
518 
519 /* Specialize for deep copy of UQ::PCE */
520 template< class ExecSpace, class DT , class ... DP , class ST , class ... SP >
521 inline
522 void deep_copy( const ExecSpace &,
523  const View<DT,DP...> & dst ,
524  const View<ST,SP...> & src
525  , typename std::enable_if<(
526  std::is_same< typename ViewTraits<DT,DP...>::specialize
528  &&
529  std::is_same< typename ViewTraits<ST,SP...>::specialize
531  )>::type * )
532 {
533  static_assert(
534  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
535  typename ViewTraits<DT,DP...>::non_const_value_type >::value
536  , "Deep copy destination must be non-const" );
537 
538  static_assert(
539  ( unsigned(ViewTraits<DT,DP...>::rank) ==
540  unsigned(ViewTraits<ST,SP...>::rank) )
541  , "Deep copy destination and source must have same rank" );
542 
543  typedef View<DT,DP...> dst_type ;
544  typedef View<ST,SP...> src_type ;
545  typedef typename dst_type::array_type dst_array_type ;
546  typedef typename src_type::array_type src_array_type ;
547 
549  dst_array_type dst_array = dst ;
550  src_array_type src_array = src ;
551  deep_copy( ExecSpace(), dst_array , src_array );
552  }
553 
554  // otherwise, use a custom kernel
555  else {
556 
557  // If views are in the same memory space, copy component-wise
558  if ( std::is_same< typename dst_type::memory_space ,
559  typename src_type::memory_space >::value ) {
561  }
562 
563  else {
564 
565  typedef View< typename src_type::non_const_data_type ,
566  typename src_type::array_layout ,
567  typename src_type::execution_space > tmp_src_type;
568  typedef typename tmp_src_type::array_type tmp_src_array_type;
569  typedef View< typename dst_type::non_const_data_type ,
570  typename dst_type::array_layout ,
571  typename dst_type::execution_space > tmp_dst_type;
572  typedef typename tmp_dst_type::array_type tmp_dst_array_type;
573 
574  // Copy src into a contiguous view in src's memory space,
575  // then copy to dst
576  if ( is_allocation_contiguous(dst) &&
577  !is_allocation_contiguous(src) ) {
578  size_t src_dims[8];
579  //src.dimensions(src_dims);
580  src_dims[0] = src.extent(0);
581  src_dims[1] = src.extent(1);
582  src_dims[2] = src.extent(2);
583  src_dims[3] = src.extent(3);
584  src_dims[4] = src.extent(4);
585  src_dims[5] = src.extent(5);
586  src_dims[6] = src.extent(6);
587  src_dims[7] = src.extent(7);
588  src_dims[src_type::Rank] = dimension_scalar(src);
589  tmp_src_type src_tmp(
590  view_alloc("src_tmp" , WithoutInitializing, cijk(src) ) ,
591  src_dims[0], src_dims[1], src_dims[2], src_dims[3],
592  src_dims[4], src_dims[5], src_dims[6], src_dims[7] );
594  dst_array_type dst_array = dst ;
595  tmp_src_array_type src_array = src_tmp ;
596  deep_copy( ExecSpace(), dst_array , src_array );
597  }
598 
599  // Copy src into a contiguous view in dst's memory space,
600  // then copy to dst
601  else if ( !is_allocation_contiguous(dst) &&
602  is_allocation_contiguous(src) ) {
603  size_t dst_dims[8];
604  //dst.dimensions(dst_dims);
605  dst_dims[0] = dst.extent(0);
606  dst_dims[1] = dst.extent(1);
607  dst_dims[2] = dst.extent(2);
608  dst_dims[3] = dst.extent(3);
609  dst_dims[4] = dst.extent(4);
610  dst_dims[5] = dst.extent(5);
611  dst_dims[6] = dst.extent(6);
612  dst_dims[7] = dst.extent(7);
613  dst_dims[dst_type::Rank] = dimension_scalar(dst);
614  tmp_dst_type dst_tmp(
615  view_alloc("dst_tmp" , WithoutInitializing, cijk(dst) ) ,
616  dst_dims[0], dst_dims[1], dst_dims[2], dst_dims[3],
617  dst_dims[4], dst_dims[5], dst_dims[6], dst_dims[7] );
618  tmp_dst_array_type dst_array = dst_tmp ;
619  src_array_type src_array = src ;
620  deep_copy( ExecSpace(), dst_array , src_array );
622  }
623 
624  // Copy src into a contiguous view in src's memory space,
625  // copy to a continugous view in dst's memory space, then copy to dst
626  else {
627  size_t src_dims[8];
628  //src.dimensions(src_dims);
629  src_dims[0] = src.extent(0);
630  src_dims[1] = src.extent(1);
631  src_dims[2] = src.extent(2);
632  src_dims[3] = src.extent(3);
633  src_dims[4] = src.extent(4);
634  src_dims[5] = src.extent(5);
635  src_dims[6] = src.extent(6);
636  src_dims[7] = src.extent(7);
637  src_dims[src_type::Rank] = dimension_scalar(src);
638  tmp_src_type src_tmp(
639  view_alloc("src_tmp" , WithoutInitializing, cijk(src) ) ,
640  src_dims[0], src_dims[1], src_dims[2], src_dims[3],
641  src_dims[4], src_dims[5], src_dims[6], src_dims[7] );
643  size_t dst_dims[8];
644  //dst.dimensions(dst_dims);
645  dst_dims[0] = dst.extent(0);
646  dst_dims[1] = dst.extent(1);
647  dst_dims[2] = dst.extent(2);
648  dst_dims[3] = dst.extent(3);
649  dst_dims[4] = dst.extent(4);
650  dst_dims[5] = dst.extent(5);
651  dst_dims[6] = dst.extent(6);
652  dst_dims[7] = dst.extent(7);
653  dst_dims[dst_type::Rank] = dimension_scalar(dst);
654  tmp_dst_type dst_tmp(
655  view_alloc("dst_tmp" , WithoutInitializing, cijk(dst) ) ,
656  dst_dims[0], dst_dims[1], dst_dims[2], dst_dims[3],
657  dst_dims[4], dst_dims[5], dst_dims[6], dst_dims[7] );
658  tmp_dst_array_type dst_array = dst_tmp ;
659  tmp_src_array_type src_array = src_tmp ;
660  deep_copy( ExecSpace(), dst_array , src_array );
662  }
663  }
664  }
665 }
666 
667 /* Specialize for deep copy of UQ::PCE */
668 template< class DT , class ... DP , class ST , class ... SP >
669 inline
670 void deep_copy( const View<DT,DP...> & dst ,
671  const View<ST,SP...> & src
672  , typename std::enable_if<(
673  std::is_same< typename ViewTraits<DT,DP...>::specialize
675  &&
676  std::is_same< typename ViewTraits<ST,SP...>::specialize
678  )>::type * )
679 {
680  using exec_space = typename View<DT,DP...>::execution_space;
681  Kokkos::fence();
682  Kokkos::deep_copy(exec_space(), dst, src);
683  Kokkos::fence();
684 }
685 
686 }
687 
688 //----------------------------------------------------------------------------
689 //----------------------------------------------------------------------------
690 //----------------------------------------------------------------------------
691 
692 namespace Kokkos {
693 //namespace Experimental {
694 namespace Impl {
695 
696 // Allow passing of Cijk tensor through ViewCtorProp
697 template< typename Value, typename Execution, typename Memory >
698 struct ViewCtorProp< void , Stokhos::CrsProductTensor<Value, Execution, Memory> >
699 {
700  ViewCtorProp() = default ;
701  ViewCtorProp( const ViewCtorProp & ) = default ;
702  ViewCtorProp & operator = ( const ViewCtorProp & ) = default ;
703 
705 
706  ViewCtorProp( const type & arg ) : value( arg ) {}
707  ViewCtorProp( type && arg ) : value( arg ) {}
708 
710 };
711 
712 template <typename AllocProp>
714 {
715  static const bool value = false;
716 };
717 
718 template< typename T >
719 struct ctor_prop_has_cijk< ViewCtorProp<T> >
720 {
721  static const bool value = false;
722 };
723 
724 template< typename Value, typename Execution, typename Memory >
726  ViewCtorProp< Stokhos::CrsProductTensor<Value, Execution, Memory> >
727  >
728 {
729  static const bool value = true;
730 };
731 
732 template< typename T, typename ... P >
733 struct ctor_prop_has_cijk< ViewCtorProp<T,P...> >
734 {
735  static const bool value =
737  ctor_prop_has_cijk< ViewCtorProp<P...> >::value;
738 };
739 
740 } /* namespace Impl */
741 //} /* namespace Experimental */
742 
743 template <typename CijkType, typename AllocProp>
744 KOKKOS_INLINE_FUNCTION
745 typename std::enable_if< !Impl::ctor_prop_has_cijk<AllocProp>::value,
746  CijkType >::type
747 extract_cijk(const AllocProp& prop)
748 {
749  return CijkType();
750 }
751 
752 template <typename CijkType, typename AllocProp>
753 KOKKOS_INLINE_FUNCTION
754 typename std::enable_if< Impl::ctor_prop_has_cijk<AllocProp>::value,
755  CijkType >::type
756 extract_cijk(const AllocProp& prop)
757 {
758  return ( (const Impl::ViewCtorProp<void,CijkType>&) prop ).value;
759 }
760 
761 } /* namespace Kokkos */
762 
763 //----------------------------------------------------------------------------
764 //----------------------------------------------------------------------------
765 //----------------------------------------------------------------------------
766 
767 namespace Kokkos {
768 namespace Impl {
769 
770 template< class DataType , class ArrayLayout , typename StorageType >
771 struct ViewDataAnalysis< DataType /* Original view data type */
772  , ArrayLayout
773  , Sacado::UQ::PCE< StorageType > >
774 {
775 private:
776 
778  typedef ViewArrayAnalysis< DataType > array_analysis ;
779 
780 public:
781 
782  // Specialized view data mapping:
784 
785  typedef typename array_analysis::dimension dimension ;
787  typedef typename array_analysis::const_value_type const_value_type ;
788  typedef typename array_analysis::non_const_value_type non_const_value_type ;
789 
790  // Generate analogous multidimensional array specification type.
791  typedef typename
792  ViewDataType< value_type , dimension >::type type ;
793  typedef typename
794  ViewDataType< const_value_type , dimension >::type const_type ;
795  typedef typename
796  ViewDataType< non_const_value_type , dimension >::type non_const_type ;
797 
798 private:
799 
800  // A const ?
801  enum { is_const = std::is_same< value_type , const_value_type >::value };
802 
803  // The unwrapped scalar types:
804  typedef typename
805  std::conditional< is_const , const ScalarType , ScalarType >::type
807 
810 
811  // Prepend or append the pce dimension based on ArrayLayout
812  typedef typename array_analysis::dimension::
813  template prepend<0>::type
815  typedef typename array_analysis::dimension::
816  template append<0>::type
818  typedef typename std::conditional<
819  std::is_same< ArrayLayout, Kokkos::LayoutLeft>::value,
822 
823 public:
824 
825  // Generate "flattened" multidimensional array specification type.
826  typedef typename
827  ViewDataType< scalar_type , scalar_dimension >::type scalar_array_type ;
828 
829  typedef typename
830  ViewDataType< const_scalar_type , scalar_dimension >::type
832 
833  typedef typename
834  ViewDataType< non_const_scalar_type , scalar_dimension >::type
836 };
837 
838 } // namespace Impl
839 } // namespace Kokkos
840 
841 //----------------------------------------------------------------------------
842 
843 namespace Kokkos {
844 namespace Experimental {
845 namespace Impl {
846 
847 // UQ::PCE allocation for dynamically-sized UQ::PCE types.
848 // In this case we allocate two chunks of data, the first for the the
849 // UQ::PCE<Storage> itself and then for the underlying scalar type
850 // (UQ::PCE<Storage>::value_type). The memory is laid out with the
851 // former followed by the latter.
852 template <class ValueType>
854  typedef ValueType value_type;
855  typedef typename Sacado::ValueType<value_type>::type scalar_type;
856  typedef typename value_type::cijk_type cijk_type;
857 
860 
861  KOKKOS_INLINE_FUNCTION
862  static constexpr size_t
863  memory_span(const size_t span, const unsigned pce_size) {
864  return span * ( pce_size * sizeof(scalar_type) + sizeof(value_type) );
865  }
866 
867  KOKKOS_INLINE_FUNCTION
869 
870  template <typename T>
871  KOKKOS_INLINE_FUNCTION
873  value_ptr = a.value_ptr;
875  return *this;
876  }
877 
878  // We are making an assumption the data is laid out as described above,
879  // which in general may not be true if the view is created from memory
880  // allocated elsewhere. We should check for that.
881  KOKKOS_INLINE_FUNCTION
882  void set(value_type* ptr, const size_t span, const unsigned pce_size) {
883  value_ptr = ptr;
884  scalar_ptr = reinterpret_cast<scalar_type*>(ptr+span);
885  }
886 
887  template <class ExecSpace>
888  struct PCEConstruct {
889  ExecSpace m_space;
892  size_t m_span;
893  unsigned m_pce_size;
895 
896  PCEConstruct() = default;
897  PCEConstruct(const PCEConstruct&) = default;
898  PCEConstruct& operator=(const PCEConstruct&) = default;
899 
900  inline
901  PCEConstruct(const ExecSpace& space,
902  value_type* p,
903  scalar_type* sp,
904  const size_t span,
905  const unsigned pce_size,
906  const cijk_type& cijk) :
907  m_space(space), m_p(p), m_sp(sp), m_span(span), m_pce_size(pce_size),
908  m_cijk(cijk) {}
909 
910  inline void execute() {
911  if ( ! m_space.in_parallel() ) {
912  typedef Kokkos::RangePolicy< ExecSpace > PolicyType ;
913  const Kokkos::Impl::ParallelFor< PCEConstruct , PolicyType >
914  closure( *this , PolicyType( 0 , m_span ) );
915  closure.execute();
916  m_space.fence();
917  }
918  else {
919  for ( size_t i = 0 ; i < m_span ; ++i ) operator()(i);
920  }
921  }
922 
923  KOKKOS_INLINE_FUNCTION
924  void operator() (const size_t i) const {
925  new (m_p+i) value_type(m_cijk, m_pce_size, m_sp+i*m_pce_size, false);
926  }
927  };
928 
929  template <class ExecSpace>
931  typedef Kokkos::Impl::ViewValueFunctor< ExecSpace, scalar_type > ScalarFunctorType ;
936 
937  ConstructDestructFunctor() = default;
940 
941  ConstructDestructFunctor(const ExecSpace & space,
942  const bool initialize,
943  const size_t span,
944  const unsigned pce_size,
945  const cijk_type& cijk,
948  m_scalar_functor( space , scalar_ptr , span*pce_size , "Stokhos_UQ_PCE_Contig_ConstructDestructFunctor" ),
949  m_pce_functor( space , value_ptr , scalar_ptr , span , pce_size , cijk ),
950  m_initialize(initialize) {}
951 
953  // First initialize the scalar_type array
954  if (m_initialize)
955  m_scalar_functor.construct_shared_allocation();
956 
957  // Construct each UQ::PCE using memory in scalar_ptr array,
958  // setting pointer to UQ::PCE values from values array
959  // Equivalent to:
960  // value_type* p = value_ptr;
961  // scalar_type* sp = scalar_ptr;
962  // for (size_t i=0; i<span; ++i) {
963  // new (p++) value_type(cijk, pce_size, sp, false);
964  // sp += pce_size;
965  // }
966  // (we always need to do this, regardless of initialization)
968  }
969 
971  // We only need to (possibly) call the destructor on values in the
972  // scalar_type array, since the value_type array is a view into it
973  if (m_initialize)
974  m_scalar_functor.destroy_shared_allocation();
975  }
976 
977  };
978 
979  template <class ExecSpace>
980  inline ConstructDestructFunctor<ExecSpace>
981  create_functor(const ExecSpace & space,
982  const bool initialize,
983  const size_t span,
984  const unsigned pce_size,
985  const cijk_type& cijk) const {
986  return ConstructDestructFunctor<ExecSpace>(space, initialize, span,
987  pce_size, cijk, scalar_ptr,
988  value_ptr);
989  }
990 
991  // Assign scalar_type pointer to give ptr
992  // This makes BIG assumption on how the data was allocated
993  template <typename T>
994  void assign(T * ptr) {
995  value_ptr = reinterpret_cast<value_type*>(ptr);
996  if (ptr != 0)
997  scalar_ptr = value_ptr->coeff();
998  else
999  scalar_ptr = 0;
1000  }
1001 };
1002 
1003 }}} // namespace Kokkos::Experimental::Impl
1004 
1005 namespace Kokkos {
1006 namespace Impl {
1007 
1008 template< class Traits >
1009 class ViewMapping< Traits , /* View internal mapping */
1010  typename std::enable_if<
1011  ( std::is_same< typename Traits::specialize
1012  , Kokkos::Experimental::Impl::ViewPCEContiguous >::value
1013  &&
1014  ( std::is_same< typename Traits::array_layout
1015  , Kokkos::LayoutLeft >::value
1016  ||
1017  std::is_same< typename Traits::array_layout
1018  , Kokkos::LayoutRight >::value
1019  ||
1020  std::is_same< typename Traits::array_layout
1021  , Kokkos::LayoutStride >::value
1022  )
1023  )
1024  , typename Traits::specialize
1025  >::type >
1026 {
1027 private:
1028 
1029  template< class , class ... > friend class ViewMapping ;
1030  template< class , class ... > friend class Kokkos::View ;
1031 
1032 public:
1036  typedef typename
1037  std::add_const< intrinsic_scalar_type >::type const_intrinsic_scalar_type ;
1038  typedef typename sacado_uq_pce_type::cijk_type cijk_type ;
1039 private:
1040 
1042 
1043  typedef ViewOffset< typename Traits::dimension
1044  , typename Traits::array_layout
1045  , void
1047 
1048  // Prepend or append the pce dimension based on array_layout
1049  typedef ViewArrayAnalysis< typename Traits::data_type > array_analysis ;
1050  typedef typename array_analysis::dimension array_dimension;
1051  typedef ViewOffset< typename array_dimension::
1052  template append<0>::type,
1053  typename Traits::array_layout,
1054  void
1056  typedef ViewOffset< typename array_dimension::
1057  template prepend<0>::type,
1058  typename Traits::array_layout,
1059  void
1061  typedef typename std::conditional<
1062  std::is_same< typename Traits::array_layout, Kokkos::LayoutLeft>::value,
1065 
1068  unsigned m_sacado_size ; // Size of sacado dimension
1069  cijk_type m_cijk ; // Sparse 3 tensor
1070  bool m_is_contiguous ; // Is data allocated contiguously
1071 
1072  // Check whether data allocation is contiguous
1073  // Since View() takes an arbitrary pointer, we can't necessarily assume
1074  // the data was allocated contiguously
1075  KOKKOS_INLINE_FUNCTION
1076  bool is_data_contiguous() const {
1077  const size_t sz = this->span();
1078  if (sz == 0)
1079  return true;
1080  const intrinsic_scalar_type* last_coeff =
1081  m_impl_handle.value_ptr[sz-1].coeff();
1082  const intrinsic_scalar_type* last_coeff_expected =
1083  m_impl_handle.scalar_ptr + (sz-1)*m_sacado_size;
1084  return last_coeff == last_coeff_expected;
1085  }
1086 
1087 public:
1088 
1089  //----------------------------------------
1090  // Domain dimensions
1091 
1092  enum { Rank = Traits::dimension::rank };
1093 
1094  // Rank corresponding to the sacado dimension
1095  enum { Sacado_Rank = std::is_same< typename Traits::array_layout, Kokkos::LayoutLeft >::value ? 0 : Rank+1 };
1096 
1097  // Using the internal offset mapping so limit to public rank:
1098  template< typename iType >
1099  KOKKOS_INLINE_FUNCTION constexpr size_t extent( const iType & r ) const
1100  { return m_impl_offset.m_dim.extent(r); }
1101 
1102  KOKKOS_INLINE_FUNCTION constexpr
1103  typename Traits::array_layout layout() const
1104  { return m_impl_offset.layout(); }
1105 
1106  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_0() const
1107  { return m_impl_offset.dimension_0(); }
1108  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_1() const
1109  { return m_impl_offset.dimension_1(); }
1110  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_2() const
1111  { return m_impl_offset.dimension_2(); }
1112  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_3() const
1113  { return m_impl_offset.dimension_3(); }
1114  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_4() const
1115  { return m_impl_offset.dimension_4(); }
1116  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_5() const
1117  { return m_impl_offset.dimension_5(); }
1118  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_6() const
1119  { return m_impl_offset.dimension_6(); }
1120  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_7() const
1121  { return m_impl_offset.dimension_7(); }
1122 
1123  // Is a regular layout with uniform striding for each index.
1124  // Since we all for striding within the data type, we can't guarantee
1125  // regular striding
1126  using is_regular = std::false_type ;
1127 
1128  KOKKOS_INLINE_FUNCTION constexpr size_t stride_0() const
1129  { return m_impl_offset.stride_0(); }
1130  KOKKOS_INLINE_FUNCTION constexpr size_t stride_1() const
1131  { return m_impl_offset.stride_1(); }
1132  KOKKOS_INLINE_FUNCTION constexpr size_t stride_2() const
1133  { return m_impl_offset.stride_2(); }
1134  KOKKOS_INLINE_FUNCTION constexpr size_t stride_3() const
1135  { return m_impl_offset.stride_3(); }
1136  KOKKOS_INLINE_FUNCTION constexpr size_t stride_4() const
1137  { return m_impl_offset.stride_4(); }
1138  KOKKOS_INLINE_FUNCTION constexpr size_t stride_5() const
1139  { return m_impl_offset.stride_5(); }
1140  KOKKOS_INLINE_FUNCTION constexpr size_t stride_6() const
1141  { return m_impl_offset.stride_6(); }
1142  KOKKOS_INLINE_FUNCTION constexpr size_t stride_7() const
1143  { return m_impl_offset.stride_7(); }
1144 
1145  template< typename iType >
1146  KOKKOS_INLINE_FUNCTION void stride( iType * const s ) const
1147  { m_impl_offset.stride(s); }
1148 
1149  // Size of sacado scalar dimension
1150  KOKKOS_FORCEINLINE_FUNCTION constexpr unsigned dimension_scalar() const
1151  { return m_sacado_size; }
1152 
1153  // Sparse tensor
1154  KOKKOS_FORCEINLINE_FUNCTION
1155  cijk_type cijk() const
1156  { return m_cijk; }
1157 
1158  // Sparse tensor
1159  KOKKOS_FORCEINLINE_FUNCTION
1160  void set_cijk(const cijk_type& cijk)
1161  { m_cijk = cijk; }
1162 
1163  // Is allocation contiguous
1164  KOKKOS_INLINE_FUNCTION
1166  { return m_is_contiguous; }
1167 
1168  // Whether the storage type is statically sized
1169  static const bool is_static = false ;
1170 
1171  // Whether sacado dimension is contiguous
1172  static const bool is_contiguous = true;
1173 
1174  //----------------------------------------
1175  // Range of mapping
1176 
1177  // Return type of reference operators
1179 
1182 
1184  KOKKOS_INLINE_FUNCTION constexpr size_t span() const
1185  { return m_impl_offset.span(); }
1186 
1188  KOKKOS_INLINE_FUNCTION constexpr bool span_is_contiguous() const
1189  { return m_impl_offset.span_is_contiguous() ; }
1190 
1192  KOKKOS_INLINE_FUNCTION constexpr pointer_type data() const
1193  { return m_impl_handle.value_ptr ; }
1194 
1195  //----------------------------------------
1196 
1197  KOKKOS_FORCEINLINE_FUNCTION
1199  { return *m_impl_handle.value_ptr; }
1200 
1201  // FIXME: Check this
1202  template< typename I0 >
1203  KOKKOS_FORCEINLINE_FUNCTION
1204  typename
1205  std::enable_if< std::is_integral<I0>::value &&
1206  ! std::is_same< typename Traits::array_layout , Kokkos::LayoutStride >::value
1207  , reference_type >::type
1208  reference( const I0 & i0 ) const
1209  { return m_impl_handle.value_ptr[i0]; }
1210 
1211  // FIXME: Check this
1212  template< typename I0 >
1213  KOKKOS_FORCEINLINE_FUNCTION
1214  typename
1215  std::enable_if< std::is_integral<I0>::value &&
1216  std::is_same< typename Traits::array_layout , Kokkos::LayoutStride >::value
1217  , reference_type >::type
1218  reference( const I0 & i0 ) const
1219  { return m_impl_handle.value_ptr[ m_impl_offset(i0) ]; }
1220 
1221  template< typename I0 , typename I1 >
1222  KOKKOS_FORCEINLINE_FUNCTION
1223  reference_type reference( const I0 & i0 , const I1 & i1 ) const
1224  { return m_impl_handle.value_ptr[ m_impl_offset(i0,i1) ]; }
1225 
1226  template< typename I0 , typename I1 , typename I2 >
1227  KOKKOS_FORCEINLINE_FUNCTION
1228  reference_type reference( const I0 & i0 , const I1 & i1 , const I2 & i2 ) const
1229  { return m_impl_handle.value_ptr[ m_impl_offset(i0,i1,i2) ]; }
1230 
1231  template< typename I0 , typename I1 , typename I2 , typename I3 >
1232  KOKKOS_FORCEINLINE_FUNCTION
1233  reference_type reference( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3 ) const
1234  { return m_impl_handle.value_ptr[ m_impl_offset(i0,i1,i2,i3) ]; }
1235 
1236  template< typename I0 , typename I1 , typename I2 , typename I3
1237  , typename I4 >
1238  KOKKOS_FORCEINLINE_FUNCTION
1239  reference_type reference( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1240  , const I4 & i4 ) const
1241  { return m_impl_handle.value_ptr[ m_impl_offset(i0,i1,i2,i3,i4) ]; }
1242 
1243  template< typename I0 , typename I1 , typename I2 , typename I3
1244  , typename I4 , typename I5 >
1245  KOKKOS_FORCEINLINE_FUNCTION
1246  reference_type reference( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1247  , const I4 & i4 , const I5 & i5 ) const
1248  { return m_impl_handle.value_ptr[ m_impl_offset(i0,i1,i2,i3,i4,i5) ]; }
1249 
1250  template< typename I0 , typename I1 , typename I2 , typename I3
1251  , typename I4 , typename I5 , typename I6 >
1252  KOKKOS_FORCEINLINE_FUNCTION
1253  reference_type reference( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1254  , const I4 & i4 , const I5 & i5 , const I6 & i6 ) const
1255  { return m_impl_handle.value_ptr[ m_impl_offset(i0,i1,i2,i3,i4,i5,i6) ]; }
1256 
1257  template< typename I0 , typename I1 , typename I2 , typename I3
1258  , typename I4 , typename I5 , typename I6 , typename I7 >
1259  KOKKOS_FORCEINLINE_FUNCTION
1260  reference_type reference( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1261  , const I4 & i4 , const I5 & i5 , const I6 & i6 , const I7 & i7 ) const
1262  { return m_impl_handle.value_ptr[ m_impl_offset(i0,i1,i2,i3,i4,i5,i6,i7) ]; }
1263 
1264  //----------------------------------------
1265 
1267  KOKKOS_INLINE_FUNCTION
1268  static size_t memory_span( typename Traits::array_layout const & layout )
1269  {
1270  // Do not introduce padding...
1271  typedef std::integral_constant< unsigned , 0 > padding ;
1272  offset_type offset( padding(), layout );
1273  unsigned sacado_size =
1275  return handle_type::memory_span( offset.span(), sacado_size );
1276  }
1277 
1278  //----------------------------------------
1279 
1280  KOKKOS_DEFAULTED_FUNCTION ~ViewMapping() = default ;
1281  KOKKOS_INLINE_FUNCTION ViewMapping() :
1282  m_impl_handle(),
1283  m_impl_offset(),
1284  m_sacado_size(0),
1285  m_cijk(),
1286  m_is_contiguous(true)
1287  {}
1288 
1289  KOKKOS_DEFAULTED_FUNCTION ViewMapping( const ViewMapping & ) = default ;
1290  KOKKOS_DEFAULTED_FUNCTION ViewMapping & operator = ( const ViewMapping & ) = default ;
1291 
1292  KOKKOS_DEFAULTED_FUNCTION ViewMapping( ViewMapping && ) = default ;
1293  KOKKOS_DEFAULTED_FUNCTION ViewMapping & operator = ( ViewMapping && ) = default ;
1294 
1295  template< class ... P >
1296  KOKKOS_INLINE_FUNCTION
1297  ViewMapping
1298  ( ViewCtorProp< P ... > const & prop
1299  , typename Traits::array_layout const & layout
1300  )
1301  : m_impl_handle()
1302  , m_impl_offset( std::integral_constant< unsigned , 0 >() , layout )
1303  , m_sacado_size( Kokkos::Impl::GetSacadoSize<unsigned(Rank)>::eval(layout) )
1304  {
1305  m_impl_handle.set( ( (ViewCtorProp<void,pointer_type> const &) prop ).value
1306  , m_impl_offset.span(), m_sacado_size );
1307  m_cijk = extract_cijk<cijk_type>(prop);
1308 #ifndef __CUDA_ARCH__
1309  if (m_cijk.dimension() == 0)
1310  m_cijk = getGlobalCijkTensor<cijk_type>();
1311  // Use 0 or KOKKOS_IMPL_CTOR_DEFAULT_ARG to signal the size wasn't
1312  // specified in the constructor
1313  if (m_sacado_size == 0 ||
1314  m_sacado_size == unsigned(KOKKOS_IMPL_CTOR_DEFAULT_ARG))
1315  m_sacado_size = m_cijk.dimension();
1316 #endif
1317  m_is_contiguous = this->is_data_contiguous();
1318  }
1319 
1321  KOKKOS_INLINE_FUNCTION
1322  void assign_data( pointer_type arg_ptr )
1323  { m_impl_handle.set( arg_ptr, m_impl_offset.span(), m_sacado_size ); }
1324 
1325  //----------------------------------------
1326  /* Allocate and construct mapped array.
1327  * Allocate via shared allocation record and
1328  * return that record for allocation tracking.
1329  */
1330  template< class ... P >
1331  SharedAllocationRecord<> *
1332  allocate_shared( ViewCtorProp< P... > const & prop
1333  , typename Traits::array_layout const & layout )
1334  {
1335  typedef ViewCtorProp< P... > ctor_prop ;
1336 
1337  typedef typename ctor_prop::execution_space execution_space ;
1338  typedef typename Traits::memory_space memory_space ;
1339  typedef typename handle_type::template ConstructDestructFunctor<execution_space> functor_type ;
1340  typedef SharedAllocationRecord< memory_space , functor_type > record_type ;
1341 
1342  // Disallow padding
1343  typedef std::integral_constant< unsigned , 0 > padding ;
1344 
1345  m_impl_offset = offset_type( padding(), layout );
1346  m_sacado_size = Kokkos::Impl::GetSacadoSize<unsigned(Rank)>::eval(layout);
1347  m_cijk = extract_cijk<cijk_type>(prop);
1348  if (m_cijk.dimension() == 0)
1349  m_cijk = getGlobalCijkTensor<cijk_type>();
1350  // Use 0 or KOKKOS_IMPL_CTOR_DEFAULT_ARG to signal the size wasn't
1351  // specified in the constructor
1352  if (m_sacado_size == 0 ||
1353  m_sacado_size == unsigned(KOKKOS_IMPL_CTOR_DEFAULT_ARG))
1354  m_sacado_size = m_cijk.dimension();
1355  m_is_contiguous = true;
1356 
1357  const size_t alloc_size =
1358  handle_type::memory_span( m_impl_offset.span(), m_sacado_size );
1359 
1360  // Create shared memory tracking record with allocate memory from the memory space
1361  record_type * const record =
1362  record_type::allocate( ( (ViewCtorProp<void,memory_space> const &) prop ).value
1363  , ( (ViewCtorProp<void,std::string> const &) prop ).value
1364  , alloc_size );
1365 
1366  // Only set the the pointer and initialize if the allocation is non-zero.
1367  // May be zero if one of the dimensions is zero.
1368  if ( alloc_size ) {
1369 
1370  m_impl_handle.set( reinterpret_cast< pointer_type >( record->data() ),
1371  m_impl_offset.span(), m_sacado_size );
1372 
1373  // Assume destruction is only required when construction is requested.
1374  // The ViewValueFunctor has both value construction and destruction operators.
1375  record->m_destroy = m_impl_handle.create_functor(
1376  ( (ViewCtorProp<void,execution_space> const &) prop).value
1377  , ctor_prop::initialize
1378  , m_impl_offset.span()
1379  , m_sacado_size
1380  , m_cijk );
1381 
1382  // Construct values
1383  record->m_destroy.construct_shared_allocation();
1384  }
1385 
1386  return record ;
1387  }
1388 
1389 };
1390 
1391 } // namespace Impl
1392 } // namespace Kokkos
1393 
1394 //----------------------------------------------------------------------------
1395 
1396 namespace Kokkos {
1397 namespace Impl {
1398 
1403 template< class DstTraits , class SrcTraits >
1404 class ViewMapping< DstTraits , SrcTraits ,
1405  typename std::enable_if<(
1406  Kokkos::Impl::MemorySpaceAccess< typename DstTraits::memory_space
1407  , typename SrcTraits::memory_space >::assignable
1408  &&
1409  // Destination view has UQ::PCE
1410  std::is_same< typename DstTraits::specialize
1411  , Kokkos::Experimental::Impl::ViewPCEContiguous >::value
1412  &&
1413  // Source view has UQ::PCE only
1414  std::is_same< typename SrcTraits::specialize
1415  , Kokkos::Experimental::Impl::ViewPCEContiguous >::value
1416  )
1417  , typename DstTraits::specialize
1418  >::type >
1419 {
1420 public:
1421 
1422  enum { is_assignable = true };
1423  enum { is_assignable_data_type = true };
1424 
1425  typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
1426  typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
1427  typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcType ;
1428 
1429  KOKKOS_INLINE_FUNCTION static
1430  void assign( DstType & dst
1431  , const SrcType & src
1432  , const TrackType & )
1433  {
1434  static_assert(
1435  (
1436  std::is_same< typename DstTraits::array_layout
1437  , Kokkos::LayoutLeft >::value ||
1438  std::is_same< typename DstTraits::array_layout
1439  , Kokkos::LayoutRight >::value ||
1440  std::is_same< typename DstTraits::array_layout
1441  , Kokkos::LayoutStride >::value
1442  )
1443  &&
1444  (
1445  std::is_same< typename SrcTraits::array_layout
1446  , Kokkos::LayoutLeft >::value ||
1447  std::is_same< typename SrcTraits::array_layout
1448  , Kokkos::LayoutRight >::value ||
1449  std::is_same< typename SrcTraits::array_layout
1450  , Kokkos::LayoutStride >::value
1451  )
1452  , "View of UQ::PCE requires LayoutLeft, LayoutRight, or LayoutStride" );
1453 
1454  static_assert(
1455  std::is_same< typename DstTraits::array_layout
1456  , typename SrcTraits::array_layout >::value ||
1457  std::is_same< typename DstTraits::array_layout
1458  , Kokkos::LayoutStride >::value ||
1459  ( unsigned(DstTraits::rank) == 1 && unsigned(SrcTraits::rank) == 1 ) ,
1460  "View assignment must have compatible layout" );
1461 
1462  static_assert(
1463  std::is_same< typename DstTraits::value_type
1464  , typename SrcTraits::value_type >::value ||
1465  std::is_same< typename DstTraits::value_type
1466  , typename SrcTraits::const_value_type >::value ,
1467  "View assignment must have same value type or const = non-const" );
1468 
1469  static_assert(
1470  ViewDimensionAssignable
1471  < typename DstType::offset_type::dimension_type
1472  , typename SrcType::offset_type::dimension_type >::value ,
1473  "View assignment must have compatible dimensions" );
1474 
1475  dst.m_impl_handle = src.m_impl_handle ;
1476  dst.m_impl_offset = src.m_impl_offset ;
1477  dst.m_sacado_size = src.m_sacado_size ;
1478  dst.m_cijk = src.m_cijk ;
1479  dst.m_is_contiguous = src.m_is_contiguous ;
1480  }
1481 };
1482 
1488 template< class DstTraits , class SrcTraits >
1489 class ViewMapping< DstTraits , SrcTraits ,
1490  typename std::enable_if<(
1491  Kokkos::Impl::MemorySpaceAccess< typename DstTraits::memory_space
1492  , typename SrcTraits::memory_space >::assignable
1493  &&
1494  // Destination view has ordinary
1495  std::is_same< typename DstTraits::specialize , void >::value
1496  &&
1497  // Source view has UQ::PCE only
1498  std::is_same< typename SrcTraits::specialize
1499  , Kokkos::Experimental::Impl::ViewPCEContiguous >::value
1500  &&
1501  // Ranks match
1502  unsigned(DstTraits::dimension::rank) == unsigned(SrcTraits::dimension::rank)+1
1503  )
1504  , typename DstTraits::specialize
1505  >::type >
1506 {
1507 public:
1508 
1509  enum { is_assignable = true };
1510  enum { is_assignable_data_type = true };
1511 
1512  typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
1513  typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
1514  typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcType ;
1515 
1516  KOKKOS_INLINE_FUNCTION static
1517  void assign( DstType & dst
1518  , const SrcType & src
1519  , const TrackType & )
1520  {
1521  static_assert(
1522  (
1523  std::is_same< typename DstTraits::array_layout
1524  , Kokkos::LayoutLeft >::value ||
1525  std::is_same< typename DstTraits::array_layout
1526  , Kokkos::LayoutRight >::value ||
1527  std::is_same< typename DstTraits::array_layout
1528  , Kokkos::LayoutStride >::value
1529  )
1530  &&
1531  (
1532  std::is_same< typename SrcTraits::array_layout
1533  , Kokkos::LayoutLeft >::value ||
1534  std::is_same< typename SrcTraits::array_layout
1535  , Kokkos::LayoutRight >::value ||
1536  std::is_same< typename SrcTraits::array_layout
1537  , Kokkos::LayoutStride >::value
1538  )
1539  , "View of UQ::PCE requires LayoutLeft, LayoutRight, or LayoutStride" );
1540 
1541  static_assert(
1542  std::is_same< typename DstTraits::array_layout
1543  , typename SrcTraits::array_layout >::value ||
1544  std::is_same< typename DstTraits::array_layout
1545  , Kokkos::LayoutStride >::value ,
1546  "View assignment must have compatible layout" );
1547 
1548  static_assert(
1549  std::is_same< typename DstTraits::scalar_array_type
1550  , typename SrcTraits::scalar_array_type >::value ||
1551  std::is_same< typename DstTraits::scalar_array_type
1552  , typename SrcTraits::const_scalar_array_type >::value ,
1553  "View assignment must have same value type or const = non-const" );
1554 
1555  static_assert(
1556  ViewDimensionAssignable<
1557  typename DstType::offset_type::dimension_type,
1558  typename SrcType::array_offset_type::dimension_type >::value,
1559  "View assignment must have compatible dimensions" );
1560 
1561  if ( !src.m_is_contiguous )
1562  Kokkos::abort("\n\n ****** Kokkos::View< Sacado::UQ::PCE ... >: can't assign non-contiguous view ******\n\n");
1563 
1564  unsigned dims[8];
1565  dims[0] = src.m_impl_offset.dimension_0();
1566  dims[1] = src.m_impl_offset.dimension_1();
1567  dims[2] = src.m_impl_offset.dimension_2();
1568  dims[3] = src.m_impl_offset.dimension_3();
1569  dims[4] = src.m_impl_offset.dimension_4();
1570  dims[5] = src.m_impl_offset.dimension_5();
1571  dims[6] = src.m_impl_offset.dimension_6();
1572  dims[7] = src.m_impl_offset.dimension_7();
1573  unsigned rank = SrcTraits::dimension::rank;
1574  unsigned sacado_size = src.m_sacado_size;
1575  if (std::is_same<typename SrcTraits::array_layout, LayoutLeft>::value) {
1576  // Move sacado_size to the first dimension, shift all others up one
1577  for (unsigned i=rank; i>0; --i)
1578  dims[i] = dims[i-1];
1579  dims[0] = sacado_size;
1580  }
1581  else {
1582  dims[rank] = sacado_size;
1583  }
1584  typedef typename DstType::offset_type dst_offset_type;
1585  dst.m_impl_offset = dst_offset_type( std::integral_constant< unsigned , 0 >(),
1586  typename DstTraits::array_layout(
1587  dims[0] , dims[1] , dims[2] , dims[3] ,
1588  dims[4] , dims[5] , dims[6] , dims[7] ) );
1589  dst.m_impl_handle = src.m_impl_handle.scalar_ptr ;
1590  }
1591 };
1592 
1599 template< class DstTraits , class SrcTraits >
1600 class ViewMapping< DstTraits , SrcTraits ,
1601  typename std::enable_if<(
1602  Kokkos::Impl::MemorySpaceAccess< typename DstTraits::memory_space
1603  , typename SrcTraits::memory_space >::assignable
1604  &&
1605  // Destination view has ordinary
1606  std::is_same< typename DstTraits::specialize , void >::value
1607  &&
1608  // Source view has UQ::PCE only
1609  std::is_same< typename SrcTraits::specialize
1610  , Kokkos::Experimental::Impl::ViewPCEContiguous >::value
1611  &&
1612  // Ranks match
1613  unsigned(DstTraits::dimension::rank) == unsigned(SrcTraits::dimension::rank)
1614  )
1615  , typename DstTraits::specialize
1616  >::type >
1617 {
1618 public:
1619 
1620  enum { is_assignable = true };
1621  enum { is_assignable_data_type = true };
1622 
1623  typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
1624  typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
1625  typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcType ;
1626 
1627  KOKKOS_INLINE_FUNCTION static
1628  void assign( DstType & dst
1629  , const SrcType & src
1630  , const TrackType & )
1631  {
1632  static_assert(
1633  (
1634  std::is_same< typename DstTraits::array_layout
1635  , Kokkos::LayoutLeft >::value ||
1636  std::is_same< typename DstTraits::array_layout
1637  , Kokkos::LayoutRight >::value ||
1638  std::is_same< typename DstTraits::array_layout
1639  , Kokkos::LayoutStride >::value
1640  )
1641  &&
1642  (
1643  std::is_same< typename SrcTraits::array_layout
1644  , Kokkos::LayoutLeft >::value ||
1645  std::is_same< typename SrcTraits::array_layout
1646  , Kokkos::LayoutRight >::value ||
1647  std::is_same< typename SrcTraits::array_layout
1648  , Kokkos::LayoutStride >::value
1649  )
1650  , "View of UQ::PCE requires LayoutLeft, LayoutRight, or LayoutStride" );
1651 
1652  static_assert(
1653  std::is_same< typename DstTraits::array_layout
1654  , typename SrcTraits::array_layout >::value ||
1655  std::is_same< typename DstTraits::array_layout
1656  , Kokkos::LayoutStride >::value ,
1657  "View assignment must have compatible layout" );
1658 
1659  static_assert(
1660  std::is_same< typename DstTraits::value_type
1661  , typename SrcTraits::non_const_value_type::value_type >::value ||
1662  std::is_same< typename DstTraits::value_type
1663  , const typename SrcTraits::non_const_value_type::value_type >::value ,
1664  "View assignment must have same value type or const = non-const" );
1665 
1666  static_assert(
1667  ViewDimensionAssignable<
1668  typename DstType::offset_type::dimension_type,
1669  typename SrcType::offset_type::dimension_type >::value,
1670  "View assignment must have compatible dimensions" );
1671 
1672  if ( !src.m_is_contiguous )
1673  Kokkos::abort("\n\n ****** Kokkos::View< Sacado::UQ::PCE ... >: can't assign non-contiguous view ******\n\n");
1674 
1675  unsigned dims[8];
1676  dims[0] = src.m_impl_offset.dimension_0();
1677  dims[1] = src.m_impl_offset.dimension_1();
1678  dims[2] = src.m_impl_offset.dimension_2();
1679  dims[3] = src.m_impl_offset.dimension_3();
1680  dims[4] = src.m_impl_offset.dimension_4();
1681  dims[5] = src.m_impl_offset.dimension_5();
1682  dims[6] = src.m_impl_offset.dimension_6();
1683  dims[7] = src.m_impl_offset.dimension_7();
1684  unsigned rank = SrcTraits::dimension::rank;
1685  unsigned sacado_size = src.m_sacado_size;
1686  if (std::is_same<typename DstTraits::array_layout, LayoutLeft>::value) {
1687  dims[0] = dims[0]*sacado_size;
1688  dims[rank] = 0;
1689  }
1690  else {
1691  dims[rank-1] = dims[rank-1]*sacado_size;
1692  dims[rank] = 0;
1693  }
1694  typedef typename DstType::offset_type dst_offset_type;
1695  dst.m_impl_offset = dst_offset_type( std::integral_constant< unsigned , 0 >(),
1696  typename DstTraits::array_layout(
1697  dims[0] , dims[1] , dims[2] , dims[3] ,
1698  dims[4] , dims[5] , dims[6] , dims[7] ) );
1699  dst.m_impl_handle = src.m_impl_handle.scalar_ptr ;
1700  }
1701 };
1702 
1703 } // namespace Impl
1704 } // namespace Kokkos
1705 
1706 //----------------------------------------------------------------------------
1707 
1708 namespace Kokkos {
1709 namespace Impl {
1710 
1711 // Subview mapping
1712 
1713 template< class DataType, class ... P , class Arg0, class ... Args >
1714 struct ViewMapping
1715  < typename std::enable_if<(
1716  // Source view has UQ::PCE only
1717  std::is_same< typename Kokkos::ViewTraits<DataType,P...>::specialize
1718  , Kokkos::Experimental::Impl::ViewPCEContiguous >::value
1719  &&
1720  (
1721  std::is_same< typename Kokkos::ViewTraits<DataType,P...>::array_layout
1722  , Kokkos::LayoutLeft >::value ||
1723  std::is_same< typename Kokkos::ViewTraits<DataType,P...>::array_layout
1724  , Kokkos::LayoutRight >::value ||
1725  std::is_same< typename Kokkos::ViewTraits<DataType,P...>::array_layout
1726  , Kokkos::LayoutStride >::value
1727  )
1728  )>::type
1729  , Kokkos::ViewTraits<DataType,P...>
1730  , Arg0, Args ... >
1731 {
1732 private:
1733 
1734  typedef Kokkos::ViewTraits<DataType,P...> SrcTraits;
1735 
1736  //static_assert( SrcTraits::rank == sizeof...(Args) , "" );
1737 
1738  enum
1739  { RZ = false
1740  , R0 = bool(is_integral_extent<0,Arg0,Args...>::value)
1741  , R1 = bool(is_integral_extent<1,Arg0,Args...>::value)
1742  , R2 = bool(is_integral_extent<2,Arg0,Args...>::value)
1743  , R3 = bool(is_integral_extent<3,Arg0,Args...>::value)
1744  , R4 = bool(is_integral_extent<4,Arg0,Args...>::value)
1745  , R5 = bool(is_integral_extent<5,Arg0,Args...>::value)
1746  , R6 = bool(is_integral_extent<6,Arg0,Args...>::value)
1747  };
1748 
1749  // Public rank
1750  enum { rank = unsigned(R0) + unsigned(R1) + unsigned(R2) + unsigned(R3)
1751  + unsigned(R4) + unsigned(R5) + unsigned(R6) };
1752 
1753  // Whether right-most non-UQ::PCE rank is a range.
1754  enum { R0_rev = ( 0 == SrcTraits::rank ? RZ : (
1755  1 == SrcTraits::rank ? R0 : (
1756  2 == SrcTraits::rank ? R1 : (
1757  3 == SrcTraits::rank ? R2 : (
1758  4 == SrcTraits::rank ? R3 : (
1759  5 == SrcTraits::rank ? R4 : (
1760  6 == SrcTraits::rank ? R5 : R6 ))))))) };
1761 
1762  // Subview's layout
1763  typedef typename std::conditional<
1764  ( /* Same array layout IF */
1765  ( rank == 0 ) /* output rank zero */
1766  ||
1767  // OutputRank 1 or 2, InputLayout Left, Interval 0
1768  // because single stride one or second index has a stride.
1769  ( rank <= 2 && R0 && std::is_same< typename SrcTraits::array_layout , Kokkos::LayoutLeft >::value )
1770  ||
1771  // OutputRank 1 or 2, InputLayout Right, Interval [InputRank-1]
1772  // because single stride one or second index has a stride.
1773  ( rank <= 2 && R0_rev && std::is_same< typename SrcTraits::array_layout , Kokkos::LayoutRight >::value )
1774  ), typename SrcTraits::array_layout , Kokkos::LayoutStride
1776 
1778 
1779  typedef typename std::conditional< rank == 0 , sacado_uq_pce_type ,
1780  typename std::conditional< rank == 1 , sacado_uq_pce_type * ,
1781  typename std::conditional< rank == 2 , sacado_uq_pce_type ** ,
1782  typename std::conditional< rank == 3 , sacado_uq_pce_type *** ,
1783  typename std::conditional< rank == 4 , sacado_uq_pce_type **** ,
1784  typename std::conditional< rank == 5 , sacado_uq_pce_type ***** ,
1785  typename std::conditional< rank == 6 , sacado_uq_pce_type ****** ,
1786  sacado_uq_pce_type *******
1789 
1790 public:
1791 
1792  typedef Kokkos::ViewTraits
1793  < data_type
1794  , array_layout
1795  , typename SrcTraits::device_type
1796  , typename SrcTraits::memory_traits > traits_type ;
1797 
1798  typedef Kokkos::View
1799  < data_type
1800  , array_layout
1801  , typename SrcTraits::device_type
1802  , typename SrcTraits::memory_traits > type ;
1803 
1804 
1805  // The presumed type is 'ViewMapping< traits_type , void >'
1806  // However, a compatible ViewMapping is acceptable.
1807  template< class DstTraits >
1808  KOKKOS_INLINE_FUNCTION
1809  static void assign( ViewMapping< DstTraits , typename DstTraits::specialize > & dst
1810  , ViewMapping< SrcTraits , typename SrcTraits::specialize > const & src
1811  , Arg0 arg0, Args ... args )
1812  {
1813  static_assert(
1814  ViewMapping< DstTraits , traits_type , typename DstTraits::specialize >::is_assignable ,
1815  "Subview destination type must be compatible with subview derived type" );
1816 
1817  typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
1818  typedef typename DstType::offset_type dst_offset_type ;
1819 
1820  const SubviewExtents< SrcTraits::rank , rank >
1821  extents( src.m_impl_offset.m_dim , arg0 , args... );
1822 
1823  const size_t offset = src.m_impl_offset( extents.domain_offset(0)
1824  , extents.domain_offset(1)
1825  , extents.domain_offset(2)
1826  , extents.domain_offset(3)
1827  , extents.domain_offset(4)
1828  , extents.domain_offset(5)
1829  , extents.domain_offset(6)
1830  , extents.domain_offset(7) );
1831 
1832  dst.m_impl_offset = dst_offset_type( src.m_impl_offset , extents );
1833  dst.m_impl_handle.value_ptr = src.m_impl_handle.value_ptr + offset;
1834  dst.m_impl_handle.scalar_ptr =
1835  src.m_impl_handle.scalar_ptr + offset * src.m_sacado_size;
1836  dst.m_sacado_size = src.m_sacado_size;
1837  dst.m_cijk = src.m_cijk;
1838  dst.m_is_contiguous = src.m_is_contiguous;
1839  }
1840 
1841 };
1842 
1843 } // namespace Impl
1844 } // namespace Kokkos
1845 
1846 //----------------------------------------------------------------------------
1847 //----------------------------------------------------------------------------
1848 //----------------------------------------------------------------------------
1849 
1850 namespace Kokkos {
1851 namespace Impl {
1852 
1853 // Specialization for deep_copy( view, view::value_type ) for Cuda
1854 #if defined( KOKKOS_ENABLE_CUDA )
1855 template< class OutputView >
1856 struct StokhosViewFill< OutputView ,
1857  typename std::enable_if< std::is_same< typename OutputView::specialize,
1858  Kokkos::Experimental::Impl::ViewPCEContiguous >::value &&
1859  std::is_same< typename OutputView::execution_space,
1860  Cuda >::value >::type >
1861 {
1862  typedef typename OutputView::const_value_type const_value_type ;
1863  typedef typename Sacado::ScalarType<const_value_type>::type scalar_type ;
1864  typedef typename OutputView::execution_space execution_space ;
1865  typedef typename OutputView::size_type size_type ;
1866 
1867  template <unsigned VectorLength>
1868  struct PCEKernel {
1869  typedef typename OutputView::execution_space execution_space ;
1870  const OutputView output;
1872 
1873  PCEKernel( const OutputView & arg_out , const_value_type & arg_in ) :
1874  output(arg_out), input(arg_in) {}
1875 
1876  typedef typename Kokkos::TeamPolicy< execution_space >::member_type team_member ;
1877 
1878  KOKKOS_INLINE_FUNCTION
1879  void operator()( const team_member & dev ) const
1880  {
1881  const size_type tidx = dev.team_rank() % VectorLength;
1882  const size_type tidy = dev.team_rank() / VectorLength;
1883  const size_type nrow = dev.team_size() / VectorLength;
1884  const size_type nvec = dimension_scalar(output);
1885 
1886  const size_type i0 = dev.league_rank() * nrow + tidy;
1887  if ( i0 >= output.extent(0) ) return;
1888 
1889  for ( size_type i1 = 0 ; i1 < output.extent(1) ; ++i1 ) {
1890  for ( size_type i2 = 0 ; i2 < output.extent(2) ; ++i2 ) {
1891  for ( size_type i3 = 0 ; i3 < output.extent(3) ; ++i3 ) {
1892  for ( size_type i4 = 0 ; i4 < output.extent(4) ; ++i4 ) {
1893  for ( size_type i5 = 0 ; i5 < output.extent(5) ; ++i5 ) {
1894  for ( size_type i6 = 0 ; i6 < output.extent(6) ; ++i6 ) {
1895  for ( size_type i7 = 0 ; i7 < output.extent(7) ; ++i7 ) {
1896  for ( size_type is = tidx ; is < nvec ; is+=VectorLength ) {
1897  output.access(i0,i1,i2,i3,i4,i5,i6,i7).fastAccessCoeff(is) =
1898  input.fastAccessCoeff(is) ;
1899  }}}}}}}}
1900  }
1901  };
1902 
1903  template <unsigned VectorLength>
1904  struct ScalarKernel {
1905  typedef typename OutputView::execution_space execution_space ;
1906  const OutputView output;
1907  const scalar_type input;
1908 
1909  ScalarKernel( const OutputView & arg_out , const scalar_type & arg_in ) :
1910  output(arg_out), input(arg_in) {}
1911 
1912  typedef typename Kokkos::TeamPolicy< execution_space >::member_type team_member ;
1913  KOKKOS_INLINE_FUNCTION
1914  void operator()( const team_member & dev ) const
1915  {
1916  const size_type tidx = dev.team_rank() % VectorLength;
1917  const size_type tidy = dev.team_rank() / VectorLength;
1918  const size_type nrow = dev.team_size() / VectorLength;
1919  const size_type npce = dimension_scalar(output);
1920 
1921  const size_type i0 = dev.league_rank() * nrow + tidy;
1922  if ( i0 >= output.extent(0) ) return;
1923 
1924  for ( size_type i1 = 0 ; i1 < output.extent(1) ; ++i1 ) {
1925  for ( size_type i2 = 0 ; i2 < output.extent(2) ; ++i2 ) {
1926  for ( size_type i3 = 0 ; i3 < output.extent(3) ; ++i3 ) {
1927  for ( size_type i4 = 0 ; i4 < output.extent(4) ; ++i4 ) {
1928  for ( size_type i5 = 0 ; i5 < output.extent(5) ; ++i5 ) {
1929  for ( size_type i6 = 0 ; i6 < output.extent(6) ; ++i6 ) {
1930  for ( size_type i7 = 0 ; i7 < output.extent(7) ; ++i7 ) {
1931  for ( size_type is = tidx ; is < npce ; is+=VectorLength ) {
1932  output.access(i0,i1,i2,i3,i4,i5,i6,i7).fastAccessCoeff(is) =
1933  is == 0 ? input : scalar_type(0) ;
1934  }}}}}}}}
1935  }
1936  };
1937 
1938  StokhosViewFill( const OutputView & output , const_value_type & input )
1939  {
1940  // Coalesced accesses are 128 bytes in size
1942  const unsigned vector_length =
1943  ( 128 + sizeof(scalar_type)-1 ) / sizeof(scalar_type);
1944 
1945  // 8 warps per block should give good occupancy
1946  const size_type block_size = 256;
1947 
1948  const size_type rows_per_block = block_size / vector_length;
1949  const size_type n = output.extent(0);
1950  const size_type league_size = ( n + rows_per_block-1 ) / rows_per_block;
1951  const size_type team_size = rows_per_block * vector_length;
1952  Kokkos::TeamPolicy< execution_space > config( league_size, team_size );
1953 
1954  if (static_cast<unsigned>(input.size()) != dimension_scalar(output) &&
1955  input.size() != 1)
1956  Kokkos::abort("StokhosViewFill: Invalid input value size");
1957 
1958  if (input.size() == 1)
1959  parallel_for(
1960  config, ScalarKernel<vector_length>(output, input.fastAccessCoeff(0)) );
1961  else
1962  parallel_for( config, PCEKernel<vector_length>(output, input) );
1963  execution_space().fence();
1964  }
1965 
1966  StokhosViewFill( const OutputView & output , const scalar_type & input )
1967  {
1968  // Coalesced accesses are 128 bytes in size
1970  const unsigned vector_length =
1971  ( 128 + sizeof(scalar_type)-1 ) / sizeof(scalar_type);
1972 
1973  // 8 warps per block should give good occupancy
1974  const size_type block_size = 256;
1975 
1976  const size_type rows_per_block = block_size / vector_length;
1977  const size_type n = output.extent(0);
1978  const size_type league_size = ( n + rows_per_block-1 ) / rows_per_block;
1979  const size_type team_size = rows_per_block * vector_length;
1980  Kokkos::TeamPolicy< execution_space > config( league_size, team_size );
1981 
1982  parallel_for( config, ScalarKernel<vector_length>(output, input) );
1983  execution_space().fence();
1984  }
1985 
1986 };
1987 #endif /* #if defined( KOKKOS_ENABLE_CUDA ) */
1988 
1989 } // namespace Impl
1990 } // namespace Kokkos
1991 
1992 #include "Kokkos_View_Utils_Def.hpp"
1993 
1994 //----------------------------------------------------------------------------
1995 //----------------------------------------------------------------------------
1996 //----------------------------------------------------------------------------
1997 
1998 #endif /* #ifndef KOKKOS_EXPERIMENTAL_VIEW_UQ_PCE_CONTIGUOUS_HPP */
static KOKKOS_INLINE_FUNCTION constexpr size_t memory_span(const size_t span, const unsigned pce_size)
Stokhos::StandardStorage< int, double > storage_type
KOKKOS_INLINE_FUNCTION PCEAllocation & operator=(const PCEAllocation< T > &a)
Kokkos::DefaultExecutionSpace execution_space
KOKKOS_INLINE_FUNCTION void operator()(const size_type i0) const
ConstructDestructFunctor< ExecSpace > create_functor(const ExecSpace &space, const bool initialize, const size_t span, const unsigned pce_size, const cijk_type &cijk) const
ViewType make_view(const std::string &label, size_t N0=0, size_t N1=0, size_t N2=0, size_t N3=0, size_t N4=0, size_t N5=0, size_t N6=0, size_t N7=0)
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< view_type >::value, bool >::type is_allocation_contiguous(const view_type &view)
OutputView::const_value_type const_value_type
std::conditional< rank==0, sacado_uq_pce_type, typename std::conditional< rank==1, sacado_uq_pce_type *, typename std::conditional< rank==2, sacado_uq_pce_type **, typename std::conditional< rank==3, sacado_uq_pce_type ***, typename std::conditional< rank==4, sacado_uq_pce_type ****, typename std::conditional< rank==5, sacado_uq_pce_type *****, typename std::conditional< rank==6, sacado_uq_pce_type ******, sacado_uq_pce_type *******>::type >::type >::type >::type >::type >::type >::type data_type
DeepCopyNonContiguous(const OutputView &arg_out, const InputView &arg_in)
Top-level namespace for Stokhos classes and functions.
KOKKOS_INLINE_FUNCTION void operator()(const size_t i) const
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< View< T, P... > >::value, unsigned >::type dimension_scalar(const View< T, P... > &view)
OutputView::execution_space execution_space
KOKKOS_INLINE_FUNCTION void operator()(const size_t i0) const
ConstructDestructFunctor & operator=(const ConstructDestructFunctor &)=default
void deep_copy(const Stokhos::CrsMatrix< ValueType, DstDevice, Layout > &dst, const Stokhos::CrsMatrix< ValueType, SrcDevice, Layout > &src)
StokhosViewFill(const OutputView &arg_out, const_value_type &arg_in)
Kokkos::Impl::ViewValueFunctor< ExecSpace, scalar_type > ScalarFunctorType
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< view_type >::value, typename CijkType< view_type >::type >::type cijk(const view_type &view)
ConstructDestructFunctor(const ExecSpace &space, const bool initialize, const size_t span, const unsigned pce_size, const cijk_type &cijk, scalar_type *scalar_ptr, value_type *value_ptr)
PCEConstruct(const ExecSpace &space, value_type *p, scalar_type *sp, const size_t span, const unsigned pce_size, const cijk_type &cijk)
KOKKOS_INLINE_FUNCTION std::enable_if< !Impl::ctor_prop_has_cijk< AllocProp >::value, CijkType >::type extract_cijk(const AllocProp &prop)
KOKKOS_INLINE_FUNCTION void set(value_type *ptr, const size_t span, const unsigned pce_size)
std::conditional< std::is_same< ArrayLayout, Kokkos::LayoutLeft >::value, prepend_scalar_dimension, append_scalar_dimension >::type scalar_dimension
PCEConstruct & operator=(const PCEConstruct &)=default
Stokhos::CrsMatrix< ValueType, Device, Layout >::HostMirror create_mirror(const Stokhos::CrsMatrix< ValueType, Device, Layout > &A)