Sacado Package Browser (Single Doxygen Collection)  Version of the Day
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 }
62 
63 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
64 
65 #include "Kokkos_View_Fad.hpp"
66 
67 namespace Kokkos {
68 
69 // Declare overloads of create_mirror() so they are in scope
70 // Kokkos_DynRankView.hpp is included below
71 
72 template< class T , class ... P >
73 inline
74 typename Kokkos::DynRankView<T,P...>::HostMirror
75 create_mirror(
76  const Kokkos::DynRankView<T,P...> & src,
77  typename std::enable_if<
78  ( std::is_same< typename ViewTraits<T,P...>::specialize ,
79  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
80  std::is_same< typename ViewTraits<T,P...>::specialize ,
81  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
82  !std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout,
83  Kokkos::LayoutStride >::value >::type * = 0);
84 
85 
86 template< class T , class ... P >
87 inline
88 typename Kokkos::DynRankView<T,P...>::HostMirror
89 create_mirror(
90  const Kokkos::DynRankView<T,P...> & src,
91  typename std::enable_if<
92  ( std::is_same< typename ViewTraits<T,P...>::specialize ,
93  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
94  std::is_same< typename ViewTraits<T,P...>::specialize ,
95  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
96  std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout,
97  Kokkos::LayoutStride >::value >::type * = 0);
98 
99 template<class Space, class T, class ... P>
100 typename Impl::MirrorDRVType<Space,T,P ...>::view_type
101 create_mirror(
102  const Space&,
103  const Kokkos::DynRankView<T,P...> & src,
104  typename std::enable_if<
105  std::is_same< typename ViewTraits<T,P...>::specialize ,
106  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
107  std::is_same< typename ViewTraits<T,P...>::specialize ,
108  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value >::type * = 0);
109 
110 } // namespace Kokkos
111 
112 #include "Kokkos_DynRankView.hpp"
113 
114 namespace Kokkos {
115 namespace Impl {
116 
117 template <>
118 struct DynRankDimTraits<Kokkos::Impl::ViewSpecializeSacadoFad> {
119 
120  enum : size_t{unspecified = ~size_t(0)};
121 
122  // Compute the rank of the view from the nonzero dimension arguments.
123  // For views of Fad, the rank is one less than the rank determined by the nonzero dimension args
125  static size_t computeRank( const size_t N0
126  , const size_t N1
127  , const size_t N2
128  , const size_t N3
129  , const size_t N4
130  , const size_t N5
131  , const size_t N6
132  , const size_t N7 )
133  {
134  return
135  ( (N7 == unspecified && N6 == unspecified && N5 == unspecified && N4 == unspecified && N3 == unspecified && N2 == unspecified && N1 == unspecified && N0 == unspecified) ? 0
136  : ( (N7 == unspecified && N6 == unspecified && N5 == unspecified && N4 == unspecified && N3 == unspecified && N2 == unspecified && N1 == unspecified) ? 0
137  : ( (N7 == unspecified && N6 == unspecified && N5 == unspecified && N4 == unspecified && N3 == unspecified && N2 == unspecified) ? 1
138  : ( (N7 == unspecified && N6 == unspecified && N5 == unspecified && N4 == unspecified && N3 == unspecified) ? 2
139  : ( (N7 == unspecified && N6 == unspecified && N5 == unspecified && N4 == unspecified) ? 3
140  : ( (N7 == unspecified && N6 == unspecified && N5 == unspecified) ? 4
141  : ( (N7 == unspecified && N6 == unspecified) ? 5
142  : ( (N7 == unspecified) ? 6
143  : 7 ) ) ) ) ) ) ) );
144  }
145 
146  // Compute the rank of the view from the nonzero layout arguments.
147  template <typename Layout>
149  static size_t computeRank( const Layout& layout )
150  {
151  return computeRank( layout.dimension[0]
152  , layout.dimension[1]
153  , layout.dimension[2]
154  , layout.dimension[3]
155  , layout.dimension[4]
156  , layout.dimension[5]
157  , layout.dimension[6]
158  , layout.dimension[7] );
159  }
160 
161  // Compute the rank of the view from the nonzero layout arguments and possible hidden dim
162  template <typename Layout, typename ... P>
164  static size_t computeRank( const ViewCtorProp<P...>& prop, const Layout& layout )
165  {
166  size_t rank = computeRank( layout.dimension[0]
167  , layout.dimension[1]
168  , layout.dimension[2]
169  , layout.dimension[3]
170  , layout.dimension[4]
171  , layout.dimension[5]
172  , layout.dimension[6]
173  , layout.dimension[7] );
174 
175  // Check if has_common_view_alloc_prop; if so, return rank+1, else rank
176  enum { test_traits_check = Kokkos::Impl::check_has_common_view_alloc_prop< P... >::value };
177  return (test_traits_check == true) ? rank+1 : rank;
178  }
179 
180  // Create the layout for the rank-7 view.
181  // For Fad we have to move the fad dimension to the last (rank 8 since the DynRankView is rank-7)
182  // LayoutLeft or LayoutRight
183  template <typename Layout>
185  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 )
186  {
187  Layout l( layout.dimension[0] != unspecified ? layout.dimension[0] : 1
188  , layout.dimension[1] != unspecified ? layout.dimension[1] : 1
189  , layout.dimension[2] != unspecified ? layout.dimension[2] : 1
190  , layout.dimension[3] != unspecified ? layout.dimension[3] : 1
191  , layout.dimension[4] != unspecified ? layout.dimension[4] : 1
192  , layout.dimension[5] != unspecified ? layout.dimension[5] : 1
193  , layout.dimension[6] != unspecified ? layout.dimension[6] : 1
194  , layout.dimension[7] != unspecified ? layout.dimension[7] : 1 );
195  const unsigned fad_dim = computeRank(layout);
196  const size_t fad_size = layout.dimension[fad_dim];
197  l.dimension[fad_dim] = 1;
198  l.dimension[7] = fad_size;
199 
200  return l;
201  }
202 
203  //LayoutStride
204  template <typename Layout>
206  static typename std::enable_if< (std::is_same<Layout , Kokkos::LayoutStride>::value) , Layout>::type createLayout( const Layout& layout )
207  {
208  Layout l( layout.dimension[0] != unspecified ? layout.dimension[0] : 1
209  , layout.stride[0]
210  , layout.dimension[1] != unspecified ? layout.dimension[1] : 1
211  , layout.stride[1]
212  , layout.dimension[2] != unspecified ? layout.dimension[2] : 1
213  , layout.stride[2]
214  , layout.dimension[3] != unspecified ? layout.dimension[3] : 1
215  , layout.stride[3]
216  , layout.dimension[4] != unspecified ? layout.dimension[4] : 1
217  , layout.stride[4]
218  , layout.dimension[5] != unspecified ? layout.dimension[5] : 1
219  , layout.stride[5]
220  , layout.dimension[6] != unspecified ? layout.dimension[6] : 1
221  , layout.stride[6]
222  , layout.dimension[7] != unspecified ? layout.dimension[7] : 1
223  , layout.stride[7]
224  );
225  const unsigned fad_dim = computeRank(layout);
226  const size_t fad_size = layout.dimension[fad_dim];
227  l.dimension[fad_dim] = 1;
228  l.dimension[7] = fad_size;
229  const size_t fad_stride = layout.stride[fad_dim];
230  l.stride[fad_dim] = 0;
231  l.stride[7] = fad_stride;
232 
233  return l;
234  }
235 
236  // If fad_dim is stored in ViewCtorProp
237  // LayoutLeft or LayoutRight
238  template <typename Traits, typename ... P>
240  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 )
241  {
242  using Layout = typename Traits::array_layout;
243 
244  Layout l( layout.dimension[0] != unspecified ? layout.dimension[0] : 1
245  , layout.dimension[1] != unspecified ? layout.dimension[1] : 1
246  , layout.dimension[2] != unspecified ? layout.dimension[2] : 1
247  , layout.dimension[3] != unspecified ? layout.dimension[3] : 1
248  , layout.dimension[4] != unspecified ? layout.dimension[4] : 1
249  , layout.dimension[5] != unspecified ? layout.dimension[5] : 1
250  , layout.dimension[6] != unspecified ? layout.dimension[6] : 1
251  , layout.dimension[7] != unspecified ? layout.dimension[7] : 1 );
252 
253  enum { test_traits_check = Kokkos::Impl::check_has_common_view_alloc_prop< P... >::value };
254  if (test_traits_check == true) {
255  using CVTR_type = typename Kokkos::Impl::CommonViewAllocProp< typename Kokkos::Impl::ViewSpecializeSacadoFad, typename Traits::value_type >;
256  auto cast_prop = ((Kokkos::Impl::ViewCtorProp<void, CVTR_type> const &)arg_prop).value;
257  l.dimension[7] = cast_prop.fad_dim;
258  }
259  else {
260  const unsigned fad_dim = computeRank(layout);
261  const size_t fad_size = layout.dimension[fad_dim];
262  l.dimension[fad_dim] = 1;
263  l.dimension[7] = fad_size;
264  }
265 
266  return l;
267  }
268 
269  // If fad_dim is stored in ViewCtorProp
270  //LayoutStride
271  template <typename Traits, typename ... P>
273  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 )
274  {
275  using Layout = typename Traits::array_layout;
276 
277  Layout l( layout.dimension[0] != unspecified ? layout.dimension[0] : 1
278  , layout.stride[0]
279  , layout.dimension[1] != unspecified ? layout.dimension[1] : 1
280  , layout.stride[1]
281  , layout.dimension[2] != unspecified ? layout.dimension[2] : 1
282  , layout.stride[2]
283  , layout.dimension[3] != unspecified ? layout.dimension[3] : 1
284  , layout.stride[3]
285  , layout.dimension[4] != unspecified ? layout.dimension[4] : 1
286  , layout.stride[4]
287  , layout.dimension[5] != unspecified ? layout.dimension[5] : 1
288  , layout.stride[5]
289  , layout.dimension[6] != unspecified ? layout.dimension[6] : 1
290  , layout.stride[6]
291  , layout.dimension[7] != unspecified ? layout.dimension[7] : 1
292  , layout.stride[7]
293  );
294 
295  enum { test_traits_check = Kokkos::Impl::check_has_common_view_alloc_prop< P... >::value };
296  const unsigned fad_dim = computeRank(layout);
297  if (test_traits_check == true) {
298  using CVTR_type = typename Kokkos::Impl::CommonViewAllocProp< typename Kokkos::Impl::ViewSpecializeSacadoFad, typename Traits::value_type >;
299  auto cast_prop = ((Kokkos::Impl::ViewCtorProp<void, CVTR_type> const &)arg_prop).value;
300  l.dimension[fad_dim] = 1;
301  l.dimension[7] = cast_prop.fad_dim;
302  }
303  else {
304  const size_t fad_size = layout.dimension[fad_dim];
305  l.dimension[fad_dim] = 1;
306  l.dimension[7] = fad_size;
307  }
308  const size_t fad_stride = layout.stride[fad_dim];
309  l.stride[fad_dim] = 0;
310  l.stride[7] = fad_stride;
311 
312  return l;
313  }
314 
315  // Create a view from the given dimension arguments.
316  // This is only necessary because the shmem constructor doesn't take a layout.
317  template <typename ViewType, typename ViewArg>
318  static ViewType createView( const ViewArg& arg
319  , const size_t N0
320  , const size_t N1
321  , const size_t N2
322  , const size_t N3
323  , const size_t N4
324  , const size_t N5
325  , const size_t N6
326  , const size_t N7 )
327  {
328  typename ViewType::array_layout l( N0, N1, N2, N3, N4, N5, N6, N7 );
329  typename ViewType::array_layout l_fad = createLayout(l);
330  return ViewType( arg
331  , l_fad.dimension[0]
332  , l_fad.dimension[1]
333  , l_fad.dimension[2]
334  , l_fad.dimension[3]
335  , l_fad.dimension[4]
336  , l_fad.dimension[5]
337  , l_fad.dimension[6]
338  , l_fad.dimension[7] );
339  }
340 
341 };
342 
343 }} // namespace Kokkos::Impl
344 
345 namespace Kokkos {
346 namespace Impl {
347 
348 template <unsigned> struct AssignDim7 {
349  template <typename Dst>
351  static void eval(Dst& dst, const size_t& src_dim) {}
352 };
353 template <> struct AssignDim7<0u> {
354  template <typename Dst>
356  static void eval(Dst& dst, const size_t& src_dim) {
357  dst.N7 = src_dim;
358  }
359 };
360 
361 // Utility class that handles calculation of the stride in Fad subview
362 template <unsigned,unsigned> struct AssignFadDimStride {};
363 template <unsigned StaticDim> struct AssignFadDimStride<0u,StaticDim> {
364  template <typename Src, typename Dst>
366  static void eval(Dst& dst, const Src& src) {
367  dst.m_stride.S0 = 0 ;
368  dst.m_stride.S1 = 0 ;
369  dst.m_stride.S2 = 0 ;
370  dst.m_stride.S3 = 0 ;
371  dst.m_stride.S4 = 0 ;
372  dst.m_stride.S5 = 0 ;
373  dst.m_stride.S6 = 0 ;
374  dst.m_stride.S7 = src.m_stride.S0 ;
375 
376  dst.m_dim.N0 = 1 ;
377  dst.m_dim.N1 = 1 ;
378  dst.m_dim.N2 = 1 ;
379  dst.m_dim.N3 = 1 ;
380  dst.m_dim.N4 = 1 ;
381  dst.m_dim.N5 = 1 ;
382  dst.m_dim.N6 = 1 ;
383  AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N0 );
384  }
385 };
386 template <unsigned StaticDim> struct AssignFadDimStride<1u,StaticDim> {
387  template <typename Src, typename Dst>
389  static void eval(Dst& dst, const Src& src) {
390  dst.m_stride.S0 = src.m_stride.S0 ;
391  dst.m_stride.S1 = 0 ;
392  dst.m_stride.S2 = 0 ;
393  dst.m_stride.S3 = 0 ;
394  dst.m_stride.S4 = 0 ;
395  dst.m_stride.S5 = 0 ;
396  dst.m_stride.S6 = 0 ;
397  dst.m_stride.S7 = src.m_stride.S1 ;
398 
399  dst.m_dim.N0 = src.m_dim.N0 ;
400  dst.m_dim.N1 = 1 ;
401  dst.m_dim.N2 = 1 ;
402  dst.m_dim.N3 = 1 ;
403  dst.m_dim.N4 = 1 ;
404  dst.m_dim.N5 = 1 ;
405  dst.m_dim.N6 = 1 ;
406  AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N1 );
407  }
408 };
409 template <unsigned StaticDim> struct AssignFadDimStride<2u,StaticDim> {
410  template <typename Src, typename Dst>
412  static void eval(Dst& dst, const Src& src) {
413  dst.m_stride.S0 = src.m_stride.S0 ;
414  dst.m_stride.S1 = src.m_stride.S1 ;
415  dst.m_stride.S2 = 0 ;
416  dst.m_stride.S3 = 0 ;
417  dst.m_stride.S4 = 0 ;
418  dst.m_stride.S5 = 0 ;
419  dst.m_stride.S6 = 0 ;
420  dst.m_stride.S7 = src.m_stride.S2 ;
421 
422  dst.m_dim.N0 = src.m_dim.N0 ;
423  dst.m_dim.N1 = src.m_dim.N1 ;
424  dst.m_dim.N2 = 1 ;
425  dst.m_dim.N3 = 1 ;
426  dst.m_dim.N4 = 1 ;
427  dst.m_dim.N5 = 1 ;
428  dst.m_dim.N6 = 1 ;
429  AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N2 );
430  }
431 };
432 template <unsigned StaticDim> struct AssignFadDimStride<3u,StaticDim> {
433  template <typename Src, typename Dst>
435  static void eval(Dst& dst, const Src& src) {
436  dst.m_stride.S0 = src.m_stride.S0 ;
437  dst.m_stride.S1 = src.m_stride.S1 ;
438  dst.m_stride.S2 = src.m_stride.S2 ;
439  dst.m_stride.S3 = 0 ;
440  dst.m_stride.S4 = 0 ;
441  dst.m_stride.S5 = 0 ;
442  dst.m_stride.S6 = 0 ;
443  dst.m_stride.S7 = src.m_stride.S3 ;
444 
445  dst.m_dim.N0 = src.m_dim.N0 ;
446  dst.m_dim.N1 = src.m_dim.N1 ;
447  dst.m_dim.N2 = src.m_dim.N2 ;
448  dst.m_dim.N3 = 1 ;
449  dst.m_dim.N4 = 1 ;
450  dst.m_dim.N5 = 1 ;
451  dst.m_dim.N6 = 1 ;
452  AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N3 );
453  }
454 };
455 template <unsigned StaticDim> struct AssignFadDimStride<4u,StaticDim> {
456  template <typename Src, typename Dst>
458  static void eval(Dst& dst, const Src& src) {
459  dst.m_stride.S0 = src.m_stride.S0 ;
460  dst.m_stride.S1 = src.m_stride.S1 ;
461  dst.m_stride.S2 = src.m_stride.S2 ;
462  dst.m_stride.S3 = src.m_stride.S3 ;
463  dst.m_stride.S4 = 0 ;
464  dst.m_stride.S5 = 0 ;
465  dst.m_stride.S6 = 0 ;
466  dst.m_stride.S7 = src.m_stride.S4 ;
467 
468  dst.m_dim.N0 = src.m_dim.N0 ;
469  dst.m_dim.N1 = src.m_dim.N1 ;
470  dst.m_dim.N2 = src.m_dim.N2 ;
471  dst.m_dim.N3 = src.m_dim.N3 ;
472  dst.m_dim.N4 = 1 ;
473  dst.m_dim.N5 = 1 ;
474  dst.m_dim.N6 = 1 ;
475  AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N4 );
476  }
477 };
478 template <unsigned StaticDim> struct AssignFadDimStride<5u,StaticDim> {
479  template <typename Src, typename Dst>
481  static void eval(Dst& dst, const Src& src) {
482  dst.m_stride.S0 = src.m_stride.S0 ;
483  dst.m_stride.S1 = src.m_stride.S1 ;
484  dst.m_stride.S2 = src.m_stride.S2 ;
485  dst.m_stride.S3 = src.m_stride.S3 ;
486  dst.m_stride.S4 = src.m_stride.S4 ;
487  dst.m_stride.S5 = 0 ;
488  dst.m_stride.S6 = 0 ;
489  dst.m_stride.S7 = src.m_stride.S5 ;
490 
491  dst.m_dim.N0 = src.m_dim.N0 ;
492  dst.m_dim.N1 = src.m_dim.N1 ;
493  dst.m_dim.N2 = src.m_dim.N2 ;
494  dst.m_dim.N3 = src.m_dim.N3 ;
495  dst.m_dim.N4 = src.m_dim.N4 ;
496  dst.m_dim.N5 = 1 ;
497  dst.m_dim.N6 = 1 ;
498  AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N5 );
499  }
500 };
501 template <unsigned StaticDim> struct AssignFadDimStride<6u,StaticDim> {
502  template <typename Src, typename Dst>
504  static void eval(Dst& dst, const Src& src) {
505  dst.m_stride.S0 = src.m_stride.S0 ;
506  dst.m_stride.S1 = src.m_stride.S1 ;
507  dst.m_stride.S2 = src.m_stride.S2 ;
508  dst.m_stride.S3 = src.m_stride.S3 ;
509  dst.m_stride.S4 = src.m_stride.S4 ;
510  dst.m_stride.S5 = src.m_stride.S5 ;
511  dst.m_stride.S6 = 0 ;
512  dst.m_stride.S7 = src.m_stride.S6 ;
513 
514  dst.m_dim.N0 = src.m_dim.N0 ;
515  dst.m_dim.N1 = src.m_dim.N1 ;
516  dst.m_dim.N2 = src.m_dim.N2 ;
517  dst.m_dim.N3 = src.m_dim.N3 ;
518  dst.m_dim.N4 = src.m_dim.N4 ;
519  dst.m_dim.N5 = src.m_dim.N5 ;
520  dst.m_dim.N6 = 1 ;
521  AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N6 );
522  }
523 };
524 template <unsigned StaticDim> struct AssignFadDimStride<7u,StaticDim> {
525  template <typename Src, typename Dst>
527  static void eval(Dst& dst, const Src& src) {
528  dst.m_stride.S0 = src.m_stride.S0 ;
529  dst.m_stride.S1 = src.m_stride.S1 ;
530  dst.m_stride.S2 = src.m_stride.S2 ;
531  dst.m_stride.S3 = src.m_stride.S3 ;
532  dst.m_stride.S4 = src.m_stride.S4 ;
533  dst.m_stride.S5 = src.m_stride.S5 ;
534  dst.m_stride.S6 = src.m_stride.S6 ;
535  dst.m_stride.S7 = src.m_stride.S7 ;
536 
537  dst.m_dim.N0 = src.m_dim.N0 ;
538  dst.m_dim.N1 = src.m_dim.N1 ;
539  dst.m_dim.N2 = src.m_dim.N2 ;
540  dst.m_dim.N3 = src.m_dim.N3 ;
541  dst.m_dim.N4 = src.m_dim.N4 ;
542  dst.m_dim.N5 = src.m_dim.N5 ;
543  dst.m_dim.N6 = src.m_dim.N6 ;
544  AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N7 );
545  }
546 };
547 
548 // Specializations for subdynrankview
549 template< class SrcTraits , class ... Args >
550 struct ViewMapping
551  < typename std::enable_if<(
552  std::is_same< typename SrcTraits::specialize ,
553  Kokkos::Impl::ViewSpecializeSacadoFad >::value
554  &&
555  (
556  std::is_same< typename SrcTraits::array_layout
557  , Kokkos::LayoutLeft >::value ||
558  std::is_same< typename SrcTraits::array_layout
559  , Kokkos::LayoutRight >::value ||
560  std::is_same< typename SrcTraits::array_layout
561  , Kokkos::LayoutStride >::value
562  )
563  ), Kokkos::Impl::DynRankSubviewTag >::type
564  , SrcTraits
565  , Args ... >
566 {
567 private:
568 
569  enum
570  { RZ = false
571  , R0 = bool(is_integral_extent<0,Args...>::value)
572  , R1 = bool(is_integral_extent<1,Args...>::value)
573  , R2 = bool(is_integral_extent<2,Args...>::value)
574  , R3 = bool(is_integral_extent<3,Args...>::value)
575  , R4 = bool(is_integral_extent<4,Args...>::value)
576  , R5 = bool(is_integral_extent<5,Args...>::value)
577  , R6 = bool(is_integral_extent<6,Args...>::value)
578  };
579 
580  enum { rank = unsigned(R0) + unsigned(R1) + unsigned(R2) + unsigned(R3)
581  + unsigned(R4) + unsigned(R5) + unsigned(R6) };
582 
583  typedef Kokkos::LayoutStride array_layout ;
584 
585  typedef typename SrcTraits::value_type value_type ;
586 
587  typedef value_type******* data_type ;
588 
589 public:
590 
591  typedef Kokkos::ViewTraits
592  < data_type
593  , array_layout
594  , typename SrcTraits::device_type
595  , typename SrcTraits::memory_traits > traits_type ;
596 
597  typedef Kokkos::View
598  < data_type
599  , array_layout
600  , typename SrcTraits::device_type
601  , typename SrcTraits::memory_traits > type ;
602 
603 
604  template< class MemoryTraits >
605  struct apply {
606 
607  static_assert( Kokkos::Impl::is_memory_traits< MemoryTraits >::value , "" );
608 
609  typedef Kokkos::ViewTraits
610  < data_type
611  , array_layout
612  , typename SrcTraits::device_type
613  , MemoryTraits > traits_type ;
614 
615  typedef Kokkos::View
616  < data_type
617  , array_layout
618  , typename SrcTraits::device_type
619  , MemoryTraits > type ;
620  };
621 
622  template < class Arg0 = int, class Arg1 = int, class Arg2 = int, class Arg3 = int, class Arg4 = int, class Arg5 = int, class Arg6 = int >
623  struct ExtentGenerator {
624  template <typename dimension>
626  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() )
627  {
628  return SubviewExtents< 7 , rank >( dim , arg0 , arg1 , arg2 , arg3 ,
629  arg4 , arg5 , arg6 );
630  }
631  };
632 
633  template < class Arg0 = int, class Arg1 = int, class Arg2 = int, class Arg3 = int, class Arg4 = int, class Arg5 = int, class Arg6 = int >
634  struct ArrayExtentGenerator {
635  template <typename dimension>
637  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() )
638  {
639  return SubviewExtents< 8 , rank+1 >( dim , arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , Kokkos::ALL() );
640  }
641  };
642 
643  typedef DynRankView< value_type , array_layout , typename SrcTraits::device_type , typename SrcTraits::memory_traits > ret_type;
644 
645  template < typename T , class ... P >
647  static ret_type subview( const unsigned src_rank , Kokkos::DynRankView< T , P...> const & src , Args ... args )
648  {
649 
650  typedef ViewMapping< traits_type, void > DstType ;
651  typedef ViewMapping< SrcTraits, void> SrcType;
652  enum { FadStaticDim = SrcType::FadStaticDimension };
653  typedef typename std::conditional< (rank==0) , ViewDimension<>
654  , typename std::conditional< (rank==1) , ViewDimension<0>
655  , typename std::conditional< (rank==2) , ViewDimension<0,0>
656  , typename std::conditional< (rank==3) , ViewDimension<0,0,0>
657  , typename std::conditional< (rank==4) , ViewDimension<0,0,0,0>
658  , typename std::conditional< (rank==5) , ViewDimension<0,0,0,0,0>
659  , typename std::conditional< (rank==6) , ViewDimension<0,0,0,0,0,0>
660  , ViewDimension<0,0,0,0,0,0,0>
661  >::type >::type >::type >::type >::type >::type >::type DstDimType ;
662  typedef typename std::conditional< (rank==0) , ViewDimension<FadStaticDim>
663  , typename std::conditional< (rank==1) , ViewDimension<0,FadStaticDim>
664  , typename std::conditional< (rank==2) , ViewDimension<0,0,FadStaticDim>
665  , typename std::conditional< (rank==3) , ViewDimension<0,0,0,FadStaticDim>
666  , typename std::conditional< (rank==4) , ViewDimension<0,0,0,0,FadStaticDim>
667  , typename std::conditional< (rank==5) , ViewDimension<0,0,0,0,0,FadStaticDim>
668  , typename std::conditional< (rank==6) , ViewDimension<0,0,0,0,0,0,FadStaticDim>
669  , ViewDimension<0,0,0,0,0,0,0,FadStaticDim>
670  >::type >::type >::type >::type >::type >::type >::type DstArrayDimType ;
671 
672  typedef ViewOffset< DstDimType , Kokkos::LayoutStride > dst_offset_type ;
673  typedef ViewOffset< DstArrayDimType , Kokkos::LayoutStride > dst_array_offset_type ;
674  typedef typename DstType::handle_type dst_handle_type ;
675 
676  ret_type dst ;
677 
678  const SubviewExtents< 7 , rank > extents =
679  ExtentGenerator< Args ... >::generator(
680  src.m_map.m_offset.m_dim , args... ) ;
681  const SubviewExtents< 8 , rank+1 > array_extents =
682  ArrayExtentGenerator< Args ... >::generator(
683  src.m_map.m_array_offset.m_dim , args... ) ;
684 
685  dst_offset_type tempdst( src.m_map.m_offset , extents ) ;
686  dst_array_offset_type temparraydst(
687  src.m_map.m_array_offset , array_extents ) ;
688 
689  dst.m_track = src.m_track ;
690 
691  dst.m_map.m_offset.m_dim.N0 = tempdst.m_dim.N0 ;
692  dst.m_map.m_offset.m_dim.N1 = tempdst.m_dim.N1 ;
693  dst.m_map.m_offset.m_dim.N2 = tempdst.m_dim.N2 ;
694  dst.m_map.m_offset.m_dim.N3 = tempdst.m_dim.N3 ;
695  dst.m_map.m_offset.m_dim.N4 = tempdst.m_dim.N4 ;
696  dst.m_map.m_offset.m_dim.N5 = tempdst.m_dim.N5 ;
697  dst.m_map.m_offset.m_dim.N6 = tempdst.m_dim.N6 ;
698 
699  dst.m_map.m_offset.m_stride.S0 = tempdst.m_stride.S0;
700  dst.m_map.m_offset.m_stride.S1 = tempdst.m_stride.S1;
701  dst.m_map.m_offset.m_stride.S2 = tempdst.m_stride.S2;
702  dst.m_map.m_offset.m_stride.S3 = tempdst.m_stride.S3;
703  dst.m_map.m_offset.m_stride.S4 = tempdst.m_stride.S4;
704  dst.m_map.m_offset.m_stride.S5 = tempdst.m_stride.S5;
705  dst.m_map.m_offset.m_stride.S6 = tempdst.m_stride.S6;
706 
707  // Move last non-unit dim and stride to N7/S7 since subview collapses
708  // out all singleton dimensions between the last rank and the fad
709  // dimension. Equivalent to:
710  // dst.m_map.m_offset.m_dim.N* = tempdst.m_dim.N*
711  // dst.m_map.m_offset.m_dim.N7 = tempdst.m_dim.N{rank}
712  // dst.m_map.m_offset.m_stride.S* = tempdst.m_stride.S*
713  // dst.m_map.m_offset.m_stride.S7 = tempdst.m_stride.S{rank}
714  AssignFadDimStride<rank,FadStaticDim>::eval( dst.m_map.m_array_offset, temparraydst );
715 
716  dst.m_track = src.m_track ;
717 
718  dst.m_map.m_handle =
719  dst_handle_type(
720  src.m_map.m_handle +
721  src.m_map.m_array_offset( array_extents.domain_offset(0)
722  , array_extents.domain_offset(1)
723  , array_extents.domain_offset(2)
724  , array_extents.domain_offset(3)
725  , array_extents.domain_offset(4)
726  , array_extents.domain_offset(5)
727  , array_extents.domain_offset(6)
728  , array_extents.domain_offset(7)
729  ) );
730 
731  dst.m_map.m_fad_size = src.m_map.m_fad_size;
732  dst.m_map.m_fad_stride = src.m_map.m_fad_stride.value;
733 
734  dst.m_rank = ( src_rank > 0 ? unsigned(R0) : 0 )
735  + ( src_rank > 1 ? unsigned(R1) : 0 )
736  + ( src_rank > 2 ? unsigned(R2) : 0 )
737  + ( src_rank > 3 ? unsigned(R3) : 0 )
738  + ( src_rank > 4 ? unsigned(R4) : 0 )
739  + ( src_rank > 5 ? unsigned(R5) : 0 )
740  + ( src_rank > 6 ? unsigned(R6) : 0 ) ;
741 
742  return dst ;
743  }
744 };
745 
746 // ViewMapping for copy and copy-assign from View to DynRankView
747 template <unsigned> struct AssignFadDim7 {
748  template <typename Src, typename Dst>
750  static void eval(Dst& dst, const Src& src , const unsigned dim ) {}
751 };
752 
753 template <> struct AssignFadDim7<0u> {
754  template <typename Src, typename Dst>
756  static void eval(Dst& dst, const Src& src , const unsigned dim ) {
757  dst.m_dim.N7 = src.m_dim.extent(dim);
758  }
759 };
760 
761 // Copy a layout, moving the Fad dimension to the last
762 template <typename Layout>
764 static Layout
765 permute_fad_layout(const Layout& src, const unsigned rank) {
766  Layout dst = src;
767  dst.dimension[rank] = 1;
768  dst.dimension[7] = src.dimension[rank];
769  return dst;
770 }
772 static LayoutStride
773 permute_fad_layout(const LayoutStride& src, const unsigned rank) {
774  LayoutStride dst = src;
775  dst.dimension[rank] = 1;
776  dst.stride[rank] = 1;
777  dst.dimension[7] = src.dimension[rank];
778  dst.stride[7] = src.stride[rank];
779  return dst;
780 }
781 
786 template< class DstTraits , class SrcTraits >
787 class ViewMapping< DstTraits , SrcTraits ,
788  typename std::enable_if<(
789  Kokkos::Impl::MemorySpaceAccess
790  < typename DstTraits::memory_space
791  , typename SrcTraits::memory_space >::assignable
792  &&
793  // Destination view has FAD only
794  std::is_same< typename DstTraits::specialize
795  , Kokkos::Impl::ViewSpecializeSacadoFad >::value
796  &&
797  // Source view has FAD only
798  std::is_same< typename SrcTraits::specialize
799  , Kokkos::Impl::ViewSpecializeSacadoFad >::value
800  ), Kokkos::Impl::ViewToDynRankViewTag >::type >
801 {
802 public:
803 
804  enum { is_assignable = true };
805 
806  typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
807  typedef ViewMapping< DstTraits , void > DstType ;
808  typedef ViewMapping< SrcTraits , void > SrcFadType ;
809 
810  template < typename DT , typename ... DP , typename ST , typename ... SP >
812  void assign( Kokkos::DynRankView< DT , DP... > & dst
813  , const Kokkos::View< ST , SP... >& src )
814  {
815  static_assert(
816  (
817  std::is_same< typename DstTraits::array_layout
818  , Kokkos::LayoutLeft >::value ||
819  std::is_same< typename DstTraits::array_layout
820  , Kokkos::LayoutRight >::value ||
821  std::is_same< typename DstTraits::array_layout
822  , Kokkos::LayoutStride >::value
823  )
824  &&
825  (
826  std::is_same< typename SrcTraits::array_layout
827  , Kokkos::LayoutLeft >::value ||
828  std::is_same< typename SrcTraits::array_layout
829  , Kokkos::LayoutRight >::value ||
830  std::is_same< typename SrcTraits::array_layout
831  , Kokkos::LayoutStride >::value
832  )
833  , "View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
834 
835  static_assert(
836  std::is_same< typename DstTraits::value_type
837  , typename SrcTraits::value_type >::value ||
838  std::is_same< typename DstTraits::value_type
839  , typename SrcTraits::const_value_type >::value ,
840  "View assignment must have same value type or const = non-const" );
841 
842  typedef typename DstType::offset_type dst_offset_type;
843  typedef typename DstType::array_offset_type dst_array_offset_type;
844  dst.m_map.m_array_offset =
845  dst_array_offset_type(std::integral_constant<unsigned,0>(),
846  permute_fad_layout(src.m_map.m_array_offset.layout(),
847  SrcTraits::rank) );
848  dst.m_map.m_offset =
849  dst_offset_type(std::integral_constant<unsigned,0>(),
850  src.m_map.m_offset.layout() );
851 
852  dst.m_map.m_handle = src.m_map.m_handle ;
853  dst.m_rank = src.Rank ;
854 
855  dst.m_map.m_fad_size = src.m_map.m_fad_size ;
856  dst.m_map.m_fad_stride = src.m_map.m_fad_stride ;
857  }
858 };
859 
864 template< class DstTraits , class SrcTraits >
865 class ViewMapping< DstTraits , SrcTraits ,
866  typename std::enable_if<(
867  Kokkos::Impl::MemorySpaceAccess
868  < typename DstTraits::memory_space
869  , typename SrcTraits::memory_space >::assignable
870  &&
871  // Destination view has ordinary
872  std::is_same< typename DstTraits::specialize , void >::value
873  &&
874  // Source view has FAD only
875  std::is_same< typename SrcTraits::specialize
876  , ViewSpecializeSacadoFad >::value
877  ), Kokkos::Impl::ViewToDynRankViewTag >::type >
878 {
879 public:
880 
881  enum { is_assignable = true };
882 
883  typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
884  typedef ViewMapping< DstTraits , void > DstType ;
885  typedef ViewMapping< SrcTraits , void > SrcFadType ;
886 
887  template < typename DT , typename ... DP , typename ST , typename ... SP >
889  void assign( Kokkos::DynRankView< DT , DP... > & dst
890  , const Kokkos::View< ST , SP... >& src )
891  {
892  static_assert(
893  (
894  std::is_same< typename DstTraits::array_layout
895  , Kokkos::LayoutLeft >::value ||
896  std::is_same< typename DstTraits::array_layout
897  , Kokkos::LayoutRight >::value ||
898  std::is_same< typename DstTraits::array_layout
899  , Kokkos::LayoutStride >::value
900  )
901  &&
902  (
903  std::is_same< typename SrcTraits::array_layout
904  , Kokkos::LayoutLeft >::value ||
905  std::is_same< typename SrcTraits::array_layout
906  , Kokkos::LayoutRight >::value ||
907  std::is_same< typename SrcTraits::array_layout
908  , Kokkos::LayoutStride >::value
909  )
910  , "View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
911 
912  static_assert(
913  std::is_same< typename DstTraits::value_type
914  , typename SrcTraits::value_type >::value ||
915  std::is_same< typename DstTraits::value_type
916  , typename SrcTraits::const_value_type >::value ,
917  "View assignment must have same value type or const = non-const" );
918 
919  typedef typename DstType::offset_type dst_offset_type;
920  dst.m_map.m_offset =
921  dst_offset_type(std::integral_constant<unsigned,0>(),
922  permute_fad_layout(src.m_map.m_array_offset.layout(),
923  SrcTraits::rank));
924 
925  dst.m_map.m_handle = src.m_map.m_handle ;
926  dst.m_rank = src.Rank ;
927  }
928 };
929 
930 }} //end Kokkos::Impl
931 
932 namespace Kokkos {
933 
934 template <typename view_type>
935 struct is_dynrankview_fad { static const bool value = false; };
936 
937 template <typename view_type>
938 struct is_dynrankview_fad_contiguous { static const bool value = false; };
939 
940 template <typename T, typename ... P>
941 struct is_dynrankview_fad< DynRankView<T,P...> > {
942  typedef DynRankView<T,P...> view_type;
943  static const bool value =
944  std::is_same< typename view_type::specialize,
945  Impl::ViewSpecializeSacadoFad >::value ||
946  std::is_same< typename view_type::specialize,
947  Impl::ViewSpecializeSacadoFadContiguous >::value;
948 };
949 
950 template <typename T, typename ... P>
951 struct is_dynrankview_fad_contiguous< DynRankView<T,P...> > {
952  typedef DynRankView<T,P...> view_type;
953  static const bool value =
954  std::is_same< typename view_type::specialize,
955  Impl::ViewSpecializeSacadoFadContiguous >::value;
956 };
957 
958 template <typename T, typename ... P>
960 constexpr typename
961 std::enable_if< is_dynrankview_fad< DynRankView<T,P...> >::value, unsigned >::type
962 dimension_scalar(const DynRankView<T,P...>& view) {
963  return view.implementation_map().dimension_scalar();
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  layout.stride[src.rank()] = src.implementation_map().stride_scalar();
1218 
1219  return dst_type(std::string(src.label()).append("_mirror"),
1220  Impl::reconstructLayout(layout, src.rank()+1));
1221 }
1222 
1223 template<class Space, class T, class ... P>
1224 typename Impl::MirrorDRVType<Space,T,P ...>::view_type
1225 create_mirror(const Space& , const Kokkos::DynRankView<T,P...> & src
1226  , typename std::enable_if<
1227  ( std::is_same< typename ViewTraits<T,P...>::specialize ,
1228  Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1229  std::is_same< typename ViewTraits<T,P...>::specialize ,
1230  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1231  >::type *) {
1232  typedef DynRankView<T,P...> src_type ;
1233  typename src_type::array_layout layout = src.layout();
1234  layout.dimension[src.rank()] = Kokkos::dimension_scalar(src);
1235  return typename Impl::MirrorDRVType<Space,T,P ...>::view_type(
1236  src.label(),Impl::reconstructLayout(layout, src.rank()+1));
1237 }
1238 
1239 } // end Kokkos
1240 
1241 #endif //defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
1242 
1243 #endif // defined(HAVE_SACADO_KOKKOSCONTAINERS)
1244 
1246 
1247 #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