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