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  enum { is_assignable_data_type = true };
808 
809  typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
810  typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
811  typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcFadType ;
812 
813  template < typename DT , typename ... DP , typename ST , typename ... SP >
815  void assign( Kokkos::DynRankView< DT , DP... > & dst
816  , const Kokkos::View< ST , SP... >& src )
817  {
818  static_assert(
819  (
820  std::is_same< typename DstTraits::array_layout
821  , Kokkos::LayoutLeft >::value ||
822  std::is_same< typename DstTraits::array_layout
823  , Kokkos::LayoutRight >::value ||
824  std::is_same< typename DstTraits::array_layout
825  , Kokkos::LayoutStride >::value
826  )
827  &&
828  (
829  std::is_same< typename SrcTraits::array_layout
830  , Kokkos::LayoutLeft >::value ||
831  std::is_same< typename SrcTraits::array_layout
832  , Kokkos::LayoutRight >::value ||
833  std::is_same< typename SrcTraits::array_layout
834  , Kokkos::LayoutStride >::value
835  )
836  , "View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
837 
838  static_assert(
839  std::is_same< typename DstTraits::value_type
840  , typename SrcTraits::value_type >::value ||
841  std::is_same< typename DstTraits::value_type
842  , typename SrcTraits::const_value_type >::value ,
843  "View assignment must have same value type or const = non-const" );
844 
845  typedef typename DstType::offset_type dst_offset_type;
846  typedef typename DstType::array_offset_type dst_array_offset_type;
847  dst.m_map.m_array_offset =
848  dst_array_offset_type(std::integral_constant<unsigned,0>(),
849  permute_fad_layout(src.m_map.m_array_offset.layout(),
850  SrcTraits::rank) );
851  dst.m_map.m_impl_offset =
852  dst_offset_type(std::integral_constant<unsigned,0>(),
853  src.m_map.m_impl_offset.layout() );
854 
855  dst.m_map.m_impl_handle = src.m_map.m_impl_handle ;
856  dst.m_rank = src.Rank ;
857 
858  dst.m_map.m_fad_size = src.m_map.m_fad_size ;
859  dst.m_map.m_fad_stride = src.m_map.m_fad_stride ;
860  }
861 };
862 
867 template< class DstTraits , class SrcTraits >
868 class ViewMapping< DstTraits , SrcTraits ,
869  typename std::enable_if<(
870  Kokkos::Impl::MemorySpaceAccess
871  < typename DstTraits::memory_space
872  , typename SrcTraits::memory_space >::assignable
873  &&
874  // Destination view has ordinary
875  std::is_same< typename DstTraits::specialize , void >::value
876  &&
877  // Source view has FAD only
878  std::is_same< typename SrcTraits::specialize
879  , ViewSpecializeSacadoFad >::value
880  ), Kokkos::Impl::ViewToDynRankViewTag >::type >
881 {
882 public:
883 
884  enum { is_assignable = true };
885  enum { is_assignable_data_type = true };
886 
887  typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
888  typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
889  typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcFadType ;
890 
891  template < typename DT , typename ... DP , typename ST , typename ... SP >
893  void assign( Kokkos::DynRankView< DT , DP... > & dst
894  , const Kokkos::View< ST , SP... >& src )
895  {
896  static_assert(
897  (
898  std::is_same< typename DstTraits::array_layout
899  , Kokkos::LayoutLeft >::value ||
900  std::is_same< typename DstTraits::array_layout
901  , Kokkos::LayoutRight >::value ||
902  std::is_same< typename DstTraits::array_layout
903  , Kokkos::LayoutStride >::value
904  )
905  &&
906  (
907  std::is_same< typename SrcTraits::array_layout
908  , Kokkos::LayoutLeft >::value ||
909  std::is_same< typename SrcTraits::array_layout
910  , Kokkos::LayoutRight >::value ||
911  std::is_same< typename SrcTraits::array_layout
912  , Kokkos::LayoutStride >::value
913  )
914  , "View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
915 
916  static_assert(
917  std::is_same< typename DstTraits::value_type
918  , typename SrcTraits::value_type >::value ||
919  std::is_same< typename DstTraits::value_type
920  , typename SrcTraits::const_value_type >::value ,
921  "View assignment must have same value type or const = non-const" );
922 
923  typedef typename DstType::offset_type dst_offset_type;
924  dst.m_map.m_impl_offset =
925  dst_offset_type(std::integral_constant<unsigned,0>(),
926  permute_fad_layout(src.m_map.m_array_offset.layout(),
927  SrcTraits::rank));
928 
929  dst.m_map.m_impl_handle = src.m_map.m_impl_handle ;
930  dst.m_rank = src.Rank ;
931  }
932 };
933 
934 }} //end Kokkos::Impl
935 
936 namespace Kokkos {
937 
938 template <typename T, typename ... P>
939 struct is_dynrankview_fad< DynRankView<T,P...> > {
940  typedef DynRankView<T,P...> view_type;
941  static const bool value =
942  std::is_same< typename view_type::specialize,
943  Impl::ViewSpecializeSacadoFad >::value ||
944  std::is_same< typename view_type::specialize,
945  Impl::ViewSpecializeSacadoFadContiguous >::value;
946 };
947 
948 template <typename T, typename ... P>
949 struct is_dynrankview_fad_contiguous< DynRankView<T,P...> > {
950  typedef DynRankView<T,P...> view_type;
951  static const bool value =
952  std::is_same< typename view_type::specialize,
953  Impl::ViewSpecializeSacadoFadContiguous >::value;
954 };
955 
956 template <typename T, typename ... P>
958 constexpr typename
959 std::enable_if< is_dynrankview_fad< DynRankView<T,P...> >::value, unsigned >::type
960 dimension_scalar(const DynRankView<T,P...>& view) {
961 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
962  return view.implementation_map().dimension_scalar();
963 #else
964  return view.impl_map().dimension_scalar();
965 #endif
966 }
967 
968 
969 // Overload of deep_copy for Fad views intializing to a constant scalar
970 
971 template< class DT, class ... DP >
972 void deep_copy(
973  const DynRankView<DT,DP...> & view ,
974  const typename Sacado::ScalarType< typename DynRankView<DT,DP...>::value_type >::type & value
975  , typename std::enable_if<(
976  std::is_same< typename ViewTraits<DT,DP...>::specialize
977  , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
978  std::is_same< typename ViewTraits<DT,DP...>::specialize
979  , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value
980  )>::type * = 0 )
981 {
982  static_assert(
983  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
984  typename ViewTraits<DT,DP...>::non_const_value_type >::value
985  , "Can only deep copy into non-const type" );
986 
987  Kokkos::Impl::DynRankViewFill< DynRankView<DT,DP...> >( view , value );
988 }
989 
990 // Overload of deep_copy for Fad views intializing to a constant Fad
991 template< class DT, class ... DP >
992 void deep_copy(
993  const DynRankView<DT,DP...> & view ,
994  const typename DynRankView<DT,DP...>::value_type & value
995  , typename std::enable_if<(
996  std::is_same< typename ViewTraits<DT,DP...>::specialize
997  , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
998  std::is_same< typename ViewTraits<DT,DP...>::specialize
999  , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value
1000  )>::type * = 0 )
1001 {
1002  static_assert(
1003  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
1004  typename ViewTraits<DT,DP...>::non_const_value_type >::value
1005  , "Can only deep copy into non-const type" );
1006 
1007  Kokkos::Impl::DynRankViewFill< DynRankView<DT,DP...> >( view , value );
1008 }
1009 
1010 template< class DstType , class SrcType >
1011 inline
1012 void deep_copy
1013  ( const DstType & dst
1014  , const SrcType & src
1015  , typename std::enable_if<(
1016  ( std::is_same< typename DstType::traits::specialize
1017  , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1018  std::is_same< typename DstType::traits::specialize
1019  , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1020  &&
1021  ( std::is_same< typename SrcType::traits::specialize
1022  , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1023  std::is_same< typename SrcType::traits::specialize
1024  , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1025  &&
1026  ( Kokkos::is_dyn_rank_view<DstType>::value || Kokkos::is_dyn_rank_view<SrcType
1027 >::value )
1028  )>::type * = 0 )
1029 {
1030  static_assert(
1031  std::is_same< typename DstType::traits::value_type ,
1032  typename DstType::traits::non_const_value_type >::value
1033  , "deep_copy requires non-const destination type" );
1034 
1035  typedef DstType dst_type ;
1036  typedef SrcType src_type ;
1037 
1038  typedef typename dst_type::execution_space dst_execution_space ;
1039  typedef typename src_type::execution_space src_execution_space ;
1040  typedef typename dst_type::memory_space dst_memory_space ;
1041  typedef typename src_type::memory_space src_memory_space ;
1042 
1043  enum { DstExecCanAccessSrc =
1044  Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< typename dst_execution_space::memory_space , src_memory_space >::value };
1045 
1046  enum { SrcExecCanAccessDst =
1047  Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< typename src_execution_space::memory_space , dst_memory_space >::value };
1048 
1049  if ( (void *) dst.data() != (void*) src.data() ) {
1050 
1051  // Concern: If overlapping views then a parallel copy will be erroneous.
1052  // ...
1053 
1054  // If same type, equal layout, equal dimensions, equal span, and contiguous memory then can byte-wise copy
1055  if ( rank(src) == 0 && rank(dst) == 0 )
1056  {
1057  typedef typename dst_type::value_type::value_type value_type ;
1058  const size_t nbytes = sizeof(value_type) * dst.span() ;
1059  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1060  }
1061  else if ( std::is_same< typename DstType::traits::value_type ,
1062  typename SrcType::traits::non_const_value_type >::value &&
1063  (
1064  ( std::is_same< typename DstType::traits::array_layout ,
1065  typename SrcType::traits::array_layout >::value
1066  &&
1067  ( std::is_same< typename DstType::traits::array_layout ,
1068  typename Kokkos::LayoutLeft>::value
1069  ||
1070  std::is_same< typename DstType::traits::array_layout ,
1071  typename Kokkos::LayoutRight>::value
1072  )
1073  )
1074  ||
1075  (
1076  rank(dst) == 1
1077  &&
1078  rank(src) == 1
1079  )
1080  ) &&
1081  dst.span_is_contiguous() &&
1082  src.span_is_contiguous() &&
1083  dst.span() == src.span() &&
1084  dst.extent(0) == src.extent(0) &&
1085  dst.extent(1) == src.extent(1) &&
1086  dst.extent(2) == src.extent(2) &&
1087  dst.extent(3) == src.extent(3) &&
1088  dst.extent(4) == src.extent(4) &&
1089  dst.extent(5) == src.extent(5) &&
1090  dst.extent(6) == src.extent(6) &&
1091  dst.extent(7) == src.extent(7) ) {
1092 
1093 // const size_t nbytes = sizeof(typename dst_type::value_type) * dst.span() * dimension_scalar(dst) ;
1094  //const size_t nbytes = sizeof(typename dst_type::scalar_array_type) * dst.span() ;
1095  const size_t nbytes = sizeof(typename dst_type::value_type::value_type) * dst.span() ;
1096  //dst_type::value_type is outer FAD type, dst_type::value_type::value_type is inner FAD type
1097 
1098  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1099  }
1100  else if ( std::is_same< typename DstType::traits::value_type ,
1101  typename SrcType::traits::non_const_value_type >::value &&
1102  (
1103  ( std::is_same< typename DstType::traits::array_layout ,
1104  typename SrcType::traits::array_layout >::value
1105  &&
1106  std::is_same< typename DstType::traits::array_layout ,
1107  typename Kokkos::LayoutStride>::value
1108  )
1109  ||
1110  (
1111  rank(dst) == 1
1112  &&
1113  rank(src) == 1
1114  )
1115  ) &&
1116  dst.span_is_contiguous() &&
1117  src.span_is_contiguous() &&
1118  dst.span() == src.span() &&
1119  dst.extent(0) == src.extent(0) &&
1120  dst.extent(1) == src.extent(1) &&
1121  dst.extent(2) == src.extent(2) &&
1122  dst.extent(3) == src.extent(3) &&
1123  dst.extent(4) == src.extent(4) &&
1124  dst.extent(5) == src.extent(5) &&
1125  dst.extent(6) == src.extent(6) &&
1126  dst.extent(7) == src.extent(7) &&
1127  dst.stride_0() == src.stride_0() &&
1128  dst.stride_1() == src.stride_1() &&
1129  dst.stride_2() == src.stride_2() &&
1130  dst.stride_3() == src.stride_3() &&
1131  dst.stride_4() == src.stride_4() &&
1132  dst.stride_5() == src.stride_5() &&
1133  dst.stride_6() == src.stride_6() &&
1134  dst.stride_7() == src.stride_7()
1135  ) {
1136 
1137  const size_t nbytes = sizeof(typename dst_type::value_type::value_type) * dst.span() ;
1138 
1139  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1140  }
1141  else if ( DstExecCanAccessSrc ) {
1142  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
1143  Kokkos::Impl::DynRankViewRemap< dst_type , src_type >( dst , src );
1144  }
1145  else if ( SrcExecCanAccessDst ) {
1146  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
1147  Kokkos::Impl::DynRankViewRemap< dst_type , src_type , src_execution_space >( dst , src );
1148  }
1149  else {
1150  Kokkos::Impl::throw_runtime_exception("deep_copy given views that would require a temporary allocation");
1151  }
1152  }
1153 }
1154 
1155 template< class T , class ... P >
1156 inline
1157 typename Kokkos::DynRankView<T,P...>::HostMirror
1158 create_mirror( const Kokkos::DynRankView<T,P...> & src
1159  , typename std::enable_if<
1160  ( std::is_same< typename ViewTraits<T,P...>::specialize ,
1161  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1162  std::is_same< typename ViewTraits<T,P...>::specialize ,
1163  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1164  &&
1165  ! std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
1166  , Kokkos::LayoutStride >::value
1167  >::type *
1168  )
1169 {
1170  typedef DynRankView<T,P...> src_type ;
1171  typedef typename src_type::HostMirror dst_type ;
1172 
1173  typename src_type::array_layout layout = src.layout();
1174  layout.dimension[src.rank()] = Kokkos::dimension_scalar(src);
1175 
1176  return dst_type(std::string(src.label()).append("_mirror"),
1177  Impl::reconstructLayout(layout, src.rank()+1));
1178 }
1179 
1180 template< class T , class ... P >
1181 inline
1182 typename Kokkos::DynRankView<T,P...>::HostMirror
1183 create_mirror( const Kokkos::DynRankView<T,P...> & src
1184  , typename std::enable_if<
1185  ( std::is_same< typename ViewTraits<T,P...>::specialize ,
1186  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1187  std::is_same< typename ViewTraits<T,P...>::specialize ,
1188  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1189  &&
1190  std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
1191  , Kokkos::LayoutStride >::value
1192  >::type *
1193  )
1194 {
1195  typedef DynRankView<T,P...> src_type ;
1196  typedef typename src_type::HostMirror dst_type ;
1197 
1198  Kokkos::LayoutStride layout ;
1199 
1200  layout.dimension[0] = src.extent(0);
1201  layout.dimension[1] = src.extent(1);
1202  layout.dimension[2] = src.extent(2);
1203  layout.dimension[3] = src.extent(3);
1204  layout.dimension[4] = src.extent(4);
1205  layout.dimension[5] = src.extent(5);
1206  layout.dimension[6] = src.extent(6);
1207  layout.dimension[7] = src.extent(7);
1208 
1209  layout.stride[0] = src.stride_0();
1210  layout.stride[1] = src.stride_1();
1211  layout.stride[2] = src.stride_2();
1212  layout.stride[3] = src.stride_3();
1213  layout.stride[4] = src.stride_4();
1214  layout.stride[5] = src.stride_5();
1215  layout.stride[6] = src.stride_6();
1216  layout.stride[7] = src.stride_7();
1217 
1218  layout.dimension[src.rank()] = Kokkos::dimension_scalar(src);
1219 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
1220  layout.stride[src.rank()] = src.implementation_map().stride_scalar();
1221 #else
1222  layout.stride[src.rank()] = src.impl_map().stride_scalar();
1223 #endif
1224 
1225  return dst_type(std::string(src.label()).append("_mirror"),
1226  Impl::reconstructLayout(layout, src.rank()+1));
1227 }
1228 
1229 template<class Space, class T, class ... P>
1230 typename Impl::MirrorDRVType<Space,T,P ...>::view_type
1231 create_mirror(const Space& , const Kokkos::DynRankView<T,P...> & src
1232  , typename std::enable_if<
1233  ( std::is_same< typename ViewTraits<T,P...>::specialize ,
1234  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1235  std::is_same< typename ViewTraits<T,P...>::specialize ,
1236  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1237  >::type *) {
1238  typedef DynRankView<T,P...> src_type ;
1239  typename src_type::array_layout layout = src.layout();
1240  layout.dimension[src.rank()] = Kokkos::dimension_scalar(src);
1241  return typename Impl::MirrorDRVType<Space,T,P ...>::view_type(
1242  src.label(),Impl::reconstructLayout(layout, src.rank()+1));
1243 }
1244 
1245 } // end Kokkos
1246 
1247 #endif //defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
1248 
1249 #endif // defined(HAVE_SACADO_KOKKOSCONTAINERS)
1250 
1252 
1253 #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
const int fad_dim
expr expr expr bar false