Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
KokkosExp_View_MP_Vector_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_MP_VECTOR_CONTIGUOUS_HPP
43 #define KOKKOS_EXPERIMENTAL_VIEW_MP_VECTOR_CONTIGUOUS_HPP
44 
45 #include "Sacado_Traits.hpp"
46 #include "Sacado_MP_Vector.hpp"
48 
49 // Only include forward declarations so any overloads appear before they
50 // might be used inside Kokkos
51 #include "Kokkos_Core_fwd.hpp"
52 #include "Kokkos_View.hpp"
53 #include "Kokkos_Layout.hpp"
54 #include "Kokkos_View_Utils.hpp"
56 
57 
58 //----------------------------------------------------------------------------
59 
60 namespace Kokkos {
61 
62  namespace Impl {
63  template<class Space, class T, class ... P>
64  struct MirrorType;
65  }
66 
67 }
68 
69 namespace Kokkos {
70 namespace Experimental {
71 namespace Impl {
72 
74 
75 template< class ... Args >
76 struct is_ViewMPVectorContiguous { enum { value = false }; };
77 
78 template< class D , class ... P , class ... Args >
79 struct is_ViewMPVectorContiguous< Kokkos::View<D,P...> , Args... > {
80  enum { value =
81  std::is_same< typename Kokkos::ViewTraits<D,P...>::specialize
83  &&
84  ( ( sizeof...(Args) == 0 ) ||
85  is_ViewMPVectorContiguous< Args... >::value ) };
86 };
87 
88 } // namespace Impl
89 } // namespace Experimental
90 } // namespace Kokkos
91 
92 namespace Kokkos {
93 
94 template <typename T, typename ... P>
95 struct is_view_mp_vector< View<T,P...> > {
96  typedef View<T,P...> view_type;
97  static const bool value =
98  std::is_same< typename view_type::specialize,
100 };
101 
102 template <typename T, typename ... P>
103 KOKKOS_INLINE_FUNCTION
104 constexpr typename
105 std::enable_if< is_view_mp_vector< View<T,P...> >::value, unsigned >::type
106 dimension_scalar(const View<T,P...>& view) {
107  return view.impl_map().dimension_scalar();
108 }
109 
110 // Declare overloads of create_mirror() so they are in scope
111 // Kokkos_Core.hpp is included below
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 T , class ... P >
125 inline
126 typename Kokkos::View<T,P...>::HostMirror
128  const Kokkos::View<T,P...> & src,
129  typename std::enable_if<
130  std::is_same< typename ViewTraits<T,P...>::specialize ,
132  std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout,
133  Kokkos::LayoutStride >::value >::type * = 0);
134 
135 template<class Space, class T, class ... P>
136 typename Impl::MirrorType<Space,T,P ...>::view_type
138  const Space&,
139  const Kokkos::View<T,P...> & src,
140  typename std::enable_if<
141  std::is_same< typename ViewTraits<T,P...>::specialize ,
143 
144 // Overload of deep_copy for MP::Vector views intializing to a constant scalar
145 template< class DT, class ... DP >
146 void deep_copy(
147  const View<DT,DP...> & view ,
148  const typename View<DT,DP...>::array_type::value_type & value
149  , typename std::enable_if<(
150  std::is_same< typename ViewTraits<DT,DP...>::specialize
152  )>::type * = 0 );
153 
154 // Overload of deep_copy for MP::Vector views intializing to a constant MP::Vector
155 template< class DT, class ... DP >
156 void deep_copy(
157  const View<DT,DP...> & view ,
158  const typename View<DT,DP...>::value_type & value
159  , typename std::enable_if<(
160  std::is_same< typename ViewTraits<DT,DP...>::specialize
162  )>::type * = 0 );
163 
164 // Overload of deep_copy for MP::Vector views intializing to a constant scalar
165 template< class ExecSpace , class DT, class ... DP >
166 void deep_copy(
167  const ExecSpace &,
168  const View<DT,DP...> & view ,
169  const typename View<DT,DP...>::array_type::value_type & value
170  , typename std::enable_if<(
171  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
172  std::is_same< typename ViewTraits<DT,DP...>::specialize
174  )>::type * = 0 );
175 
176 // Overload of deep_copy for MP::Vector views intializing to a constant MP::Vector
177 template< class ExecSpace , class DT, class ... DP >
178 void deep_copy(
179  const ExecSpace &,
180  const View<DT,DP...> & view ,
181  const typename View<DT,DP...>::value_type & value
182  , typename std::enable_if<(
183  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
184  std::is_same< typename ViewTraits<DT,DP...>::specialize
186  )>::type * = 0 );
187 
188 /* Specialize for deep copy of MP::Vector */
189 template< class DT , class ... DP , class ST , class ... SP >
190 inline
191 void deep_copy( const View<DT,DP...> & dst ,
192  const View<ST,SP...> & src
193  , typename std::enable_if<(
194  std::is_same< typename ViewTraits<DT,DP...>::specialize
196  &&
197  std::is_same< typename ViewTraits<ST,SP...>::specialize
199  )>::type * = 0 );
200 
201 /* Specialize for deep copy of MP::Vector */
202 template< class ExecSpace, class DT , class ... DP , class ST , class ... SP >
203 inline
204 void deep_copy( const ExecSpace &,
205  const View<DT,DP...> & dst ,
206  const View<ST,SP...> & src
207  , typename std::enable_if<(
208  std::is_same< typename ViewTraits<DT,DP...>::specialize
210  &&
211  std::is_same< typename ViewTraits<ST,SP...>::specialize
213  )>::type * = 0 );
214 
215 } // namespace Kokkos
216 
217 //----------------------------------------------------------------------------
218 
219 #include "Kokkos_Core.hpp"
220 
221 namespace Kokkos {
222 
223 template <typename D, typename ... P>
224 struct FlatArrayType< View<D,P...>,
225  typename std::enable_if< is_view_mp_vector< View<D,P...> >::value >::type > {
226  typedef View<D,P...> view_type;
227  typedef typename view_type::traits::dimension dimension;
229  typedef typename Kokkos::Impl::ViewDataType< flat_value_type , dimension >::type flat_data_type;
230  typedef View<flat_data_type,P...> type;
231 };
232 
233 template< class T , class ... P >
234 inline
235 typename Kokkos::View<T,P...>::HostMirror
236 create_mirror( const Kokkos::View<T,P...> & src
237  , typename std::enable_if<
238  std::is_same< typename ViewTraits<T,P...>::specialize ,
240  &&
241  ! std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
242  , Kokkos::LayoutStride >::value
243  >::type *
244  )
245 {
246  typedef View<T,P...> src_type ;
247  typedef typename src_type::HostMirror dst_type ;
248 
249  typename src_type::array_layout layout = src.layout();
250  layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
251 
252  return dst_type(std::string(src.label()).append("_mirror"), layout);
253 }
254 
255 template< class T , class ... P >
256 inline
257 typename Kokkos::View<T,P...>::HostMirror
258 create_mirror( const Kokkos::View<T,P...> & src
259  , typename std::enable_if<
260  std::is_same< typename ViewTraits<T,P...>::specialize ,
262  &&
263  std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
264  , Kokkos::LayoutStride >::value
265  >::type *
266  )
267 {
268  typedef View<T,P...> src_type ;
269  typedef typename src_type::HostMirror dst_type ;
270 
271  Kokkos::LayoutStride layout ;
272 
273  layout.dimension[0] = src.extent(0);
274  layout.dimension[1] = src.extent(1);
275  layout.dimension[2] = src.extent(2);
276  layout.dimension[3] = src.extent(3);
277  layout.dimension[4] = src.extent(4);
278  layout.dimension[5] = src.extent(5);
279  layout.dimension[6] = src.extent(6);
280  layout.dimension[7] = src.extent(7);
281 
282  layout.stride[0] = src.stride_0();
283  layout.stride[1] = src.stride_1();
284  layout.stride[2] = src.stride_2();
285  layout.stride[3] = src.stride_3();
286  layout.stride[4] = src.stride_4();
287  layout.stride[5] = src.stride_5();
288  layout.stride[6] = src.stride_6();
289  layout.stride[7] = src.stride_7();
290 
291  layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
292 
293  return dst_type(std::string(src.label()).append("_mirror"), layout);
294 }
295 
296 template<class Space, class T, class ... P>
297 typename Impl::MirrorType<Space,T,P ...>::view_type
298 create_mirror(const Space& , const Kokkos::View<T,P...> & src
299  , typename std::enable_if<
300  std::is_same< typename ViewTraits<T,P...>::specialize ,
302  >::type *) {
303  typedef View<T,P...> src_type ;
304  typename src_type::array_layout layout = src.layout();
305  layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
306  return typename Impl::MirrorType<Space,T,P ...>::view_type(src.label(),layout);
307 }
308 
309 // Overload of deep_copy for MP::Vector views intializing to a constant scalar
310 template< class DT, class ... DP >
312  const View<DT,DP...> & view ,
313  const typename View<DT,DP...>::array_type::value_type & value
314  , typename std::enable_if<(
315  std::is_same< typename ViewTraits<DT,DP...>::specialize
317  )>::type * )
318 {
319  static_assert(
320  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
321  typename ViewTraits<DT,DP...>::non_const_value_type >::value
322  , "Can only deep copy into non-const type" );
323 
324  typedef typename FlatArrayType< View<DT,DP...> >::type flat_array_type;
326 }
327 
328 // Overload of deep_copy for MP::Vector views intializing to a constant MP::Vector
329 template< class DT, class ... DP >
331  const View<DT,DP...> & view ,
332  const typename View<DT,DP...>::value_type & value
333  , typename std::enable_if<(
334  std::is_same< typename ViewTraits<DT,DP...>::specialize
336  )>::type * )
337 {
338  static_assert(
339  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
340  typename ViewTraits<DT,DP...>::non_const_value_type >::value
341  , "Can only deep copy into non-const type" );
342 
343  // static_assert(
344  // Sacado::StaticSize< typename View<DT,DP...>::value_type >::value
345  // ||
346  // std::is_same< Kokkos::Impl::ActiveExecutionMemorySpace
347  // , Kokkos::HostSpace >::value
348  // , "Deep copy from a FAD type must be statically sized or host space" );
349 
350  Kokkos::Impl::StokhosViewFill< View<DT,DP...> >( view , value );
351 }
352 
353 // Overload of deep_copy for MP::Vector views intializing to a constant scalar
354 template< class ExecSpace , class DT, class ... DP >
356  const ExecSpace &,
357  const View<DT,DP...> & view ,
358  const typename View<DT,DP...>::array_type::value_type & value
359  , typename std::enable_if<(
360  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
361  std::is_same< typename ViewTraits<DT,DP...>::specialize
363  )>::type * )
364 {
365  static_assert(
366  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
367  typename ViewTraits<DT,DP...>::non_const_value_type >::value
368  , "Can only deep copy into non-const type" );
369 
370  typedef typename FlatArrayType< View<DT,DP...> >::type flat_array_type;
372 }
373 
374 // Overload of deep_copy for MP::Vector views intializing to a constant MP::Vector
375 template< class ExecSpace , class DT, class ... DP >
377  const ExecSpace &,
378  const View<DT,DP...> & view ,
379  const typename View<DT,DP...>::value_type & value
380  , typename std::enable_if<(
381  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
382  std::is_same< typename ViewTraits<DT,DP...>::specialize
384  )>::type * )
385 {
386  static_assert(
387  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
388  typename ViewTraits<DT,DP...>::non_const_value_type >::value
389  , "Can only deep copy into non-const type" );
390 
391  // static_assert(
392  // Sacado::StaticSize< typename View<DT,DP...>::value_type >::value
393  // ||
394  // std::is_same< Kokkos::Impl::ActiveExecutionMemorySpace
395  // , Kokkos::HostSpace >::value
396  // , "Deep copy from a FAD type must be statically sized or host space" );
397 
398  Kokkos::Impl::StokhosViewFill< View<DT,DP...> >( view , value );
399 }
400 
401 /* Specialize for deep copy of MP::Vector */
402 template< class ExecSpace, class DT , class ... DP , class ST , class ... SP >
403 inline
404 void deep_copy( const ExecSpace &,
405  const View<DT,DP...> & dst ,
406  const View<ST,SP...> & src
407  , typename std::enable_if<(
408  std::is_same< typename ViewTraits<DT,DP...>::specialize
410  &&
411  std::is_same< typename ViewTraits<ST,SP...>::specialize
413  )>::type * )
414 {
415  static_assert(
416  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
417  typename ViewTraits<DT,DP...>::non_const_value_type >::value
418  , "Deep copy destination must be non-const" );
419 
420  static_assert(
421  ( unsigned(ViewTraits<DT,DP...>::rank) ==
422  unsigned(ViewTraits<ST,SP...>::rank) )
423  , "Deep copy destination and source must have same rank" );
424 
425  // Note ETP 09/29/2016: Use FlatArrayType instead of array_type to work
426  // around issue where dst and src are rank-1, but have differing layouts.
427  // Kokkos' deep_copy() doesn't work in this case because the array_type
428  // will be rank-2. It should be possible to make deep_copy() work there,
429  // but this seems easier.
430 
431  // Kokkos::deep_copy(
432  // ExecSpace() ,
433  // typename View<DT,DP...>::array_type( dst ) ,
434  // typename View<ST,SP...>::array_type( src ) );
435 
437  ExecSpace() ,
438  typename FlatArrayType< View<DT,DP...> >::type( dst ) ,
439  typename FlatArrayType< View<ST,SP...> >::type( src ) );
440 }
441 
442 /* Specialize for deep copy of MP::Vector */
443 template< class DT , class ... DP , class ST , class ... SP >
444 inline
445 void deep_copy( const View<DT,DP...> & dst ,
446  const View<ST,SP...> & src
447  , typename std::enable_if<(
448  std::is_same< typename ViewTraits<DT,DP...>::specialize
450  &&
451  std::is_same< typename ViewTraits<ST,SP...>::specialize
453  )>::type * )
454 {
455  using exec_space = typename View<DT,DP...>::execution_space;
456  Kokkos::fence();
457  Kokkos::deep_copy(exec_space(), dst, src);
458  Kokkos::fence();
459 }
460 
461 }
462 
463 namespace Kokkos {
464 namespace Impl {
465 
466 template< class DataType , class ArrayLayout , typename StorageType >
467 struct ViewDataAnalysis< DataType /* Original view data type */
468  , ArrayLayout
469  , Sacado::MP::Vector< StorageType > >
470 {
471 private:
472 
474  typedef ViewArrayAnalysis< DataType > array_analysis ;
475  static const int DimVector = StorageType::static_size;
476 
477 public:
478 
479  // Specialized view data mapping:
481 
482  typedef typename array_analysis::dimension dimension ;
484  typedef typename array_analysis::const_value_type const_value_type ;
485  typedef typename array_analysis::non_const_value_type non_const_value_type ;
486 
487  // Generate analogous multidimensional array specification type.
488  typedef typename
489  ViewDataType< value_type , dimension >::type type ;
490  typedef typename
491  ViewDataType< const_value_type , dimension >::type const_type ;
492  typedef typename
493  ViewDataType< non_const_value_type , dimension >::type non_const_type ;
494 
495 private:
496 
497  // A const ?
498  enum { is_const = std::is_same< value_type , const_value_type >::value };
499 
500  // The unwrapped scalar types:
501  typedef typename
502  std::conditional< is_const , const ScalarType , ScalarType >::type
504 
507 
508  // Prepend or append the vector dimension based on ArrayLayout
509  // Note: you can't prepend a static dimension, so use 0 for LayoutLeft
510  typedef typename array_analysis::dimension::
511  template prepend<0>::type
513  typedef typename array_analysis::dimension::
514  template append<DimVector>::type
516  typedef typename std::conditional<
517  std::is_same< ArrayLayout, Kokkos::LayoutLeft>::value,
520 
521 public:
522 
523  // Generate "flattened" multidimensional array specification type.
524  typedef typename
525  ViewDataType< scalar_type , scalar_dimension >::type scalar_array_type ;
526 
527  typedef typename
528  ViewDataType< const_scalar_type , scalar_dimension >::type
530 
531  typedef typename
532  ViewDataType< non_const_scalar_type , scalar_dimension >::type
534 };
535 
536 } // namespace Impl
537 } // namespace Kokkos
538 
539 //----------------------------------------------------------------------------
540 
541 namespace Kokkos {
542 namespace Experimental {
543 namespace Impl {
544 
545  template < class ValueType,
546  bool is_static = Sacado::IsStaticallySized<ValueType>::value >
548 
549 // MP::Vector allocation for statically-sized MP::Vector types.
550 // In this case we can reinterpret cast directly between pointers of types
551 // MP::Vector<Storage> and MP::Vector<Storage>::value_type.
552 template <class ValueType>
553 struct MPVectorAllocation<ValueType, true> {
554  typedef ValueType value_type;
555  typedef typename Sacado::ValueType<value_type>::type scalar_type;
556 
559 
560  KOKKOS_INLINE_FUNCTION
561  static constexpr size_t
562  memory_span(const size_t span, const unsigned vector_size) {
563  return span * vector_size * sizeof(scalar_type);
564  }
565 
566  KOKKOS_INLINE_FUNCTION
567  MPVectorAllocation() : value_ptr(0), scalar_ptr(0) {}
568 
569  template <typename T>
570  KOKKOS_INLINE_FUNCTION
572  value_ptr = a.value_ptr;
573  scalar_ptr = a.scalar_ptr;
574  return *this;
575  }
576 
577  KOKKOS_INLINE_FUNCTION
578  void set(value_type* ptr, const size_t span, const unsigned vector_size) {
579  value_ptr = ptr;
580  scalar_ptr = reinterpret_cast<scalar_type*>(ptr);
581  }
582 
583  template <class ExecSpace>
584  struct ConstructDestructFunctor {
585  typedef Kokkos::Impl::ViewValueFunctor< ExecSpace, scalar_type > FunctorType ;
588 
589  ConstructDestructFunctor() = default;
590  ConstructDestructFunctor(const ConstructDestructFunctor&) = default;
591  ConstructDestructFunctor& operator=(const ConstructDestructFunctor&) = default;
592 
593  ConstructDestructFunctor(const ExecSpace & space,
594  const bool initialize,
595  const size_t span,
596  const unsigned vector_size,
597  scalar_type* scalar_ptr) :
598  m_functor( space , scalar_ptr , span*vector_size , "Stokhos_MP_VectorContig_ConstructDestructFunctor1" ),
599  m_initialize(initialize) {}
600 
602  if (m_initialize)
603  m_functor.construct_shared_allocation();
604  }
605 
607  if (m_initialize)
608  m_functor.destroy_shared_allocation();
609  }
610 
611  };
612 
613  template <class ExecSpace>
614  inline ConstructDestructFunctor<ExecSpace>
615  create_functor(const ExecSpace & space,
616  const bool initialize,
617  const size_t span,
618  const unsigned vector_size) const {
619  return ConstructDestructFunctor<ExecSpace>(space, initialize, span, vector_size, scalar_ptr);
620  }
621 
622  // Assign scalar_type pointer to give ptr
623  template <typename T>
624  KOKKOS_INLINE_FUNCTION
625  void assign(T * ptr) {
626  value_ptr = reinterpret_cast<value_type*>(ptr);
627  scalar_ptr = reinterpret_cast<scalar_type*>(ptr);
628  }
629 
630 };
631 
632 // MP::Vector allocation for dynamically-sized MP::Vector types.
633 // In this case we allocate two chunks of data, the first for the the
634 // MP::Vector<Storage> itself and then for the underlying scalar type
635 // (MP::Vector<Storage>::value_type). The memory is laid out with the
636 // former followed by the latter.
637 template <class ValueType>
638 struct MPVectorAllocation<ValueType, false> {
639  typedef ValueType value_type;
640  typedef typename Sacado::ValueType<value_type>::type scalar_type;
641 
644 
645  KOKKOS_INLINE_FUNCTION
646  static constexpr size_t
647  memory_span(const size_t span, const unsigned vector_size) {
648  return span * ( vector_size * sizeof(scalar_type) + sizeof(value_type) );
649  }
650 
651  KOKKOS_INLINE_FUNCTION
652  MPVectorAllocation() : value_ptr(0), scalar_ptr(0) {}
653 
654  template <typename T>
655  KOKKOS_INLINE_FUNCTION
657  value_ptr = a.value_ptr;
658  scalar_ptr = a.scalar_ptr;
659  return *this;
660  }
661 
662  // We are making an assumption the data is laid out as described above,
663  // which in general may not be true if the view is created from memory
664  // allocated elsewhere. We should check for that.
665  KOKKOS_INLINE_FUNCTION
666  void set(value_type* ptr, const size_t span, const unsigned vector_size) {
667  value_ptr = ptr;
668  scalar_ptr = reinterpret_cast<scalar_type*>(ptr+span);
669  }
670 
671  template <class ExecSpace>
672  struct VectorConstruct {
673  ExecSpace m_space;
676  size_t m_span;
677  unsigned m_vector_size;
678 
679  VectorConstruct() = default;
680  VectorConstruct(const VectorConstruct&) = default;
681  VectorConstruct& operator=(const VectorConstruct&) = default;
682 
683  inline
684  VectorConstruct(const ExecSpace& space,
685  value_type* p,
686  scalar_type* sp,
687  const size_t span,
688  const unsigned vector_size) :
689  m_space(space), m_p(p), m_sp(sp), m_span(span), m_vector_size(vector_size) {}
690 
691  inline void execute() {
692  if ( ! m_space.in_parallel() ) {
693  typedef Kokkos::RangePolicy< ExecSpace > PolicyType ;
694  const Kokkos::Impl::ParallelFor< VectorConstruct , PolicyType >
695  closure( *this , PolicyType( 0 , m_span ) );
696  closure.execute();
697  m_space.fence();
698  }
699  else {
700  for ( size_t i = 0 ; i < m_span ; ++i ) operator()(i);
701  }
702  }
703 
704  KOKKOS_INLINE_FUNCTION
705  void operator() (const size_t i) const {
706  new (m_p+i) value_type(m_vector_size, m_sp+i*m_vector_size, false);
707  }
708  };
709 
710  template <class ExecSpace>
711  struct ConstructDestructFunctor {
712  typedef Kokkos::Impl::ViewValueFunctor< ExecSpace, scalar_type > ScalarFunctorType ;
713  typedef VectorConstruct< ExecSpace > VectorFunctorType ;
717 
718  ConstructDestructFunctor() = default;
719  ConstructDestructFunctor(const ConstructDestructFunctor&) = default;
720  ConstructDestructFunctor& operator=(const ConstructDestructFunctor&) = default;
721 
722  ConstructDestructFunctor(const ExecSpace & space,
723  const bool initialize,
724  const size_t span,
725  const unsigned vector_size,
726  scalar_type* scalar_ptr,
727  value_type* value_ptr) :
728  m_scalar_functor( space , scalar_ptr , span*vector_size , "Stokhos_MP_VectorContig_ConstructDestructFunctor2" ),
729  m_vector_functor( space , value_ptr , scalar_ptr , span , vector_size ),
730  m_initialize(initialize) {}
731 
733  // First initialize the scalar_type array
734  if (m_initialize)
735  m_scalar_functor.construct_shared_allocation();
736 
737  // Construct each MP::Vector using memory in scalar_ptr array,
738  // setting pointer to MP::Vector values from values array
739  // Equivalent to:
740  // value_type* p = value_ptr;
741  // scalar_type* sp = scalar_ptr;
742  // for (size_t i=0; i<span; ++i) {
743  // new (p++) value_type(vector_size, sp, false);
744  // sp += vector_size;
745  // }
746  // (we always need to do this, regardless of initialization)
747  m_vector_functor.execute();
748  }
749 
751  // We only need to (possibly) call the destructor on values in the
752  // scalar_type array, since the value_type array is a view into it
753  if (m_initialize)
754  m_scalar_functor.destroy_shared_allocation();
755  }
756 
757  };
758 
759  template <class ExecSpace>
760  inline ConstructDestructFunctor<ExecSpace>
761  create_functor(const ExecSpace & space,
762  const bool initialize,
763  const size_t span,
764  const unsigned vector_size) const {
765  return ConstructDestructFunctor<ExecSpace>(space, initialize, span, vector_size, scalar_ptr, value_ptr);
766  }
767 
768  // Assign scalar_type pointer to give ptr
769  // This makes BIG assumption on how the data was allocated
770  template <typename T>
771  KOKKOS_INLINE_FUNCTION
772  void assign(T * ptr) {
773  value_ptr = reinterpret_cast<value_type*>(ptr);
774  if (ptr != 0)
775  scalar_ptr = value_ptr->coeff();
776  else
777  scalar_ptr = 0;
778  }
779 };
780 
781 }}} // namespace Kokkos::Experimental::Impl
782 
783 namespace Kokkos {
784 namespace Impl {
785 
786 template< class Traits >
787 class ViewMapping< Traits , /* View internal mapping */
788  typename std::enable_if<
789  ( std::is_same< typename Traits::specialize
790  , Kokkos::Experimental::Impl::ViewMPVectorContiguous >::value
791  &&
792  ( std::is_same< typename Traits::array_layout
793  , Kokkos::LayoutLeft >::value
794  ||
795  std::is_same< typename Traits::array_layout
796  , Kokkos::LayoutRight >::value
797  ||
798  std::is_same< typename Traits::array_layout
799  , Kokkos::LayoutStride >::value
800  )
801  )
802  , typename Traits::specialize
803  >::type >
804 {
805 private:
806 
807  template< class , class ... > friend class ViewMapping ;
808  template< class , class ... > friend class Kokkos::View ;
809 
813  typedef typename
814  std::add_const< intrinsic_scalar_type >::type const_intrinsic_scalar_type ;
815 
816  enum { StokhosStorageStaticDimension = stokhos_storage_type::static_size };
817  typedef Sacado::integral_nonzero< unsigned , StokhosStorageStaticDimension > sacado_size_type;
818 
820 
821  typedef ViewOffset< typename Traits::dimension
822  , typename Traits::array_layout
823  , void
825 
826  // Prepend or append the vector dimension based on array_layout
827  // Note: you can't prepend a static dimension, so use 0 for LayoutLeft
828  typedef ViewArrayAnalysis< typename Traits::data_type > array_analysis ;
829  typedef typename array_analysis::dimension array_dimension;
830  typedef ViewOffset< typename array_dimension::
831  template append<StokhosStorageStaticDimension>::type,
832  typename Traits::array_layout,
833  void
835  typedef ViewOffset< typename array_dimension::
836  template prepend<0>::type,
837  typename Traits::array_layout,
838  void
840  typedef typename std::conditional<
841  std::is_same< typename Traits::array_layout, Kokkos::LayoutLeft>::value,
844 
847  unsigned m_stride ;
848  sacado_size_type m_sacado_size ; // Size of sacado dimension
849 
850  // Note: if the view is partitioned, m_sacado_size is not the stride in
851  // memory between consecutive MP::Vector entries for given vector index:
852  //
853  // original_sacado_size = m_stride * m_sacado_size
854  // m_stride = 1 for original allocation.
855  //
856  // Stride here has a slightly different meaning than in the standard
857  // View implementation. For the moment we are assuming no padding within
858  // the view array itself and stride is to allow for partitioning the view
859  // by dividing up the scalar type.
860  //
861  // I suspect we could combine this with the way the stride is managed in
862  // the default view, in which case, I don't think we even need a
863  // specialization
864  //
865  // For reshaping by folding the sacado dimension into its next adjacent
866  // dimension, padding wouldn't generally work. So unless there becomes
867  // a way to turn padding off in the default view, a specialization
868  // will be necessary.
869 
870 public:
871 
872  //----------------------------------------
873  // Domain dimensions
874 
875  enum { Rank = Traits::dimension::rank };
876 
877  // Rank corresponding to the sacado dimension
878  enum { Sacado_Rank = std::is_same< typename Traits::array_layout, Kokkos::LayoutLeft >::value ? 0 : Rank+1 };
879 
880  // Using the internal offset mapping so limit to public rank:
881  template< typename iType >
882  KOKKOS_INLINE_FUNCTION constexpr size_t extent( const iType & r ) const
883  { return m_impl_offset.m_dim.extent(r); }
884 
885  KOKKOS_INLINE_FUNCTION constexpr
886  typename Traits::array_layout layout() const
887  { return m_impl_offset.layout(); }
888 
889  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_0() const
890  { return m_impl_offset.dimension_0(); }
891  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_1() const
892  { return m_impl_offset.dimension_1(); }
893  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_2() const
894  { return m_impl_offset.dimension_2(); }
895  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_3() const
896  { return m_impl_offset.dimension_3(); }
897  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_4() const
898  { return m_impl_offset.dimension_4(); }
899  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_5() const
900  { return m_impl_offset.dimension_5(); }
901  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_6() const
902  { return m_impl_offset.dimension_6(); }
903  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_7() const
904  { return m_impl_offset.dimension_7(); }
905 
906  // Is a regular layout with uniform striding for each index.
907  // Since we all for striding within the data type, we can't guarantee
908  // regular striding
909  using is_regular = std::false_type ;
910 
911  // FIXME: Adjust these for m_stride
912  KOKKOS_INLINE_FUNCTION constexpr size_t stride_0() const
913  { return m_impl_offset.stride_0(); }
914  KOKKOS_INLINE_FUNCTION constexpr size_t stride_1() const
915  { return m_impl_offset.stride_1(); }
916  KOKKOS_INLINE_FUNCTION constexpr size_t stride_2() const
917  { return m_impl_offset.stride_2(); }
918  KOKKOS_INLINE_FUNCTION constexpr size_t stride_3() const
919  { return m_impl_offset.stride_3(); }
920  KOKKOS_INLINE_FUNCTION constexpr size_t stride_4() const
921  { return m_impl_offset.stride_4(); }
922  KOKKOS_INLINE_FUNCTION constexpr size_t stride_5() const
923  { return m_impl_offset.stride_5(); }
924  KOKKOS_INLINE_FUNCTION constexpr size_t stride_6() const
925  { return m_impl_offset.stride_6(); }
926  KOKKOS_INLINE_FUNCTION constexpr size_t stride_7() const
927  { return m_impl_offset.stride_7(); }
928 
929  template< typename iType >
930  KOKKOS_INLINE_FUNCTION void stride( iType * const s ) const
931  { m_impl_offset.stride(s); }
932 
933  // Size of sacado scalar dimension
934  KOKKOS_FORCEINLINE_FUNCTION constexpr unsigned dimension_scalar() const
935  { return m_sacado_size.value; }
936 
937  // Whether the storage type is statically sized
938  static const bool is_static = stokhos_storage_type::is_static ;
939 
940  // Whether sacado dimension is contiguous
941  static const bool is_contiguous = true;
942 
943  //----------------------------------------
944  // Range of mapping
945 
946  // Return type of reference operators
948 
951 
953  KOKKOS_INLINE_FUNCTION constexpr size_t span() const
954  { return m_impl_offset.span(); }
955 
957  KOKKOS_INLINE_FUNCTION constexpr bool span_is_contiguous() const
958  { return m_impl_offset.span_is_contiguous() && (m_stride == 1); }
959 
961  KOKKOS_INLINE_FUNCTION constexpr pointer_type data() const
962  { return m_impl_handle.value_ptr ; }
963 
964  //----------------------------------------
965 
966  KOKKOS_FORCEINLINE_FUNCTION
968  { return *m_impl_handle.value_ptr; }
969 
970  // FIXME: Check this
971  template< typename I0 >
972  KOKKOS_FORCEINLINE_FUNCTION
973  typename
974  std::enable_if< std::is_integral<I0>::value &&
975  ! std::is_same< typename Traits::array_layout , Kokkos::LayoutStride >::value
976  , reference_type >::type
977  reference( const I0 & i0 ) const
978  { return m_impl_handle.value_ptr[m_stride * i0]; }
979 
980  // FIXME: Check this
981  template< typename I0 >
982  KOKKOS_FORCEINLINE_FUNCTION
983  typename
984  std::enable_if< std::is_integral<I0>::value &&
985  std::is_same< typename Traits::array_layout , Kokkos::LayoutStride >::value
986  , reference_type >::type
987  reference( const I0 & i0 ) const
988  { return m_impl_handle.value_ptr[ m_stride * m_impl_offset(i0) ]; }
989 
990  template< typename I0 , typename I1 >
991  KOKKOS_FORCEINLINE_FUNCTION
992  reference_type reference( const I0 & i0 , const I1 & i1 ) const
993  { return m_impl_handle.value_ptr[ m_stride * m_impl_offset(i0,i1) ]; }
994 
995  template< typename I0 , typename I1 , typename I2 >
996  KOKKOS_FORCEINLINE_FUNCTION
997  reference_type reference( const I0 & i0 , const I1 & i1 , const I2 & i2 ) const
998  { return m_impl_handle.value_ptr[ m_stride * m_impl_offset(i0,i1,i2) ]; }
999 
1000  template< typename I0 , typename I1 , typename I2 , typename I3 >
1001  KOKKOS_FORCEINLINE_FUNCTION
1002  reference_type reference( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3 ) const
1003  { return m_impl_handle.value_ptr[ m_stride * m_impl_offset(i0,i1,i2,i3) ]; }
1004 
1005  template< typename I0 , typename I1 , typename I2 , typename I3
1006  , typename I4 >
1007  KOKKOS_FORCEINLINE_FUNCTION
1008  reference_type reference( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1009  , const I4 & i4 ) const
1010  { return m_impl_handle.value_ptr[ m_stride * m_impl_offset(i0,i1,i2,i3,i4) ]; }
1011 
1012  template< typename I0 , typename I1 , typename I2 , typename I3
1013  , typename I4 , typename I5 >
1014  KOKKOS_FORCEINLINE_FUNCTION
1015  reference_type reference( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1016  , const I4 & i4 , const I5 & i5 ) const
1017  { return m_impl_handle.value_ptr[ m_stride * m_impl_offset(i0,i1,i2,i3,i4,i5) ]; }
1018 
1019  template< typename I0 , typename I1 , typename I2 , typename I3
1020  , typename I4 , typename I5 , typename I6 >
1021  KOKKOS_FORCEINLINE_FUNCTION
1022  reference_type reference( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1023  , const I4 & i4 , const I5 & i5 , const I6 & i6 ) const
1024  { return m_impl_handle.value_ptr[ m_stride * m_impl_offset(i0,i1,i2,i3,i4,i5,i6) ]; }
1025 
1026  template< typename I0 , typename I1 , typename I2 , typename I3
1027  , typename I4 , typename I5 , typename I6 , typename I7 >
1028  KOKKOS_FORCEINLINE_FUNCTION
1029  reference_type reference( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1030  , const I4 & i4 , const I5 & i5 , const I6 & i6 , const I7 & i7 ) const
1031  { return m_impl_handle.value_ptr[ m_stride * m_impl_offset(i0,i1,i2,i3,i4,i5,i6,i7) ]; }
1032 
1033  //----------------------------------------
1034 
1036  KOKKOS_INLINE_FUNCTION
1037  static size_t memory_span( typename Traits::array_layout const & layout )
1038  {
1039  // Do not introduce padding...
1040  typedef std::integral_constant< unsigned , 0 > padding ;
1041  offset_type offset( padding(), layout );
1042 
1043  // Always use static dimension if we are static
1044  const unsigned static_dim = StokhosStorageStaticDimension;
1045  if (static_dim > 0)
1046  return handle_type::memory_span( offset.span(), static_dim );
1047 
1048  // Else get size from prescribed layout
1049  const size_t sacado_size =
1051  return handle_type::memory_span( offset.span(), sacado_size );
1052  }
1053 
1054  //----------------------------------------
1055 
1056  KOKKOS_DEFAULTED_FUNCTION ~ViewMapping() = default ;
1057  KOKKOS_INLINE_FUNCTION ViewMapping() :
1058  m_impl_handle(),
1059  m_impl_offset(),
1060  m_stride(1),
1061  m_sacado_size(0)
1062  {}
1063 
1064  KOKKOS_DEFAULTED_FUNCTION ViewMapping( const ViewMapping & ) = default ;
1065  KOKKOS_DEFAULTED_FUNCTION ViewMapping & operator = ( const ViewMapping & ) = default ;
1066 
1067  KOKKOS_DEFAULTED_FUNCTION ViewMapping( ViewMapping && ) = default ;
1068  KOKKOS_DEFAULTED_FUNCTION ViewMapping & operator = ( ViewMapping && ) = default ;
1069 
1070  template< class ... P >
1071  KOKKOS_INLINE_FUNCTION
1072  ViewMapping
1073  ( ViewCtorProp< P ... > const & prop
1074  , typename Traits::array_layout const & layout
1075  )
1076  : m_impl_handle()
1077  , m_impl_offset( std::integral_constant< unsigned , 0 >()
1078  , layout )
1079  , m_stride( 1 )
1080  , m_sacado_size( Kokkos::Impl::GetSacadoSize<unsigned(Rank)>::eval(layout) )
1081  {
1082  m_impl_handle.set( ( (ViewCtorProp<void,pointer_type> const &) prop ).value,
1083  m_impl_offset.span(), m_sacado_size.value );
1084  }
1085 
1087  KOKKOS_INLINE_FUNCTION
1088  void assign_data( pointer_type arg_ptr )
1089  { m_impl_handle.set( arg_ptr, m_impl_offset.span(), m_sacado_size.value ); }
1090 
1091  //----------------------------------------
1092  /* Allocate and construct mapped array.
1093  * Allocate via shared allocation record and
1094  * return that record for allocation tracking.
1095  */
1096  template< class ... P >
1097  SharedAllocationRecord<> *
1098  allocate_shared( ViewCtorProp< P... > const & prop
1099  , typename Traits::array_layout const & layout )
1100  {
1101  typedef ViewCtorProp< P... > ctor_prop ;
1102 
1103  typedef typename ctor_prop::execution_space execution_space ;
1104  typedef typename Traits::memory_space memory_space ;
1105  typedef typename handle_type::template ConstructDestructFunctor<execution_space> functor_type ;
1106  typedef SharedAllocationRecord< memory_space , functor_type > record_type ;
1107 
1108  // Disallow padding
1109  typedef std::integral_constant< unsigned , 0 > padding ;
1110 
1111  m_impl_offset = offset_type( padding(), layout );
1112  m_stride = 1;
1113  m_sacado_size = Kokkos::Impl::GetSacadoSize<unsigned(Rank)>::eval(layout);
1114 
1115  const size_t alloc_size =
1116  handle_type::memory_span( m_impl_offset.span(), m_sacado_size.value );
1117 
1118  // Create shared memory tracking record with allocate memory from the memory space
1119  record_type * const record =
1120  record_type::allocate( ( (ViewCtorProp<void,memory_space> const &) prop ).value
1121  , ( (ViewCtorProp<void,std::string> const &) prop ).value
1122  , alloc_size );
1123 
1124  // Only set the the pointer and initialize if the allocation is non-zero.
1125  // May be zero if one of the dimensions is zero.
1126  if ( alloc_size ) {
1127 
1128  m_impl_handle.set( reinterpret_cast< pointer_type >( record->data() ),
1129  m_impl_offset.span(), m_sacado_size.value );
1130 
1131  // Assume destruction is only required when construction is requested.
1132  // The ViewValueFunctor has both value construction and destruction operators.
1133  record->m_destroy = m_impl_handle.create_functor(
1134  ( (ViewCtorProp<void,execution_space> const &) prop).value
1135  , ctor_prop::initialize
1136  , m_impl_offset.span()
1137  , m_sacado_size.value );
1138 
1139  // Construct values
1140  record->m_destroy.construct_shared_allocation();
1141  }
1142 
1143  return record ;
1144  }
1145 
1146  //----------------------------------------
1147  // If the View is to construct or destroy the elements.
1148 
1149  /*
1150  template< class ExecSpace >
1151  void construct( const ExecSpace & space ) const
1152  {
1153  m_impl_handle.construct( space, m_impl_offset.span(), m_sacado_size.value );
1154  }
1155 
1156  template< class ExecSpace >
1157  void destroy( const ExecSpace & space ) const
1158  {
1159  m_impl_handle.destruct( space, m_impl_offset.span(), m_sacado_size.value );
1160  }
1161  */
1162 };
1163 
1164 } // namespace Impl
1165 } // namespace Kokkos
1166 
1167 //----------------------------------------------------------------------------
1168 
1169 namespace Kokkos {
1170 namespace Impl {
1171 
1176 template< class DstTraits , class SrcTraits >
1177 class ViewMapping< DstTraits , SrcTraits ,
1178  typename std::enable_if<(
1179  Kokkos::Impl::MemorySpaceAccess< typename DstTraits::memory_space
1180  , typename SrcTraits::memory_space >::assignable
1181  &&
1182  // Destination view has MP::Vector
1183  std::is_same< typename DstTraits::specialize
1184  , Kokkos::Experimental::Impl::ViewMPVectorContiguous >::value
1185  &&
1186  // Source view has MP::Vector only
1187  std::is_same< typename SrcTraits::specialize
1188  , Kokkos::Experimental::Impl::ViewMPVectorContiguous >::value
1189  )
1190  , typename DstTraits::specialize
1191  >::type >
1192 {
1193 public:
1194 
1195  enum { is_assignable = true };
1196  enum { is_assignable_data_type = true };
1197 
1198  typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
1199  typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
1200  typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcType ;
1201 
1202  KOKKOS_INLINE_FUNCTION static
1203  void assign( DstType & dst
1204  , const SrcType & src
1205  , const TrackType & )
1206  {
1207  static_assert(
1208  (
1209  std::is_same< typename DstTraits::array_layout
1210  , Kokkos::LayoutLeft >::value ||
1211  std::is_same< typename DstTraits::array_layout
1212  , Kokkos::LayoutRight >::value ||
1213  std::is_same< typename DstTraits::array_layout
1214  , Kokkos::LayoutStride >::value
1215  )
1216  &&
1217  (
1218  std::is_same< typename SrcTraits::array_layout
1219  , Kokkos::LayoutLeft >::value ||
1220  std::is_same< typename SrcTraits::array_layout
1221  , Kokkos::LayoutRight >::value ||
1222  std::is_same< typename SrcTraits::array_layout
1223  , Kokkos::LayoutStride >::value
1224  )
1225  , "View of MP::Vector requires LayoutLeft, LayoutRight, or LayoutStride" );
1226 
1227  static_assert(
1228  std::is_same< typename DstTraits::array_layout
1229  , typename SrcTraits::array_layout >::value ||
1230  std::is_same< typename DstTraits::array_layout
1231  , Kokkos::LayoutStride >::value ||
1232  ( unsigned(DstTraits::rank) == 0 && unsigned(SrcTraits::rank) == 0 ) ||
1233  ( unsigned(DstTraits::rank) == 1 && unsigned(SrcTraits::rank) == 1 ) ,
1234  "View assignment must have compatible layout" );
1235 
1236  static_assert(
1237  std::is_same< typename DstTraits::value_type
1238  , typename SrcTraits::value_type >::value ||
1239  std::is_same< typename DstTraits::value_type
1240  , typename SrcTraits::const_value_type >::value ,
1241  "View assignment must have same value type or const = non-const" );
1242 
1243  static_assert(
1244  ViewDimensionAssignable
1245  < typename DstType::offset_type::dimension_type
1246  , typename SrcType::offset_type::dimension_type >::value ,
1247  "View assignment must have compatible dimensions" );
1248 
1249  dst.m_impl_handle = src.m_impl_handle ;
1250  dst.m_impl_offset = src.m_impl_offset ;
1251  dst.m_stride = src.m_stride ;
1252  dst.m_sacado_size = src.m_sacado_size ;
1253  }
1254 };
1255 
1261 template< class DstTraits , class SrcTraits >
1262 class ViewMapping< DstTraits , SrcTraits ,
1263  typename std::enable_if<(
1264  Kokkos::Impl::MemorySpaceAccess< typename DstTraits::memory_space
1265  , typename SrcTraits::memory_space >::assignable
1266  &&
1267  // Destination view has ordinary
1268  std::is_same< typename DstTraits::specialize , void >::value
1269  &&
1270  // Source view has MP::Vector only
1271  std::is_same< typename SrcTraits::specialize
1272  , Kokkos::Experimental::Impl::ViewMPVectorContiguous >::value
1273  &&
1274  // Ranks match
1275  unsigned(DstTraits::dimension::rank) == unsigned(SrcTraits::dimension::rank)+1
1276  )
1277  , typename DstTraits::specialize
1278  >::type >
1279 {
1280 public:
1281 
1282  enum { is_assignable = true };
1283  enum { is_assignable_data_type = true };
1284 
1285  typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
1286  typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
1287  typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcType ;
1288 
1289  KOKKOS_INLINE_FUNCTION static
1290  void assign( DstType & dst
1291  , const SrcType & src
1292  , const TrackType & )
1293  {
1294  static_assert(
1295  (
1296  std::is_same< typename DstTraits::array_layout
1297  , Kokkos::LayoutLeft >::value ||
1298  std::is_same< typename DstTraits::array_layout
1299  , Kokkos::LayoutRight >::value ||
1300  std::is_same< typename DstTraits::array_layout
1301  , Kokkos::LayoutStride >::value
1302  )
1303  &&
1304  (
1305  std::is_same< typename SrcTraits::array_layout
1306  , Kokkos::LayoutLeft >::value ||
1307  std::is_same< typename SrcTraits::array_layout
1308  , Kokkos::LayoutRight >::value ||
1309  std::is_same< typename SrcTraits::array_layout
1310  , Kokkos::LayoutStride >::value
1311  )
1312  , "View of MP::Vector requires LayoutLeft, LayoutRight, or LayoutStride" );
1313 
1314  static_assert(
1315  std::is_same< typename DstTraits::array_layout
1316  , typename SrcTraits::array_layout >::value ||
1317  std::is_same< typename DstTraits::array_layout
1318  , Kokkos::LayoutStride >::value ,
1319  "View assignment must have compatible layout" );
1320 
1321  static_assert(
1322  std::is_same< typename DstTraits::scalar_array_type
1323  , typename SrcTraits::scalar_array_type >::value ||
1324  std::is_same< typename DstTraits::scalar_array_type
1325  , typename SrcTraits::const_scalar_array_type >::value ,
1326  "View assignment must have same value type or const = non-const" );
1327 
1328  static_assert(
1329  ViewDimensionAssignable<
1330  typename DstType::offset_type::dimension_type,
1331  typename SrcType::array_offset_type::dimension_type >::value,
1332  "View assignment must have compatible dimensions" );
1333 
1334  if ( src.m_stride != 1 ) {
1335  Kokkos::abort("\n\n ****** Kokkos::View< Sacado::MP::Vector ... > cannot assign with non-unit stride ******\n\n");
1336  }
1337 
1338  unsigned dims[8];
1339  dims[0] = src.m_impl_offset.dimension_0();
1340  dims[1] = src.m_impl_offset.dimension_1();
1341  dims[2] = src.m_impl_offset.dimension_2();
1342  dims[3] = src.m_impl_offset.dimension_3();
1343  dims[4] = src.m_impl_offset.dimension_4();
1344  dims[5] = src.m_impl_offset.dimension_5();
1345  dims[6] = src.m_impl_offset.dimension_6();
1346  dims[7] = src.m_impl_offset.dimension_7();
1347  unsigned rank = SrcTraits::dimension::rank;
1348  unsigned sacado_size = src.m_sacado_size.value;
1349  if (std::is_same<typename SrcTraits::array_layout, LayoutLeft>::value) {
1350  // Move sacado_size to the first dimension, shift all others up one
1351  for (unsigned i=rank; i>0; --i)
1352  dims[i] = dims[i-1];
1353  dims[0] = sacado_size;
1354  }
1355  else {
1356  dims[rank] = sacado_size;
1357  }
1358  typedef typename DstType::offset_type dst_offset_type;
1359  dst.m_impl_offset = dst_offset_type( std::integral_constant< unsigned , 0 >(),
1360  typename DstTraits::array_layout(
1361  dims[0] , dims[1] , dims[2] , dims[3] ,
1362  dims[4] , dims[5] , dims[6] , dims[7] ) );
1363  dst.m_impl_handle = src.m_impl_handle.scalar_ptr ;
1364  }
1365 };
1366 
1373 template< class DstTraits , class SrcTraits >
1374 class ViewMapping< DstTraits , SrcTraits ,
1375  typename std::enable_if<(
1376  Kokkos::Impl::MemorySpaceAccess< typename DstTraits::memory_space
1377  , typename SrcTraits::memory_space >::assignable
1378  &&
1379  // Destination view has ordinary
1380  std::is_same< typename DstTraits::specialize , void >::value
1381  &&
1382  // Source view has MP::Vector only
1383  std::is_same< typename SrcTraits::specialize
1384  , Kokkos::Experimental::Impl::ViewMPVectorContiguous >::value
1385  &&
1386  // Ranks match
1387  unsigned(DstTraits::dimension::rank) == unsigned(SrcTraits::dimension::rank)
1388  )
1389  , typename DstTraits::specialize
1390  >::type >
1391 {
1392 public:
1393 
1394  enum { is_assignable = true };
1395  enum { is_assignable_data_type = true };
1396 
1397  typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
1398  typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
1399  typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcType ;
1400 
1401  KOKKOS_INLINE_FUNCTION static
1402  void assign( DstType & dst
1403  , const SrcType & src
1404  , const TrackType & )
1405  {
1406  static_assert(
1407  (
1408  std::is_same< typename DstTraits::array_layout
1409  , Kokkos::LayoutLeft >::value ||
1410  std::is_same< typename DstTraits::array_layout
1411  , Kokkos::LayoutRight >::value ||
1412  std::is_same< typename DstTraits::array_layout
1413  , Kokkos::LayoutStride >::value
1414  )
1415  &&
1416  (
1417  std::is_same< typename SrcTraits::array_layout
1418  , Kokkos::LayoutLeft >::value ||
1419  std::is_same< typename SrcTraits::array_layout
1420  , Kokkos::LayoutRight >::value ||
1421  std::is_same< typename SrcTraits::array_layout
1422  , Kokkos::LayoutStride >::value
1423  )
1424  , "View of MP::Vector requires LayoutLeft, LayoutRight, or LayoutStride" );
1425 
1426  static_assert(
1427  std::is_same< typename DstTraits::array_layout
1428  , typename SrcTraits::array_layout >::value ||
1429  std::is_same< typename DstTraits::array_layout
1430  , Kokkos::LayoutStride >::value ,
1431  "View assignment must have compatible layout" );
1432 
1433  static_assert(
1434  std::is_same< typename DstTraits::value_type
1435  , typename SrcTraits::non_const_value_type::value_type >::value ||
1436  std::is_same< typename DstTraits::value_type
1437  , const typename SrcTraits::non_const_value_type::value_type >::value ,
1438  "View assignment must have same value type or const = non-const" );
1439 
1440  static_assert(
1441  ViewDimensionAssignable<
1442  typename DstType::offset_type::dimension_type,
1443  typename SrcType::offset_type::dimension_type >::value,
1444  "View assignment must have compatible dimensions" );
1445 
1446  if ( src.m_stride != 1 ) {
1447  Kokkos::abort("\n\n ****** Kokkos::View< Sacado::MP::Vector ... > cannot assign with non-unit stride ******\n\n");
1448  }
1449 
1450  unsigned dims[8];
1451  dims[0] = src.m_impl_offset.dimension_0();
1452  dims[1] = src.m_impl_offset.dimension_1();
1453  dims[2] = src.m_impl_offset.dimension_2();
1454  dims[3] = src.m_impl_offset.dimension_3();
1455  dims[4] = src.m_impl_offset.dimension_4();
1456  dims[5] = src.m_impl_offset.dimension_5();
1457  dims[6] = src.m_impl_offset.dimension_6();
1458  dims[7] = src.m_impl_offset.dimension_7();
1459  unsigned rank = SrcTraits::dimension::rank;
1460  unsigned sacado_size = src.m_sacado_size.value;
1461  if (std::is_same<typename DstTraits::array_layout, LayoutLeft>::value) {
1462  dims[0] = dims[0]*sacado_size;
1463  dims[rank] = 0;
1464  }
1465  else {
1466  dims[rank-1] = dims[rank-1]*sacado_size;
1467  dims[rank] = 0;
1468  }
1469  typedef typename DstType::offset_type dst_offset_type;
1470  dst.m_impl_offset = dst_offset_type( std::integral_constant< unsigned , 0 >(),
1471  typename DstTraits::array_layout(
1472  dims[0] , dims[1] , dims[2] , dims[3] ,
1473  dims[4] , dims[5] , dims[6] , dims[7] ) );
1474  dst.m_impl_handle = src.m_impl_handle.scalar_ptr ;
1475  }
1476 };
1477 
1478 } // namespace Impl
1479 } // namespace Kokkos
1480 
1481 //----------------------------------------------------------------------------
1482 
1483 namespace Kokkos {
1484 namespace Impl {
1485 
1486 // Subview mapping
1487 
1488 template< class DataType, class ... P , class Arg0, class ... Args >
1489 struct ViewMapping
1490  < typename std::enable_if<(
1491  // Source view has MP::Vector only
1492  std::is_same< typename Kokkos::ViewTraits<DataType,P...>::specialize
1493  , Kokkos::Experimental::Impl::ViewMPVectorContiguous >::value
1494  &&
1495  (
1496  std::is_same< typename Kokkos::ViewTraits<DataType,P...>::array_layout
1497  , Kokkos::LayoutLeft >::value ||
1498  std::is_same< typename Kokkos::ViewTraits<DataType,P...>::array_layout
1499  , Kokkos::LayoutRight >::value ||
1500  std::is_same< typename Kokkos::ViewTraits<DataType,P...>::array_layout
1501  , Kokkos::LayoutStride >::value
1502  )
1503  && !Sacado::MP::is_vector_partition<Arg0>::value
1504  )>::type
1505  , Kokkos::ViewTraits<DataType,P...>
1506  , Arg0, Args ... >
1507 {
1508 private:
1509 
1510  typedef Kokkos::ViewTraits<DataType,P...> SrcTraits;
1511 
1512  //static_assert( SrcTraits::rank == sizeof...(Args) , "" );
1513 
1514  enum
1515  { RZ = false
1516  , R0 = bool(is_integral_extent<0,Arg0,Args...>::value)
1517  , R1 = bool(is_integral_extent<1,Arg0,Args...>::value)
1518  , R2 = bool(is_integral_extent<2,Arg0,Args...>::value)
1519  , R3 = bool(is_integral_extent<3,Arg0,Args...>::value)
1520  , R4 = bool(is_integral_extent<4,Arg0,Args...>::value)
1521  , R5 = bool(is_integral_extent<5,Arg0,Args...>::value)
1522  , R6 = bool(is_integral_extent<6,Arg0,Args...>::value)
1523  };
1524 
1525  // Public rank
1526  enum { rank = unsigned(R0) + unsigned(R1) + unsigned(R2) + unsigned(R3)
1527  + unsigned(R4) + unsigned(R5) + unsigned(R6) };
1528 
1529  // Whether right-most non-MP::Vector rank is a range.
1530  enum { R0_rev = ( 0 == SrcTraits::rank ? RZ : (
1531  1 == SrcTraits::rank ? R0 : (
1532  2 == SrcTraits::rank ? R1 : (
1533  3 == SrcTraits::rank ? R2 : (
1534  4 == SrcTraits::rank ? R3 : (
1535  5 == SrcTraits::rank ? R4 : (
1536  6 == SrcTraits::rank ? R5 : R6 ))))))) };
1537 
1538  // Subview's layout
1539  typedef typename std::conditional<
1540  ( /* Same array layout IF */
1541  ( rank == 0 ) /* output rank zero */
1542  ||
1543  // OutputRank 1 or 2, InputLayout Left, Interval 0
1544  // because single stride one or second index has a stride.
1545  ( rank <= 2 && R0 && std::is_same< typename SrcTraits::array_layout , Kokkos::LayoutLeft >::value )
1546  ||
1547  // OutputRank 1 or 2, InputLayout Right, Interval [InputRank-1]
1548  // because single stride one or second index has a stride.
1549  ( rank <= 2 && R0_rev && std::is_same< typename SrcTraits::array_layout , Kokkos::LayoutRight >::value )
1550  ), typename SrcTraits::array_layout , Kokkos::LayoutStride
1552 
1554 
1555  typedef typename std::conditional< rank == 0 , sacado_mp_vector_type ,
1556  typename std::conditional< rank == 1 , sacado_mp_vector_type * ,
1557  typename std::conditional< rank == 2 , sacado_mp_vector_type ** ,
1558  typename std::conditional< rank == 3 , sacado_mp_vector_type *** ,
1559  typename std::conditional< rank == 4 , sacado_mp_vector_type **** ,
1560  typename std::conditional< rank == 5 , sacado_mp_vector_type ***** ,
1561  typename std::conditional< rank == 6 , sacado_mp_vector_type ****** ,
1562  sacado_mp_vector_type *******
1565 
1566 public:
1567 
1568  typedef Kokkos::ViewTraits
1569  < data_type
1570  , array_layout
1571  , typename SrcTraits::device_type
1572  , typename SrcTraits::memory_traits > traits_type ;
1573 
1574  typedef Kokkos::View
1575  < data_type
1576  , array_layout
1577  , typename SrcTraits::device_type
1578  , typename SrcTraits::memory_traits > type ;
1579 
1580 
1581  // The presumed type is 'ViewMapping< traits_type , void >'
1582  // However, a compatible ViewMapping is acceptable.
1583  template< class DstTraits >
1584  KOKKOS_INLINE_FUNCTION
1585  static void assign( ViewMapping< DstTraits , typename DstTraits::specialize > & dst
1586  , ViewMapping< SrcTraits , typename SrcTraits::specialize > const & src
1587  , Arg0 arg0, Args ... args )
1588  {
1589  static_assert(
1590  ViewMapping< DstTraits , traits_type , typename DstTraits::specialize >::is_assignable ,
1591  "Subview destination type must be compatible with subview derived type" );
1592 
1593  typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
1594  typedef typename DstType::offset_type dst_offset_type ;
1595 
1596  const SubviewExtents< SrcTraits::rank , rank >
1597  extents( src.m_impl_offset.m_dim , arg0 , args... );
1598 
1599  const size_t offset = src.m_impl_offset( extents.domain_offset(0)
1600  , extents.domain_offset(1)
1601  , extents.domain_offset(2)
1602  , extents.domain_offset(3)
1603  , extents.domain_offset(4)
1604  , extents.domain_offset(5)
1605  , extents.domain_offset(6)
1606  , extents.domain_offset(7) );
1607 
1608  dst.m_impl_offset = dst_offset_type( src.m_impl_offset , extents );
1609  dst.m_impl_handle.value_ptr = src.m_impl_handle.value_ptr + offset;
1610  dst.m_impl_handle.scalar_ptr =
1611  src.m_impl_handle.scalar_ptr + offset * src.m_stride * src.m_sacado_size.value;
1612  dst.m_stride = src.m_stride;
1613  dst.m_sacado_size = src.m_sacado_size;
1614  }
1615 
1616 };
1617 
1618 } // namespace Impl
1619 } // namespace Kokkos
1620 
1621 //----------------------------------------------------------------------------
1622 //----------------------------------------------------------------------------
1623 //----------------------------------------------------------------------------
1624 
1625 namespace Kokkos {
1626 namespace Impl {
1627 
1628 // Partition mapping
1629 
1630 template< class DataType, class ...P, unsigned Size >
1631 class ViewMapping<
1632  void,
1633  ViewTraits<DataType,P...> ,
1634  Sacado::MP::VectorPartition<Size> >
1635 {
1636 public:
1637 
1638  enum { is_assignable = true };
1639  enum { is_assignable_data_type = true };
1640 
1641  typedef ViewTraits<DataType,P...> src_traits;
1642  typedef ViewMapping< src_traits , typename src_traits::specialize > src_type ;
1643 
1644  typedef typename src_type::offset_type::dimension_type src_dimension;
1647  typedef typename storage_type::template apply_N<Size> storage_apply;
1648  typedef typename storage_apply::type strided_storage_type;
1650  typedef typename
1651  ViewDataType< strided_value_type , src_dimension >::type strided_data_type;
1652  typedef ViewTraits<strided_data_type,P...> dst_traits;
1653  typedef View<strided_data_type,P...> type;
1654  typedef ViewMapping< dst_traits , typename dst_traits::specialize > dst_type ;
1655 
1656  KOKKOS_INLINE_FUNCTION static
1657  void assign( dst_type & dst
1658  , const src_type & src
1659  , const Sacado::MP::VectorPartition<Size> & part )
1660  {
1661  // The pointer assignments below are not sufficient for dynamically sized
1662  // scalar types, so disallow this case for now
1663  static_assert( storage_type::is_static,
1664  "For performance reasons, partitioned assignment is only implemented for statically-sized MP::Vector types" );
1665 
1666  unsigned len = part.end - part.begin;
1667  if ( Size != len || Size == 0 ) {
1668  Kokkos::abort("\n\n ****** Kokkos::View< Sacado::MP::Vector ... > Invalid size in partitioned view assignment ******\n\n");
1669  }
1670 
1671  dst.m_impl_handle.value_ptr =
1672  reinterpret_cast<strided_value_type*>( src.m_impl_handle.value_ptr ) +
1673  part.begin / len ;
1674  dst.m_impl_handle.scalar_ptr = src.m_impl_handle.scalar_ptr +
1675  (part.begin / len) * src.m_stride * src.m_sacado_size.value ;
1676  dst.m_impl_offset = src.m_impl_offset ;
1677  dst.m_stride = src.m_stride * src.m_sacado_size.value / Size ;
1678  dst.m_sacado_size = len ;
1679  }
1680 };
1681 
1682 } // namespace Impl
1683 } // namespace Kokkos
1684 
1685 namespace Kokkos {
1686 
1687 template< unsigned Size, typename D, typename ... P >
1688 KOKKOS_INLINE_FUNCTION
1689 typename Kokkos::Impl::ViewMapping< void, typename Kokkos::ViewTraits<D,P...>, Sacado::MP::VectorPartition<Size> >::type
1690 partition( const Kokkos::View<D,P...> & src ,
1691  const unsigned beg )
1692 {
1693  typedef Kokkos::ViewTraits<D,P...> traits;
1694  typedef typename Kokkos::Impl::ViewMapping< void, traits, Sacado::MP::VectorPartition<Size> >::type DstViewType;
1695  const Sacado::MP::VectorPartition<Size> part( beg , beg+Size );
1696  return DstViewType(src, part);
1697 }
1698 
1699 } // namespace Kokkos
1700 
1701 //----------------------------------------------------------------------------
1702 //----------------------------------------------------------------------------
1703 //----------------------------------------------------------------------------
1704 
1705 namespace Kokkos {
1706 namespace Impl {
1707 
1708 // Specialization for deep_copy( view, view::value_type ) for Cuda
1709 #if defined( KOKKOS_ENABLE_CUDA )
1710 template< class OutputView >
1711 struct StokhosViewFill< OutputView ,
1712  typename std::enable_if< std::is_same< typename OutputView::specialize,
1713  Kokkos::Experimental::Impl::ViewMPVectorContiguous >::value &&
1714  std::is_same< typename OutputView::execution_space,
1715  Cuda >::value >::type >
1716 {
1717  typedef typename OutputView::const_value_type const_value_type ;
1718  typedef typename OutputView::execution_space execution_space ;
1719  typedef typename OutputView::size_type size_type ;
1720 
1721  template <unsigned VectorLength>
1722  struct Kernel {
1723  typedef typename OutputView::execution_space execution_space ;
1724  const OutputView output;
1726 
1727  Kernel( const OutputView & arg_out , const_value_type & arg_in ) :
1728  output(arg_out), input(arg_in) {}
1729 
1730  typedef typename Kokkos::TeamPolicy< execution_space >::member_type team_member ;
1731 
1732  KOKKOS_INLINE_FUNCTION
1733  void operator()( const team_member & dev ) const
1734  {
1735  const size_type tidx = dev.team_rank() % VectorLength;
1736  const size_type tidy = dev.team_rank() / VectorLength;
1737  const size_type nrow = dev.team_size() / VectorLength;
1738  const size_type nvec = dimension_scalar(output);
1739 
1740  const size_type i0 = dev.league_rank() * nrow + tidy;
1741  if ( i0 >= output.extent(0) ) return;
1742 
1743  for ( size_type i1 = 0 ; i1 < output.extent(1) ; ++i1 ) {
1744  for ( size_type i2 = 0 ; i2 < output.extent(2) ; ++i2 ) {
1745  for ( size_type i3 = 0 ; i3 < output.extent(3) ; ++i3 ) {
1746  for ( size_type i4 = 0 ; i4 < output.extent(4) ; ++i4 ) {
1747  for ( size_type i5 = 0 ; i5 < output.extent(5) ; ++i5 ) {
1748  for ( size_type i6 = 0 ; i6 < output.extent(6) ; ++i6 ) {
1749  for ( size_type i7 = 0 ; i7 < output.extent(7) ; ++i7 ) {
1750  for ( size_type is = tidx ; is < nvec ; is+=VectorLength ) {
1751  output.access(i0,i1,i2,i3,i4,i5,i6,i7).fastAccessCoeff(is) =
1752  input.fastAccessCoeff(is) ;
1753  }}}}}}}}
1754  }
1755  };
1756 
1757  StokhosViewFill( const OutputView & output , const_value_type & input )
1758  {
1759  if ( Sacado::is_constant(input) ) {
1760  deep_copy( output , input.fastAccessCoeff(0) );
1761  }
1762  else {
1763 
1764  // Coalesced accesses are 128 bytes in size
1766  const unsigned vector_length =
1767  ( 128 + sizeof(scalar_type)-1 ) / sizeof(scalar_type);
1768 
1769  // 8 warps per block should give good occupancy
1770  const size_type block_size = 256;
1771 
1772  const size_type rows_per_block = block_size / vector_length;
1773  const size_type n = output.extent(0);
1774  const size_type league_size = ( n + rows_per_block-1 ) / rows_per_block;
1775  const size_type team_size = rows_per_block * vector_length;
1776  Kokkos::TeamPolicy< execution_space > config( league_size, team_size );
1777 
1778  parallel_for( config, Kernel<vector_length>(output, input) );
1779  execution_space().fence();
1780  }
1781  }
1782 
1783 };
1784 #endif /* #if defined( KOKKOS_ENABLE_CUDA ) */
1785 
1786 } // namespace Impl
1787 } // namespace Kokkos
1788 
1789 //----------------------------------------------------------------------------
1790 //----------------------------------------------------------------------------
1791 //----------------------------------------------------------------------------
1792 
1793 namespace Kokkos {
1794 namespace Impl {
1795 
1796 struct ViewSpecializeSacadoFad;
1797 
1804 template< class DstTraits , class SrcTraits >
1805 class ViewMapping< DstTraits , SrcTraits ,
1806  typename std::enable_if<(
1807  Kokkos::Impl::MemorySpaceAccess< typename DstTraits::memory_space
1808  , typename SrcTraits::memory_space >::assignable
1809  &&
1810  // Destination view has MP::Vector only
1811  std::is_same< typename DstTraits::specialize
1812  , Kokkos::Experimental::Impl::ViewMPVectorContiguous >::value
1813  &&
1814  // Source view has FAD only
1815  std::is_same< typename SrcTraits::specialize
1816  , ViewSpecializeSacadoFad >::value
1817  )
1818  , typename DstTraits::specialize
1819  >::type >
1820 {
1821 public:
1822 
1823  enum { is_assignable = true };
1824  enum { is_assignable_data_type = true };
1825 
1826  typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
1827  typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
1828  typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcFadType ;
1829 
1830  template< class DstType >
1831  KOKKOS_INLINE_FUNCTION static
1832  void assign( DstType & dst
1833  , const SrcFadType & src
1834  , const TrackType & )
1835  {
1836  static_assert(
1837  (
1838  std::is_same< typename DstTraits::array_layout
1839  , Kokkos::LayoutLeft >::value ||
1840  std::is_same< typename DstTraits::array_layout
1841  , Kokkos::LayoutRight >::value ||
1842  std::is_same< typename DstTraits::array_layout
1843  , Kokkos::LayoutStride >::value
1844  )
1845  &&
1846  (
1847  std::is_same< typename SrcTraits::array_layout
1848  , Kokkos::LayoutLeft >::value ||
1849  std::is_same< typename SrcTraits::array_layout
1850  , Kokkos::LayoutRight >::value ||
1851  std::is_same< typename SrcTraits::array_layout
1852  , Kokkos::LayoutStride >::value
1853  )
1854  , "View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
1855 
1856  static_assert(
1857  std::is_same< typename DstTraits::array_layout
1858  , typename SrcTraits::array_layout >::value ||
1859  std::is_same< typename DstTraits::array_layout
1860  , Kokkos::LayoutStride >::value ,
1861  "View assignment must have compatible layout" );
1862 
1863  static_assert(
1864  std::is_same< typename DstTraits::data_type
1865  , typename SrcTraits::scalar_array_type >::value ||
1866  std::is_same< typename DstTraits::data_type
1867  , typename SrcTraits::const_scalar_array_type >::value ,
1868  "View assignment must have same value type or const = non-const" );
1869 
1870  static_assert(
1871  ViewDimensionAssignable
1872  < typename DstType::offset_type::dimension_type
1873  , typename SrcFadType::array_offset_type::dimension_type >::value ,
1874  "View assignment must have compatible dimensions" );
1875 
1876  typedef typename DstType::offset_type dst_offset_type ;
1877 
1878  dst.m_impl_offset = dst_offset_type( src.m_array_offset );
1879  dst.m_impl_handle.assign(src.m_impl_handle) ;
1880  dst.m_stride = 1;
1881 
1882  // Don't need to set dst.m_sacado_size since it is determined statically
1883  static_assert( DstType::is_static,
1884  "Destination view must be statically allocated" );
1885  }
1886 };
1887 
1888 } // namespace Impl
1889 } // namespace Kokkos
1890 
1891 //----------------------------------------------------------------------------
1892 //----------------------------------------------------------------------------
1893 //----------------------------------------------------------------------------
1894 
1895 #include "Kokkos_View_Utils_Def.hpp"
1896 
1897 #endif /* #ifndef KOKKOS_EXPERIMENTAL_VIEW_MP_VECTOR_CONTIGUOUS_HPP */
static KOKKOS_INLINE_FUNCTION void assign(dst_type &dst, const src_type &src, const Sacado::MP::VectorPartition< Size > &part)
KOKKOS_INLINE_FUNCTION MPVectorAllocation & operator=(const MPVectorAllocation< T, true > &a)
Stokhos::StandardStorage< int, double > storage_type
static KOKKOS_INLINE_FUNCTION constexpr size_t memory_span(const size_t span, const unsigned vector_size)
KOKKOS_INLINE_FUNCTION MPVectorAllocation & operator=(const MPVectorAllocation< T, false > &a)
Kokkos::DefaultExecutionSpace execution_space
std::conditional< std::is_same< ArrayLayout, Kokkos::LayoutLeft >::value, prepend_scalar_dimension, append_scalar_dimension >::type scalar_dimension
std::conditional< rank==0, sacado_mp_vector_type, typename std::conditional< rank==1, sacado_mp_vector_type *, typename std::conditional< rank==2, sacado_mp_vector_type **, typename std::conditional< rank==3, sacado_mp_vector_type ***, typename std::conditional< rank==4, sacado_mp_vector_type ****, typename std::conditional< rank==5, sacado_mp_vector_type *****, typename std::conditional< rank==6, sacado_mp_vector_type ******, sacado_mp_vector_type *******>::type >::type >::type >::type >::type >::type >::type data_type
ConstructDestructFunctor< ExecSpace > create_functor(const ExecSpace &space, const bool initialize, const size_t span, const unsigned vector_size) const
OutputView::const_value_type const_value_type
VectorConstruct(const ExecSpace &space, value_type *p, scalar_type *sp, const size_t span, const unsigned vector_size)
static KOKKOS_INLINE_FUNCTION constexpr size_t memory_span(const size_t span, const unsigned vector_size)
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< View< T, P... > >::value, unsigned >::type dimension_scalar(const View< T, P... > &view)
OutputView::execution_space execution_space
KOKKOS_INLINE_FUNCTION void operator()(const size_t i0) const
KOKKOS_INLINE_FUNCTION bool is_constant(const T &x)
void deep_copy(const Stokhos::CrsMatrix< ValueType, DstDevice, Layout > &dst, const Stokhos::CrsMatrix< ValueType, SrcDevice, Layout > &src)
StokhosViewFill(const OutputView &arg_out, const_value_type &arg_in)
ConstructDestructFunctor(const ExecSpace &space, const bool initialize, const size_t span, const unsigned vector_size, scalar_type *scalar_ptr, value_type *value_ptr)
ConstructDestructFunctor(const ExecSpace &space, const bool initialize, const size_t span, const unsigned vector_size, scalar_type *scalar_ptr)
KOKKOS_INLINE_FUNCTION Kokkos::Impl::ViewMapping< void, typename Kokkos::ViewTraits< D, P... >, Sacado::MP::VectorPartition< Size > >::type partition(const Kokkos::View< D, P... > &src, const unsigned beg)
Stokhos::CrsMatrix< ValueType, Device, Layout >::HostMirror create_mirror(const Stokhos::CrsMatrix< ValueType, Device, Layout > &A)
ConstructDestructFunctor< ExecSpace > create_functor(const ExecSpace &space, const bool initialize, const size_t span, const unsigned vector_size) const