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