Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Kokkos_DynRankView_Fad.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Sacado Package
4 //
5 // Copyright 2006 NTESS and the Sacado contributors.
6 // SPDX-License-Identifier: LGPL-2.1-or-later
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef KOKKOS_DYN_RANK_VIEW_SACADO_FAD_HPP
11 #define KOKKOS_DYN_RANK_VIEW_SACADO_FAD_HPP
12 
13 #include "Sacado_ConfigDefs.h"
14 
15 // This file is setup to always work even when KokkosContainers (which contains
16 // Kokkos::DynRankView) isn't enabled.
17 
18 #if defined(HAVE_SACADO_KOKKOS)
19 
20 // We are hooking into Kokkos Core internals here
21 // Need to define this macro since we include non-public headers
22 #ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
23 #define KOKKOS_IMPL_PUBLIC_INCLUDE
24 #define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
25 #endif
26 // Only include forward declarations so any overloads appear before they
27 // might be used inside Kokkos
28 #include "Kokkos_Core_fwd.hpp"
29 #include "Kokkos_Layout.hpp"
30 //#include "Kokkos_DynRankView.hpp"
31 #ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
32 #undef KOKKOS_IMPL_PUBLIC_INCLUDE
33 #undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
34 #endif
35 
36 namespace Kokkos {
37 
38 template< class DataType , class ... Properties >
39 struct ViewTraits ;
40 
41 template< class DataType , class ... Properties >
42 class DynRankView ;
43 
44 namespace Impl {
45 
46 template<class Space, class T, class ... P>
47 struct MirrorDRViewType;
48 
49 }
50 
51 template <typename view_type>
52 struct is_dynrankview_fad { static const bool value = false; };
53 
54 template <typename view_type>
55 struct is_dynrankview_fad_contiguous { static const bool value = false; };
56 
57 }
58 
59 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
60 
61 #include "Kokkos_View_Fad.hpp"
62 
63 namespace Kokkos {
64 
65 // Declare overloads of create_mirror() so they are in scope
66 // Kokkos_DynRankView.hpp is included below
67 
68 template< class T , class ... P >
69 inline
70 typename Kokkos::DynRankView<T,P...>::HostMirror
71 create_mirror(
72  const Kokkos::DynRankView<T,P...> & src,
73  typename std::enable_if<
74  ( std::is_same< typename ViewTraits<T,P...>::specialize ,
75  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
76  std::is_same< typename ViewTraits<T,P...>::specialize ,
77  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
78  !std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout,
79  Kokkos::LayoutStride >::value >::type * = 0);
80 
81 
82 template< class T , class ... P >
83 inline
84 typename Kokkos::DynRankView<T,P...>::HostMirror
85 create_mirror(
86  const Kokkos::DynRankView<T,P...> & src,
87  typename std::enable_if<
88  ( std::is_same< typename ViewTraits<T,P...>::specialize ,
89  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
90  std::is_same< typename ViewTraits<T,P...>::specialize ,
91  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
92  std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout,
93  Kokkos::LayoutStride >::value >::type * = 0);
94 
95 template<class Space, class T, class ... P>
96 typename Impl::MirrorDRViewType<Space,T,P ...>::dest_view_type
97 create_mirror(
98  const Space&,
99  const Kokkos::DynRankView<T,P...> & src,
100  typename std::enable_if<
101  std::is_same< typename ViewTraits<T,P...>::specialize ,
102  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
103  std::is_same< typename ViewTraits<T,P...>::specialize ,
104  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value >::type * = 0);
105 
106 namespace Impl {
107 
108 template <unsigned N, typename T, typename... Args>
109 KOKKOS_FUNCTION auto as_view_of_rank_n(
110  DynRankView<T, Args...> v,
111  typename std::enable_if<
112  ( std::is_same< typename ViewTraits<T,Args...>::specialize,
113  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
114  std::is_same< typename ViewTraits<T,Args...>::specialize ,
115  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
116  >::type * = 0 );
117 
118 }
119 
120 } // namespace Kokkos
121 
122 #include "Kokkos_DynRankView.hpp"
123 
124 namespace Kokkos {
125 namespace Impl {
126 
127 template <>
128 struct DynRankDimTraits<Kokkos::Impl::ViewSpecializeSacadoFad> {
129 
130  enum : size_t{unspecified = ~size_t(0)};
131 
132  // Compute the rank of the view from the nonzero dimension arguments.
133  // For views of Fad, the rank is one less than the rank determined by the nonzero dimension args
134  KOKKOS_INLINE_FUNCTION
135  static size_t computeRank( const size_t N0
136  , const size_t N1
137  , const size_t N2
138  , const size_t N3
139  , const size_t N4
140  , const size_t N5
141  , const size_t N6
142  , const size_t N7 )
143  {
144  return
145  ( (N7 == unspecified && N6 == unspecified && N5 == unspecified && N4 == unspecified && N3 == unspecified && N2 == unspecified && N1 == unspecified && N0 == unspecified) ? 0
146  : ( (N7 == unspecified && N6 == unspecified && N5 == unspecified && N4 == unspecified && N3 == unspecified && N2 == unspecified && N1 == unspecified) ? 0
147  : ( (N7 == unspecified && N6 == unspecified && N5 == unspecified && N4 == unspecified && N3 == unspecified && N2 == unspecified) ? 1
148  : ( (N7 == unspecified && N6 == unspecified && N5 == unspecified && N4 == unspecified && N3 == unspecified) ? 2
149  : ( (N7 == unspecified && N6 == unspecified && N5 == unspecified && N4 == unspecified) ? 3
150  : ( (N7 == unspecified && N6 == unspecified && N5 == unspecified) ? 4
151  : ( (N7 == unspecified && N6 == unspecified) ? 5
152  : ( (N7 == unspecified) ? 6
153  : 7 ) ) ) ) ) ) ) );
154  }
155 
156  // Compute the rank of the view from the nonzero layout arguments.
157  template <typename Layout>
158  KOKKOS_INLINE_FUNCTION
159  static size_t computeRank( const Layout& layout )
160  {
161  return computeRank( layout.dimension[0]
162  , layout.dimension[1]
163  , layout.dimension[2]
164  , layout.dimension[3]
165  , layout.dimension[4]
166  , layout.dimension[5]
167  , layout.dimension[6]
168  , layout.dimension[7] );
169  }
170 
171  // Compute the rank of the view from the nonzero layout arguments and possible hidden dim
172  template <typename Layout, typename ... P>
173  KOKKOS_INLINE_FUNCTION
174  static size_t computeRank( const ViewCtorProp<P...>& /* prop */, const Layout& layout )
175  {
176  size_t rank = computeRank( layout.dimension[0]
177  , layout.dimension[1]
178  , layout.dimension[2]
179  , layout.dimension[3]
180  , layout.dimension[4]
181  , layout.dimension[5]
182  , layout.dimension[6]
183  , layout.dimension[7] );
184 
185  // Check if has_common_view_alloc_prop; if so, return rank+1, else rank
186  enum { test_traits_check = Kokkos::Impl::check_has_common_view_alloc_prop< P... >::value };
187  return (test_traits_check == true) ? rank+1 : rank;
188  }
189 
190  // Create the layout for the rank-7 view.
191  // For Fad we have to move the fad dimension to the last (rank 8 since the DynRankView is rank-7)
192  // LayoutLeft or LayoutRight
193  template <typename Layout>
194  KOKKOS_INLINE_FUNCTION
195  static typename std::enable_if< (std::is_same<Layout , Kokkos::LayoutRight>::value || std::is_same<Layout , Kokkos::LayoutLeft>::value) , Layout >::type createLayout( const Layout& layout )
196  {
197  Layout l( layout.dimension[0] != unspecified ? layout.dimension[0] : 1
198  , layout.dimension[1] != unspecified ? layout.dimension[1] : 1
199  , layout.dimension[2] != unspecified ? layout.dimension[2] : 1
200  , layout.dimension[3] != unspecified ? layout.dimension[3] : 1
201  , layout.dimension[4] != unspecified ? layout.dimension[4] : 1
202  , layout.dimension[5] != unspecified ? layout.dimension[5] : 1
203  , layout.dimension[6] != unspecified ? layout.dimension[6] : 1
204  , layout.dimension[7] != unspecified ? layout.dimension[7] : 1 );
205  const unsigned fad_dim = computeRank(layout);
206  const size_t fad_size = layout.dimension[fad_dim];
207  l.dimension[fad_dim] = 1;
208  l.dimension[7] = fad_size;
209 
210  return l;
211  }
212 
213  //LayoutStride
214  template <typename Layout>
215  KOKKOS_INLINE_FUNCTION
216  static typename std::enable_if< (std::is_same<Layout , Kokkos::LayoutStride>::value) , Layout>::type createLayout( const Layout& layout )
217  {
218  Layout l( layout.dimension[0] != unspecified ? layout.dimension[0] : 1
219  , layout.stride[0]
220  , layout.dimension[1] != unspecified ? layout.dimension[1] : 1
221  , layout.stride[1]
222  , layout.dimension[2] != unspecified ? layout.dimension[2] : 1
223  , layout.stride[2]
224  , layout.dimension[3] != unspecified ? layout.dimension[3] : 1
225  , layout.stride[3]
226  , layout.dimension[4] != unspecified ? layout.dimension[4] : 1
227  , layout.stride[4]
228  , layout.dimension[5] != unspecified ? layout.dimension[5] : 1
229  , layout.stride[5]
230  , layout.dimension[6] != unspecified ? layout.dimension[6] : 1
231  , layout.stride[6]
232  , layout.dimension[7] != unspecified ? layout.dimension[7] : 1
233  , layout.stride[7]
234  );
235  const unsigned fad_dim = computeRank(layout);
236  const size_t fad_size = layout.dimension[fad_dim];
237  l.dimension[fad_dim] = 1;
238  l.dimension[7] = fad_size;
239  const size_t fad_stride = layout.stride[fad_dim];
240  l.stride[fad_dim] = 0;
241  l.stride[7] = fad_stride;
242 
243  return l;
244  }
245 
246  // If fad_dim is stored in ViewCtorProp
247  // LayoutLeft or LayoutRight
248  template <typename Traits, typename ... P>
249  KOKKOS_INLINE_FUNCTION
250  static typename std::enable_if< (std::is_same<typename Traits::array_layout , Kokkos::LayoutRight>::value || std::is_same<typename Traits::array_layout , Kokkos::LayoutLeft>::value) , typename Traits::array_layout >::type createLayout( const ViewCtorProp<P...> & arg_prop, const typename Traits::array_layout& layout )
251  {
252  using Layout = typename Traits::array_layout;
253 
254  Layout l( layout.dimension[0] != unspecified ? layout.dimension[0] : 1
255  , layout.dimension[1] != unspecified ? layout.dimension[1] : 1
256  , layout.dimension[2] != unspecified ? layout.dimension[2] : 1
257  , layout.dimension[3] != unspecified ? layout.dimension[3] : 1
258  , layout.dimension[4] != unspecified ? layout.dimension[4] : 1
259  , layout.dimension[5] != unspecified ? layout.dimension[5] : 1
260  , layout.dimension[6] != unspecified ? layout.dimension[6] : 1
261  , layout.dimension[7] != unspecified ? layout.dimension[7] : 1 );
262 
263  enum { test_traits_check = Kokkos::Impl::check_has_common_view_alloc_prop< P... >::value };
264  if (test_traits_check == true) {
265  l.dimension[7] = compute_fad_dim_from_alloc_prop<P...>::eval(arg_prop);
266  }
267  else {
268  const unsigned fad_dim = computeRank(layout);
269  const size_t fad_size = layout.dimension[fad_dim];
270  l.dimension[fad_dim] = 1;
271  l.dimension[7] = fad_size;
272  }
273 
274  return l;
275  }
276 
277  // If fad_dim is stored in ViewCtorProp
278  //LayoutStride
279  template <typename Traits, typename ... P>
280  KOKKOS_INLINE_FUNCTION
281  static typename std::enable_if< (std::is_same<typename Traits::array_layout , Kokkos::LayoutStride>::value) , typename Traits::array_layout>::type createLayout( const ViewCtorProp<P...> & arg_prop, const typename Traits::array_layout& layout )
282  {
283  using Layout = typename Traits::array_layout;
284 
285  Layout l( layout.dimension[0] != unspecified ? layout.dimension[0] : 1
286  , layout.stride[0]
287  , layout.dimension[1] != unspecified ? layout.dimension[1] : 1
288  , layout.stride[1]
289  , layout.dimension[2] != unspecified ? layout.dimension[2] : 1
290  , layout.stride[2]
291  , layout.dimension[3] != unspecified ? layout.dimension[3] : 1
292  , layout.stride[3]
293  , layout.dimension[4] != unspecified ? layout.dimension[4] : 1
294  , layout.stride[4]
295  , layout.dimension[5] != unspecified ? layout.dimension[5] : 1
296  , layout.stride[5]
297  , layout.dimension[6] != unspecified ? layout.dimension[6] : 1
298  , layout.stride[6]
299  , layout.dimension[7] != unspecified ? layout.dimension[7] : 1
300  , layout.stride[7]
301  );
302 
303  enum { test_traits_check = Kokkos::Impl::check_has_common_view_alloc_prop< P... >::value };
304  const unsigned fad_dim = computeRank(layout);
305  if (test_traits_check == true) {
306  l.dimension[fad_dim] = 1;
307  l.dimension[7] = compute_fad_dim_from_alloc_prop<P...>::eval(arg_prop);
308  }
309  else {
310  const size_t fad_size = layout.dimension[fad_dim];
311  l.dimension[fad_dim] = 1;
312  l.dimension[7] = fad_size;
313  }
314  const size_t fad_stride = layout.stride[fad_dim];
315  l.stride[fad_dim] = 0;
316  l.stride[7] = fad_stride;
317 
318  return l;
319  }
320 
321  // Create a view from the given dimension arguments.
322  // This is only necessary because the shmem constructor doesn't take a layout.
323  template <typename ViewType, typename ViewArg>
324  static ViewType createView( const ViewArg& arg
325  , const size_t N0
326  , const size_t N1
327  , const size_t N2
328  , const size_t N3
329  , const size_t N4
330  , const size_t N5
331  , const size_t N6
332  , const size_t N7 )
333  {
334  typename ViewType::array_layout l( N0, N1, N2, N3, N4, N5, N6, N7 );
335  typename ViewType::array_layout l_fad = createLayout(l);
336  return ViewType( arg
337  , l_fad.dimension[0]
338  , l_fad.dimension[1]
339  , l_fad.dimension[2]
340  , l_fad.dimension[3]
341  , l_fad.dimension[4]
342  , l_fad.dimension[5]
343  , l_fad.dimension[6]
344  , l_fad.dimension[7] );
345  }
346 
347 };
348 
349 }} // namespace Kokkos::Impl
350 
351 namespace Kokkos {
352 namespace Impl {
353 
354 template <unsigned> struct AssignDim7 {
355  template <typename Dst>
356  KOKKOS_INLINE_FUNCTION
357  static void eval(Dst& dst, const size_t src_dim) {}
358 };
359 template <> struct AssignDim7<0u> {
360  template <typename Dst>
361  KOKKOS_INLINE_FUNCTION
362  static void eval(Dst& dst, const size_t src_dim) {
363  dst.N7 = src_dim;
364  }
365 };
366 
367 // Utility class that handles calculation of the stride in Fad subview
368 template <unsigned,unsigned> struct AssignFadDimStride {};
369 template <unsigned StaticDim> struct AssignFadDimStride<0u,StaticDim> {
370  template <typename Src, typename Dst>
371  KOKKOS_INLINE_FUNCTION
372  static void eval(Dst& dst, const Src& src) {
373  dst.m_stride.S0 = 0 ;
374  dst.m_stride.S1 = 0 ;
375  dst.m_stride.S2 = 0 ;
376  dst.m_stride.S3 = 0 ;
377  dst.m_stride.S4 = 0 ;
378  dst.m_stride.S5 = 0 ;
379  dst.m_stride.S6 = 0 ;
380  dst.m_stride.S7 = src.m_stride.S0 ;
381 
382  dst.m_dim.N0 = 1 ;
383  dst.m_dim.N1 = 1 ;
384  dst.m_dim.N2 = 1 ;
385  dst.m_dim.N3 = 1 ;
386  dst.m_dim.N4 = 1 ;
387  dst.m_dim.N5 = 1 ;
388  dst.m_dim.N6 = 1 ;
389  AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N0 );
390  }
391 };
392 template <unsigned StaticDim> struct AssignFadDimStride<1u,StaticDim> {
393  template <typename Src, typename Dst>
394  KOKKOS_INLINE_FUNCTION
395  static void eval(Dst& dst, const Src& src) {
396  dst.m_stride.S0 = src.m_stride.S0 ;
397  dst.m_stride.S1 = 0 ;
398  dst.m_stride.S2 = 0 ;
399  dst.m_stride.S3 = 0 ;
400  dst.m_stride.S4 = 0 ;
401  dst.m_stride.S5 = 0 ;
402  dst.m_stride.S6 = 0 ;
403  dst.m_stride.S7 = src.m_stride.S1 ;
404 
405  dst.m_dim.N0 = src.m_dim.N0 ;
406  dst.m_dim.N1 = 1 ;
407  dst.m_dim.N2 = 1 ;
408  dst.m_dim.N3 = 1 ;
409  dst.m_dim.N4 = 1 ;
410  dst.m_dim.N5 = 1 ;
411  dst.m_dim.N6 = 1 ;
412  AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N1 );
413  }
414 };
415 template <unsigned StaticDim> struct AssignFadDimStride<2u,StaticDim> {
416  template <typename Src, typename Dst>
417  KOKKOS_INLINE_FUNCTION
418  static void eval(Dst& dst, const Src& src) {
419  dst.m_stride.S0 = src.m_stride.S0 ;
420  dst.m_stride.S1 = src.m_stride.S1 ;
421  dst.m_stride.S2 = 0 ;
422  dst.m_stride.S3 = 0 ;
423  dst.m_stride.S4 = 0 ;
424  dst.m_stride.S5 = 0 ;
425  dst.m_stride.S6 = 0 ;
426  dst.m_stride.S7 = src.m_stride.S2 ;
427 
428  dst.m_dim.N0 = src.m_dim.N0 ;
429  dst.m_dim.N1 = src.m_dim.N1 ;
430  dst.m_dim.N2 = 1 ;
431  dst.m_dim.N3 = 1 ;
432  dst.m_dim.N4 = 1 ;
433  dst.m_dim.N5 = 1 ;
434  dst.m_dim.N6 = 1 ;
435  AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N2 );
436  }
437 };
438 template <unsigned StaticDim> struct AssignFadDimStride<3u,StaticDim> {
439  template <typename Src, typename Dst>
440  KOKKOS_INLINE_FUNCTION
441  static void eval(Dst& dst, const Src& src) {
442  dst.m_stride.S0 = src.m_stride.S0 ;
443  dst.m_stride.S1 = src.m_stride.S1 ;
444  dst.m_stride.S2 = src.m_stride.S2 ;
445  dst.m_stride.S3 = 0 ;
446  dst.m_stride.S4 = 0 ;
447  dst.m_stride.S5 = 0 ;
448  dst.m_stride.S6 = 0 ;
449  dst.m_stride.S7 = src.m_stride.S3 ;
450 
451  dst.m_dim.N0 = src.m_dim.N0 ;
452  dst.m_dim.N1 = src.m_dim.N1 ;
453  dst.m_dim.N2 = src.m_dim.N2 ;
454  dst.m_dim.N3 = 1 ;
455  dst.m_dim.N4 = 1 ;
456  dst.m_dim.N5 = 1 ;
457  dst.m_dim.N6 = 1 ;
458  AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N3 );
459  }
460 };
461 template <unsigned StaticDim> struct AssignFadDimStride<4u,StaticDim> {
462  template <typename Src, typename Dst>
463  KOKKOS_INLINE_FUNCTION
464  static void eval(Dst& dst, const Src& src) {
465  dst.m_stride.S0 = src.m_stride.S0 ;
466  dst.m_stride.S1 = src.m_stride.S1 ;
467  dst.m_stride.S2 = src.m_stride.S2 ;
468  dst.m_stride.S3 = src.m_stride.S3 ;
469  dst.m_stride.S4 = 0 ;
470  dst.m_stride.S5 = 0 ;
471  dst.m_stride.S6 = 0 ;
472  dst.m_stride.S7 = src.m_stride.S4 ;
473 
474  dst.m_dim.N0 = src.m_dim.N0 ;
475  dst.m_dim.N1 = src.m_dim.N1 ;
476  dst.m_dim.N2 = src.m_dim.N2 ;
477  dst.m_dim.N3 = src.m_dim.N3 ;
478  dst.m_dim.N4 = 1 ;
479  dst.m_dim.N5 = 1 ;
480  dst.m_dim.N6 = 1 ;
481  AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N4 );
482  }
483 };
484 template <unsigned StaticDim> struct AssignFadDimStride<5u,StaticDim> {
485  template <typename Src, typename Dst>
486  KOKKOS_INLINE_FUNCTION
487  static void eval(Dst& dst, const Src& src) {
488  dst.m_stride.S0 = src.m_stride.S0 ;
489  dst.m_stride.S1 = src.m_stride.S1 ;
490  dst.m_stride.S2 = src.m_stride.S2 ;
491  dst.m_stride.S3 = src.m_stride.S3 ;
492  dst.m_stride.S4 = src.m_stride.S4 ;
493  dst.m_stride.S5 = 0 ;
494  dst.m_stride.S6 = 0 ;
495  dst.m_stride.S7 = src.m_stride.S5 ;
496 
497  dst.m_dim.N0 = src.m_dim.N0 ;
498  dst.m_dim.N1 = src.m_dim.N1 ;
499  dst.m_dim.N2 = src.m_dim.N2 ;
500  dst.m_dim.N3 = src.m_dim.N3 ;
501  dst.m_dim.N4 = src.m_dim.N4 ;
502  dst.m_dim.N5 = 1 ;
503  dst.m_dim.N6 = 1 ;
504  AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N5 );
505  }
506 };
507 template <unsigned StaticDim> struct AssignFadDimStride<6u,StaticDim> {
508  template <typename Src, typename Dst>
509  KOKKOS_INLINE_FUNCTION
510  static void eval(Dst& dst, const Src& src) {
511  dst.m_stride.S0 = src.m_stride.S0 ;
512  dst.m_stride.S1 = src.m_stride.S1 ;
513  dst.m_stride.S2 = src.m_stride.S2 ;
514  dst.m_stride.S3 = src.m_stride.S3 ;
515  dst.m_stride.S4 = src.m_stride.S4 ;
516  dst.m_stride.S5 = src.m_stride.S5 ;
517  dst.m_stride.S6 = 0 ;
518  dst.m_stride.S7 = src.m_stride.S6 ;
519 
520  dst.m_dim.N0 = src.m_dim.N0 ;
521  dst.m_dim.N1 = src.m_dim.N1 ;
522  dst.m_dim.N2 = src.m_dim.N2 ;
523  dst.m_dim.N3 = src.m_dim.N3 ;
524  dst.m_dim.N4 = src.m_dim.N4 ;
525  dst.m_dim.N5 = src.m_dim.N5 ;
526  dst.m_dim.N6 = 1 ;
527  AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N6 );
528  }
529 };
530 template <unsigned StaticDim> struct AssignFadDimStride<7u,StaticDim> {
531  template <typename Src, typename Dst>
532  KOKKOS_INLINE_FUNCTION
533  static void eval(Dst& dst, const Src& src) {
534  dst.m_stride.S0 = src.m_stride.S0 ;
535  dst.m_stride.S1 = src.m_stride.S1 ;
536  dst.m_stride.S2 = src.m_stride.S2 ;
537  dst.m_stride.S3 = src.m_stride.S3 ;
538  dst.m_stride.S4 = src.m_stride.S4 ;
539  dst.m_stride.S5 = src.m_stride.S5 ;
540  dst.m_stride.S6 = src.m_stride.S6 ;
541  dst.m_stride.S7 = src.m_stride.S7 ;
542 
543  dst.m_dim.N0 = src.m_dim.N0 ;
544  dst.m_dim.N1 = src.m_dim.N1 ;
545  dst.m_dim.N2 = src.m_dim.N2 ;
546  dst.m_dim.N3 = src.m_dim.N3 ;
547  dst.m_dim.N4 = src.m_dim.N4 ;
548  dst.m_dim.N5 = src.m_dim.N5 ;
549  dst.m_dim.N6 = src.m_dim.N6 ;
550  AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N7 );
551  }
552 };
553 
554 // Specializations for subdynrankview
555 template< class SrcTraits , class ... Args >
556 struct ViewMapping
557  < typename std::enable_if<(
558  std::is_same< typename SrcTraits::specialize ,
559  Kokkos::Impl::ViewSpecializeSacadoFad >::value
560  &&
561  (
562  std::is_same< typename SrcTraits::array_layout
563  , Kokkos::LayoutLeft >::value ||
564  std::is_same< typename SrcTraits::array_layout
565  , Kokkos::LayoutRight >::value ||
566  std::is_same< typename SrcTraits::array_layout
567  , Kokkos::LayoutStride >::value
568  )
569  ), Kokkos::Impl::DynRankSubviewTag >::type
570  , SrcTraits
571  , Args ... >
572 {
573 private:
574 
575  enum
576  { RZ = false
584  };
585 
586  enum { rank = unsigned(R0) + unsigned(R1) + unsigned(R2) + unsigned(R3)
587  + unsigned(R4) + unsigned(R5) + unsigned(R6) };
588 
589  typedef Kokkos::LayoutStride array_layout ;
590 
591  typedef typename SrcTraits::value_type value_type ;
592 
593  typedef value_type******* data_type ;
594 
595 public:
596 
597  typedef Kokkos::ViewTraits
598  < data_type
599  , array_layout
600  , typename SrcTraits::device_type
601  , typename SrcTraits::memory_traits > traits_type ;
602 
603  typedef Kokkos::View
604  < data_type
605  , array_layout
606  , typename SrcTraits::device_type
607  , typename SrcTraits::memory_traits > type ;
608 
609 
610  template< class MemoryTraits >
611  struct apply {
612 
614 
615  typedef Kokkos::ViewTraits
616  < data_type
617  , array_layout
618  , typename SrcTraits::device_type
619  , MemoryTraits > traits_type ;
620 
621  typedef Kokkos::View
622  < data_type
623  , array_layout
624  , typename SrcTraits::device_type
625  , MemoryTraits > type ;
626  };
627 
628  template < class Arg0 = int, class Arg1 = int, class Arg2 = int, class Arg3 = int, class Arg4 = int, class Arg5 = int, class Arg6 = int >
629  struct ExtentGenerator {
630  template <typename dimension>
631  KOKKOS_INLINE_FUNCTION
632  static SubviewExtents< 7 , rank > generator ( const dimension & dim , Arg0 arg0 = Arg0(), Arg1 arg1 = Arg1(), Arg2 arg2 = Arg2(), Arg3 arg3 = Arg3(), Arg4 arg4 = Arg4(), Arg5 arg5 = Arg5(), Arg6 arg6 = Arg6() )
633  {
634  return SubviewExtents< 7 , rank >( dim , arg0 , arg1 , arg2 , arg3 ,
635  arg4 , arg5 , arg6 );
636  }
637  };
638 
639  template < class Arg0 = int, class Arg1 = int, class Arg2 = int, class Arg3 = int, class Arg4 = int, class Arg5 = int, class Arg6 = int >
640  struct ArrayExtentGenerator {
641  template <typename dimension>
642  KOKKOS_INLINE_FUNCTION
643  static SubviewExtents< 8 , rank+1 > generator ( const dimension & dim , Arg0 arg0 = Arg0(), Arg1 arg1 = Arg1(), Arg2 arg2 = Arg2(), Arg3 arg3 = Arg3(), Arg4 arg4 = Arg4(), Arg5 arg5 = Arg5(), Arg6 arg6 = Arg6() )
644  {
645  return SubviewExtents< 8 , rank+1 >( dim , arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , Kokkos::ALL() );
646  }
647  };
648 
649  typedef DynRankView< value_type , array_layout , typename SrcTraits::device_type , typename SrcTraits::memory_traits > ret_type;
650 
651  template < typename T , class ... P >
652  KOKKOS_INLINE_FUNCTION
653  static ret_type subview( const unsigned src_rank , Kokkos::DynRankView< T , P...> const & src , Args ... args )
654  {
655 
656  typedef ViewMapping< traits_type, typename traits_type::specialize> DstType ;
657  typedef ViewMapping< SrcTraits, typename SrcTraits::specialize> SrcType;
658  enum { FadStaticDim = SrcType::FadStaticDimension };
659  typedef typename std::conditional< (rank==0) , ViewDimension<>
660  , typename std::conditional< (rank==1) , ViewDimension<0>
661  , typename std::conditional< (rank==2) , ViewDimension<0,0>
662  , typename std::conditional< (rank==3) , ViewDimension<0,0,0>
663  , typename std::conditional< (rank==4) , ViewDimension<0,0,0,0>
664  , typename std::conditional< (rank==5) , ViewDimension<0,0,0,0,0>
665  , typename std::conditional< (rank==6) , ViewDimension<0,0,0,0,0,0>
666  , ViewDimension<0,0,0,0,0,0,0>
667  >::type >::type >::type >::type >::type >::type >::type DstDimType ;
668  typedef typename std::conditional< (rank==0) , ViewDimension<FadStaticDim>
669  , typename std::conditional< (rank==1) , ViewDimension<0,FadStaticDim>
670  , typename std::conditional< (rank==2) , ViewDimension<0,0,FadStaticDim>
671  , typename std::conditional< (rank==3) , ViewDimension<0,0,0,FadStaticDim>
672  , typename std::conditional< (rank==4) , ViewDimension<0,0,0,0,FadStaticDim>
673  , typename std::conditional< (rank==5) , ViewDimension<0,0,0,0,0,FadStaticDim>
674  , typename std::conditional< (rank==6) , ViewDimension<0,0,0,0,0,0,FadStaticDim>
675  , ViewDimension<0,0,0,0,0,0,0,FadStaticDim>
676  >::type >::type >::type >::type >::type >::type >::type DstArrayDimType ;
677 
678  typedef ViewOffset< DstDimType , Kokkos::LayoutStride > dst_offset_type ;
679  typedef ViewOffset< DstArrayDimType , Kokkos::LayoutStride > dst_array_offset_type ;
680  typedef typename DstType::handle_type dst_handle_type ;
681 
682  ret_type dst ;
683 
684  const SubviewExtents< 7 , rank > extents =
685  ExtentGenerator< Args ... >::generator(
686  src.m_map.m_impl_offset.m_dim , args... ) ;
687  const SubviewExtents< 8 , rank+1 > array_extents =
688  ArrayExtentGenerator< Args ... >::generator(
689  src.m_map.m_array_offset.m_dim , args... ) ;
690 
691  dst_offset_type tempdst( src.m_map.m_impl_offset , extents ) ;
692  dst_array_offset_type temparraydst(
693  src.m_map.m_array_offset , array_extents ) ;
694 
695  dst.m_track = src.m_track ;
696 
697  dst.m_map.m_impl_offset.m_dim.N0 = tempdst.m_dim.N0 ;
698  dst.m_map.m_impl_offset.m_dim.N1 = tempdst.m_dim.N1 ;
699  dst.m_map.m_impl_offset.m_dim.N2 = tempdst.m_dim.N2 ;
700  dst.m_map.m_impl_offset.m_dim.N3 = tempdst.m_dim.N3 ;
701  dst.m_map.m_impl_offset.m_dim.N4 = tempdst.m_dim.N4 ;
702  dst.m_map.m_impl_offset.m_dim.N5 = tempdst.m_dim.N5 ;
703  dst.m_map.m_impl_offset.m_dim.N6 = tempdst.m_dim.N6 ;
704 
705  dst.m_map.m_impl_offset.m_stride.S0 = tempdst.m_stride.S0;
706  dst.m_map.m_impl_offset.m_stride.S1 = tempdst.m_stride.S1;
707  dst.m_map.m_impl_offset.m_stride.S2 = tempdst.m_stride.S2;
708  dst.m_map.m_impl_offset.m_stride.S3 = tempdst.m_stride.S3;
709  dst.m_map.m_impl_offset.m_stride.S4 = tempdst.m_stride.S4;
710  dst.m_map.m_impl_offset.m_stride.S5 = tempdst.m_stride.S5;
711  dst.m_map.m_impl_offset.m_stride.S6 = tempdst.m_stride.S6;
712 
713  // Move last non-unit dim and stride to N7/S7 since subview collapses
714  // out all singleton dimensions between the last rank and the fad
715  // dimension. Equivalent to:
716  // dst.m_map.m_impl_offset.m_dim.N* = tempdst.m_dim.N*
717  // dst.m_map.m_impl_offset.m_dim.N7 = tempdst.m_dim.N{rank}
718  // dst.m_map.m_impl_offset.m_stride.S* = tempdst.m_stride.S*
719  // dst.m_map.m_impl_offset.m_stride.S7 = tempdst.m_stride.S{rank}
720  AssignFadDimStride<rank,FadStaticDim>::eval( dst.m_map.m_array_offset, temparraydst );
721 
722  dst.m_track = src.m_track ;
723 
724  dst.m_map.m_impl_handle =
725  dst_handle_type(
726  src.m_map.m_impl_handle +
727  src.m_map.m_array_offset( array_extents.domain_offset(0)
728  , array_extents.domain_offset(1)
729  , array_extents.domain_offset(2)
730  , array_extents.domain_offset(3)
731  , array_extents.domain_offset(4)
732  , array_extents.domain_offset(5)
733  , array_extents.domain_offset(6)
734  , array_extents.domain_offset(7)
735  ) );
736 
737  dst.m_map.m_fad_size = src.m_map.m_fad_size;
738  dst.m_map.m_fad_stride = src.m_map.m_fad_stride.value;
739 
740  dst.m_rank = ( src_rank > 0 ? unsigned(R0) : 0 )
741  + ( src_rank > 1 ? unsigned(R1) : 0 )
742  + ( src_rank > 2 ? unsigned(R2) : 0 )
743  + ( src_rank > 3 ? unsigned(R3) : 0 )
744  + ( src_rank > 4 ? unsigned(R4) : 0 )
745  + ( src_rank > 5 ? unsigned(R5) : 0 )
746  + ( src_rank > 6 ? unsigned(R6) : 0 ) ;
747 
748  return dst ;
749  }
750 };
751 
752 // ViewMapping for copy and copy-assign from View to DynRankView
753 template <unsigned> struct AssignFadDim7 {
754  template <typename Src, typename Dst>
755  KOKKOS_INLINE_FUNCTION
756  static void eval(Dst& dst, const Src& src , const unsigned dim ) {}
757 };
758 
759 template <> struct AssignFadDim7<0u> {
760  template <typename Src, typename Dst>
761  KOKKOS_INLINE_FUNCTION
762  static void eval(Dst& dst, const Src& src , const unsigned dim ) {
763  dst.m_dim.N7 = src.m_dim.extent(dim);
764  }
765 };
766 
767 // Copy a layout, moving the Fad dimension to the last
768 template <typename Layout>
769 KOKKOS_INLINE_FUNCTION
770 static Layout
771 permute_fad_layout(const Layout& src, const unsigned rank) {
772  Layout dst = src;
773  dst.dimension[rank] = 1;
774  dst.dimension[7] = src.dimension[rank];
775  return dst;
776 }
777 KOKKOS_INLINE_FUNCTION
778 static LayoutStride
779 permute_fad_layout(const LayoutStride& src, const unsigned rank) {
780  LayoutStride dst = src;
781  dst.dimension[rank] = 1;
782  dst.stride[rank] = 1;
783  dst.dimension[7] = src.dimension[rank];
784  dst.stride[7] = src.stride[rank];
785  return dst;
786 }
787 
792 template< class DstTraits , class SrcTraits >
793 class ViewMapping< DstTraits , SrcTraits ,
794  typename std::enable_if<(
795  Kokkos::Impl::MemorySpaceAccess
796  < typename DstTraits::memory_space
797  , typename SrcTraits::memory_space >::assignable
798  &&
799  // Destination view has FAD only
800  std::is_same< typename DstTraits::specialize
801  , Kokkos::Impl::ViewSpecializeSacadoFad >::value
802  &&
803  // Source view has FAD only
804  std::is_same< typename SrcTraits::specialize
805  , Kokkos::Impl::ViewSpecializeSacadoFad >::value
806  ), Kokkos::Impl::ViewToDynRankViewTag >::type >
807 {
808 public:
809 
810  enum { is_assignable = true };
811  enum { is_assignable_data_type = true };
812 
813  typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
814  typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
815  typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcFadType ;
816 
817  template < typename DT , typename ... DP , typename ST , typename ... SP >
818  KOKKOS_INLINE_FUNCTION static
819  void assign( Kokkos::DynRankView< DT , DP... > & dst
820  , const Kokkos::View< ST , SP... >& src )
821  {
822  static_assert(
823  (
824  std::is_same< typename DstTraits::array_layout
825  , Kokkos::LayoutLeft >::value ||
826  std::is_same< typename DstTraits::array_layout
827  , Kokkos::LayoutRight >::value ||
828  std::is_same< typename DstTraits::array_layout
829  , Kokkos::LayoutStride >::value
830  )
831  &&
832  (
833  std::is_same< typename SrcTraits::array_layout
834  , Kokkos::LayoutLeft >::value ||
835  std::is_same< typename SrcTraits::array_layout
836  , Kokkos::LayoutRight >::value ||
837  std::is_same< typename SrcTraits::array_layout
838  , Kokkos::LayoutStride >::value
839  )
840  , "View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
841 
842  static_assert(
843  std::is_same< typename DstTraits::value_type
844  , typename SrcTraits::value_type >::value ||
845  std::is_same< typename DstTraits::value_type
846  , typename SrcTraits::const_value_type >::value ,
847  "View assignment must have same value type or const = non-const" );
848 
849  typedef typename DstType::offset_type dst_offset_type;
850  typedef typename DstType::array_offset_type dst_array_offset_type;
851  dst.m_map.m_array_offset =
852  dst_array_offset_type(std::integral_constant<unsigned,0>(),
853  permute_fad_layout(src.m_map.m_array_offset.layout(),
854  SrcTraits::rank) );
855  dst.m_map.m_impl_offset =
856  dst_offset_type(std::integral_constant<unsigned,0>(),
857  src.m_map.m_impl_offset.layout() );
858 
859  dst.m_map.m_impl_handle = src.m_map.m_impl_handle ;
860  dst.m_rank = src.rank ;
861 
862  dst.m_map.m_fad_size = src.m_map.m_fad_size ;
863  dst.m_map.m_fad_stride = src.m_map.m_fad_stride ;
864  }
865 };
866 
871 template< class DstTraits , class SrcTraits >
872 class ViewMapping< DstTraits , SrcTraits ,
873  typename std::enable_if<(
874  Kokkos::Impl::MemorySpaceAccess
875  < typename DstTraits::memory_space
876  , typename SrcTraits::memory_space >::assignable
877  &&
878  // Destination view has ordinary
879  std::is_same< typename DstTraits::specialize , void >::value
880  &&
881  // Source view has FAD only
882  std::is_same< typename SrcTraits::specialize
883  , ViewSpecializeSacadoFad >::value
884  ), Kokkos::Impl::ViewToDynRankViewTag >::type >
885 {
886 public:
887 
888  enum { is_assignable = true };
889  enum { is_assignable_data_type = true };
890 
891  typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
892  typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
893  typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcFadType ;
894 
895  template < typename DT , typename ... DP , typename ST , typename ... SP >
896  KOKKOS_INLINE_FUNCTION static
897  void assign( Kokkos::DynRankView< DT , DP... > & dst
898  , const Kokkos::View< ST , SP... >& src )
899  {
900  static_assert(
901  (
902  std::is_same< typename DstTraits::array_layout
903  , Kokkos::LayoutLeft >::value ||
904  std::is_same< typename DstTraits::array_layout
905  , Kokkos::LayoutRight >::value ||
906  std::is_same< typename DstTraits::array_layout
907  , Kokkos::LayoutStride >::value
908  )
909  &&
910  (
911  std::is_same< typename SrcTraits::array_layout
912  , Kokkos::LayoutLeft >::value ||
913  std::is_same< typename SrcTraits::array_layout
914  , Kokkos::LayoutRight >::value ||
915  std::is_same< typename SrcTraits::array_layout
916  , Kokkos::LayoutStride >::value
917  )
918  , "View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
919 
920  static_assert(
921  std::is_same< typename DstTraits::value_type
922  , typename SrcTraits::value_type >::value ||
923  std::is_same< typename DstTraits::value_type
924  , typename SrcTraits::const_value_type >::value ,
925  "View assignment must have same value type or const = non-const" );
926 
927  typedef typename DstType::offset_type dst_offset_type;
928  dst.m_map.m_impl_offset =
929  dst_offset_type(std::integral_constant<unsigned,0>(),
930  permute_fad_layout(src.m_map.m_array_offset.layout(),
931  SrcTraits::rank));
932 
933  dst.m_map.m_impl_handle = src.m_map.m_impl_handle ;
934  dst.m_rank = src.Rank ;
935  }
936 };
937 
938 }} //end Kokkos::Impl
939 
940 namespace Kokkos {
941 
942 template <typename T, typename ... P>
943 struct is_dynrankview_fad< DynRankView<T,P...> > {
944  typedef DynRankView<T,P...> view_type;
945  static const bool value =
946  std::is_same< typename view_type::specialize,
947  Impl::ViewSpecializeSacadoFad >::value ||
948  std::is_same< typename view_type::specialize,
949  Impl::ViewSpecializeSacadoFadContiguous >::value;
950 };
951 
952 template <typename T, typename ... P>
953 struct is_dynrankview_fad_contiguous< DynRankView<T,P...> > {
954  typedef DynRankView<T,P...> view_type;
955  static const bool value =
956  std::is_same< typename view_type::specialize,
957  Impl::ViewSpecializeSacadoFadContiguous >::value;
958 };
959 
960 template <typename T, typename ... P>
961 KOKKOS_INLINE_FUNCTION
962 constexpr typename
963 std::enable_if< is_dynrankview_fad< DynRankView<T,P...> >::value, unsigned >::type
964 dimension_scalar(const DynRankView<T,P...>& view) {
965 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
966  return view.implementation_map().dimension_scalar();
967 #else
968  return view.impl_map().dimension_scalar();
969 #endif
970 }
971 
972 
973 // Overload of deep_copy for Fad views intializing to a constant scalar
974 
975 template< class DT, class ... DP >
976 void deep_copy(
977  const DynRankView<DT,DP...> & view ,
978  const typename Sacado::ScalarType< typename DynRankView<DT,DP...>::value_type >::type & value
979  , typename std::enable_if<(
980  std::is_same< typename ViewTraits<DT,DP...>::specialize
981  , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
982  std::is_same< typename ViewTraits<DT,DP...>::specialize
983  , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value
984  )>::type * = 0 )
985 {
986  static_assert(
987  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
988  typename ViewTraits<DT,DP...>::non_const_value_type >::value
989  , "Can only deep copy into non-const type" );
990 
991  switch(view.rank()) {
992  case 0: deep_copy(Impl::as_view_of_rank_n<0>(view), value); break;
993  case 1: deep_copy(Impl::as_view_of_rank_n<1>(view), value); break;
994  case 2: deep_copy(Impl::as_view_of_rank_n<2>(view), value); break;
995  case 3: deep_copy(Impl::as_view_of_rank_n<3>(view), value); break;
996  case 4: deep_copy(Impl::as_view_of_rank_n<4>(view), value); break;
997  case 5: deep_copy(Impl::as_view_of_rank_n<5>(view), value); break;
998  case 6: deep_copy(Impl::as_view_of_rank_n<6>(view), value); break;
999  case 7: deep_copy(Impl::as_view_of_rank_n<7>(view), value); break;
1000  }
1001 }
1002 
1003 // Overload of deep_copy for Fad views intializing to a constant Fad
1004 template< class DT, class ... DP >
1005 void deep_copy(
1006  const DynRankView<DT,DP...> & view ,
1007  const typename DynRankView<DT,DP...>::value_type & value
1008  , typename std::enable_if<(
1009  std::is_same< typename ViewTraits<DT,DP...>::specialize
1010  , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1011  std::is_same< typename ViewTraits<DT,DP...>::specialize
1012  , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value
1013  )>::type * = 0 )
1014 {
1015  static_assert(
1016  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
1017  typename ViewTraits<DT,DP...>::non_const_value_type >::value
1018  , "Can only deep copy into non-const type" );
1019 
1020  switch(view.rank()) {
1021  case 0: deep_copy(Impl::as_view_of_rank_n<0>(view), value); break;
1022  case 1: deep_copy(Impl::as_view_of_rank_n<1>(view), value); break;
1023  case 2: deep_copy(Impl::as_view_of_rank_n<2>(view), value); break;
1024  case 3: deep_copy(Impl::as_view_of_rank_n<3>(view), value); break;
1025  case 4: deep_copy(Impl::as_view_of_rank_n<4>(view), value); break;
1026  case 5: deep_copy(Impl::as_view_of_rank_n<5>(view), value); break;
1027  case 6: deep_copy(Impl::as_view_of_rank_n<6>(view), value); break;
1028  case 7: deep_copy(Impl::as_view_of_rank_n<7>(view), value); break;
1029  }
1030 }
1031 
1032 template< class DstType , class SrcType >
1033 inline
1034 void deep_copy
1035  ( const DstType & dst
1036  , const SrcType & src
1037  , typename std::enable_if<(
1038  ( std::is_same< typename DstType::traits::specialize
1039  , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1040  std::is_same< typename DstType::traits::specialize
1041  , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1042  &&
1043  ( std::is_same< typename SrcType::traits::specialize
1044  , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1045  std::is_same< typename SrcType::traits::specialize
1046  , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1047  &&
1048  ( Kokkos::is_dyn_rank_view<DstType>::value || Kokkos::is_dyn_rank_view<SrcType
1049 >::value )
1050  )>::type * = 0 )
1051 {
1052  static_assert(
1053  std::is_same< typename DstType::traits::value_type ,
1054  typename DstType::traits::non_const_value_type >::value
1055  , "deep_copy requires non-const destination type" );
1056 
1057  typedef DstType dst_type ;
1058  typedef SrcType src_type ;
1059 
1060  typedef typename dst_type::execution_space dst_execution_space ;
1061  typedef typename src_type::execution_space src_execution_space ;
1062  typedef typename dst_type::memory_space dst_memory_space ;
1063  typedef typename src_type::memory_space src_memory_space ;
1064 
1065  enum { DstExecCanAccessSrc =
1066  Kokkos::SpaceAccessibility< typename dst_execution_space::memory_space, src_memory_space >::accessible };
1067 
1068  enum { SrcExecCanAccessDst =
1069  Kokkos::SpaceAccessibility< typename src_execution_space::memory_space, dst_memory_space >::accessible };
1070 
1071  if ( (void *) dst.data() != (void*) src.data() ) {
1072 
1073  // Concern: If overlapping views then a parallel copy will be erroneous.
1074  // ...
1075 
1076  // If same type, equal layout, equal dimensions, equal span, and contiguous memory then can byte-wise copy
1077  if ( rank(src) == 0 && rank(dst) == 0 )
1078  {
1079  typedef typename dst_type::value_type::value_type value_type ;
1080  const size_t nbytes = sizeof(value_type) * dst.span() ;
1081  Kokkos::fence();
1082  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1083  Kokkos::fence();
1084  }
1085  else if ( std::is_same< typename DstType::traits::value_type ,
1086  typename SrcType::traits::non_const_value_type >::value &&
1087  (
1088  ( std::is_same< typename DstType::traits::array_layout ,
1089  typename SrcType::traits::array_layout >::value
1090  &&
1091  ( std::is_same< typename DstType::traits::array_layout ,
1092  typename Kokkos::LayoutLeft>::value
1093  ||
1094  std::is_same< typename DstType::traits::array_layout ,
1095  typename Kokkos::LayoutRight>::value
1096  )
1097  )
1098  ||
1099  (
1100  rank(dst) == 1
1101  &&
1102  rank(src) == 1
1103  )
1104  ) &&
1105  dst.span_is_contiguous() &&
1106  src.span_is_contiguous() &&
1107  dst.span() == src.span() &&
1108  dst.extent(0) == src.extent(0) &&
1109  dst.extent(1) == src.extent(1) &&
1110  dst.extent(2) == src.extent(2) &&
1111  dst.extent(3) == src.extent(3) &&
1112  dst.extent(4) == src.extent(4) &&
1113  dst.extent(5) == src.extent(5) &&
1114  dst.extent(6) == src.extent(6) &&
1115  dst.extent(7) == src.extent(7) ) {
1116 
1117 // const size_t nbytes = sizeof(typename dst_type::value_type) * dst.span() * dimension_scalar(dst) ;
1118  //const size_t nbytes = sizeof(typename dst_type::scalar_array_type) * dst.span() ;
1119  const size_t nbytes = sizeof(typename dst_type::value_type::value_type) * dst.span() ;
1120  //dst_type::value_type is outer FAD type, dst_type::value_type::value_type is inner FAD type
1121  Kokkos::fence();
1122  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1123  Kokkos::fence();
1124  }
1125  else if ( std::is_same< typename DstType::traits::value_type ,
1126  typename SrcType::traits::non_const_value_type >::value &&
1127  (
1128  ( std::is_same< typename DstType::traits::array_layout ,
1129  typename SrcType::traits::array_layout >::value
1130  &&
1131  std::is_same< typename DstType::traits::array_layout ,
1132  typename Kokkos::LayoutStride>::value
1133  )
1134  ||
1135  (
1136  rank(dst) == 1
1137  &&
1138  rank(src) == 1
1139  )
1140  ) &&
1141  dst.span_is_contiguous() &&
1142  src.span_is_contiguous() &&
1143  dst.span() == src.span() &&
1144  dst.extent(0) == src.extent(0) &&
1145  dst.extent(1) == src.extent(1) &&
1146  dst.extent(2) == src.extent(2) &&
1147  dst.extent(3) == src.extent(3) &&
1148  dst.extent(4) == src.extent(4) &&
1149  dst.extent(5) == src.extent(5) &&
1150  dst.extent(6) == src.extent(6) &&
1151  dst.extent(7) == src.extent(7) &&
1152  dst.stride_0() == src.stride_0() &&
1153  dst.stride_1() == src.stride_1() &&
1154  dst.stride_2() == src.stride_2() &&
1155  dst.stride_3() == src.stride_3() &&
1156  dst.stride_4() == src.stride_4() &&
1157  dst.stride_5() == src.stride_5() &&
1158  dst.stride_6() == src.stride_6() &&
1159  dst.stride_7() == src.stride_7()
1160  ) {
1161 
1162  const size_t nbytes = sizeof(typename dst_type::value_type::value_type) * dst.span() ;
1163  Kokkos::fence();
1164  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1165  Kokkos::fence();
1166  }
1167  else if ( DstExecCanAccessSrc ) {
1168  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
1169  Kokkos::fence();
1170  Kokkos::Impl::DynRankViewRemap< dst_type , src_type >( dst , src );
1171  Kokkos::fence();
1172  }
1173  else if ( SrcExecCanAccessDst ) {
1174  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
1175  Kokkos::fence();
1176  Kokkos::Impl::DynRankViewRemap< dst_type , src_type , src_execution_space >( dst , src );
1177  Kokkos::fence();
1178  }
1179  else {
1180  Kokkos::Impl::throw_runtime_exception("deep_copy given views that would require a temporary allocation");
1181  }
1182  }
1183  else {
1184  Kokkos::fence();
1185  }
1186 }
1187 
1188 template< class T , class ... P >
1189 inline
1190 typename Kokkos::DynRankView<T,P...>::HostMirror
1191 create_mirror( const Kokkos::DynRankView<T,P...> & src
1192  , typename std::enable_if<
1193  ( std::is_same< typename ViewTraits<T,P...>::specialize ,
1194  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1195  std::is_same< typename ViewTraits<T,P...>::specialize ,
1196  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1197  &&
1198  ! std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
1199  , Kokkos::LayoutStride >::value
1200  >::type *
1201  )
1202 {
1203  typedef DynRankView<T,P...> src_type ;
1204  typedef typename src_type::HostMirror dst_type ;
1205 
1206  typename src_type::array_layout layout = src.layout();
1207  layout.dimension[src.rank()] = Kokkos::dimension_scalar(src);
1208 
1209  return dst_type(std::string(src.label()).append("_mirror"),
1210  Impl::reconstructLayout(layout, src.rank()+1));
1211 }
1212 
1213 template< class T , class ... P >
1214 inline
1215 typename Kokkos::DynRankView<T,P...>::HostMirror
1216 create_mirror( const Kokkos::DynRankView<T,P...> & src
1217  , typename std::enable_if<
1218  ( std::is_same< typename ViewTraits<T,P...>::specialize ,
1219  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1220  std::is_same< typename ViewTraits<T,P...>::specialize ,
1221  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1222  &&
1223  std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
1224  , Kokkos::LayoutStride >::value
1225  >::type *
1226  )
1227 {
1228  typedef DynRankView<T,P...> src_type ;
1229  typedef typename src_type::HostMirror dst_type ;
1230 
1231  Kokkos::LayoutStride layout ;
1232 
1233  layout.dimension[0] = src.extent(0);
1234  layout.dimension[1] = src.extent(1);
1235  layout.dimension[2] = src.extent(2);
1236  layout.dimension[3] = src.extent(3);
1237  layout.dimension[4] = src.extent(4);
1238  layout.dimension[5] = src.extent(5);
1239  layout.dimension[6] = src.extent(6);
1240  layout.dimension[7] = src.extent(7);
1241 
1242  layout.stride[0] = src.stride_0();
1243  layout.stride[1] = src.stride_1();
1244  layout.stride[2] = src.stride_2();
1245  layout.stride[3] = src.stride_3();
1246  layout.stride[4] = src.stride_4();
1247  layout.stride[5] = src.stride_5();
1248  layout.stride[6] = src.stride_6();
1249  layout.stride[7] = src.stride_7();
1250 
1251  layout.dimension[src.rank()] = Kokkos::dimension_scalar(src);
1252 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
1253  layout.stride[src.rank()] = src.implementation_map().stride_scalar();
1254 #else
1255  layout.stride[src.rank()] = src.impl_map().stride_scalar();
1256 #endif
1257 
1258  return dst_type(std::string(src.label()).append("_mirror"),
1259  Impl::reconstructLayout(layout, src.rank()+1));
1260 }
1261 
1262 template<class Space, class T, class ... P>
1263 typename Impl::MirrorDRViewType<Space,T,P ...>::dest_view_type
1264 create_mirror(const Space& , const Kokkos::DynRankView<T,P...> & src
1265  , typename std::enable_if<
1266  ( std::is_same< typename ViewTraits<T,P...>::specialize ,
1267  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1268  std::is_same< typename ViewTraits<T,P...>::specialize ,
1269  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1270  >::type *) {
1271  typedef DynRankView<T,P...> src_type ;
1272  typename src_type::array_layout layout = src.layout();
1273  layout.dimension[src.rank()] = Kokkos::dimension_scalar(src);
1274  return typename Impl::MirrorDRViewType<Space,T,P ...>::dest_view_type(
1275  src.label(),Impl::reconstructLayout(layout, src.rank()+1));
1276 }
1277 
1278 namespace Impl {
1279 
1280 template <unsigned N, typename T, typename... Args>
1281 KOKKOS_FUNCTION auto as_view_of_rank_n(
1282  DynRankView<T, Args...> v,
1283  typename std::enable_if<
1284  ( std::is_same< typename ViewTraits<T,Args...>::specialize,
1285  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1286  std::is_same< typename ViewTraits<T,Args...>::specialize ,
1287  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1288  >::type*)
1289 {
1290  if (v.rank() != N) {
1291  KOKKOS_IF_ON_HOST(
1292  const std::string message =
1293  "Converting DynRankView of rank " + std::to_string(v.rank()) +
1294  " to a View of mis-matched rank " + std::to_string(N) + "!";
1295  Kokkos::abort(message.c_str());)
1296  KOKKOS_IF_ON_DEVICE(
1297  Kokkos::abort("Converting DynRankView to a View of mis-matched rank!");)
1298  }
1299 
1300  auto layout = v.impl_map().layout();
1301  layout.dimension[v.rank()] = Kokkos::dimension_scalar(v);
1302  return View<typename RankDataType<T, N>::type, Args...>(
1303  v.data(), Impl::reconstructLayout(layout, v.rank()+1));
1304 }
1305 
1306 }
1307 
1308 } // end Kokkos
1309 
1310 #endif //defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
1311 
1312 #endif // defined(HAVE_SACADO_KOKKOS)
1313 
1315 
1316 #endif /* #ifndef KOKKOS_DYN_RANK_VIEW_SACADO_FAD_HPP */
Base template specification for ScalarType.
#define T
Definition: Sacado_rad.hpp:553
const int N
const int fad_dim
int value
expr expr expr bar false