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 template <typename T, typename ... P>
191 struct is_view_uq_pce< View<T,P...> > {
192  typedef View<T,P...> view_type;
193  static const bool value =
194  std::is_same< typename view_type::specialize,
196 };
197 
198 template <typename ViewType>
199 struct CijkType< ViewType,
200  typename std::enable_if< is_view_uq_pce< ViewType >::value >::type > {
201  typedef typename ViewType::non_const_value_type::cijk_type type;
202 };
203 
204 template <typename T, typename ... P>
205 KOKKOS_INLINE_FUNCTION
206 constexpr typename
207 std::enable_if< is_view_uq_pce< View<T,P...> >::value, unsigned >::type
208 dimension_scalar(const View<T,P...>& view) {
209  return view.implementation_map().dimension_scalar();
210 }
211 
212 template <typename view_type>
213 KOKKOS_INLINE_FUNCTION
214 constexpr typename
215 std::enable_if< is_view_uq_pce<view_type>::value,
216  typename CijkType<view_type>::type >::type
217 cijk(const view_type& view) {
218  return view.implementation_map().cijk();
219 }
220 
221 template <typename view_type>
222 KOKKOS_INLINE_FUNCTION
223 constexpr typename
224 std::enable_if< is_view_uq_pce<view_type>::value, bool >::type
225 is_allocation_contiguous(const view_type& view) {
226  return view.implementation_map().is_allocation_contiguous();
227 }
228 
229 template <typename ViewType>
230 ViewType
231 make_view(const std::string& label,
232  const typename CijkType<ViewType>::type& cijk,
233  size_t N0 = 0, size_t N1 = 0, size_t N2 = 0, size_t N3 = 0,
234  size_t N4 = 0, size_t N5 = 0, size_t N6 = 0, size_t N7 = 0)
235 {
236  return ViewType(view_alloc(label,cijk),
237  N0, N1, N2, N3, N4, N5, N6, N7);
238 }
239 
240 template <typename ViewType>
241 ViewType
242 make_view(const std::string& label,
243  const Impl::WithoutInitializing_t& init,
244  const typename CijkType<ViewType>::type& cijk,
245  size_t N0 = 0, size_t N1 = 0, size_t N2 = 0, size_t N3 = 0,
246  size_t N4 = 0, size_t N5 = 0, size_t N6 = 0, size_t N7 = 0)
247 {
248  return ViewType(view_alloc(label,init,cijk),
249  N0, N1, N2, N3, N4, N5, N6, N7);
250 }
251 
252 template <typename ViewType>
253 ViewType
254 make_view(const ViewAllocateWithoutInitializing& init,
255  const typename CijkType<ViewType>::type& cijk,
256  size_t N0 = 0, size_t N1 = 0, size_t N2 = 0, size_t N3 = 0,
257  size_t N4 = 0, size_t N5 = 0, size_t N6 = 0, size_t N7 = 0)
258 {
259  return ViewType(view_alloc(init.label,
260  WithoutInitializing,
261  cijk),
262  N0, N1, N2, N3, N4, N5, N6, N7);
263 }
264 
265 template <typename ViewType>
266 typename std::enable_if< is_view_uq_pce<ViewType>::value, ViewType>::type
267 make_view(typename ViewType::pointer_type ptr,
268  const typename CijkType<ViewType>::type& cijk,
269  size_t N0 = 0, size_t N1 = 0, size_t N2 = 0, size_t N3 = 0,
270  size_t N4 = 0, size_t N5 = 0, size_t N6 = 0, size_t N7 = 0)
271 {
272  size_t N[8] = { N0, N1, N2, N3, N4, N5, N6, N7 };
273  N[ViewType::rank] = cijk.dimension();
274  ViewType v(view_wrap(ptr, cijk),
275  N[0], N[1], N[2], N[3], N[4], N[5], N[6], N[7]);
276  return v;
277 }
278 
279 } // namespace Kokkos
280 
281 #include "Sacado_Traits.hpp"
282 #include "Sacado_UQ_PCE.hpp"
283 #include "Sacado_UQ_PCE_Traits.hpp"
284 #include "Kokkos_Core.hpp"
285 
286 namespace Kokkos {
287 
288 template <typename D, typename ... P>
289 struct FlatArrayType< View<D,P...>,
290  typename std::enable_if< is_view_uq_pce< View<D,P...> >::value >::type > {
291  typedef View<D,P...> view_type;
292  typedef typename view_type::traits::dimension dimension;
294  typedef typename Kokkos::Impl::ViewDataType< flat_value_type , dimension >::type flat_data_type;
295  typedef View<flat_data_type,P...> type;
296 };
297 
298 template< class T , class ... P >
299 inline
300 typename Kokkos::View<T,P...>::HostMirror
301 create_mirror( const Kokkos::View<T,P...> & src
302  , typename std::enable_if<
303  std::is_same< typename ViewTraits<T,P...>::specialize ,
305  &&
306  ! std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
307  , Kokkos::LayoutStride >::value
308  >::type *
309  )
310 {
311  typedef View<T,P...> src_type ;
312  typedef typename src_type::HostMirror dst_type ;
313 
314  typename src_type::array_layout layout = src.layout();
315  layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
316 
317  return dst_type(view_alloc(std::string(src.label()).append("_mirror"),
318  src.implementation_map().cijk()), layout);
319 }
320 
321 template< class T , class ... P >
322 inline
323 typename Kokkos::View<T,P...>::HostMirror
324 create_mirror( const Kokkos::View<T,P...> & src
325  , typename std::enable_if<
326  std::is_same< typename ViewTraits<T,P...>::specialize ,
328  &&
329  std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
330  , Kokkos::LayoutStride >::value
331  >::type *
332  )
333 {
334  typedef View<T,P...> src_type ;
335  typedef typename src_type::HostMirror dst_type ;
336 
337  Kokkos::LayoutStride layout ;
338 
339  layout.dimension[0] = src.extent(0);
340  layout.dimension[1] = src.extent(1);
341  layout.dimension[2] = src.extent(2);
342  layout.dimension[3] = src.extent(3);
343  layout.dimension[4] = src.extent(4);
344  layout.dimension[5] = src.extent(5);
345  layout.dimension[6] = src.extent(6);
346  layout.dimension[7] = src.extent(7);
347 
348  layout.stride[0] = src.stride_0();
349  layout.stride[1] = src.stride_1();
350  layout.stride[2] = src.stride_2();
351  layout.stride[3] = src.stride_3();
352  layout.stride[4] = src.stride_4();
353  layout.stride[5] = src.stride_5();
354  layout.stride[6] = src.stride_6();
355  layout.stride[7] = src.stride_7();
356 
357  layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
358 
359  return dst_type(view_alloc(std::string(src.label()).append("_mirror"),
360  src.implementation_map().cijk()), layout);
361 }
362 
363 template<class Space, class T, class ... P>
364 typename Impl::MirrorType<Space,T,P ...>::view_type
365 create_mirror(const Space& , const Kokkos::View<T,P...> & src
366  , typename std::enable_if<
367  std::is_same< typename ViewTraits<T,P...>::specialize ,
369  >::type *) {
370  typedef View<T,P...> src_type ;
371  typename src_type::array_layout layout = src.layout();
372  layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
374  view_alloc(src.label(), src.implementation_map().cijk()),layout);
375 }
376 
377 // Overload of deep_copy for UQ::PCE views intializing to a constant scalar
378 template< class DT, class ... DP >
380  const View<DT,DP...> & view ,
381  const typename View<DT,DP...>::array_type::value_type & value
382  , typename std::enable_if<(
383  std::is_same< typename ViewTraits<DT,DP...>::specialize
385  )>::type * )
386 {
387  static_assert(
388  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
389  typename ViewTraits<DT,DP...>::non_const_value_type >::value
390  , "Can only deep copy into non-const type" );
391 
392  typedef View<DT,DP...> view_type;
394  typedef typename FlatArrayType<view_type>::type flat_array_type;
395  if (value == scalar_type(0))
397  else
399 }
400 
401 // Overload of deep_copy for UQ::PCE views intializing to a constant UQ::PCE
402 template< class DT, class ... DP >
404  const View<DT,DP...> & view ,
405  const typename View<DT,DP...>::value_type & value
406  , typename std::enable_if<(
407  std::is_same< typename ViewTraits<DT,DP...>::specialize
409  )>::type * )
410 {
411  static_assert(
412  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
413  typename ViewTraits<DT,DP...>::non_const_value_type >::value
414  , "Can only deep copy into non-const type" );
415 
416  Kokkos::Impl::StokhosViewFill< View<DT,DP...> >( view , value );
417 }
418 
419 // Overload of deep_copy for UQ::PCE views intializing to a constant scalar
420 template< class ExecSpace , class DT, class ... DP >
422  const ExecSpace &,
423  const View<DT,DP...> & view ,
424  const typename View<DT,DP...>::array_type::value_type & value
425  , typename std::enable_if<(
426  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
427  std::is_same< typename ViewTraits<DT,DP...>::specialize
429  )>::type * )
430 {
431  static_assert(
432  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
433  typename ViewTraits<DT,DP...>::non_const_value_type >::value
434  , "Can only deep copy into non-const type" );
435 
436  typedef View<DT,DP...> view_type;
438  typedef typename FlatArrayType<view_type>::type flat_array_type;
439  if (value == scalar_type(0))
441  else
443 }
444 
445 // Overload of deep_copy for UQ::PCE views intializing to a constant UQ::PCE
446 template< class ExecSpace , class DT, class ... DP >
448  const ExecSpace &,
449  const View<DT,DP...> & view ,
450  const typename View<DT,DP...>::value_type & value
451  , typename std::enable_if<(
452  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
453  std::is_same< typename ViewTraits<DT,DP...>::specialize
455  )>::type * )
456 {
457  static_assert(
458  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
459  typename ViewTraits<DT,DP...>::non_const_value_type >::value
460  , "Can only deep copy into non-const type" );
461 
462  Kokkos::Impl::StokhosViewFill< View<DT,DP...> >( view , value );
463 }
464 
465 namespace Experimental {
466 namespace Impl {
467 
468 // Deep copy between views not assuming contiguous storage of arrays
469 // Need to use team interface for Cuda
470 template< class OutputView , class InputView >
472 {
474  typedef typename execution_space::size_type size_type ;
475 
476  const OutputView output ;
477  const InputView input ;
478 
479  DeepCopyNonContiguous( const OutputView & arg_out ,
480  const InputView & arg_in ) :
481  output( arg_out ), input( arg_in )
482  {
483  parallel_for( output.extent(0) , *this );
484  execution_space::fence();
485  }
486 
487  KOKKOS_INLINE_FUNCTION
488  void operator()( const size_type i0 ) const
489  {
490  for ( size_type i1 = 0 ; i1 < output.extent(1) ; ++i1 ) {
491  for ( size_type i2 = 0 ; i2 < output.extent(2) ; ++i2 ) {
492  for ( size_type i3 = 0 ; i3 < output.extent(3) ; ++i3 ) {
493  for ( size_type i4 = 0 ; i4 < output.extent(4) ; ++i4 ) {
494  for ( size_type i5 = 0 ; i5 < output.extent(5) ; ++i5 ) {
495  for ( size_type i6 = 0 ; i6 < output.extent(6) ; ++i6 ) {
496  for ( size_type i7 = 0 ; i7 < output.extent(7) ; ++i7 ) {
497  output.access(i0,i1,i2,i3,i4,i5,i6,i7) = input.access(i0,i1,i2,i3,i4,i5,i6,i7) ;
498  }}}}}}}
499  }
500 };
501 
502 } // namespace Impl
503 } // namespace Experimental
504 
505 /* Specialize for deep copy of UQ::PCE */
506 template< class DT , class ... DP , class ST , class ... SP >
507 inline
508 void deep_copy( const View<DT,DP...> & dst ,
509  const View<ST,SP...> & src
510  , typename std::enable_if<(
511  std::is_same< typename ViewTraits<DT,DP...>::specialize
513  &&
514  std::is_same< typename ViewTraits<ST,SP...>::specialize
516  )>::type * )
517 {
518  static_assert(
519  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
520  typename ViewTraits<DT,DP...>::non_const_value_type >::value
521  , "Deep copy destination must be non-const" );
522 
523  static_assert(
524  ( unsigned(ViewTraits<DT,DP...>::rank) ==
525  unsigned(ViewTraits<ST,SP...>::rank) )
526  , "Deep copy destination and source must have same rank" );
527 
528  typedef View<DT,DP...> dst_type ;
529  typedef View<ST,SP...> src_type ;
530  typedef typename dst_type::array_type dst_array_type ;
531  typedef typename src_type::array_type src_array_type ;
532 
534  dst_array_type dst_array = dst ;
535  src_array_type src_array = src ;
536  deep_copy( dst_array , src_array );
537  }
538 
539  // otherwise, use a custom kernel
540  else {
541 
542  // If views are in the same memory space, copy component-wise
543  if ( Impl::is_same< typename dst_type::memory_space ,
544  typename src_type::memory_space >::value ) {
546  }
547 
548  else {
549 
550  typedef View< typename src_type::non_const_data_type ,
551  typename src_type::array_layout ,
552  typename src_type::execution_space > tmp_src_type;
553  typedef typename tmp_src_type::array_type tmp_src_array_type;
554  typedef View< typename dst_type::non_const_data_type ,
555  typename dst_type::array_layout ,
556  typename dst_type::execution_space > tmp_dst_type;
557  typedef typename tmp_dst_type::array_type tmp_dst_array_type;
558 
559  // Copy src into a contiguous view in src's memory space,
560  // then copy to dst
561  if ( is_allocation_contiguous(dst) &&
562  !is_allocation_contiguous(src) ) {
563  size_t src_dims[8];
564  //src.dimensions(src_dims);
565  src_dims[0] = src.extent(0);
566  src_dims[1] = src.extent(1);
567  src_dims[2] = src.extent(2);
568  src_dims[3] = src.extent(3);
569  src_dims[4] = src.extent(4);
570  src_dims[5] = src.extent(5);
571  src_dims[6] = src.extent(6);
572  src_dims[7] = src.extent(7);
573  src_dims[src_type::Rank] = dimension_scalar(src);
574  tmp_src_type src_tmp(
575  view_alloc("src_tmp" , WithoutInitializing, cijk(src) ) ,
576  src_dims[0], src_dims[1], src_dims[2], src_dims[3],
577  src_dims[4], src_dims[5], src_dims[6], src_dims[7] );
579  dst_array_type dst_array = dst ;
580  tmp_src_array_type src_array = src_tmp ;
581  deep_copy( dst_array , src_array );
582  }
583 
584  // Copy src into a contiguous view in dst's memory space,
585  // then copy to dst
586  else if ( !is_allocation_contiguous(dst) &&
587  is_allocation_contiguous(src) ) {
588  size_t dst_dims[8];
589  //dst.dimensions(dst_dims);
590  dst_dims[0] = dst.extent(0);
591  dst_dims[1] = dst.extent(1);
592  dst_dims[2] = dst.extent(2);
593  dst_dims[3] = dst.extent(3);
594  dst_dims[4] = dst.extent(4);
595  dst_dims[5] = dst.extent(5);
596  dst_dims[6] = dst.extent(6);
597  dst_dims[7] = dst.extent(7);
598  dst_dims[dst_type::Rank] = dimension_scalar(dst);
599  tmp_dst_type dst_tmp(
600  view_alloc("dst_tmp" , WithoutInitializing, cijk(dst) ) ,
601  dst_dims[0], dst_dims[1], dst_dims[2], dst_dims[3],
602  dst_dims[4], dst_dims[5], dst_dims[6], dst_dims[7] );
603  tmp_dst_array_type dst_array = dst_tmp ;
604  src_array_type src_array = src ;
605  deep_copy( dst_array , src_array );
607  }
608 
609  // Copy src into a contiguous view in src's memory space,
610  // copy to a continugous view in dst's memory space, then copy to dst
611  else {
612  size_t src_dims[8];
613  //src.dimensions(src_dims);
614  src_dims[0] = src.extent(0);
615  src_dims[1] = src.extent(1);
616  src_dims[2] = src.extent(2);
617  src_dims[3] = src.extent(3);
618  src_dims[4] = src.extent(4);
619  src_dims[5] = src.extent(5);
620  src_dims[6] = src.extent(6);
621  src_dims[7] = src.extent(7);
622  src_dims[src_type::Rank] = dimension_scalar(src);
623  tmp_src_type src_tmp(
624  view_alloc("src_tmp" , WithoutInitializing, cijk(src) ) ,
625  src_dims[0], src_dims[1], src_dims[2], src_dims[3],
626  src_dims[4], src_dims[5], src_dims[6], src_dims[7] );
628  size_t dst_dims[8];
629  //dst.dimensions(dst_dims);
630  dst_dims[0] = dst.extent(0);
631  dst_dims[1] = dst.extent(1);
632  dst_dims[2] = dst.extent(2);
633  dst_dims[3] = dst.extent(3);
634  dst_dims[4] = dst.extent(4);
635  dst_dims[5] = dst.extent(5);
636  dst_dims[6] = dst.extent(6);
637  dst_dims[7] = dst.extent(7);
638  dst_dims[dst_type::Rank] = dimension_scalar(dst);
639  tmp_dst_type dst_tmp(
640  view_alloc("dst_tmp" , WithoutInitializing, cijk(dst) ) ,
641  dst_dims[0], dst_dims[1], dst_dims[2], dst_dims[3],
642  dst_dims[4], dst_dims[5], dst_dims[6], dst_dims[7] );
643  tmp_dst_array_type dst_array = dst_tmp ;
644  tmp_src_array_type src_array = src_tmp ;
645  deep_copy( dst_array , src_array );
647  }
648  }
649  }
650 }
651 
652 }
653 
654 //----------------------------------------------------------------------------
655 //----------------------------------------------------------------------------
656 //----------------------------------------------------------------------------
657 
658 namespace Kokkos {
659 //namespace Experimental {
660 namespace Impl {
661 
662 // Allow passing of Cijk tensor through ViewCtorProp
663 template< typename Value, typename Execution, typename Memory >
664 struct ViewCtorProp< void , Stokhos::CrsProductTensor<Value, Execution, Memory> >
665 {
666  ViewCtorProp() = default ;
667  ViewCtorProp( const ViewCtorProp & ) = default ;
668  ViewCtorProp & operator = ( const ViewCtorProp & ) = default ;
669 
671 
672  ViewCtorProp( const type & arg ) : value( arg ) {}
673  ViewCtorProp( type && arg ) : value( arg ) {}
674 
676 };
677 
678 template <typename AllocProp>
680 {
681  static const bool value = false;
682 };
683 
684 template< typename T >
685 struct ctor_prop_has_cijk< ViewCtorProp<T> >
686 {
687  static const bool value = false;
688 };
689 
690 template< typename Value, typename Execution, typename Memory >
692  ViewCtorProp< Stokhos::CrsProductTensor<Value, Execution, Memory> >
693  >
694 {
695  static const bool value = true;
696 };
697 
698 template< typename T, typename ... P >
699 struct ctor_prop_has_cijk< ViewCtorProp<T,P...> >
700 {
701  static const bool value =
703  ctor_prop_has_cijk< ViewCtorProp<P...> >::value;
704 };
705 
706 } /* namespace Impl */
707 //} /* namespace Experimental */
708 
709 template <typename CijkType, typename AllocProp>
710 KOKKOS_INLINE_FUNCTION
711 typename std::enable_if< !Impl::ctor_prop_has_cijk<AllocProp>::value,
712  CijkType >::type
713 extract_cijk(const AllocProp& prop)
714 {
715  return CijkType();
716 }
717 
718 template <typename CijkType, typename AllocProp>
719 KOKKOS_INLINE_FUNCTION
720 typename std::enable_if< Impl::ctor_prop_has_cijk<AllocProp>::value,
721  CijkType >::type
722 extract_cijk(const AllocProp& prop)
723 {
724  return ( (const Impl::ViewCtorProp<void,CijkType>&) prop ).value;
725 }
726 
727 } /* namespace Kokkos */
728 
729 //----------------------------------------------------------------------------
730 //----------------------------------------------------------------------------
731 //----------------------------------------------------------------------------
732 
733 namespace Kokkos {
734 namespace Impl {
735 
736 template< class DataType , class ArrayLayout , typename StorageType >
737 struct ViewDataAnalysis< DataType /* Original view data type */
738  , ArrayLayout
739  , Sacado::UQ::PCE< StorageType > >
740 {
741 private:
742 
744  typedef ViewArrayAnalysis< DataType > array_analysis ;
745 
746 public:
747 
748  // Specialized view data mapping:
750 
751  typedef typename array_analysis::dimension dimension ;
753  typedef typename array_analysis::const_value_type const_value_type ;
754  typedef typename array_analysis::non_const_value_type non_const_value_type ;
755 
756  // Generate analogous multidimensional array specification type.
757  typedef typename
758  ViewDataType< value_type , dimension >::type type ;
759  typedef typename
760  ViewDataType< const_value_type , dimension >::type const_type ;
761  typedef typename
762  ViewDataType< non_const_value_type , dimension >::type non_const_type ;
763 
764 private:
765 
766  // A const ?
767  enum { is_const = std::is_same< value_type , const_value_type >::value };
768 
769  // The unwrapped scalar types:
770  typedef typename
771  std::conditional< is_const , const ScalarType , ScalarType >::type
773 
776 
777  // Prepend or append the pce dimension based on ArrayLayout
778  typedef typename array_analysis::dimension::
779  template prepend<0>::type
781  typedef typename array_analysis::dimension::
782  template append<0>::type
784  typedef typename std::conditional<
785  std::is_same< ArrayLayout, Kokkos::LayoutLeft>::value,
788 
789 public:
790 
791  // Generate "flattened" multidimensional array specification type.
792  typedef typename
793  ViewDataType< scalar_type , scalar_dimension >::type scalar_array_type ;
794 
795  typedef typename
796  ViewDataType< const_scalar_type , scalar_dimension >::type
798 
799  typedef typename
800  ViewDataType< non_const_scalar_type , scalar_dimension >::type
802 };
803 
804 } // namespace Impl
805 } // namespace Kokkos
806 
807 //----------------------------------------------------------------------------
808 
809 namespace Kokkos {
810 namespace Experimental {
811 namespace Impl {
812 
813 // UQ::PCE allocation for dynamically-sized UQ::PCE types.
814 // In this case we allocate two chunks of data, the first for the the
815 // UQ::PCE<Storage> itself and then for the underlying scalar type
816 // (UQ::PCE<Storage>::value_type). The memory is laid out with the
817 // former followed by the latter.
818 template <class ValueType>
820  typedef ValueType value_type;
821  typedef typename Sacado::ValueType<value_type>::type scalar_type;
822  typedef typename value_type::cijk_type cijk_type;
823 
826 
827  KOKKOS_INLINE_FUNCTION
828  static constexpr size_t
829  memory_span(const size_t span, const unsigned pce_size) {
830  return span * ( pce_size * sizeof(scalar_type) + sizeof(value_type) );
831  }
832 
833  KOKKOS_INLINE_FUNCTION
835 
836  template <typename T>
837  KOKKOS_INLINE_FUNCTION
839  value_ptr = a.value_ptr;
841  return *this;
842  }
843 
844  // We are making an assumption the data is laid out as described above,
845  // which in general may not be true if the view is created from memory
846  // allocated elsewhere. We should check for that.
847  KOKKOS_INLINE_FUNCTION
848  void set(value_type* ptr, const size_t span, const unsigned pce_size) {
849  value_ptr = ptr;
850  scalar_ptr = reinterpret_cast<scalar_type*>(ptr+span);
851  }
852 
853  template <class ExecSpace>
854  struct PCEConstruct {
855  ExecSpace m_space;
858  size_t m_span;
859  unsigned m_pce_size;
861 
862  PCEConstruct() = default;
863  PCEConstruct(const PCEConstruct&) = default;
864  PCEConstruct& operator=(const PCEConstruct&) = default;
865 
866  inline
867  PCEConstruct(const ExecSpace& space,
868  value_type* p,
869  scalar_type* sp,
870  const size_t span,
871  const unsigned pce_size,
872  const cijk_type& cijk) :
873  m_space(space), m_p(p), m_sp(sp), m_span(span), m_pce_size(pce_size),
874  m_cijk(cijk) {}
875 
876  inline void execute() {
877  if ( ! m_space.in_parallel() ) {
878  typedef Kokkos::RangePolicy< ExecSpace > PolicyType ;
879  const Kokkos::Impl::ParallelFor< PCEConstruct , PolicyType >
880  closure( *this , PolicyType( 0 , m_span ) );
881  closure.execute();
882  m_space.fence();
883  }
884  else {
885  for ( size_t i = 0 ; i < m_span ; ++i ) operator()(i);
886  }
887  }
888 
889  KOKKOS_INLINE_FUNCTION
890  void operator() (const size_t i) const {
891  new (m_p+i) value_type(m_cijk, m_pce_size, m_sp+i*m_pce_size, false);
892  }
893  };
894 
895  template <class ExecSpace>
897  typedef Kokkos::Impl::ViewValueFunctor< ExecSpace, scalar_type > ScalarFunctorType ;
902 
903  ConstructDestructFunctor() = default;
906 
907  ConstructDestructFunctor(const ExecSpace & space,
908  const bool initialize,
909  const size_t span,
910  const unsigned pce_size,
911  const cijk_type& cijk,
914  m_scalar_functor( space , scalar_ptr , span*pce_size ),
915  m_pce_functor( space , value_ptr , scalar_ptr , span , pce_size , cijk ),
916  m_initialize(initialize) {}
917 
919  // First initialize the scalar_type array
920  if (m_initialize)
921  m_scalar_functor.construct_shared_allocation();
922 
923  // Construct each UQ::PCE using memory in scalar_ptr array,
924  // setting pointer to UQ::PCE values from values array
925  // Equivalent to:
926  // value_type* p = value_ptr;
927  // scalar_type* sp = scalar_ptr;
928  // for (size_t i=0; i<span; ++i) {
929  // new (p++) value_type(cijk, pce_size, sp, false);
930  // sp += pce_size;
931  // }
932  // (we always need to do this, regardless of initialization)
934  }
935 
937  // We only need to (possibly) call the destructor on values in the
938  // scalar_type array, since the value_type array is a view into it
939  if (m_initialize)
940  m_scalar_functor.destroy_shared_allocation();
941  }
942 
943  };
944 
945  template <class ExecSpace>
946  inline ConstructDestructFunctor<ExecSpace>
947  create_functor(const ExecSpace & space,
948  const bool initialize,
949  const size_t span,
950  const unsigned pce_size,
951  const cijk_type& cijk) const {
952  return ConstructDestructFunctor<ExecSpace>(space, initialize, span,
953  pce_size, cijk, scalar_ptr,
954  value_ptr);
955  }
956 
957  // Assign scalar_type pointer to give ptr
958  // This makes BIG assumption on how the data was allocated
959  template <typename T>
960  void assign(T * ptr) {
961  value_ptr = reinterpret_cast<value_type*>(ptr);
962  if (ptr != 0)
963  scalar_ptr = value_ptr->coeff();
964  else
965  scalar_ptr = 0;
966  }
967 };
968 
969 }}} // namespace Kokkos::Experimental::Impl
970 
971 namespace Kokkos {
972 namespace Impl {
973 
974 template< class Traits >
975 class ViewMapping< Traits , /* View internal mapping */
976  typename std::enable_if<
977  ( std::is_same< typename Traits::specialize
978  , Kokkos::Experimental::Impl::ViewPCEContiguous >::value
979  &&
980  ( std::is_same< typename Traits::array_layout
981  , Kokkos::LayoutLeft >::value
982  ||
983  std::is_same< typename Traits::array_layout
984  , Kokkos::LayoutRight >::value
985  ||
986  std::is_same< typename Traits::array_layout
987  , Kokkos::LayoutStride >::value
988  )
989  )>::type >
990 {
991 private:
992 
993  template< class , class ... > friend class ViewMapping ;
994  template< class , class ... > friend class Kokkos::View ;
995 
996 public:
1000  typedef typename
1001  std::add_const< intrinsic_scalar_type >::type const_intrinsic_scalar_type ;
1002  typedef typename sacado_uq_pce_type::cijk_type cijk_type ;
1003 private:
1004 
1006 
1007  typedef ViewOffset< typename Traits::dimension
1008  , typename Traits::array_layout
1009  , void
1011 
1012  // Prepend or append the pce dimension based on array_layout
1013  typedef ViewArrayAnalysis< typename Traits::data_type > array_analysis ;
1014  typedef typename array_analysis::dimension array_dimension;
1015  typedef ViewOffset< typename array_dimension::
1016  template append<0>::type,
1017  typename Traits::array_layout,
1018  void
1020  typedef ViewOffset< typename array_dimension::
1021  template prepend<0>::type,
1022  typename Traits::array_layout,
1023  void
1025  typedef typename std::conditional<
1026  std::is_same< typename Traits::array_layout, Kokkos::LayoutLeft>::value,
1029 
1032  unsigned m_sacado_size ; // Size of sacado dimension
1033  cijk_type m_cijk ; // Sparse 3 tensor
1034  bool m_is_contiguous ; // Is data allocated contiguously
1035 
1036  // Check whether data allocation is contiguous
1037  // Since View() takes an arbitrary pointer, we can't necessarily assume
1038  // the data was allocated contiguously
1039  KOKKOS_INLINE_FUNCTION
1040  bool is_data_contiguous() const {
1041  const size_t sz = this->span();
1042  if (sz == 0)
1043  return true;
1044  const intrinsic_scalar_type* last_coeff =
1045  m_handle.value_ptr[sz-1].coeff();
1046  const intrinsic_scalar_type* last_coeff_expected =
1047  m_handle.scalar_ptr + (sz-1)*m_sacado_size;
1048  return last_coeff == last_coeff_expected;
1049  }
1050 
1051 public:
1052 
1053  //----------------------------------------
1054  // Domain dimensions
1055 
1056  enum { Rank = Traits::dimension::rank };
1057 
1058  // Rank corresponding to the sacado dimension
1059  enum { Sacado_Rank = std::is_same< typename Traits::array_layout, Kokkos::LayoutLeft >::value ? 0 : Rank+1 };
1060 
1061  // Using the internal offset mapping so limit to public rank:
1062  template< typename iType >
1063  KOKKOS_INLINE_FUNCTION constexpr size_t extent( const iType & r ) const
1064  { return m_offset.m_dim.extent(r); }
1065 
1066  KOKKOS_INLINE_FUNCTION constexpr
1067  typename Traits::array_layout layout() const
1068  { return m_offset.layout(); }
1069 
1070  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_0() const
1071  { return m_offset.dimension_0(); }
1072  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_1() const
1073  { return m_offset.dimension_1(); }
1074  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_2() const
1075  { return m_offset.dimension_2(); }
1076  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_3() const
1077  { return m_offset.dimension_3(); }
1078  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_4() const
1079  { return m_offset.dimension_4(); }
1080  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_5() const
1081  { return m_offset.dimension_5(); }
1082  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_6() const
1083  { return m_offset.dimension_6(); }
1084  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_7() const
1085  { return m_offset.dimension_7(); }
1086 
1087  // Is a regular layout with uniform striding for each index.
1088  // Since we all for striding within the data type, we can't guarantee
1089  // regular striding
1090  using is_regular = std::false_type ;
1091 
1092  KOKKOS_INLINE_FUNCTION constexpr size_t stride_0() const
1093  { return m_offset.stride_0(); }
1094  KOKKOS_INLINE_FUNCTION constexpr size_t stride_1() const
1095  { return m_offset.stride_1(); }
1096  KOKKOS_INLINE_FUNCTION constexpr size_t stride_2() const
1097  { return m_offset.stride_2(); }
1098  KOKKOS_INLINE_FUNCTION constexpr size_t stride_3() const
1099  { return m_offset.stride_3(); }
1100  KOKKOS_INLINE_FUNCTION constexpr size_t stride_4() const
1101  { return m_offset.stride_4(); }
1102  KOKKOS_INLINE_FUNCTION constexpr size_t stride_5() const
1103  { return m_offset.stride_5(); }
1104  KOKKOS_INLINE_FUNCTION constexpr size_t stride_6() const
1105  { return m_offset.stride_6(); }
1106  KOKKOS_INLINE_FUNCTION constexpr size_t stride_7() const
1107  { return m_offset.stride_7(); }
1108 
1109  template< typename iType >
1110  KOKKOS_INLINE_FUNCTION void stride( iType * const s ) const
1111  { m_offset.stride(s); }
1112 
1113  // Size of sacado scalar dimension
1114  KOKKOS_FORCEINLINE_FUNCTION constexpr unsigned dimension_scalar() const
1115  { return m_sacado_size; }
1116 
1117  // Sparse tensor
1118  KOKKOS_FORCEINLINE_FUNCTION
1119  cijk_type cijk() const
1120  { return m_cijk; }
1121 
1122  // Sparse tensor
1123  KOKKOS_FORCEINLINE_FUNCTION
1124  void set_cijk(const cijk_type& cijk)
1125  { m_cijk = cijk; }
1126 
1127  // Is allocation contiguous
1128  KOKKOS_INLINE_FUNCTION
1130  { return m_is_contiguous; }
1131 
1132  // Whether the storage type is statically sized
1133  static const bool is_static = false ;
1134 
1135  // Whether sacado dimension is contiguous
1136  static const bool is_contiguous = true;
1137 
1138  //----------------------------------------
1139  // Range of mapping
1140 
1141  // Return type of reference operators
1143 
1146 
1148  KOKKOS_INLINE_FUNCTION constexpr size_t span() const
1149  { return m_offset.span(); }
1150 
1152  KOKKOS_INLINE_FUNCTION constexpr bool span_is_contiguous() const
1153  { return m_offset.span_is_contiguous() ; }
1154 
1156  KOKKOS_INLINE_FUNCTION constexpr pointer_type data() const
1157  { return m_handle.value_ptr ; }
1158 
1159  //----------------------------------------
1160 
1161  KOKKOS_FORCEINLINE_FUNCTION
1163  { return *m_handle.value_ptr; }
1164 
1165  // FIXME: Check this
1166  template< typename I0 >
1167  KOKKOS_FORCEINLINE_FUNCTION
1168  typename
1169  std::enable_if< std::is_integral<I0>::value &&
1170  ! std::is_same< typename Traits::array_layout , Kokkos::LayoutStride >::value
1171  , reference_type >::type
1172  reference( const I0 & i0 ) const
1173  { return m_handle.value_ptr[i0]; }
1174 
1175  // FIXME: Check this
1176  template< typename I0 >
1177  KOKKOS_FORCEINLINE_FUNCTION
1178  typename
1179  std::enable_if< std::is_integral<I0>::value &&
1180  std::is_same< typename Traits::array_layout , Kokkos::LayoutStride >::value
1181  , reference_type >::type
1182  reference( const I0 & i0 ) const
1183  { return m_handle.value_ptr[ m_offset(i0) ]; }
1184 
1185  template< typename I0 , typename I1 >
1186  KOKKOS_FORCEINLINE_FUNCTION
1187  reference_type reference( const I0 & i0 , const I1 & i1 ) const
1188  { return m_handle.value_ptr[ m_offset(i0,i1) ]; }
1189 
1190  template< typename I0 , typename I1 , typename I2 >
1191  KOKKOS_FORCEINLINE_FUNCTION
1192  reference_type reference( const I0 & i0 , const I1 & i1 , const I2 & i2 ) const
1193  { return m_handle.value_ptr[ m_offset(i0,i1,i2) ]; }
1194 
1195  template< typename I0 , typename I1 , typename I2 , typename I3 >
1196  KOKKOS_FORCEINLINE_FUNCTION
1197  reference_type reference( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3 ) const
1198  { return m_handle.value_ptr[ m_offset(i0,i1,i2,i3) ]; }
1199 
1200  template< typename I0 , typename I1 , typename I2 , typename I3
1201  , typename I4 >
1202  KOKKOS_FORCEINLINE_FUNCTION
1203  reference_type reference( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1204  , const I4 & i4 ) const
1205  { return m_handle.value_ptr[ m_offset(i0,i1,i2,i3,i4) ]; }
1206 
1207  template< typename I0 , typename I1 , typename I2 , typename I3
1208  , typename I4 , typename I5 >
1209  KOKKOS_FORCEINLINE_FUNCTION
1210  reference_type reference( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1211  , const I4 & i4 , const I5 & i5 ) const
1212  { return m_handle.value_ptr[ m_offset(i0,i1,i2,i3,i4,i5) ]; }
1213 
1214  template< typename I0 , typename I1 , typename I2 , typename I3
1215  , typename I4 , typename I5 , typename I6 >
1216  KOKKOS_FORCEINLINE_FUNCTION
1217  reference_type reference( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1218  , const I4 & i4 , const I5 & i5 , const I6 & i6 ) const
1219  { return m_handle.value_ptr[ m_offset(i0,i1,i2,i3,i4,i5,i6) ]; }
1220 
1221  template< typename I0 , typename I1 , typename I2 , typename I3
1222  , typename I4 , typename I5 , typename I6 , typename I7 >
1223  KOKKOS_FORCEINLINE_FUNCTION
1224  reference_type reference( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1225  , const I4 & i4 , const I5 & i5 , const I6 & i6 , const I7 & i7 ) const
1226  { return m_handle.value_ptr[ m_offset(i0,i1,i2,i3,i4,i5,i6,i7) ]; }
1227 
1228  //----------------------------------------
1229 
1231  KOKKOS_INLINE_FUNCTION
1232  static size_t memory_span( typename Traits::array_layout const & layout )
1233  {
1234  // Do not introduce padding...
1235  typedef std::integral_constant< unsigned , 0 > padding ;
1236  offset_type offset( padding(), layout );
1237  unsigned sacado_size =
1239  return handle_type::memory_span( offset.span(), sacado_size );
1240  }
1241 
1242  //----------------------------------------
1243 
1244  KOKKOS_INLINE_FUNCTION ~ViewMapping() = default ;
1245  KOKKOS_INLINE_FUNCTION ViewMapping() :
1246  m_handle(),
1247  m_offset(),
1248  m_sacado_size(0),
1249  m_cijk(),
1250  m_is_contiguous(true)
1251  {}
1252 
1253  KOKKOS_INLINE_FUNCTION ViewMapping( const ViewMapping & ) = default ;
1254  KOKKOS_INLINE_FUNCTION ViewMapping & operator = ( const ViewMapping & ) = default ;
1255 
1256  KOKKOS_INLINE_FUNCTION ViewMapping( ViewMapping && ) = default ;
1257  KOKKOS_INLINE_FUNCTION ViewMapping & operator = ( ViewMapping && ) = default ;
1258 
1259  template< class ... P >
1260  KOKKOS_INLINE_FUNCTION
1261  ViewMapping
1262  ( ViewCtorProp< P ... > const & prop
1263  , typename Traits::array_layout const & layout
1264  )
1265  : m_handle()
1266  , m_offset( std::integral_constant< unsigned , 0 >() , layout )
1267  , m_sacado_size( Kokkos::Impl::GetSacadoSize<unsigned(Rank)>::eval(layout) )
1268  {
1269  m_handle.set( ( (ViewCtorProp<void,pointer_type> const &) prop ).value
1270  , m_offset.span(), m_sacado_size );
1271  m_cijk = extract_cijk<cijk_type>(prop);
1272 #ifndef __CUDA_ARCH__
1273  if (m_cijk.dimension() == 0)
1274  m_cijk = getGlobalCijkTensor<cijk_type>();
1275  // Use 0 or 1 to signal the size wasn't specified in the constructor,
1276  // since now dimesion_i() == 1 for all i >= rank
1277  if (m_sacado_size == 0 || m_sacado_size == 1)
1278  m_sacado_size = m_cijk.dimension();
1279 #endif
1280  m_is_contiguous = this->is_data_contiguous();
1281  }
1282 
1283  //----------------------------------------
1284  /* Allocate and construct mapped array.
1285  * Allocate via shared allocation record and
1286  * return that record for allocation tracking.
1287  */
1288  template< class ... P >
1289  SharedAllocationRecord<> *
1290  allocate_shared( ViewCtorProp< P... > const & prop
1291  , typename Traits::array_layout const & layout )
1292  {
1293  typedef ViewCtorProp< P... > ctor_prop ;
1294 
1295  typedef typename ctor_prop::execution_space execution_space ;
1296  typedef typename Traits::memory_space memory_space ;
1297  typedef typename handle_type::template ConstructDestructFunctor<execution_space> functor_type ;
1298  typedef SharedAllocationRecord< memory_space , functor_type > record_type ;
1299 
1300  // Disallow padding
1301  typedef std::integral_constant< unsigned , 0 > padding ;
1302 
1303  m_offset = offset_type( padding(), layout );
1304  m_sacado_size = Kokkos::Impl::GetSacadoSize<unsigned(Rank)>::eval(layout);
1305  m_cijk = extract_cijk<cijk_type>(prop);
1306  if (m_cijk.dimension() == 0)
1307  m_cijk = getGlobalCijkTensor<cijk_type>();
1308  // Use 0 or 1 to signal the size wasn't specified in the constructor,
1309  // since now dimesion_i() == 1 for all i >= rank
1310  if (m_sacado_size == 0 || m_sacado_size == 1)
1311  m_sacado_size = m_cijk.dimension();
1312  m_is_contiguous = true;
1313 
1314  const size_t alloc_size =
1315  handle_type::memory_span( m_offset.span(), m_sacado_size );
1316 
1317  // Create shared memory tracking record with allocate memory from the memory space
1318  record_type * const record =
1319  record_type::allocate( ( (ViewCtorProp<void,memory_space> const &) prop ).value
1320  , ( (ViewCtorProp<void,std::string> const &) prop ).value
1321  , alloc_size );
1322 
1323  // Only set the the pointer and initialize if the allocation is non-zero.
1324  // May be zero if one of the dimensions is zero.
1325  if ( alloc_size ) {
1326 
1327  m_handle.set( reinterpret_cast< pointer_type >( record->data() ),
1328  m_offset.span(), m_sacado_size );
1329 
1330  // Assume destruction is only required when construction is requested.
1331  // The ViewValueFunctor has both value construction and destruction operators.
1332  record->m_destroy = m_handle.create_functor(
1333  ( (ViewCtorProp<void,execution_space> const &) prop).value
1334  , ctor_prop::initialize
1335  , m_offset.span()
1336  , m_sacado_size
1337  , m_cijk );
1338 
1339  // Construct values
1340  record->m_destroy.construct_shared_allocation();
1341  }
1342 
1343  return record ;
1344  }
1345 
1346 };
1347 
1348 } // namespace Impl
1349 } // namespace Kokkos
1350 
1351 //----------------------------------------------------------------------------
1352 
1353 namespace Kokkos {
1354 namespace Impl {
1355 
1360 template< class DstTraits , class SrcTraits >
1361 class ViewMapping< DstTraits , SrcTraits ,
1362  typename std::enable_if<(
1363  Kokkos::Impl::MemorySpaceAccess< typename DstTraits::memory_space
1364  , typename SrcTraits::memory_space >::assignable
1365  &&
1366  // Destination view has UQ::PCE
1367  std::is_same< typename DstTraits::specialize
1368  , Kokkos::Experimental::Impl::ViewPCEContiguous >::value
1369  &&
1370  // Source view has UQ::PCE only
1371  std::is_same< typename SrcTraits::specialize
1372  , Kokkos::Experimental::Impl::ViewPCEContiguous >::value
1373  )>::type >
1374 {
1375 public:
1376 
1377  enum { is_assignable = true };
1378 
1379  typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
1380  typedef ViewMapping< DstTraits , void > DstType ;
1381  typedef ViewMapping< SrcTraits , void > SrcType ;
1382 
1383  KOKKOS_INLINE_FUNCTION static
1384  void assign( DstType & dst
1385  , const SrcType & src
1386  , const TrackType & )
1387  {
1388  static_assert(
1389  (
1390  std::is_same< typename DstTraits::array_layout
1391  , Kokkos::LayoutLeft >::value ||
1392  std::is_same< typename DstTraits::array_layout
1393  , Kokkos::LayoutRight >::value ||
1394  std::is_same< typename DstTraits::array_layout
1395  , Kokkos::LayoutStride >::value
1396  )
1397  &&
1398  (
1399  std::is_same< typename SrcTraits::array_layout
1400  , Kokkos::LayoutLeft >::value ||
1401  std::is_same< typename SrcTraits::array_layout
1402  , Kokkos::LayoutRight >::value ||
1403  std::is_same< typename SrcTraits::array_layout
1404  , Kokkos::LayoutStride >::value
1405  )
1406  , "View of UQ::PCE requires LayoutLeft, LayoutRight, or LayoutStride" );
1407 
1408  static_assert(
1409  std::is_same< typename DstTraits::array_layout
1410  , typename SrcTraits::array_layout >::value ||
1411  std::is_same< typename DstTraits::array_layout
1412  , Kokkos::LayoutStride >::value ||
1413  ( unsigned(DstTraits::rank) == 1 && unsigned(SrcTraits::rank) == 1 ) ,
1414  "View assignment must have compatible layout" );
1415 
1416  static_assert(
1417  std::is_same< typename DstTraits::value_type
1418  , typename SrcTraits::value_type >::value ||
1419  std::is_same< typename DstTraits::value_type
1420  , typename SrcTraits::const_value_type >::value ,
1421  "View assignment must have same value type or const = non-const" );
1422 
1423  static_assert(
1424  ViewDimensionAssignable
1425  < typename DstType::offset_type::dimension_type
1426  , typename SrcType::offset_type::dimension_type >::value ,
1427  "View assignment must have compatible dimensions" );
1428 
1429  dst.m_handle = src.m_handle ;
1430  dst.m_offset = src.m_offset ;
1431  dst.m_sacado_size = src.m_sacado_size ;
1432  dst.m_cijk = src.m_cijk ;
1433  dst.m_is_contiguous = src.m_is_contiguous ;
1434  }
1435 };
1436 
1442 template< class DstTraits , class SrcTraits >
1443 class ViewMapping< DstTraits , SrcTraits ,
1444  typename std::enable_if<(
1445  Kokkos::Impl::MemorySpaceAccess< typename DstTraits::memory_space
1446  , typename SrcTraits::memory_space >::assignable
1447  &&
1448  // Destination view has ordinary
1449  std::is_same< typename DstTraits::specialize , void >::value
1450  &&
1451  // Source view has UQ::PCE only
1452  std::is_same< typename SrcTraits::specialize
1453  , Kokkos::Experimental::Impl::ViewPCEContiguous >::value
1454  &&
1455  // Ranks match
1456  unsigned(DstTraits::dimension::rank) == unsigned(SrcTraits::dimension::rank)+1
1457  )>::type >
1458 {
1459 public:
1460 
1461  enum { is_assignable = true };
1462 
1463  typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
1464  typedef ViewMapping< DstTraits , void > DstType ;
1465  typedef ViewMapping< SrcTraits , void > SrcType ;
1466 
1467  KOKKOS_INLINE_FUNCTION static
1468  void assign( DstType & dst
1469  , const SrcType & src
1470  , const TrackType & )
1471  {
1472  static_assert(
1473  (
1474  std::is_same< typename DstTraits::array_layout
1475  , Kokkos::LayoutLeft >::value ||
1476  std::is_same< typename DstTraits::array_layout
1477  , Kokkos::LayoutRight >::value ||
1478  std::is_same< typename DstTraits::array_layout
1479  , Kokkos::LayoutStride >::value
1480  )
1481  &&
1482  (
1483  std::is_same< typename SrcTraits::array_layout
1484  , Kokkos::LayoutLeft >::value ||
1485  std::is_same< typename SrcTraits::array_layout
1486  , Kokkos::LayoutRight >::value ||
1487  std::is_same< typename SrcTraits::array_layout
1488  , Kokkos::LayoutStride >::value
1489  )
1490  , "View of UQ::PCE requires LayoutLeft, LayoutRight, or LayoutStride" );
1491 
1492  static_assert(
1493  std::is_same< typename DstTraits::array_layout
1494  , typename SrcTraits::array_layout >::value ||
1495  std::is_same< typename DstTraits::array_layout
1496  , Kokkos::LayoutStride >::value ,
1497  "View assignment must have compatible layout" );
1498 
1499  static_assert(
1500  std::is_same< typename DstTraits::scalar_array_type
1501  , typename SrcTraits::scalar_array_type >::value ||
1502  std::is_same< typename DstTraits::scalar_array_type
1503  , typename SrcTraits::const_scalar_array_type >::value ,
1504  "View assignment must have same value type or const = non-const" );
1505 
1506  static_assert(
1507  ViewDimensionAssignable<
1508  typename DstType::offset_type::dimension_type,
1509  typename SrcType::array_offset_type::dimension_type >::value,
1510  "View assignment must have compatible dimensions" );
1511 
1512  if ( !src.m_is_contiguous )
1513  Kokkos::abort("\n\n ****** Kokkos::View< Sacado::UQ::PCE ... >: can't assign non-contiguous view ******\n\n");
1514 
1515  unsigned dims[8];
1516  dims[0] = src.m_offset.dimension_0();
1517  dims[1] = src.m_offset.dimension_1();
1518  dims[2] = src.m_offset.dimension_2();
1519  dims[3] = src.m_offset.dimension_3();
1520  dims[4] = src.m_offset.dimension_4();
1521  dims[5] = src.m_offset.dimension_5();
1522  dims[6] = src.m_offset.dimension_6();
1523  dims[7] = src.m_offset.dimension_7();
1524  unsigned rank = SrcTraits::dimension::rank;
1525  unsigned sacado_size = src.m_sacado_size;
1526  if (std::is_same<typename SrcTraits::array_layout, LayoutLeft>::value) {
1527  // Move sacado_size to the first dimension, shift all others up one
1528  for (unsigned i=rank; i>0; --i)
1529  dims[i] = dims[i-1];
1530  dims[0] = sacado_size;
1531  }
1532  else {
1533  dims[rank] = sacado_size;
1534  }
1535  typedef typename DstType::offset_type dst_offset_type;
1536  dst.m_offset = dst_offset_type( std::integral_constant< unsigned , 0 >(),
1537  typename DstTraits::array_layout(
1538  dims[0] , dims[1] , dims[2] , dims[3] ,
1539  dims[4] , dims[5] , dims[6] , dims[7] ) );
1540  dst.m_handle = src.m_handle.scalar_ptr ;
1541  }
1542 };
1543 
1550 template< class DstTraits , class SrcTraits >
1551 class ViewMapping< DstTraits , SrcTraits ,
1552  typename std::enable_if<(
1553  Kokkos::Impl::MemorySpaceAccess< typename DstTraits::memory_space
1554  , typename SrcTraits::memory_space >::assignable
1555  &&
1556  // Destination view has ordinary
1557  std::is_same< typename DstTraits::specialize , void >::value
1558  &&
1559  // Source view has UQ::PCE only
1560  std::is_same< typename SrcTraits::specialize
1561  , Kokkos::Experimental::Impl::ViewPCEContiguous >::value
1562  &&
1563  // Ranks match
1564  unsigned(DstTraits::dimension::rank) == unsigned(SrcTraits::dimension::rank)
1565  )>::type >
1566 {
1567 public:
1568 
1569  enum { is_assignable = true };
1570 
1571  typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
1572  typedef ViewMapping< DstTraits , void > DstType ;
1573  typedef ViewMapping< SrcTraits , void > SrcType ;
1574 
1575  KOKKOS_INLINE_FUNCTION static
1576  void assign( DstType & dst
1577  , const SrcType & src
1578  , const TrackType & )
1579  {
1580  static_assert(
1581  (
1582  std::is_same< typename DstTraits::array_layout
1583  , Kokkos::LayoutLeft >::value ||
1584  std::is_same< typename DstTraits::array_layout
1585  , Kokkos::LayoutRight >::value ||
1586  std::is_same< typename DstTraits::array_layout
1587  , Kokkos::LayoutStride >::value
1588  )
1589  &&
1590  (
1591  std::is_same< typename SrcTraits::array_layout
1592  , Kokkos::LayoutLeft >::value ||
1593  std::is_same< typename SrcTraits::array_layout
1594  , Kokkos::LayoutRight >::value ||
1595  std::is_same< typename SrcTraits::array_layout
1596  , Kokkos::LayoutStride >::value
1597  )
1598  , "View of UQ::PCE requires LayoutLeft, LayoutRight, or LayoutStride" );
1599 
1600  static_assert(
1601  std::is_same< typename DstTraits::array_layout
1602  , typename SrcTraits::array_layout >::value ||
1603  std::is_same< typename DstTraits::array_layout
1604  , Kokkos::LayoutStride >::value ,
1605  "View assignment must have compatible layout" );
1606 
1607  static_assert(
1608  std::is_same< typename DstTraits::value_type
1609  , typename SrcTraits::non_const_value_type::value_type >::value ||
1610  std::is_same< typename DstTraits::value_type
1611  , const typename SrcTraits::non_const_value_type::value_type >::value ,
1612  "View assignment must have same value type or const = non-const" );
1613 
1614  static_assert(
1615  ViewDimensionAssignable<
1616  typename DstType::offset_type::dimension_type,
1617  typename SrcType::offset_type::dimension_type >::value,
1618  "View assignment must have compatible dimensions" );
1619 
1620  if ( !src.m_is_contiguous )
1621  Kokkos::abort("\n\n ****** Kokkos::View< Sacado::UQ::PCE ... >: can't assign non-contiguous view ******\n\n");
1622 
1623  unsigned dims[8];
1624  dims[0] = src.m_offset.dimension_0();
1625  dims[1] = src.m_offset.dimension_1();
1626  dims[2] = src.m_offset.dimension_2();
1627  dims[3] = src.m_offset.dimension_3();
1628  dims[4] = src.m_offset.dimension_4();
1629  dims[5] = src.m_offset.dimension_5();
1630  dims[6] = src.m_offset.dimension_6();
1631  dims[7] = src.m_offset.dimension_7();
1632  unsigned rank = SrcTraits::dimension::rank;
1633  unsigned sacado_size = src.m_sacado_size;
1634  if (std::is_same<typename DstTraits::array_layout, LayoutLeft>::value) {
1635  dims[0] = dims[0]*sacado_size;
1636  dims[rank] = 0;
1637  }
1638  else {
1639  dims[rank-1] = dims[rank-1]*sacado_size;
1640  dims[rank] = 0;
1641  }
1642  typedef typename DstType::offset_type dst_offset_type;
1643  dst.m_offset = dst_offset_type( std::integral_constant< unsigned , 0 >(),
1644  typename DstTraits::array_layout(
1645  dims[0] , dims[1] , dims[2] , dims[3] ,
1646  dims[4] , dims[5] , dims[6] , dims[7] ) );
1647  dst.m_handle = src.m_handle.scalar_ptr ;
1648  }
1649 };
1650 
1651 } // namespace Impl
1652 } // namespace Kokkos
1653 
1654 //----------------------------------------------------------------------------
1655 
1656 namespace Kokkos {
1657 namespace Impl {
1658 
1659 // Subview mapping
1660 
1661 template< class DataType, class ... P , class Arg0, class ... Args >
1662 struct ViewMapping
1663  < typename std::enable_if<(
1664  // Source view has UQ::PCE only
1665  std::is_same< typename Kokkos::ViewTraits<DataType,P...>::specialize
1666  , Kokkos::Experimental::Impl::ViewPCEContiguous >::value
1667  &&
1668  (
1669  std::is_same< typename Kokkos::ViewTraits<DataType,P...>::array_layout
1670  , Kokkos::LayoutLeft >::value ||
1671  std::is_same< typename Kokkos::ViewTraits<DataType,P...>::array_layout
1672  , Kokkos::LayoutRight >::value ||
1673  std::is_same< typename Kokkos::ViewTraits<DataType,P...>::array_layout
1674  , Kokkos::LayoutStride >::value
1675  )
1676  )>::type
1677  , Kokkos::ViewTraits<DataType,P...>
1678  , Arg0, Args ... >
1679 {
1680 private:
1681 
1682  typedef Kokkos::ViewTraits<DataType,P...> SrcTraits;
1683 
1684  //static_assert( SrcTraits::rank == sizeof...(Args) , "" );
1685 
1686  enum
1687  { RZ = false
1688  , R0 = bool(is_integral_extent<0,Arg0,Args...>::value)
1689  , R1 = bool(is_integral_extent<1,Arg0,Args...>::value)
1690  , R2 = bool(is_integral_extent<2,Arg0,Args...>::value)
1691  , R3 = bool(is_integral_extent<3,Arg0,Args...>::value)
1692  , R4 = bool(is_integral_extent<4,Arg0,Args...>::value)
1693  , R5 = bool(is_integral_extent<5,Arg0,Args...>::value)
1694  , R6 = bool(is_integral_extent<6,Arg0,Args...>::value)
1695  };
1696 
1697  // Public rank
1698  enum { rank = unsigned(R0) + unsigned(R1) + unsigned(R2) + unsigned(R3)
1699  + unsigned(R4) + unsigned(R5) + unsigned(R6) };
1700 
1701  // Whether right-most non-UQ::PCE rank is a range.
1702  enum { R0_rev = ( 0 == SrcTraits::rank ? RZ : (
1703  1 == SrcTraits::rank ? R0 : (
1704  2 == SrcTraits::rank ? R1 : (
1705  3 == SrcTraits::rank ? R2 : (
1706  4 == SrcTraits::rank ? R3 : (
1707  5 == SrcTraits::rank ? R4 : (
1708  6 == SrcTraits::rank ? R5 : R6 ))))))) };
1709 
1710  // Subview's layout
1711  typedef typename std::conditional<
1712  ( /* Same array layout IF */
1713  ( rank == 0 ) /* output rank zero */
1714  ||
1715  // OutputRank 1 or 2, InputLayout Left, Interval 0
1716  // because single stride one or second index has a stride.
1717  ( rank <= 2 && R0 && std::is_same< typename SrcTraits::array_layout , Kokkos::LayoutLeft >::value )
1718  ||
1719  // OutputRank 1 or 2, InputLayout Right, Interval [InputRank-1]
1720  // because single stride one or second index has a stride.
1721  ( rank <= 2 && R0_rev && std::is_same< typename SrcTraits::array_layout , Kokkos::LayoutRight >::value )
1722  ), typename SrcTraits::array_layout , Kokkos::LayoutStride
1724 
1726 
1727  typedef typename std::conditional< rank == 0 , sacado_uq_pce_type ,
1728  typename std::conditional< rank == 1 , sacado_uq_pce_type * ,
1729  typename std::conditional< rank == 2 , sacado_uq_pce_type ** ,
1730  typename std::conditional< rank == 3 , sacado_uq_pce_type *** ,
1731  typename std::conditional< rank == 4 , sacado_uq_pce_type **** ,
1732  typename std::conditional< rank == 5 , sacado_uq_pce_type ***** ,
1733  typename std::conditional< rank == 6 , sacado_uq_pce_type ****** ,
1734  sacado_uq_pce_type *******
1737 
1738 public:
1739 
1740  typedef Kokkos::ViewTraits
1741  < data_type
1742  , array_layout
1743  , typename SrcTraits::device_type
1744  , typename SrcTraits::memory_traits > traits_type ;
1745 
1746  typedef Kokkos::View
1747  < data_type
1748  , array_layout
1749  , typename SrcTraits::device_type
1750  , typename SrcTraits::memory_traits > type ;
1751 
1752 
1753  // The presumed type is 'ViewMapping< traits_type , void >'
1754  // However, a compatible ViewMapping is acceptable.
1755  template< class DstTraits >
1756  KOKKOS_INLINE_FUNCTION
1757  static void assign( ViewMapping< DstTraits , void > & dst
1758  , ViewMapping< SrcTraits , void > const & src
1759  , Arg0 arg0, Args ... args )
1760  {
1761  static_assert(
1762  ViewMapping< DstTraits , traits_type , void >::is_assignable ,
1763  "Subview destination type must be compatible with subview derived type" );
1764 
1765  typedef ViewMapping< DstTraits , void > DstType ;
1766  typedef typename DstType::offset_type dst_offset_type ;
1767 
1768  const SubviewExtents< SrcTraits::rank , rank >
1769  extents( src.m_offset.m_dim , arg0 , args... );
1770 
1771  const size_t offset = src.m_offset( extents.domain_offset(0)
1772  , extents.domain_offset(1)
1773  , extents.domain_offset(2)
1774  , extents.domain_offset(3)
1775  , extents.domain_offset(4)
1776  , extents.domain_offset(5)
1777  , extents.domain_offset(6)
1778  , extents.domain_offset(7) );
1779 
1780  dst.m_offset = dst_offset_type( src.m_offset , extents );
1781  dst.m_handle.value_ptr = src.m_handle.value_ptr + offset;
1782  dst.m_handle.scalar_ptr =
1783  src.m_handle.scalar_ptr + offset * src.m_sacado_size;
1784  dst.m_sacado_size = src.m_sacado_size;
1785  dst.m_cijk = src.m_cijk;
1786  dst.m_is_contiguous = src.m_is_contiguous;
1787  }
1788 
1789 };
1790 
1791 } // namespace Impl
1792 } // namespace Kokkos
1793 
1794 //----------------------------------------------------------------------------
1795 //----------------------------------------------------------------------------
1796 //----------------------------------------------------------------------------
1797 
1798 namespace Kokkos {
1799 namespace Impl {
1800 
1801 // Specialization for deep_copy( view, view::value_type ) for Cuda
1802 #if defined( KOKKOS_ENABLE_CUDA )
1803 template< class OutputView >
1804 struct StokhosViewFill< OutputView ,
1805  typename std::enable_if< std::is_same< typename OutputView::specialize,
1806  Kokkos::Experimental::Impl::ViewPCEContiguous >::value &&
1807  std::is_same< typename OutputView::execution_space,
1808  Cuda >::value >::type >
1809 {
1810  typedef typename OutputView::const_value_type const_value_type ;
1811  typedef typename Sacado::ScalarType<const_value_type>::type scalar_type ;
1812  typedef typename OutputView::execution_space execution_space ;
1813  typedef typename OutputView::size_type size_type ;
1814 
1815  template <unsigned VectorLength>
1816  struct PCEKernel {
1817  typedef typename OutputView::execution_space execution_space ;
1818  const OutputView output;
1820 
1821  PCEKernel( const OutputView & arg_out , const_value_type & arg_in ) :
1822  output(arg_out), input(arg_in) {}
1823 
1824  typedef typename Kokkos::TeamPolicy< execution_space >::member_type team_member ;
1825 
1826  KOKKOS_INLINE_FUNCTION
1827  void operator()( const team_member & dev ) const
1828  {
1829  const size_type tidx = dev.team_rank() % VectorLength;
1830  const size_type tidy = dev.team_rank() / VectorLength;
1831  const size_type nrow = dev.team_size() / VectorLength;
1832  const size_type nvec = dimension_scalar(output);
1833 
1834  const size_type i0 = dev.league_rank() * nrow + tidy;
1835  if ( i0 >= output.extent(0) ) return;
1836 
1837  for ( size_type i1 = 0 ; i1 < output.extent(1) ; ++i1 ) {
1838  for ( size_type i2 = 0 ; i2 < output.extent(2) ; ++i2 ) {
1839  for ( size_type i3 = 0 ; i3 < output.extent(3) ; ++i3 ) {
1840  for ( size_type i4 = 0 ; i4 < output.extent(4) ; ++i4 ) {
1841  for ( size_type i5 = 0 ; i5 < output.extent(5) ; ++i5 ) {
1842  for ( size_type i6 = 0 ; i6 < output.extent(6) ; ++i6 ) {
1843  for ( size_type i7 = 0 ; i7 < output.extent(7) ; ++i7 ) {
1844  for ( size_type is = tidx ; is < nvec ; is+=VectorLength ) {
1845  output.access(i0,i1,i2,i3,i4,i5,i6,i7).fastAccessCoeff(is) =
1846  input.fastAccessCoeff(is) ;
1847  }}}}}}}}
1848  }
1849  };
1850 
1851  template <unsigned VectorLength>
1852  struct ScalarKernel {
1853  typedef typename OutputView::execution_space execution_space ;
1854  const OutputView output;
1855  const scalar_type input;
1856 
1857  ScalarKernel( const OutputView & arg_out , const scalar_type & arg_in ) :
1858  output(arg_out), input(arg_in) {}
1859 
1860  typedef typename Kokkos::TeamPolicy< execution_space >::member_type team_member ;
1861  KOKKOS_INLINE_FUNCTION
1862  void operator()( const team_member & dev ) const
1863  {
1864  const size_type tidx = dev.team_rank() % VectorLength;
1865  const size_type tidy = dev.team_rank() / VectorLength;
1866  const size_type nrow = dev.team_size() / VectorLength;
1867  const size_type npce = dimension_scalar(output);
1868 
1869  const size_type i0 = dev.league_rank() * nrow + tidy;
1870  if ( i0 >= output.extent(0) ) return;
1871 
1872  for ( size_type i1 = 0 ; i1 < output.extent(1) ; ++i1 ) {
1873  for ( size_type i2 = 0 ; i2 < output.extent(2) ; ++i2 ) {
1874  for ( size_type i3 = 0 ; i3 < output.extent(3) ; ++i3 ) {
1875  for ( size_type i4 = 0 ; i4 < output.extent(4) ; ++i4 ) {
1876  for ( size_type i5 = 0 ; i5 < output.extent(5) ; ++i5 ) {
1877  for ( size_type i6 = 0 ; i6 < output.extent(6) ; ++i6 ) {
1878  for ( size_type i7 = 0 ; i7 < output.extent(7) ; ++i7 ) {
1879  for ( size_type is = tidx ; is < npce ; is+=VectorLength ) {
1880  output.access(i0,i1,i2,i3,i4,i5,i6,i7).fastAccessCoeff(is) =
1881  is == 0 ? input : scalar_type(0) ;
1882  }}}}}}}}
1883  }
1884  };
1885 
1886  StokhosViewFill( const OutputView & output , const_value_type & input )
1887  {
1888  // Coalesced accesses are 128 bytes in size
1890  const unsigned vector_length =
1891  ( 128 + sizeof(scalar_type)-1 ) / sizeof(scalar_type);
1892 
1893  // 8 warps per block should give good occupancy
1894  const size_type block_size = 256;
1895 
1896  const size_type rows_per_block = block_size / vector_length;
1897  const size_type n = output.extent(0);
1898  const size_type league_size = ( n + rows_per_block-1 ) / rows_per_block;
1899  const size_type team_size = rows_per_block * vector_length;
1900  Kokkos::TeamPolicy< execution_space > config( league_size, team_size );
1901 
1902  if (static_cast<unsigned>(input.size()) != dimension_scalar(output) &&
1903  input.size() != 1)
1904  Kokkos::abort("StokhosViewFill: Invalid input value size");
1905 
1906  if (input.size() == 1)
1907  parallel_for(
1908  config, ScalarKernel<vector_length>(output, input.fastAccessCoeff(0)) );
1909  else
1910  parallel_for( config, PCEKernel<vector_length>(output, input) );
1911  execution_space::fence();
1912  }
1913 
1914  StokhosViewFill( const OutputView & output , const scalar_type & input )
1915  {
1916  // Coalesced accesses are 128 bytes in size
1918  const unsigned vector_length =
1919  ( 128 + sizeof(scalar_type)-1 ) / sizeof(scalar_type);
1920 
1921  // 8 warps per block should give good occupancy
1922  const size_type block_size = 256;
1923 
1924  const size_type rows_per_block = block_size / vector_length;
1925  const size_type n = output.extent(0);
1926  const size_type league_size = ( n + rows_per_block-1 ) / rows_per_block;
1927  const size_type team_size = rows_per_block * vector_length;
1928  Kokkos::TeamPolicy< execution_space > config( league_size, team_size );
1929 
1930  parallel_for( config, ScalarKernel<vector_length>(output, input) );
1931  execution_space::fence();
1932  }
1933 
1934 };
1935 #endif /* #if defined( KOKKOS_ENABLE_CUDA ) */
1936 
1937 } // namespace Impl
1938 } // namespace Kokkos
1939 
1940 #include "Kokkos_View_Utils_Def.hpp"
1941 
1942 //----------------------------------------------------------------------------
1943 //----------------------------------------------------------------------------
1944 //----------------------------------------------------------------------------
1945 
1946 #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)