Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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.impl_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.impl_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.impl_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.impl_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.impl_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.impl_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
834  PCEAllocation() : value_ptr(0), scalar_ptr(0) {}
835 
836  template <typename T>
837  KOKKOS_INLINE_FUNCTION
839  value_ptr = a.value_ptr;
840  scalar_ptr = a.scalar_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;
905  ConstructDestructFunctor& operator=(const 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,
912  scalar_type* scalar_ptr,
913  value_type* value_ptr) :
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)
933  m_pce_functor.execute();
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  )
990  , typename Traits::specialize
991  >::type >
992 {
993 private:
994 
995  template< class , class ... > friend class ViewMapping ;
996  template< class , class ... > friend class Kokkos::View ;
997 
998 public:
1002  typedef typename
1003  std::add_const< intrinsic_scalar_type >::type const_intrinsic_scalar_type ;
1004  typedef typename sacado_uq_pce_type::cijk_type cijk_type ;
1005 private:
1006 
1008 
1009  typedef ViewOffset< typename Traits::dimension
1010  , typename Traits::array_layout
1011  , void
1013 
1014  // Prepend or append the pce dimension based on array_layout
1015  typedef ViewArrayAnalysis< typename Traits::data_type > array_analysis ;
1016  typedef typename array_analysis::dimension array_dimension;
1017  typedef ViewOffset< typename array_dimension::
1018  template append<0>::type,
1019  typename Traits::array_layout,
1020  void
1022  typedef ViewOffset< typename array_dimension::
1023  template prepend<0>::type,
1024  typename Traits::array_layout,
1025  void
1027  typedef typename std::conditional<
1028  std::is_same< typename Traits::array_layout, Kokkos::LayoutLeft>::value,
1031 
1034  unsigned m_sacado_size ; // Size of sacado dimension
1035  cijk_type m_cijk ; // Sparse 3 tensor
1036  bool m_is_contiguous ; // Is data allocated contiguously
1037 
1038  // Check whether data allocation is contiguous
1039  // Since View() takes an arbitrary pointer, we can't necessarily assume
1040  // the data was allocated contiguously
1041  KOKKOS_INLINE_FUNCTION
1042  bool is_data_contiguous() const {
1043  const size_t sz = this->span();
1044  if (sz == 0)
1045  return true;
1046  const intrinsic_scalar_type* last_coeff =
1047  m_impl_handle.value_ptr[sz-1].coeff();
1048  const intrinsic_scalar_type* last_coeff_expected =
1049  m_impl_handle.scalar_ptr + (sz-1)*m_sacado_size;
1050  return last_coeff == last_coeff_expected;
1051  }
1052 
1053 public:
1054 
1055  //----------------------------------------
1056  // Domain dimensions
1057 
1058  enum { Rank = Traits::dimension::rank };
1059 
1060  // Rank corresponding to the sacado dimension
1061  enum { Sacado_Rank = std::is_same< typename Traits::array_layout, Kokkos::LayoutLeft >::value ? 0 : Rank+1 };
1062 
1063  // Using the internal offset mapping so limit to public rank:
1064  template< typename iType >
1065  KOKKOS_INLINE_FUNCTION constexpr size_t extent( const iType & r ) const
1066  { return m_impl_offset.m_dim.extent(r); }
1067 
1068  KOKKOS_INLINE_FUNCTION constexpr
1069  typename Traits::array_layout layout() const
1070  { return m_impl_offset.layout(); }
1071 
1072  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_0() const
1073  { return m_impl_offset.dimension_0(); }
1074  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_1() const
1075  { return m_impl_offset.dimension_1(); }
1076  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_2() const
1077  { return m_impl_offset.dimension_2(); }
1078  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_3() const
1079  { return m_impl_offset.dimension_3(); }
1080  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_4() const
1081  { return m_impl_offset.dimension_4(); }
1082  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_5() const
1083  { return m_impl_offset.dimension_5(); }
1084  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_6() const
1085  { return m_impl_offset.dimension_6(); }
1086  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_7() const
1087  { return m_impl_offset.dimension_7(); }
1088 
1089  // Is a regular layout with uniform striding for each index.
1090  // Since we all for striding within the data type, we can't guarantee
1091  // regular striding
1092  using is_regular = std::false_type ;
1093 
1094  KOKKOS_INLINE_FUNCTION constexpr size_t stride_0() const
1095  { return m_impl_offset.stride_0(); }
1096  KOKKOS_INLINE_FUNCTION constexpr size_t stride_1() const
1097  { return m_impl_offset.stride_1(); }
1098  KOKKOS_INLINE_FUNCTION constexpr size_t stride_2() const
1099  { return m_impl_offset.stride_2(); }
1100  KOKKOS_INLINE_FUNCTION constexpr size_t stride_3() const
1101  { return m_impl_offset.stride_3(); }
1102  KOKKOS_INLINE_FUNCTION constexpr size_t stride_4() const
1103  { return m_impl_offset.stride_4(); }
1104  KOKKOS_INLINE_FUNCTION constexpr size_t stride_5() const
1105  { return m_impl_offset.stride_5(); }
1106  KOKKOS_INLINE_FUNCTION constexpr size_t stride_6() const
1107  { return m_impl_offset.stride_6(); }
1108  KOKKOS_INLINE_FUNCTION constexpr size_t stride_7() const
1109  { return m_impl_offset.stride_7(); }
1110 
1111  template< typename iType >
1112  KOKKOS_INLINE_FUNCTION void stride( iType * const s ) const
1113  { m_impl_offset.stride(s); }
1114 
1115  // Size of sacado scalar dimension
1116  KOKKOS_FORCEINLINE_FUNCTION constexpr unsigned dimension_scalar() const
1117  { return m_sacado_size; }
1118 
1119  // Sparse tensor
1120  KOKKOS_FORCEINLINE_FUNCTION
1121  cijk_type cijk() const
1122  { return m_cijk; }
1123 
1124  // Sparse tensor
1125  KOKKOS_FORCEINLINE_FUNCTION
1126  void set_cijk(const cijk_type& cijk)
1127  { m_cijk = cijk; }
1128 
1129  // Is allocation contiguous
1130  KOKKOS_INLINE_FUNCTION
1132  { return m_is_contiguous; }
1133 
1134  // Whether the storage type is statically sized
1135  static const bool is_static = false ;
1136 
1137  // Whether sacado dimension is contiguous
1138  static const bool is_contiguous = true;
1139 
1140  //----------------------------------------
1141  // Range of mapping
1142 
1143  // Return type of reference operators
1145 
1148 
1150  KOKKOS_INLINE_FUNCTION constexpr size_t span() const
1151  { return m_impl_offset.span(); }
1152 
1154  KOKKOS_INLINE_FUNCTION constexpr bool span_is_contiguous() const
1155  { return m_impl_offset.span_is_contiguous() ; }
1156 
1158  KOKKOS_INLINE_FUNCTION constexpr pointer_type data() const
1159  { return m_impl_handle.value_ptr ; }
1160 
1161  //----------------------------------------
1162 
1163  KOKKOS_FORCEINLINE_FUNCTION
1165  { return *m_impl_handle.value_ptr; }
1166 
1167  // FIXME: Check this
1168  template< typename I0 >
1169  KOKKOS_FORCEINLINE_FUNCTION
1170  typename
1171  std::enable_if< std::is_integral<I0>::value &&
1172  ! std::is_same< typename Traits::array_layout , Kokkos::LayoutStride >::value
1173  , reference_type >::type
1174  reference( const I0 & i0 ) const
1175  { return m_impl_handle.value_ptr[i0]; }
1176 
1177  // FIXME: Check this
1178  template< typename I0 >
1179  KOKKOS_FORCEINLINE_FUNCTION
1180  typename
1181  std::enable_if< std::is_integral<I0>::value &&
1182  std::is_same< typename Traits::array_layout , Kokkos::LayoutStride >::value
1183  , reference_type >::type
1184  reference( const I0 & i0 ) const
1185  { return m_impl_handle.value_ptr[ m_impl_offset(i0) ]; }
1186 
1187  template< typename I0 , typename I1 >
1188  KOKKOS_FORCEINLINE_FUNCTION
1189  reference_type reference( const I0 & i0 , const I1 & i1 ) const
1190  { return m_impl_handle.value_ptr[ m_impl_offset(i0,i1) ]; }
1191 
1192  template< typename I0 , typename I1 , typename I2 >
1193  KOKKOS_FORCEINLINE_FUNCTION
1194  reference_type reference( const I0 & i0 , const I1 & i1 , const I2 & i2 ) const
1195  { return m_impl_handle.value_ptr[ m_impl_offset(i0,i1,i2) ]; }
1196 
1197  template< typename I0 , typename I1 , typename I2 , typename I3 >
1198  KOKKOS_FORCEINLINE_FUNCTION
1199  reference_type reference( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3 ) const
1200  { return m_impl_handle.value_ptr[ m_impl_offset(i0,i1,i2,i3) ]; }
1201 
1202  template< typename I0 , typename I1 , typename I2 , typename I3
1203  , typename I4 >
1204  KOKKOS_FORCEINLINE_FUNCTION
1205  reference_type reference( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1206  , const I4 & i4 ) const
1207  { return m_impl_handle.value_ptr[ m_impl_offset(i0,i1,i2,i3,i4) ]; }
1208 
1209  template< typename I0 , typename I1 , typename I2 , typename I3
1210  , typename I4 , typename I5 >
1211  KOKKOS_FORCEINLINE_FUNCTION
1212  reference_type reference( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1213  , const I4 & i4 , const I5 & i5 ) const
1214  { return m_impl_handle.value_ptr[ m_impl_offset(i0,i1,i2,i3,i4,i5) ]; }
1215 
1216  template< typename I0 , typename I1 , typename I2 , typename I3
1217  , typename I4 , typename I5 , typename I6 >
1218  KOKKOS_FORCEINLINE_FUNCTION
1219  reference_type reference( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1220  , const I4 & i4 , const I5 & i5 , const I6 & i6 ) const
1221  { return m_impl_handle.value_ptr[ m_impl_offset(i0,i1,i2,i3,i4,i5,i6) ]; }
1222 
1223  template< typename I0 , typename I1 , typename I2 , typename I3
1224  , typename I4 , typename I5 , typename I6 , typename I7 >
1225  KOKKOS_FORCEINLINE_FUNCTION
1226  reference_type reference( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1227  , const I4 & i4 , const I5 & i5 , const I6 & i6 , const I7 & i7 ) const
1228  { return m_impl_handle.value_ptr[ m_impl_offset(i0,i1,i2,i3,i4,i5,i6,i7) ]; }
1229 
1230  //----------------------------------------
1231 
1233  KOKKOS_INLINE_FUNCTION
1234  static size_t memory_span( typename Traits::array_layout const & layout )
1235  {
1236  // Do not introduce padding...
1237  typedef std::integral_constant< unsigned , 0 > padding ;
1238  offset_type offset( padding(), layout );
1239  unsigned sacado_size =
1241  return handle_type::memory_span( offset.span(), sacado_size );
1242  }
1243 
1244  //----------------------------------------
1245 
1246  KOKKOS_INLINE_FUNCTION ~ViewMapping() = default ;
1247  KOKKOS_INLINE_FUNCTION ViewMapping() :
1248  m_impl_handle(),
1249  m_impl_offset(),
1250  m_sacado_size(0),
1251  m_cijk(),
1252  m_is_contiguous(true)
1253  {}
1254 
1255  KOKKOS_INLINE_FUNCTION ViewMapping( const ViewMapping & ) = default ;
1256  KOKKOS_INLINE_FUNCTION ViewMapping & operator = ( const ViewMapping & ) = default ;
1257 
1258  KOKKOS_INLINE_FUNCTION ViewMapping( ViewMapping && ) = default ;
1259  KOKKOS_INLINE_FUNCTION ViewMapping & operator = ( ViewMapping && ) = default ;
1260 
1261  template< class ... P >
1262  KOKKOS_INLINE_FUNCTION
1263  ViewMapping
1264  ( ViewCtorProp< P ... > const & prop
1265  , typename Traits::array_layout const & layout
1266  )
1267  : m_impl_handle()
1268  , m_impl_offset( std::integral_constant< unsigned , 0 >() , layout )
1269  , m_sacado_size( Kokkos::Impl::GetSacadoSize<unsigned(Rank)>::eval(layout) )
1270  {
1271  m_impl_handle.set( ( (ViewCtorProp<void,pointer_type> const &) prop ).value
1272  , m_impl_offset.span(), m_sacado_size );
1273  m_cijk = extract_cijk<cijk_type>(prop);
1274 #ifndef __CUDA_ARCH__
1275  if (m_cijk.dimension() == 0)
1276  m_cijk = getGlobalCijkTensor<cijk_type>();
1277  // Use 0 or KOKKOS_IMPL_CTOR_DEFAULT_ARG to signal the size wasn't
1278  // specified in the constructor
1279  if (m_sacado_size == 0 ||
1280  m_sacado_size == unsigned(KOKKOS_IMPL_CTOR_DEFAULT_ARG))
1281  m_sacado_size = m_cijk.dimension();
1282 #endif
1283  m_is_contiguous = this->is_data_contiguous();
1284  }
1285 
1286  //----------------------------------------
1287  /* Allocate and construct mapped array.
1288  * Allocate via shared allocation record and
1289  * return that record for allocation tracking.
1290  */
1291  template< class ... P >
1292  SharedAllocationRecord<> *
1293  allocate_shared( ViewCtorProp< P... > const & prop
1294  , typename Traits::array_layout const & layout )
1295  {
1296  typedef ViewCtorProp< P... > ctor_prop ;
1297 
1298  typedef typename ctor_prop::execution_space execution_space ;
1299  typedef typename Traits::memory_space memory_space ;
1300  typedef typename handle_type::template ConstructDestructFunctor<execution_space> functor_type ;
1301  typedef SharedAllocationRecord< memory_space , functor_type > record_type ;
1302 
1303  // Disallow padding
1304  typedef std::integral_constant< unsigned , 0 > padding ;
1305 
1306  m_impl_offset = offset_type( padding(), layout );
1307  m_sacado_size = Kokkos::Impl::GetSacadoSize<unsigned(Rank)>::eval(layout);
1308  m_cijk = extract_cijk<cijk_type>(prop);
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  m_is_contiguous = true;
1317 
1318  const size_t alloc_size =
1319  handle_type::memory_span( m_impl_offset.span(), m_sacado_size );
1320 
1321  // Create shared memory tracking record with allocate memory from the memory space
1322  record_type * const record =
1323  record_type::allocate( ( (ViewCtorProp<void,memory_space> const &) prop ).value
1324  , ( (ViewCtorProp<void,std::string> const &) prop ).value
1325  , alloc_size );
1326 
1327  // Only set the the pointer and initialize if the allocation is non-zero.
1328  // May be zero if one of the dimensions is zero.
1329  if ( alloc_size ) {
1330 
1331  m_impl_handle.set( reinterpret_cast< pointer_type >( record->data() ),
1332  m_impl_offset.span(), m_sacado_size );
1333 
1334  // Assume destruction is only required when construction is requested.
1335  // The ViewValueFunctor has both value construction and destruction operators.
1336  record->m_destroy = m_impl_handle.create_functor(
1337  ( (ViewCtorProp<void,execution_space> const &) prop).value
1338  , ctor_prop::initialize
1339  , m_impl_offset.span()
1340  , m_sacado_size
1341  , m_cijk );
1342 
1343  // Construct values
1344  record->m_destroy.construct_shared_allocation();
1345  }
1346 
1347  return record ;
1348  }
1349 
1350 };
1351 
1352 } // namespace Impl
1353 } // namespace Kokkos
1354 
1355 //----------------------------------------------------------------------------
1356 
1357 namespace Kokkos {
1358 namespace Impl {
1359 
1364 template< class DstTraits , class SrcTraits >
1365 class ViewMapping< DstTraits , SrcTraits ,
1366  typename std::enable_if<(
1367  Kokkos::Impl::MemorySpaceAccess< typename DstTraits::memory_space
1368  , typename SrcTraits::memory_space >::assignable
1369  &&
1370  // Destination view has UQ::PCE
1371  std::is_same< typename DstTraits::specialize
1372  , Kokkos::Experimental::Impl::ViewPCEContiguous >::value
1373  &&
1374  // Source view has UQ::PCE only
1375  std::is_same< typename SrcTraits::specialize
1376  , Kokkos::Experimental::Impl::ViewPCEContiguous >::value
1377  )
1378  , typename DstTraits::specialize
1379  >::type >
1380 {
1381 public:
1382 
1383  enum { is_assignable = true };
1384 
1385  typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
1386  typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
1387  typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcType ;
1388 
1389  KOKKOS_INLINE_FUNCTION static
1390  void assign( DstType & dst
1391  , const SrcType & src
1392  , const TrackType & )
1393  {
1394  static_assert(
1395  (
1396  std::is_same< typename DstTraits::array_layout
1397  , Kokkos::LayoutLeft >::value ||
1398  std::is_same< typename DstTraits::array_layout
1399  , Kokkos::LayoutRight >::value ||
1400  std::is_same< typename DstTraits::array_layout
1401  , Kokkos::LayoutStride >::value
1402  )
1403  &&
1404  (
1405  std::is_same< typename SrcTraits::array_layout
1406  , Kokkos::LayoutLeft >::value ||
1407  std::is_same< typename SrcTraits::array_layout
1408  , Kokkos::LayoutRight >::value ||
1409  std::is_same< typename SrcTraits::array_layout
1410  , Kokkos::LayoutStride >::value
1411  )
1412  , "View of UQ::PCE requires LayoutLeft, LayoutRight, or LayoutStride" );
1413 
1414  static_assert(
1415  std::is_same< typename DstTraits::array_layout
1416  , typename SrcTraits::array_layout >::value ||
1417  std::is_same< typename DstTraits::array_layout
1418  , Kokkos::LayoutStride >::value ||
1419  ( unsigned(DstTraits::rank) == 1 && unsigned(SrcTraits::rank) == 1 ) ,
1420  "View assignment must have compatible layout" );
1421 
1422  static_assert(
1423  std::is_same< typename DstTraits::value_type
1424  , typename SrcTraits::value_type >::value ||
1425  std::is_same< typename DstTraits::value_type
1426  , typename SrcTraits::const_value_type >::value ,
1427  "View assignment must have same value type or const = non-const" );
1428 
1429  static_assert(
1430  ViewDimensionAssignable
1431  < typename DstType::offset_type::dimension_type
1432  , typename SrcType::offset_type::dimension_type >::value ,
1433  "View assignment must have compatible dimensions" );
1434 
1435  dst.m_impl_handle = src.m_impl_handle ;
1436  dst.m_impl_offset = src.m_impl_offset ;
1437  dst.m_sacado_size = src.m_sacado_size ;
1438  dst.m_cijk = src.m_cijk ;
1439  dst.m_is_contiguous = src.m_is_contiguous ;
1440  }
1441 };
1442 
1448 template< class DstTraits , class SrcTraits >
1449 class ViewMapping< DstTraits , SrcTraits ,
1450  typename std::enable_if<(
1451  Kokkos::Impl::MemorySpaceAccess< typename DstTraits::memory_space
1452  , typename SrcTraits::memory_space >::assignable
1453  &&
1454  // Destination view has ordinary
1455  std::is_same< typename DstTraits::specialize , void >::value
1456  &&
1457  // Source view has UQ::PCE only
1458  std::is_same< typename SrcTraits::specialize
1459  , Kokkos::Experimental::Impl::ViewPCEContiguous >::value
1460  &&
1461  // Ranks match
1462  unsigned(DstTraits::dimension::rank) == unsigned(SrcTraits::dimension::rank)+1
1463  )
1464  , typename DstTraits::specialize
1465  >::type >
1466 {
1467 public:
1468 
1469  enum { is_assignable = true };
1470 
1471  typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
1472  typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
1473  typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcType ;
1474 
1475  KOKKOS_INLINE_FUNCTION static
1476  void assign( DstType & dst
1477  , const SrcType & src
1478  , const TrackType & )
1479  {
1480  static_assert(
1481  (
1482  std::is_same< typename DstTraits::array_layout
1483  , Kokkos::LayoutLeft >::value ||
1484  std::is_same< typename DstTraits::array_layout
1485  , Kokkos::LayoutRight >::value ||
1486  std::is_same< typename DstTraits::array_layout
1487  , Kokkos::LayoutStride >::value
1488  )
1489  &&
1490  (
1491  std::is_same< typename SrcTraits::array_layout
1492  , Kokkos::LayoutLeft >::value ||
1493  std::is_same< typename SrcTraits::array_layout
1494  , Kokkos::LayoutRight >::value ||
1495  std::is_same< typename SrcTraits::array_layout
1496  , Kokkos::LayoutStride >::value
1497  )
1498  , "View of UQ::PCE requires LayoutLeft, LayoutRight, or LayoutStride" );
1499 
1500  static_assert(
1501  std::is_same< typename DstTraits::array_layout
1502  , typename SrcTraits::array_layout >::value ||
1503  std::is_same< typename DstTraits::array_layout
1504  , Kokkos::LayoutStride >::value ,
1505  "View assignment must have compatible layout" );
1506 
1507  static_assert(
1508  std::is_same< typename DstTraits::scalar_array_type
1509  , typename SrcTraits::scalar_array_type >::value ||
1510  std::is_same< typename DstTraits::scalar_array_type
1511  , typename SrcTraits::const_scalar_array_type >::value ,
1512  "View assignment must have same value type or const = non-const" );
1513 
1514  static_assert(
1515  ViewDimensionAssignable<
1516  typename DstType::offset_type::dimension_type,
1517  typename SrcType::array_offset_type::dimension_type >::value,
1518  "View assignment must have compatible dimensions" );
1519 
1520  if ( !src.m_is_contiguous )
1521  Kokkos::abort("\n\n ****** Kokkos::View< Sacado::UQ::PCE ... >: can't assign non-contiguous view ******\n\n");
1522 
1523  unsigned dims[8];
1524  dims[0] = src.m_impl_offset.dimension_0();
1525  dims[1] = src.m_impl_offset.dimension_1();
1526  dims[2] = src.m_impl_offset.dimension_2();
1527  dims[3] = src.m_impl_offset.dimension_3();
1528  dims[4] = src.m_impl_offset.dimension_4();
1529  dims[5] = src.m_impl_offset.dimension_5();
1530  dims[6] = src.m_impl_offset.dimension_6();
1531  dims[7] = src.m_impl_offset.dimension_7();
1532  unsigned rank = SrcTraits::dimension::rank;
1533  unsigned sacado_size = src.m_sacado_size;
1534  if (std::is_same<typename SrcTraits::array_layout, LayoutLeft>::value) {
1535  // Move sacado_size to the first dimension, shift all others up one
1536  for (unsigned i=rank; i>0; --i)
1537  dims[i] = dims[i-1];
1538  dims[0] = sacado_size;
1539  }
1540  else {
1541  dims[rank] = sacado_size;
1542  }
1543  typedef typename DstType::offset_type dst_offset_type;
1544  dst.m_impl_offset = dst_offset_type( std::integral_constant< unsigned , 0 >(),
1545  typename DstTraits::array_layout(
1546  dims[0] , dims[1] , dims[2] , dims[3] ,
1547  dims[4] , dims[5] , dims[6] , dims[7] ) );
1548  dst.m_impl_handle = src.m_impl_handle.scalar_ptr ;
1549  }
1550 };
1551 
1558 template< class DstTraits , class SrcTraits >
1559 class ViewMapping< DstTraits , SrcTraits ,
1560  typename std::enable_if<(
1561  Kokkos::Impl::MemorySpaceAccess< typename DstTraits::memory_space
1562  , typename SrcTraits::memory_space >::assignable
1563  &&
1564  // Destination view has ordinary
1565  std::is_same< typename DstTraits::specialize , void >::value
1566  &&
1567  // Source view has UQ::PCE only
1568  std::is_same< typename SrcTraits::specialize
1569  , Kokkos::Experimental::Impl::ViewPCEContiguous >::value
1570  &&
1571  // Ranks match
1572  unsigned(DstTraits::dimension::rank) == unsigned(SrcTraits::dimension::rank)
1573  )
1574  , typename DstTraits::specialize
1575  >::type >
1576 {
1577 public:
1578 
1579  enum { is_assignable = true };
1580 
1581  typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
1582  typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
1583  typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcType ;
1584 
1585  KOKKOS_INLINE_FUNCTION static
1586  void assign( DstType & dst
1587  , const SrcType & src
1588  , const TrackType & )
1589  {
1590  static_assert(
1591  (
1592  std::is_same< typename DstTraits::array_layout
1593  , Kokkos::LayoutLeft >::value ||
1594  std::is_same< typename DstTraits::array_layout
1595  , Kokkos::LayoutRight >::value ||
1596  std::is_same< typename DstTraits::array_layout
1597  , Kokkos::LayoutStride >::value
1598  )
1599  &&
1600  (
1601  std::is_same< typename SrcTraits::array_layout
1602  , Kokkos::LayoutLeft >::value ||
1603  std::is_same< typename SrcTraits::array_layout
1604  , Kokkos::LayoutRight >::value ||
1605  std::is_same< typename SrcTraits::array_layout
1606  , Kokkos::LayoutStride >::value
1607  )
1608  , "View of UQ::PCE requires LayoutLeft, LayoutRight, or LayoutStride" );
1609 
1610  static_assert(
1611  std::is_same< typename DstTraits::array_layout
1612  , typename SrcTraits::array_layout >::value ||
1613  std::is_same< typename DstTraits::array_layout
1614  , Kokkos::LayoutStride >::value ,
1615  "View assignment must have compatible layout" );
1616 
1617  static_assert(
1618  std::is_same< typename DstTraits::value_type
1619  , typename SrcTraits::non_const_value_type::value_type >::value ||
1620  std::is_same< typename DstTraits::value_type
1621  , const typename SrcTraits::non_const_value_type::value_type >::value ,
1622  "View assignment must have same value type or const = non-const" );
1623 
1624  static_assert(
1625  ViewDimensionAssignable<
1626  typename DstType::offset_type::dimension_type,
1627  typename SrcType::offset_type::dimension_type >::value,
1628  "View assignment must have compatible dimensions" );
1629 
1630  if ( !src.m_is_contiguous )
1631  Kokkos::abort("\n\n ****** Kokkos::View< Sacado::UQ::PCE ... >: can't assign non-contiguous view ******\n\n");
1632 
1633  unsigned dims[8];
1634  dims[0] = src.m_impl_offset.dimension_0();
1635  dims[1] = src.m_impl_offset.dimension_1();
1636  dims[2] = src.m_impl_offset.dimension_2();
1637  dims[3] = src.m_impl_offset.dimension_3();
1638  dims[4] = src.m_impl_offset.dimension_4();
1639  dims[5] = src.m_impl_offset.dimension_5();
1640  dims[6] = src.m_impl_offset.dimension_6();
1641  dims[7] = src.m_impl_offset.dimension_7();
1642  unsigned rank = SrcTraits::dimension::rank;
1643  unsigned sacado_size = src.m_sacado_size;
1644  if (std::is_same<typename DstTraits::array_layout, LayoutLeft>::value) {
1645  dims[0] = dims[0]*sacado_size;
1646  dims[rank] = 0;
1647  }
1648  else {
1649  dims[rank-1] = dims[rank-1]*sacado_size;
1650  dims[rank] = 0;
1651  }
1652  typedef typename DstType::offset_type dst_offset_type;
1653  dst.m_impl_offset = dst_offset_type( std::integral_constant< unsigned , 0 >(),
1654  typename DstTraits::array_layout(
1655  dims[0] , dims[1] , dims[2] , dims[3] ,
1656  dims[4] , dims[5] , dims[6] , dims[7] ) );
1657  dst.m_impl_handle = src.m_impl_handle.scalar_ptr ;
1658  }
1659 };
1660 
1661 } // namespace Impl
1662 } // namespace Kokkos
1663 
1664 //----------------------------------------------------------------------------
1665 
1666 namespace Kokkos {
1667 namespace Impl {
1668 
1669 // Subview mapping
1670 
1671 template< class DataType, class ... P , class Arg0, class ... Args >
1672 struct ViewMapping
1673  < typename std::enable_if<(
1674  // Source view has UQ::PCE only
1675  std::is_same< typename Kokkos::ViewTraits<DataType,P...>::specialize
1676  , Kokkos::Experimental::Impl::ViewPCEContiguous >::value
1677  &&
1678  (
1679  std::is_same< typename Kokkos::ViewTraits<DataType,P...>::array_layout
1680  , Kokkos::LayoutLeft >::value ||
1681  std::is_same< typename Kokkos::ViewTraits<DataType,P...>::array_layout
1682  , Kokkos::LayoutRight >::value ||
1683  std::is_same< typename Kokkos::ViewTraits<DataType,P...>::array_layout
1684  , Kokkos::LayoutStride >::value
1685  )
1686  )>::type
1687  , Kokkos::ViewTraits<DataType,P...>
1688  , Arg0, Args ... >
1689 {
1690 private:
1691 
1692  typedef Kokkos::ViewTraits<DataType,P...> SrcTraits;
1693 
1694  //static_assert( SrcTraits::rank == sizeof...(Args) , "" );
1695 
1696  enum
1697  { RZ = false
1698  , R0 = bool(is_integral_extent<0,Arg0,Args...>::value)
1699  , R1 = bool(is_integral_extent<1,Arg0,Args...>::value)
1700  , R2 = bool(is_integral_extent<2,Arg0,Args...>::value)
1701  , R3 = bool(is_integral_extent<3,Arg0,Args...>::value)
1702  , R4 = bool(is_integral_extent<4,Arg0,Args...>::value)
1703  , R5 = bool(is_integral_extent<5,Arg0,Args...>::value)
1704  , R6 = bool(is_integral_extent<6,Arg0,Args...>::value)
1705  };
1706 
1707  // Public rank
1708  enum { rank = unsigned(R0) + unsigned(R1) + unsigned(R2) + unsigned(R3)
1709  + unsigned(R4) + unsigned(R5) + unsigned(R6) };
1710 
1711  // Whether right-most non-UQ::PCE rank is a range.
1712  enum { R0_rev = ( 0 == SrcTraits::rank ? RZ : (
1713  1 == SrcTraits::rank ? R0 : (
1714  2 == SrcTraits::rank ? R1 : (
1715  3 == SrcTraits::rank ? R2 : (
1716  4 == SrcTraits::rank ? R3 : (
1717  5 == SrcTraits::rank ? R4 : (
1718  6 == SrcTraits::rank ? R5 : R6 ))))))) };
1719 
1720  // Subview's layout
1721  typedef typename std::conditional<
1722  ( /* Same array layout IF */
1723  ( rank == 0 ) /* output rank zero */
1724  ||
1725  // OutputRank 1 or 2, InputLayout Left, Interval 0
1726  // because single stride one or second index has a stride.
1727  ( rank <= 2 && R0 && std::is_same< typename SrcTraits::array_layout , Kokkos::LayoutLeft >::value )
1728  ||
1729  // OutputRank 1 or 2, InputLayout Right, Interval [InputRank-1]
1730  // because single stride one or second index has a stride.
1731  ( rank <= 2 && R0_rev && std::is_same< typename SrcTraits::array_layout , Kokkos::LayoutRight >::value )
1732  ), typename SrcTraits::array_layout , Kokkos::LayoutStride
1734 
1736 
1737  typedef typename std::conditional< rank == 0 , sacado_uq_pce_type ,
1738  typename std::conditional< rank == 1 , sacado_uq_pce_type * ,
1739  typename std::conditional< rank == 2 , sacado_uq_pce_type ** ,
1740  typename std::conditional< rank == 3 , sacado_uq_pce_type *** ,
1741  typename std::conditional< rank == 4 , sacado_uq_pce_type **** ,
1742  typename std::conditional< rank == 5 , sacado_uq_pce_type ***** ,
1743  typename std::conditional< rank == 6 , sacado_uq_pce_type ****** ,
1744  sacado_uq_pce_type *******
1747 
1748 public:
1749 
1750  typedef Kokkos::ViewTraits
1751  < data_type
1752  , array_layout
1753  , typename SrcTraits::device_type
1754  , typename SrcTraits::memory_traits > traits_type ;
1755 
1756  typedef Kokkos::View
1757  < data_type
1758  , array_layout
1759  , typename SrcTraits::device_type
1760  , typename SrcTraits::memory_traits > type ;
1761 
1762 
1763  // The presumed type is 'ViewMapping< traits_type , void >'
1764  // However, a compatible ViewMapping is acceptable.
1765  template< class DstTraits >
1766  KOKKOS_INLINE_FUNCTION
1767  static void assign( ViewMapping< DstTraits , typename DstTraits::specialize > & dst
1768  , ViewMapping< SrcTraits , typename SrcTraits::specialize > const & src
1769  , Arg0 arg0, Args ... args )
1770  {
1771  static_assert(
1772  ViewMapping< DstTraits , traits_type , typename DstTraits::specialize >::is_assignable ,
1773  "Subview destination type must be compatible with subview derived type" );
1774 
1775  typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
1776  typedef typename DstType::offset_type dst_offset_type ;
1777 
1778  const SubviewExtents< SrcTraits::rank , rank >
1779  extents( src.m_impl_offset.m_dim , arg0 , args... );
1780 
1781  const size_t offset = src.m_impl_offset( extents.domain_offset(0)
1782  , extents.domain_offset(1)
1783  , extents.domain_offset(2)
1784  , extents.domain_offset(3)
1785  , extents.domain_offset(4)
1786  , extents.domain_offset(5)
1787  , extents.domain_offset(6)
1788  , extents.domain_offset(7) );
1789 
1790  dst.m_impl_offset = dst_offset_type( src.m_impl_offset , extents );
1791  dst.m_impl_handle.value_ptr = src.m_impl_handle.value_ptr + offset;
1792  dst.m_impl_handle.scalar_ptr =
1793  src.m_impl_handle.scalar_ptr + offset * src.m_sacado_size;
1794  dst.m_sacado_size = src.m_sacado_size;
1795  dst.m_cijk = src.m_cijk;
1796  dst.m_is_contiguous = src.m_is_contiguous;
1797  }
1798 
1799 };
1800 
1801 } // namespace Impl
1802 } // namespace Kokkos
1803 
1804 //----------------------------------------------------------------------------
1805 //----------------------------------------------------------------------------
1806 //----------------------------------------------------------------------------
1807 
1808 namespace Kokkos {
1809 namespace Impl {
1810 
1811 // Specialization for deep_copy( view, view::value_type ) for Cuda
1812 #if defined( KOKKOS_ENABLE_CUDA )
1813 template< class OutputView >
1814 struct StokhosViewFill< OutputView ,
1815  typename std::enable_if< std::is_same< typename OutputView::specialize,
1816  Kokkos::Experimental::Impl::ViewPCEContiguous >::value &&
1817  std::is_same< typename OutputView::execution_space,
1818  Cuda >::value >::type >
1819 {
1820  typedef typename OutputView::const_value_type const_value_type ;
1821  typedef typename Sacado::ScalarType<const_value_type>::type scalar_type ;
1822  typedef typename OutputView::execution_space execution_space ;
1823  typedef typename OutputView::size_type size_type ;
1824 
1825  template <unsigned VectorLength>
1826  struct PCEKernel {
1827  typedef typename OutputView::execution_space execution_space ;
1828  const OutputView output;
1829  const_value_type input;
1830 
1831  PCEKernel( const OutputView & arg_out , const_value_type & arg_in ) :
1832  output(arg_out), input(arg_in) {}
1833 
1834  typedef typename Kokkos::TeamPolicy< execution_space >::member_type team_member ;
1835 
1836  KOKKOS_INLINE_FUNCTION
1837  void operator()( const team_member & dev ) const
1838  {
1839  const size_type tidx = dev.team_rank() % VectorLength;
1840  const size_type tidy = dev.team_rank() / VectorLength;
1841  const size_type nrow = dev.team_size() / VectorLength;
1842  const size_type nvec = dimension_scalar(output);
1843 
1844  const size_type i0 = dev.league_rank() * nrow + tidy;
1845  if ( i0 >= output.extent(0) ) return;
1846 
1847  for ( size_type i1 = 0 ; i1 < output.extent(1) ; ++i1 ) {
1848  for ( size_type i2 = 0 ; i2 < output.extent(2) ; ++i2 ) {
1849  for ( size_type i3 = 0 ; i3 < output.extent(3) ; ++i3 ) {
1850  for ( size_type i4 = 0 ; i4 < output.extent(4) ; ++i4 ) {
1851  for ( size_type i5 = 0 ; i5 < output.extent(5) ; ++i5 ) {
1852  for ( size_type i6 = 0 ; i6 < output.extent(6) ; ++i6 ) {
1853  for ( size_type i7 = 0 ; i7 < output.extent(7) ; ++i7 ) {
1854  for ( size_type is = tidx ; is < nvec ; is+=VectorLength ) {
1855  output.access(i0,i1,i2,i3,i4,i5,i6,i7).fastAccessCoeff(is) =
1856  input.fastAccessCoeff(is) ;
1857  }}}}}}}}
1858  }
1859  };
1860 
1861  template <unsigned VectorLength>
1862  struct ScalarKernel {
1863  typedef typename OutputView::execution_space execution_space ;
1864  const OutputView output;
1865  const scalar_type input;
1866 
1867  ScalarKernel( const OutputView & arg_out , const scalar_type & arg_in ) :
1868  output(arg_out), input(arg_in) {}
1869 
1870  typedef typename Kokkos::TeamPolicy< execution_space >::member_type team_member ;
1871  KOKKOS_INLINE_FUNCTION
1872  void operator()( const team_member & dev ) const
1873  {
1874  const size_type tidx = dev.team_rank() % VectorLength;
1875  const size_type tidy = dev.team_rank() / VectorLength;
1876  const size_type nrow = dev.team_size() / VectorLength;
1877  const size_type npce = dimension_scalar(output);
1878 
1879  const size_type i0 = dev.league_rank() * nrow + tidy;
1880  if ( i0 >= output.extent(0) ) return;
1881 
1882  for ( size_type i1 = 0 ; i1 < output.extent(1) ; ++i1 ) {
1883  for ( size_type i2 = 0 ; i2 < output.extent(2) ; ++i2 ) {
1884  for ( size_type i3 = 0 ; i3 < output.extent(3) ; ++i3 ) {
1885  for ( size_type i4 = 0 ; i4 < output.extent(4) ; ++i4 ) {
1886  for ( size_type i5 = 0 ; i5 < output.extent(5) ; ++i5 ) {
1887  for ( size_type i6 = 0 ; i6 < output.extent(6) ; ++i6 ) {
1888  for ( size_type i7 = 0 ; i7 < output.extent(7) ; ++i7 ) {
1889  for ( size_type is = tidx ; is < npce ; is+=VectorLength ) {
1890  output.access(i0,i1,i2,i3,i4,i5,i6,i7).fastAccessCoeff(is) =
1891  is == 0 ? input : scalar_type(0) ;
1892  }}}}}}}}
1893  }
1894  };
1895 
1896  StokhosViewFill( const OutputView & output , const_value_type & input )
1897  {
1898  // Coalesced accesses are 128 bytes in size
1900  const unsigned vector_length =
1901  ( 128 + sizeof(scalar_type)-1 ) / sizeof(scalar_type);
1902 
1903  // 8 warps per block should give good occupancy
1904  const size_type block_size = 256;
1905 
1906  const size_type rows_per_block = block_size / vector_length;
1907  const size_type n = output.extent(0);
1908  const size_type league_size = ( n + rows_per_block-1 ) / rows_per_block;
1909  const size_type team_size = rows_per_block * vector_length;
1910  Kokkos::TeamPolicy< execution_space > config( league_size, team_size );
1911 
1912  if (static_cast<unsigned>(input.size()) != dimension_scalar(output) &&
1913  input.size() != 1)
1914  Kokkos::abort("StokhosViewFill: Invalid input value size");
1915 
1916  if (input.size() == 1)
1917  parallel_for(
1918  config, ScalarKernel<vector_length>(output, input.fastAccessCoeff(0)) );
1919  else
1920  parallel_for( config, PCEKernel<vector_length>(output, input) );
1921  execution_space::fence();
1922  }
1923 
1924  StokhosViewFill( const OutputView & output , const scalar_type & input )
1925  {
1926  // Coalesced accesses are 128 bytes in size
1928  const unsigned vector_length =
1929  ( 128 + sizeof(scalar_type)-1 ) / sizeof(scalar_type);
1930 
1931  // 8 warps per block should give good occupancy
1932  const size_type block_size = 256;
1933 
1934  const size_type rows_per_block = block_size / vector_length;
1935  const size_type n = output.extent(0);
1936  const size_type league_size = ( n + rows_per_block-1 ) / rows_per_block;
1937  const size_type team_size = rows_per_block * vector_length;
1938  Kokkos::TeamPolicy< execution_space > config( league_size, team_size );
1939 
1940  parallel_for( config, ScalarKernel<vector_length>(output, input) );
1941  execution_space::fence();
1942  }
1943 
1944 };
1945 #endif /* #if defined( KOKKOS_ENABLE_CUDA ) */
1946 
1947 } // namespace Impl
1948 } // namespace Kokkos
1949 
1950 #include "Kokkos_View_Utils_Def.hpp"
1951 
1952 //----------------------------------------------------------------------------
1953 //----------------------------------------------------------------------------
1954 //----------------------------------------------------------------------------
1955 
1956 #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 constexpr std::enable_if< is_view_uq_pce< View< T, P...> >::value, unsigned >::type dimension_scalar(const View< T, P...> &view)
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)
DeepCopyNonContiguous(const OutputView &arg_out, const InputView &arg_in)
void deep_copy(const Stokhos::CrsMatrix< ValueType, DstDevice, Layout > &dst, const Stokhos::CrsMatrix< ValueType, SrcDevice, Layout > &src)
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)
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
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
Stokhos::CrsMatrix< ValueType, Device, Layout >::HostMirror create_mirror(const Stokhos::CrsMatrix< ValueType, Device, Layout > &A)
int n