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