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 ( std::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_DEFAULTED_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_DEFAULTED_FUNCTION ViewMapping( const ViewMapping & ) = default ;
1256  KOKKOS_DEFAULTED_FUNCTION ViewMapping & operator = ( const ViewMapping & ) = default ;
1257 
1258  KOKKOS_DEFAULTED_FUNCTION ViewMapping( ViewMapping && ) = default ;
1259  KOKKOS_DEFAULTED_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 
1287  KOKKOS_INLINE_FUNCTION
1288  void assign_data( pointer_type arg_ptr )
1289  { m_impl_handle.set( arg_ptr, m_impl_offset.span(), m_sacado_size ); }
1290 
1291  //----------------------------------------
1292  /* Allocate and construct mapped array.
1293  * Allocate via shared allocation record and
1294  * return that record for allocation tracking.
1295  */
1296  template< class ... P >
1297  SharedAllocationRecord<> *
1298  allocate_shared( ViewCtorProp< P... > const & prop
1299  , typename Traits::array_layout const & layout )
1300  {
1301  typedef ViewCtorProp< P... > ctor_prop ;
1302 
1303  typedef typename ctor_prop::execution_space execution_space ;
1304  typedef typename Traits::memory_space memory_space ;
1305  typedef typename handle_type::template ConstructDestructFunctor<execution_space> functor_type ;
1306  typedef SharedAllocationRecord< memory_space , functor_type > record_type ;
1307 
1308  // Disallow padding
1309  typedef std::integral_constant< unsigned , 0 > padding ;
1310 
1311  m_impl_offset = offset_type( padding(), layout );
1312  m_sacado_size = Kokkos::Impl::GetSacadoSize<unsigned(Rank)>::eval(layout);
1313  m_cijk = extract_cijk<cijk_type>(prop);
1314  if (m_cijk.dimension() == 0)
1315  m_cijk = getGlobalCijkTensor<cijk_type>();
1316  // Use 0 or KOKKOS_IMPL_CTOR_DEFAULT_ARG to signal the size wasn't
1317  // specified in the constructor
1318  if (m_sacado_size == 0 ||
1319  m_sacado_size == unsigned(KOKKOS_IMPL_CTOR_DEFAULT_ARG))
1320  m_sacado_size = m_cijk.dimension();
1321  m_is_contiguous = true;
1322 
1323  const size_t alloc_size =
1324  handle_type::memory_span( m_impl_offset.span(), m_sacado_size );
1325 
1326  // Create shared memory tracking record with allocate memory from the memory space
1327  record_type * const record =
1328  record_type::allocate( ( (ViewCtorProp<void,memory_space> const &) prop ).value
1329  , ( (ViewCtorProp<void,std::string> const &) prop ).value
1330  , alloc_size );
1331 
1332  // Only set the the pointer and initialize if the allocation is non-zero.
1333  // May be zero if one of the dimensions is zero.
1334  if ( alloc_size ) {
1335 
1336  m_impl_handle.set( reinterpret_cast< pointer_type >( record->data() ),
1337  m_impl_offset.span(), m_sacado_size );
1338 
1339  // Assume destruction is only required when construction is requested.
1340  // The ViewValueFunctor has both value construction and destruction operators.
1341  record->m_destroy = m_impl_handle.create_functor(
1342  ( (ViewCtorProp<void,execution_space> const &) prop).value
1343  , ctor_prop::initialize
1344  , m_impl_offset.span()
1345  , m_sacado_size
1346  , m_cijk );
1347 
1348  // Construct values
1349  record->m_destroy.construct_shared_allocation();
1350  }
1351 
1352  return record ;
1353  }
1354 
1355 };
1356 
1357 } // namespace Impl
1358 } // namespace Kokkos
1359 
1360 //----------------------------------------------------------------------------
1361 
1362 namespace Kokkos {
1363 namespace Impl {
1364 
1369 template< class DstTraits , class SrcTraits >
1370 class ViewMapping< DstTraits , SrcTraits ,
1371  typename std::enable_if<(
1372  Kokkos::Impl::MemorySpaceAccess< typename DstTraits::memory_space
1373  , typename SrcTraits::memory_space >::assignable
1374  &&
1375  // Destination view has UQ::PCE
1376  std::is_same< typename DstTraits::specialize
1377  , Kokkos::Experimental::Impl::ViewPCEContiguous >::value
1378  &&
1379  // Source view has UQ::PCE only
1380  std::is_same< typename SrcTraits::specialize
1381  , Kokkos::Experimental::Impl::ViewPCEContiguous >::value
1382  )
1383  , typename DstTraits::specialize
1384  >::type >
1385 {
1386 public:
1387 
1388  enum { is_assignable = true };
1389  enum { is_assignable_data_type = true };
1390 
1391  typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
1392  typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
1393  typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcType ;
1394 
1395  KOKKOS_INLINE_FUNCTION static
1396  void assign( DstType & dst
1397  , const SrcType & src
1398  , const TrackType & )
1399  {
1400  static_assert(
1401  (
1402  std::is_same< typename DstTraits::array_layout
1403  , Kokkos::LayoutLeft >::value ||
1404  std::is_same< typename DstTraits::array_layout
1405  , Kokkos::LayoutRight >::value ||
1406  std::is_same< typename DstTraits::array_layout
1407  , Kokkos::LayoutStride >::value
1408  )
1409  &&
1410  (
1411  std::is_same< typename SrcTraits::array_layout
1412  , Kokkos::LayoutLeft >::value ||
1413  std::is_same< typename SrcTraits::array_layout
1414  , Kokkos::LayoutRight >::value ||
1415  std::is_same< typename SrcTraits::array_layout
1416  , Kokkos::LayoutStride >::value
1417  )
1418  , "View of UQ::PCE requires LayoutLeft, LayoutRight, or LayoutStride" );
1419 
1420  static_assert(
1421  std::is_same< typename DstTraits::array_layout
1422  , typename SrcTraits::array_layout >::value ||
1423  std::is_same< typename DstTraits::array_layout
1424  , Kokkos::LayoutStride >::value ||
1425  ( unsigned(DstTraits::rank) == 1 && unsigned(SrcTraits::rank) == 1 ) ,
1426  "View assignment must have compatible layout" );
1427 
1428  static_assert(
1429  std::is_same< typename DstTraits::value_type
1430  , typename SrcTraits::value_type >::value ||
1431  std::is_same< typename DstTraits::value_type
1432  , typename SrcTraits::const_value_type >::value ,
1433  "View assignment must have same value type or const = non-const" );
1434 
1435  static_assert(
1436  ViewDimensionAssignable
1437  < typename DstType::offset_type::dimension_type
1438  , typename SrcType::offset_type::dimension_type >::value ,
1439  "View assignment must have compatible dimensions" );
1440 
1441  dst.m_impl_handle = src.m_impl_handle ;
1442  dst.m_impl_offset = src.m_impl_offset ;
1443  dst.m_sacado_size = src.m_sacado_size ;
1444  dst.m_cijk = src.m_cijk ;
1445  dst.m_is_contiguous = src.m_is_contiguous ;
1446  }
1447 };
1448 
1454 template< class DstTraits , class SrcTraits >
1455 class ViewMapping< DstTraits , SrcTraits ,
1456  typename std::enable_if<(
1457  Kokkos::Impl::MemorySpaceAccess< typename DstTraits::memory_space
1458  , typename SrcTraits::memory_space >::assignable
1459  &&
1460  // Destination view has ordinary
1461  std::is_same< typename DstTraits::specialize , void >::value
1462  &&
1463  // Source view has UQ::PCE only
1464  std::is_same< typename SrcTraits::specialize
1465  , Kokkos::Experimental::Impl::ViewPCEContiguous >::value
1466  &&
1467  // Ranks match
1468  unsigned(DstTraits::dimension::rank) == unsigned(SrcTraits::dimension::rank)+1
1469  )
1470  , typename DstTraits::specialize
1471  >::type >
1472 {
1473 public:
1474 
1475  enum { is_assignable = true };
1476  enum { is_assignable_data_type = true };
1477 
1478  typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
1479  typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
1480  typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcType ;
1481 
1482  KOKKOS_INLINE_FUNCTION static
1483  void assign( DstType & dst
1484  , const SrcType & src
1485  , const TrackType & )
1486  {
1487  static_assert(
1488  (
1489  std::is_same< typename DstTraits::array_layout
1490  , Kokkos::LayoutLeft >::value ||
1491  std::is_same< typename DstTraits::array_layout
1492  , Kokkos::LayoutRight >::value ||
1493  std::is_same< typename DstTraits::array_layout
1494  , Kokkos::LayoutStride >::value
1495  )
1496  &&
1497  (
1498  std::is_same< typename SrcTraits::array_layout
1499  , Kokkos::LayoutLeft >::value ||
1500  std::is_same< typename SrcTraits::array_layout
1501  , Kokkos::LayoutRight >::value ||
1502  std::is_same< typename SrcTraits::array_layout
1503  , Kokkos::LayoutStride >::value
1504  )
1505  , "View of UQ::PCE requires LayoutLeft, LayoutRight, or LayoutStride" );
1506 
1507  static_assert(
1508  std::is_same< typename DstTraits::array_layout
1509  , typename SrcTraits::array_layout >::value ||
1510  std::is_same< typename DstTraits::array_layout
1511  , Kokkos::LayoutStride >::value ,
1512  "View assignment must have compatible layout" );
1513 
1514  static_assert(
1515  std::is_same< typename DstTraits::scalar_array_type
1516  , typename SrcTraits::scalar_array_type >::value ||
1517  std::is_same< typename DstTraits::scalar_array_type
1518  , typename SrcTraits::const_scalar_array_type >::value ,
1519  "View assignment must have same value type or const = non-const" );
1520 
1521  static_assert(
1522  ViewDimensionAssignable<
1523  typename DstType::offset_type::dimension_type,
1524  typename SrcType::array_offset_type::dimension_type >::value,
1525  "View assignment must have compatible dimensions" );
1526 
1527  if ( !src.m_is_contiguous )
1528  Kokkos::abort("\n\n ****** Kokkos::View< Sacado::UQ::PCE ... >: can't assign non-contiguous view ******\n\n");
1529 
1530  unsigned dims[8];
1531  dims[0] = src.m_impl_offset.dimension_0();
1532  dims[1] = src.m_impl_offset.dimension_1();
1533  dims[2] = src.m_impl_offset.dimension_2();
1534  dims[3] = src.m_impl_offset.dimension_3();
1535  dims[4] = src.m_impl_offset.dimension_4();
1536  dims[5] = src.m_impl_offset.dimension_5();
1537  dims[6] = src.m_impl_offset.dimension_6();
1538  dims[7] = src.m_impl_offset.dimension_7();
1539  unsigned rank = SrcTraits::dimension::rank;
1540  unsigned sacado_size = src.m_sacado_size;
1541  if (std::is_same<typename SrcTraits::array_layout, LayoutLeft>::value) {
1542  // Move sacado_size to the first dimension, shift all others up one
1543  for (unsigned i=rank; i>0; --i)
1544  dims[i] = dims[i-1];
1545  dims[0] = sacado_size;
1546  }
1547  else {
1548  dims[rank] = sacado_size;
1549  }
1550  typedef typename DstType::offset_type dst_offset_type;
1551  dst.m_impl_offset = dst_offset_type( std::integral_constant< unsigned , 0 >(),
1552  typename DstTraits::array_layout(
1553  dims[0] , dims[1] , dims[2] , dims[3] ,
1554  dims[4] , dims[5] , dims[6] , dims[7] ) );
1555  dst.m_impl_handle = src.m_impl_handle.scalar_ptr ;
1556  }
1557 };
1558 
1565 template< class DstTraits , class SrcTraits >
1566 class ViewMapping< DstTraits , SrcTraits ,
1567  typename std::enable_if<(
1568  Kokkos::Impl::MemorySpaceAccess< typename DstTraits::memory_space
1569  , typename SrcTraits::memory_space >::assignable
1570  &&
1571  // Destination view has ordinary
1572  std::is_same< typename DstTraits::specialize , void >::value
1573  &&
1574  // Source view has UQ::PCE only
1575  std::is_same< typename SrcTraits::specialize
1576  , Kokkos::Experimental::Impl::ViewPCEContiguous >::value
1577  &&
1578  // Ranks match
1579  unsigned(DstTraits::dimension::rank) == unsigned(SrcTraits::dimension::rank)
1580  )
1581  , typename DstTraits::specialize
1582  >::type >
1583 {
1584 public:
1585 
1586  enum { is_assignable = true };
1587  enum { is_assignable_data_type = true };
1588 
1589  typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
1590  typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
1591  typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcType ;
1592 
1593  KOKKOS_INLINE_FUNCTION static
1594  void assign( DstType & dst
1595  , const SrcType & src
1596  , const TrackType & )
1597  {
1598  static_assert(
1599  (
1600  std::is_same< typename DstTraits::array_layout
1601  , Kokkos::LayoutLeft >::value ||
1602  std::is_same< typename DstTraits::array_layout
1603  , Kokkos::LayoutRight >::value ||
1604  std::is_same< typename DstTraits::array_layout
1605  , Kokkos::LayoutStride >::value
1606  )
1607  &&
1608  (
1609  std::is_same< typename SrcTraits::array_layout
1610  , Kokkos::LayoutLeft >::value ||
1611  std::is_same< typename SrcTraits::array_layout
1612  , Kokkos::LayoutRight >::value ||
1613  std::is_same< typename SrcTraits::array_layout
1614  , Kokkos::LayoutStride >::value
1615  )
1616  , "View of UQ::PCE requires LayoutLeft, LayoutRight, or LayoutStride" );
1617 
1618  static_assert(
1619  std::is_same< typename DstTraits::array_layout
1620  , typename SrcTraits::array_layout >::value ||
1621  std::is_same< typename DstTraits::array_layout
1622  , Kokkos::LayoutStride >::value ,
1623  "View assignment must have compatible layout" );
1624 
1625  static_assert(
1626  std::is_same< typename DstTraits::value_type
1627  , typename SrcTraits::non_const_value_type::value_type >::value ||
1628  std::is_same< typename DstTraits::value_type
1629  , const typename SrcTraits::non_const_value_type::value_type >::value ,
1630  "View assignment must have same value type or const = non-const" );
1631 
1632  static_assert(
1633  ViewDimensionAssignable<
1634  typename DstType::offset_type::dimension_type,
1635  typename SrcType::offset_type::dimension_type >::value,
1636  "View assignment must have compatible dimensions" );
1637 
1638  if ( !src.m_is_contiguous )
1639  Kokkos::abort("\n\n ****** Kokkos::View< Sacado::UQ::PCE ... >: can't assign non-contiguous view ******\n\n");
1640 
1641  unsigned dims[8];
1642  dims[0] = src.m_impl_offset.dimension_0();
1643  dims[1] = src.m_impl_offset.dimension_1();
1644  dims[2] = src.m_impl_offset.dimension_2();
1645  dims[3] = src.m_impl_offset.dimension_3();
1646  dims[4] = src.m_impl_offset.dimension_4();
1647  dims[5] = src.m_impl_offset.dimension_5();
1648  dims[6] = src.m_impl_offset.dimension_6();
1649  dims[7] = src.m_impl_offset.dimension_7();
1650  unsigned rank = SrcTraits::dimension::rank;
1651  unsigned sacado_size = src.m_sacado_size;
1652  if (std::is_same<typename DstTraits::array_layout, LayoutLeft>::value) {
1653  dims[0] = dims[0]*sacado_size;
1654  dims[rank] = 0;
1655  }
1656  else {
1657  dims[rank-1] = dims[rank-1]*sacado_size;
1658  dims[rank] = 0;
1659  }
1660  typedef typename DstType::offset_type dst_offset_type;
1661  dst.m_impl_offset = dst_offset_type( std::integral_constant< unsigned , 0 >(),
1662  typename DstTraits::array_layout(
1663  dims[0] , dims[1] , dims[2] , dims[3] ,
1664  dims[4] , dims[5] , dims[6] , dims[7] ) );
1665  dst.m_impl_handle = src.m_impl_handle.scalar_ptr ;
1666  }
1667 };
1668 
1669 } // namespace Impl
1670 } // namespace Kokkos
1671 
1672 //----------------------------------------------------------------------------
1673 
1674 namespace Kokkos {
1675 namespace Impl {
1676 
1677 // Subview mapping
1678 
1679 template< class DataType, class ... P , class Arg0, class ... Args >
1680 struct ViewMapping
1681  < typename std::enable_if<(
1682  // Source view has UQ::PCE only
1683  std::is_same< typename Kokkos::ViewTraits<DataType,P...>::specialize
1684  , Kokkos::Experimental::Impl::ViewPCEContiguous >::value
1685  &&
1686  (
1687  std::is_same< typename Kokkos::ViewTraits<DataType,P...>::array_layout
1688  , Kokkos::LayoutLeft >::value ||
1689  std::is_same< typename Kokkos::ViewTraits<DataType,P...>::array_layout
1690  , Kokkos::LayoutRight >::value ||
1691  std::is_same< typename Kokkos::ViewTraits<DataType,P...>::array_layout
1692  , Kokkos::LayoutStride >::value
1693  )
1694  )>::type
1695  , Kokkos::ViewTraits<DataType,P...>
1696  , Arg0, Args ... >
1697 {
1698 private:
1699 
1700  typedef Kokkos::ViewTraits<DataType,P...> SrcTraits;
1701 
1702  //static_assert( SrcTraits::rank == sizeof...(Args) , "" );
1703 
1704  enum
1705  { RZ = false
1706  , R0 = bool(is_integral_extent<0,Arg0,Args...>::value)
1707  , R1 = bool(is_integral_extent<1,Arg0,Args...>::value)
1708  , R2 = bool(is_integral_extent<2,Arg0,Args...>::value)
1709  , R3 = bool(is_integral_extent<3,Arg0,Args...>::value)
1710  , R4 = bool(is_integral_extent<4,Arg0,Args...>::value)
1711  , R5 = bool(is_integral_extent<5,Arg0,Args...>::value)
1712  , R6 = bool(is_integral_extent<6,Arg0,Args...>::value)
1713  };
1714 
1715  // Public rank
1716  enum { rank = unsigned(R0) + unsigned(R1) + unsigned(R2) + unsigned(R3)
1717  + unsigned(R4) + unsigned(R5) + unsigned(R6) };
1718 
1719  // Whether right-most non-UQ::PCE rank is a range.
1720  enum { R0_rev = ( 0 == SrcTraits::rank ? RZ : (
1721  1 == SrcTraits::rank ? R0 : (
1722  2 == SrcTraits::rank ? R1 : (
1723  3 == SrcTraits::rank ? R2 : (
1724  4 == SrcTraits::rank ? R3 : (
1725  5 == SrcTraits::rank ? R4 : (
1726  6 == SrcTraits::rank ? R5 : R6 ))))))) };
1727 
1728  // Subview's layout
1729  typedef typename std::conditional<
1730  ( /* Same array layout IF */
1731  ( rank == 0 ) /* output rank zero */
1732  ||
1733  // OutputRank 1 or 2, InputLayout Left, Interval 0
1734  // because single stride one or second index has a stride.
1735  ( rank <= 2 && R0 && std::is_same< typename SrcTraits::array_layout , Kokkos::LayoutLeft >::value )
1736  ||
1737  // OutputRank 1 or 2, InputLayout Right, Interval [InputRank-1]
1738  // because single stride one or second index has a stride.
1739  ( rank <= 2 && R0_rev && std::is_same< typename SrcTraits::array_layout , Kokkos::LayoutRight >::value )
1740  ), typename SrcTraits::array_layout , Kokkos::LayoutStride
1742 
1744 
1745  typedef typename std::conditional< rank == 0 , sacado_uq_pce_type ,
1746  typename std::conditional< rank == 1 , sacado_uq_pce_type * ,
1747  typename std::conditional< rank == 2 , sacado_uq_pce_type ** ,
1748  typename std::conditional< rank == 3 , sacado_uq_pce_type *** ,
1749  typename std::conditional< rank == 4 , sacado_uq_pce_type **** ,
1750  typename std::conditional< rank == 5 , sacado_uq_pce_type ***** ,
1751  typename std::conditional< rank == 6 , sacado_uq_pce_type ****** ,
1752  sacado_uq_pce_type *******
1755 
1756 public:
1757 
1758  typedef Kokkos::ViewTraits
1759  < data_type
1760  , array_layout
1761  , typename SrcTraits::device_type
1762  , typename SrcTraits::memory_traits > traits_type ;
1763 
1764  typedef Kokkos::View
1765  < data_type
1766  , array_layout
1767  , typename SrcTraits::device_type
1768  , typename SrcTraits::memory_traits > type ;
1769 
1770 
1771  // The presumed type is 'ViewMapping< traits_type , void >'
1772  // However, a compatible ViewMapping is acceptable.
1773  template< class DstTraits >
1774  KOKKOS_INLINE_FUNCTION
1775  static void assign( ViewMapping< DstTraits , typename DstTraits::specialize > & dst
1776  , ViewMapping< SrcTraits , typename SrcTraits::specialize > const & src
1777  , Arg0 arg0, Args ... args )
1778  {
1779  static_assert(
1780  ViewMapping< DstTraits , traits_type , typename DstTraits::specialize >::is_assignable ,
1781  "Subview destination type must be compatible with subview derived type" );
1782 
1783  typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
1784  typedef typename DstType::offset_type dst_offset_type ;
1785 
1786  const SubviewExtents< SrcTraits::rank , rank >
1787  extents( src.m_impl_offset.m_dim , arg0 , args... );
1788 
1789  const size_t offset = src.m_impl_offset( extents.domain_offset(0)
1790  , extents.domain_offset(1)
1791  , extents.domain_offset(2)
1792  , extents.domain_offset(3)
1793  , extents.domain_offset(4)
1794  , extents.domain_offset(5)
1795  , extents.domain_offset(6)
1796  , extents.domain_offset(7) );
1797 
1798  dst.m_impl_offset = dst_offset_type( src.m_impl_offset , extents );
1799  dst.m_impl_handle.value_ptr = src.m_impl_handle.value_ptr + offset;
1800  dst.m_impl_handle.scalar_ptr =
1801  src.m_impl_handle.scalar_ptr + offset * src.m_sacado_size;
1802  dst.m_sacado_size = src.m_sacado_size;
1803  dst.m_cijk = src.m_cijk;
1804  dst.m_is_contiguous = src.m_is_contiguous;
1805  }
1806 
1807 };
1808 
1809 } // namespace Impl
1810 } // namespace Kokkos
1811 
1812 //----------------------------------------------------------------------------
1813 //----------------------------------------------------------------------------
1814 //----------------------------------------------------------------------------
1815 
1816 namespace Kokkos {
1817 namespace Impl {
1818 
1819 // Specialization for deep_copy( view, view::value_type ) for Cuda
1820 #if defined( KOKKOS_ENABLE_CUDA )
1821 template< class OutputView >
1822 struct StokhosViewFill< OutputView ,
1823  typename std::enable_if< std::is_same< typename OutputView::specialize,
1824  Kokkos::Experimental::Impl::ViewPCEContiguous >::value &&
1825  std::is_same< typename OutputView::execution_space,
1826  Cuda >::value >::type >
1827 {
1828  typedef typename OutputView::const_value_type const_value_type ;
1829  typedef typename Sacado::ScalarType<const_value_type>::type scalar_type ;
1830  typedef typename OutputView::execution_space execution_space ;
1831  typedef typename OutputView::size_type size_type ;
1832 
1833  template <unsigned VectorLength>
1834  struct PCEKernel {
1835  typedef typename OutputView::execution_space execution_space ;
1836  const OutputView output;
1837  const_value_type input;
1838 
1839  PCEKernel( const OutputView & arg_out , const_value_type & arg_in ) :
1840  output(arg_out), input(arg_in) {}
1841 
1842  typedef typename Kokkos::TeamPolicy< execution_space >::member_type team_member ;
1843 
1844  KOKKOS_INLINE_FUNCTION
1845  void operator()( const team_member & dev ) const
1846  {
1847  const size_type tidx = dev.team_rank() % VectorLength;
1848  const size_type tidy = dev.team_rank() / VectorLength;
1849  const size_type nrow = dev.team_size() / VectorLength;
1850  const size_type nvec = dimension_scalar(output);
1851 
1852  const size_type i0 = dev.league_rank() * nrow + tidy;
1853  if ( i0 >= output.extent(0) ) return;
1854 
1855  for ( size_type i1 = 0 ; i1 < output.extent(1) ; ++i1 ) {
1856  for ( size_type i2 = 0 ; i2 < output.extent(2) ; ++i2 ) {
1857  for ( size_type i3 = 0 ; i3 < output.extent(3) ; ++i3 ) {
1858  for ( size_type i4 = 0 ; i4 < output.extent(4) ; ++i4 ) {
1859  for ( size_type i5 = 0 ; i5 < output.extent(5) ; ++i5 ) {
1860  for ( size_type i6 = 0 ; i6 < output.extent(6) ; ++i6 ) {
1861  for ( size_type i7 = 0 ; i7 < output.extent(7) ; ++i7 ) {
1862  for ( size_type is = tidx ; is < nvec ; is+=VectorLength ) {
1863  output.access(i0,i1,i2,i3,i4,i5,i6,i7).fastAccessCoeff(is) =
1864  input.fastAccessCoeff(is) ;
1865  }}}}}}}}
1866  }
1867  };
1868 
1869  template <unsigned VectorLength>
1870  struct ScalarKernel {
1871  typedef typename OutputView::execution_space execution_space ;
1872  const OutputView output;
1873  const scalar_type input;
1874 
1875  ScalarKernel( const OutputView & arg_out , const scalar_type & arg_in ) :
1876  output(arg_out), input(arg_in) {}
1877 
1878  typedef typename Kokkos::TeamPolicy< execution_space >::member_type team_member ;
1879  KOKKOS_INLINE_FUNCTION
1880  void operator()( const team_member & dev ) const
1881  {
1882  const size_type tidx = dev.team_rank() % VectorLength;
1883  const size_type tidy = dev.team_rank() / VectorLength;
1884  const size_type nrow = dev.team_size() / VectorLength;
1885  const size_type npce = dimension_scalar(output);
1886 
1887  const size_type i0 = dev.league_rank() * nrow + tidy;
1888  if ( i0 >= output.extent(0) ) return;
1889 
1890  for ( size_type i1 = 0 ; i1 < output.extent(1) ; ++i1 ) {
1891  for ( size_type i2 = 0 ; i2 < output.extent(2) ; ++i2 ) {
1892  for ( size_type i3 = 0 ; i3 < output.extent(3) ; ++i3 ) {
1893  for ( size_type i4 = 0 ; i4 < output.extent(4) ; ++i4 ) {
1894  for ( size_type i5 = 0 ; i5 < output.extent(5) ; ++i5 ) {
1895  for ( size_type i6 = 0 ; i6 < output.extent(6) ; ++i6 ) {
1896  for ( size_type i7 = 0 ; i7 < output.extent(7) ; ++i7 ) {
1897  for ( size_type is = tidx ; is < npce ; is+=VectorLength ) {
1898  output.access(i0,i1,i2,i3,i4,i5,i6,i7).fastAccessCoeff(is) =
1899  is == 0 ? input : scalar_type(0) ;
1900  }}}}}}}}
1901  }
1902  };
1903 
1904  StokhosViewFill( const OutputView & output , const_value_type & input )
1905  {
1906  // Coalesced accesses are 128 bytes in size
1908  const unsigned vector_length =
1909  ( 128 + sizeof(scalar_type)-1 ) / sizeof(scalar_type);
1910 
1911  // 8 warps per block should give good occupancy
1912  const size_type block_size = 256;
1913 
1914  const size_type rows_per_block = block_size / vector_length;
1915  const size_type n = output.extent(0);
1916  const size_type league_size = ( n + rows_per_block-1 ) / rows_per_block;
1917  const size_type team_size = rows_per_block * vector_length;
1918  Kokkos::TeamPolicy< execution_space > config( league_size, team_size );
1919 
1920  if (static_cast<unsigned>(input.size()) != dimension_scalar(output) &&
1921  input.size() != 1)
1922  Kokkos::abort("StokhosViewFill: Invalid input value size");
1923 
1924  if (input.size() == 1)
1925  parallel_for(
1926  config, ScalarKernel<vector_length>(output, input.fastAccessCoeff(0)) );
1927  else
1928  parallel_for( config, PCEKernel<vector_length>(output, input) );
1929  execution_space().fence();
1930  }
1931 
1932  StokhosViewFill( const OutputView & output , const scalar_type & input )
1933  {
1934  // Coalesced accesses are 128 bytes in size
1936  const unsigned vector_length =
1937  ( 128 + sizeof(scalar_type)-1 ) / sizeof(scalar_type);
1938 
1939  // 8 warps per block should give good occupancy
1940  const size_type block_size = 256;
1941 
1942  const size_type rows_per_block = block_size / vector_length;
1943  const size_type n = output.extent(0);
1944  const size_type league_size = ( n + rows_per_block-1 ) / rows_per_block;
1945  const size_type team_size = rows_per_block * vector_length;
1946  Kokkos::TeamPolicy< execution_space > config( league_size, team_size );
1947 
1948  parallel_for( config, ScalarKernel<vector_length>(output, input) );
1949  execution_space().fence();
1950  }
1951 
1952 };
1953 #endif /* #if defined( KOKKOS_ENABLE_CUDA ) */
1954 
1955 } // namespace Impl
1956 } // namespace Kokkos
1957 
1958 #include "Kokkos_View_Utils_Def.hpp"
1959 
1960 //----------------------------------------------------------------------------
1961 //----------------------------------------------------------------------------
1962 //----------------------------------------------------------------------------
1963 
1964 #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