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_Contiguous.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Sacado Package
4 //
5 // Copyright 2006 NTESS and the Sacado contributors.
6 // SPDX-License-Identifier: LGPL-2.1-or-later
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef KOKKOS_DYN_RANK_VIEW_SACADO_FAD_CONTIGUOUS_HPP
11 #define KOKKOS_DYN_RANK_VIEW_SACADO_FAD_CONTIGUOUS_HPP
12 
13 #include "Sacado_ConfigDefs.h"
14 
15 // This file is setup to always work even when KokkosContainers (which contains
16 // Kokkos::DynRankView) isn't enabled.
17 
18 #if defined(HAVE_SACADO_KOKKOS)
19 
20 #include "Kokkos_DynRankView.hpp"
21 
22 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
23 
24 #include "Kokkos_View_Fad.hpp"
25 
26 #ifndef SACADO_HAS_NEW_KOKKOS_VIEW_IMPL
27 namespace Kokkos {
28 namespace Impl {
29 
30 template <>
31 struct DynRankDimTraits<Kokkos::Impl::ViewSpecializeSacadoFadContiguous> {
32 
33  enum : size_t{unspecified = ~size_t(0)};
34 
35  // Compute the rank of the view from the nonzero dimension arguments.
36  // For views of Fad, the rank is one less than the rank determined by the nonzero dimension args
37  KOKKOS_INLINE_FUNCTION
38  static size_t computeRank( const size_t N0
39  , const size_t N1
40  , const size_t N2
41  , const size_t N3
42  , const size_t N4
43  , const size_t N5
44  , const size_t N6
45  , const size_t N7 )
46  {
47  return
48  ( (N7 == unspecified && N6 == unspecified && N5 == unspecified && N4 == unspecified && N3 == unspecified && N2 == unspecified && N1 == unspecified && N0 == unspecified) ? 0
49  : ( (N7 == unspecified && N6 == unspecified && N5 == unspecified && N4 == unspecified && N3 == unspecified && N2 == unspecified && N1 == unspecified) ? 0
50  : ( (N7 == unspecified && N6 == unspecified && N5 == unspecified && N4 == unspecified && N3 == unspecified && N2 == unspecified) ? 1
51  : ( (N7 == unspecified && N6 == unspecified && N5 == unspecified && N4 == unspecified && N3 == unspecified) ? 2
52  : ( (N7 == unspecified && N6 == unspecified && N5 == unspecified && N4 == unspecified) ? 3
53  : ( (N7 == unspecified && N6 == unspecified && N5 == unspecified) ? 4
54  : ( (N7 == unspecified && N6 == unspecified) ? 5
55  : ( (N7 == unspecified) ? 6
56  : 7 ) ) ) ) ) ) ) );
57  }
58 
59  // Compute the rank of the view from the nonzero layout arguments.
60  template <typename Layout>
61  KOKKOS_INLINE_FUNCTION
62  static size_t computeRank( const Layout& layout )
63  {
64  return computeRank( layout.dimension[0]
65  , layout.dimension[1]
66  , layout.dimension[2]
67  , layout.dimension[3]
68  , layout.dimension[4]
69  , layout.dimension[5]
70  , layout.dimension[6]
71  , layout.dimension[7] );
72  }
73 
74  // Compute the rank of the view from the nonzero layout arguments and possible hidden dim
75  template <typename Layout, typename ... P>
76  KOKKOS_INLINE_FUNCTION
77  static size_t computeRank( const ViewCtorProp<P...>& prop, const Layout& layout )
78  {
79  size_t rank = computeRank( layout.dimension[0]
80  , layout.dimension[1]
81  , layout.dimension[2]
82  , layout.dimension[3]
83  , layout.dimension[4]
84  , layout.dimension[5]
85  , layout.dimension[6]
86  , layout.dimension[7] );
87 
88  // Check if has_common_view_alloc_prop; if so, return rank+1, else rank
89  enum { test_traits_check = Kokkos::Impl::check_has_common_view_alloc_prop< P... >::value };
90  return (test_traits_check == true) ? rank+1 : rank;
91  }
92 
93  // Create the layout for the rank-7 view.
94  // For Fad we have to move the fad dimension to the last (rank 8 since the DynRankView is rank-7)
95  // LayoutLeft or LayoutRight
96  template <typename Layout>
97  KOKKOS_INLINE_FUNCTION
98  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 )
99  {
100  Layout l( layout.dimension[0] != unspecified ? layout.dimension[0] : 1
101  , layout.dimension[1] != unspecified ? layout.dimension[1] : 1
102  , layout.dimension[2] != unspecified ? layout.dimension[2] : 1
103  , layout.dimension[3] != unspecified ? layout.dimension[3] : 1
104  , layout.dimension[4] != unspecified ? layout.dimension[4] : 1
105  , layout.dimension[5] != unspecified ? layout.dimension[5] : 1
106  , layout.dimension[6] != unspecified ? layout.dimension[6] : 1
107  , layout.dimension[7] != unspecified ? layout.dimension[7] : 1 );
108  const unsigned fad_dim = computeRank(layout);
109  const size_t fad_size = layout.dimension[fad_dim];
110  l.dimension[fad_dim] = 1;
111  l.dimension[7] = fad_size;
112 
113  return l;
114  }
115 
116  //LayoutStride
117  template <typename Layout>
118  KOKKOS_INLINE_FUNCTION
119  static typename std::enable_if< (std::is_same<Layout , Kokkos::LayoutStride>::value) , Layout>::type createLayout( const Layout& layout )
120  {
121  Layout l( layout.dimension[0] != unspecified ? layout.dimension[0] : 1
122  , layout.stride[0]
123  , layout.dimension[1] != unspecified ? layout.dimension[1] : 1
124  , layout.stride[1]
125  , layout.dimension[2] != unspecified ? layout.dimension[2] : 1
126  , layout.stride[2]
127  , layout.dimension[3] != unspecified ? layout.dimension[3] : 1
128  , layout.stride[3]
129  , layout.dimension[4] != unspecified ? layout.dimension[4] : 1
130  , layout.stride[4]
131  , layout.dimension[5] != unspecified ? layout.dimension[5] : 1
132  , layout.stride[5]
133  , layout.dimension[6] != unspecified ? layout.dimension[6] : 1
134  , layout.stride[6]
135  , layout.dimension[7] != unspecified ? layout.dimension[7] : 1
136  , layout.stride[7]
137  );
138  const unsigned fad_dim = computeRank(layout);
139  const size_t fad_size = layout.dimension[fad_dim];
140  l.dimension[fad_dim] = 1;
141  l.dimension[7] = fad_size;
142 
143  return l;
144  }
145 
146  // If fad_dim is stored in ViewCtorProp
147  // LayoutLeft or LayoutRight
148  template <typename Traits, typename ... P>
149  KOKKOS_INLINE_FUNCTION
150  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 )
151  {
152  using Layout = typename Traits::array_layout;
153 
154  Layout l( layout.dimension[0] != unspecified ? layout.dimension[0] : 1
155  , layout.dimension[1] != unspecified ? layout.dimension[1] : 1
156  , layout.dimension[2] != unspecified ? layout.dimension[2] : 1
157  , layout.dimension[3] != unspecified ? layout.dimension[3] : 1
158  , layout.dimension[4] != unspecified ? layout.dimension[4] : 1
159  , layout.dimension[5] != unspecified ? layout.dimension[5] : 1
160  , layout.dimension[6] != unspecified ? layout.dimension[6] : 1
161  , layout.dimension[7] != unspecified ? layout.dimension[7] : 1 );
162 
163  enum { test_traits_check = Kokkos::Impl::check_has_common_view_alloc_prop< P... >::value };
164  if (test_traits_check == true) {
165  l.dimension[7] = compute_fad_dim_from_alloc_prop<P...>::eval(arg_prop);
166  }
167  else {
168  const unsigned fad_dim = computeRank(layout);
169  const size_t fad_size = layout.dimension[fad_dim];
170  l.dimension[fad_dim] = 1;
171  l.dimension[7] = fad_size;
172  }
173 
174  return l;
175  }
176 
177  // If fad_dim is stored in ViewCtorProp
178  //LayoutStride
179  template <typename Traits, typename ... P>
180  KOKKOS_INLINE_FUNCTION
181  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 )
182  {
183  using Layout = typename Traits::array_layout;
184 
185  Layout l( layout.dimension[0] != unspecified ? layout.dimension[0] : 1
186  , layout.stride[0]
187  , layout.dimension[1] != unspecified ? layout.dimension[1] : 1
188  , layout.stride[1]
189  , layout.dimension[2] != unspecified ? layout.dimension[2] : 1
190  , layout.stride[2]
191  , layout.dimension[3] != unspecified ? layout.dimension[3] : 1
192  , layout.stride[3]
193  , layout.dimension[4] != unspecified ? layout.dimension[4] : 1
194  , layout.stride[4]
195  , layout.dimension[5] != unspecified ? layout.dimension[5] : 1
196  , layout.stride[5]
197  , layout.dimension[6] != unspecified ? layout.dimension[6] : 1
198  , layout.stride[6]
199  , layout.dimension[7] != unspecified ? layout.dimension[7] : 1
200  , layout.stride[7]
201  );
202 
203  enum { test_traits_check = Kokkos::Impl::check_has_common_view_alloc_prop< P... >::value };
204  if (test_traits_check == true) {
205  l.dimension[7] = compute_fad_dim_from_alloc_prop<P...>::eval(arg_prop);
206  }
207  else {
208  const unsigned fad_dim = computeRank(layout);
209  const size_t fad_size = layout.dimension[fad_dim];
210  l.dimension[fad_dim] = 1;
211  l.dimension[7] = fad_size;
212  }
213 
214  return l;
215  }
216 
217 
218  // Create a view from the given dimension arguments.
219  // This is only necessary because the shmem constructor doesn't take a layout.
220  template <typename ViewType, typename ViewArg>
221  static ViewType createView( const ViewArg& arg
222  , const size_t N0
223  , const size_t N1
224  , const size_t N2
225  , const size_t N3
226  , const size_t N4
227  , const size_t N5
228  , const size_t N6
229  , const size_t N7 )
230  {
231  typename ViewType::array_layout l( N0, N1, N2, N3, N4, N5, N6, N7 );
232  typename ViewType::array_layout l_fad = createLayout(l);
233  return ViewType( arg
234  , l_fad.dimension[0]
235  , l_fad.dimension[1]
236  , l_fad.dimension[2]
237  , l_fad.dimension[3]
238  , l_fad.dimension[4]
239  , l_fad.dimension[5]
240  , l_fad.dimension[6]
241  , l_fad.dimension[7] );
242  }
243 
244 };
245 
246 }} // end Kokkos::Impl
247 
248 namespace Kokkos {
249 namespace Impl {
250 
251 // Specializations for subdynrankview
252 
253 template< class SrcTraits , class ... Args >
254 struct ViewMapping
255  < typename std::enable_if<(
256  std::is_same< typename SrcTraits::specialize ,
257  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value
258  &&
259  (
260  std::is_same< typename SrcTraits::array_layout
261  , Kokkos::LayoutRight >::value ||
262  std::is_same< typename SrcTraits::array_layout
263  , Kokkos::LayoutStride >::value
264  )
265  ), Kokkos::Impl::DynRankSubviewTag >::type
266  , SrcTraits
267  , Args ... >
268 {
269 private:
270 
271  enum
272  { RZ = false
280  };
281 
282  enum { rank = unsigned(R0) + unsigned(R1) + unsigned(R2) + unsigned(R3)
283  + unsigned(R4) + unsigned(R5) + unsigned(R6) };
284 
286 
287  typedef typename SrcTraits::value_type value_type ;
288 
289  typedef value_type******* data_type ;
290 
291 public:
292 
293  typedef Kokkos::ViewTraits
294  < data_type
295  , array_layout
296  , typename SrcTraits::device_type
297  , typename SrcTraits::memory_traits > traits_type ;
298 
299  typedef Kokkos::View
300  < data_type
301  , array_layout
302  , typename SrcTraits::device_type
303  , typename SrcTraits::memory_traits > type ;
304 
305 
306  template< class MemoryTraits >
307  struct apply {
308 
310 
311  typedef Kokkos::ViewTraits
312  < data_type
313  , array_layout
314  , typename SrcTraits::device_type
315  , MemoryTraits > traits_type ;
316 
317  typedef Kokkos::View
318  < data_type
319  , array_layout
320  , typename SrcTraits::device_type
321  , MemoryTraits > type ;
322  };
323 
324  template < class Arg0 = int, class Arg1 = int, class Arg2 = int, class Arg3 = int, class Arg4 = int, class Arg5 = int, class Arg6 = int >
325  struct ExtentGenerator {
326  template <typename dimension>
327  KOKKOS_INLINE_FUNCTION
328  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() )
329  {
330  return SubviewExtents< 7 , rank >( dim , arg0 , arg1 , arg2 , arg3 ,
331  arg4 , arg5 , arg6 );
332  }
333  };
334 
335  template < class Arg0 = int, class Arg1 = int, class Arg2 = int, class Arg3 = int, class Arg4 = int, class Arg5 = int, class Arg6 = int >
336  struct ArrayExtentGenerator {
337  template <typename dimension>
338  KOKKOS_INLINE_FUNCTION
339  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() )
340  {
341  return SubviewExtents< 8 , rank+1 >( dim , arg0 , arg1 , arg2 , arg3 ,
342  arg4 , arg5 , arg6 , Kokkos::ALL() );
343  }
344  };
345 
346  typedef DynRankView< value_type , array_layout , typename SrcTraits::device_type , typename SrcTraits::memory_traits > ret_type;
347 
348  template < typename T , class ... P >
349  KOKKOS_INLINE_FUNCTION
350  static ret_type subview( const unsigned src_rank , Kokkos::DynRankView< T , P...> const & src , Args ... args )
351  {
352 
353  typedef ViewMapping< traits_type, typename traits_type::specialize > DstType ;
354  typedef typename std::conditional< (rank==0) , ViewDimension<>
355  , typename std::conditional< (rank==1) , ViewDimension<0>
356  , typename std::conditional< (rank==2) , ViewDimension<0,0>
357  , typename std::conditional< (rank==3) , ViewDimension<0,0,0>
358  , typename std::conditional< (rank==4) , ViewDimension<0,0,0,0>
359  , typename std::conditional< (rank==5) , ViewDimension<0,0,0,0,0>
360  , typename std::conditional< (rank==6) , ViewDimension<0,0,0,0,0,0>
361  , ViewDimension<0,0,0,0,0,0,0>
362  >::type >::type >::type >::type >::type >::type >::type DstDimType ;
363  typedef typename std::conditional< (rank==0) , ViewDimension<0>
364  , typename std::conditional< (rank==1) , ViewDimension<0,0>
365  , typename std::conditional< (rank==2) , ViewDimension<0,0,0>
366  , typename std::conditional< (rank==3) , ViewDimension<0,0,0,0>
367  , typename std::conditional< (rank==4) , ViewDimension<0,0,0,0,0>
368  , typename std::conditional< (rank==5) , ViewDimension<0,0,0,0,0,0>
369  , typename std::conditional< (rank==6) , ViewDimension<0,0,0,0,0,0,0>
370  , ViewDimension<0,0,0,0,0,0,0,0>
371  >::type >::type >::type >::type >::type >::type >::type DstArrayDimType ;
372 
373  typedef ViewOffset< DstDimType , Kokkos::LayoutStride > dst_offset_type ;
374  typedef ViewOffset< DstArrayDimType , Kokkos::LayoutStride > dst_array_offset_type ;
375  typedef typename DstType::handle_type dst_handle_type ;
376 
377  ret_type dst ;
378 
379  const SubviewExtents< 7 , rank > extents =
380  ExtentGenerator< Args ... >::generator(
381  src.m_map.m_impl_offset.m_dim , args... ) ;
382  const SubviewExtents< 8 , rank+1 > array_extents =
383  ArrayExtentGenerator< Args ... >::generator(
384  src.m_map.m_array_offset.m_dim , args... ) ;
385 
386  dst_offset_type tempdst( src.m_map.m_impl_offset , extents ) ;
387  dst_array_offset_type temparraydst(
388  src.m_map.m_array_offset , array_extents ) ;
389 
390  dst.m_track = src.m_track ;
391 
392  dst.m_map.m_impl_offset.m_dim.N0 = tempdst.m_dim.N0 ;
393  dst.m_map.m_impl_offset.m_dim.N1 = tempdst.m_dim.N1 ;
394  dst.m_map.m_impl_offset.m_dim.N2 = tempdst.m_dim.N2 ;
395  dst.m_map.m_impl_offset.m_dim.N3 = tempdst.m_dim.N3 ;
396  dst.m_map.m_impl_offset.m_dim.N4 = tempdst.m_dim.N4 ;
397  dst.m_map.m_impl_offset.m_dim.N5 = tempdst.m_dim.N5 ;
398  dst.m_map.m_impl_offset.m_dim.N6 = tempdst.m_dim.N6 ;
399 
400  dst.m_map.m_impl_offset.m_stride.S0 = tempdst.m_stride.S0;
401  dst.m_map.m_impl_offset.m_stride.S1 = tempdst.m_stride.S1;
402  dst.m_map.m_impl_offset.m_stride.S2 = tempdst.m_stride.S2;
403  dst.m_map.m_impl_offset.m_stride.S3 = tempdst.m_stride.S3;
404  dst.m_map.m_impl_offset.m_stride.S4 = tempdst.m_stride.S4;
405  dst.m_map.m_impl_offset.m_stride.S5 = tempdst.m_stride.S5;
406  dst.m_map.m_impl_offset.m_stride.S6 = tempdst.m_stride.S6;
407 
408  // Move last non-unit dim and stride to N7/S7 since subview collapses
409  // out all singleton dimensions between the last rank and the fad
410  // dimension. Equivalent to:
411  // dst.m_map.m_array_offset.m_dim.N* = temparraydst.m_dim.N*
412  // dst.m_map.m_array_offset.m_dim.N7 = temparraydst.m_dim.N{rank}
413  // dst.m_map.m_array_offset.m_stride.S* = temparraydst.m_stride.S*
414  // dst.m_map.m_array_offset.m_stride.S7 = temparraydst.m_stride.S{rank}
415  AssignFadDimStride<rank,0>::eval( dst.m_map.m_array_offset, temparraydst );
416 
417  dst.m_track = src.m_track ;
418 
419  dst.m_map.m_impl_handle =
420  dst_handle_type(
421  src.m_map.m_impl_handle +
422  src.m_map.m_array_offset( array_extents.domain_offset(0)
423  , array_extents.domain_offset(1)
424  , array_extents.domain_offset(2)
425  , array_extents.domain_offset(3)
426  , array_extents.domain_offset(4)
427  , array_extents.domain_offset(5)
428  , array_extents.domain_offset(6)
429  , array_extents.domain_offset(7)
430  ) );
431 
432  dst.m_map.m_fad_size = src.m_map.m_fad_size;
433  dst.m_map.m_original_fad_size = src.m_map.m_original_fad_size;
434  dst.m_map.m_fad_stride = src.m_map.m_fad_stride;
435  dst.m_map.m_fad_index = src.m_map.m_fad_index;
436 
437  dst.m_rank = ( src_rank > 0 ? unsigned(R0) : 0 )
438  + ( src_rank > 1 ? unsigned(R1) : 0 )
439  + ( src_rank > 2 ? unsigned(R2) : 0 )
440  + ( src_rank > 3 ? unsigned(R3) : 0 )
441  + ( src_rank > 4 ? unsigned(R4) : 0 )
442  + ( src_rank > 5 ? unsigned(R5) : 0 )
443  + ( src_rank > 6 ? unsigned(R6) : 0 ) ;
444 
445  return dst ;
446  }
447 };
448 
449 template< class SrcTraits , class ... Args >
450 struct ViewMapping
451  < typename std::enable_if<(
452  std::is_same< typename SrcTraits::specialize ,
453  Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value
454  &&
455  std::is_same< typename SrcTraits::array_layout
456  , Kokkos::LayoutLeft >::value
457  ), Kokkos::Impl::DynRankSubviewTag >::type
458  , SrcTraits
459  , Args ... >
460 {
461 private:
462 
463  enum
464  { RZ = false
472  };
473 
474  enum { rank = unsigned(R0) + unsigned(R1) + unsigned(R2) + unsigned(R3)
475  + unsigned(R4) + unsigned(R5) + unsigned(R6) };
476 
478 
479  typedef typename SrcTraits::value_type value_type ;
480 
481  typedef value_type******* data_type ;
482 
483 public:
484 
485  typedef Kokkos::ViewTraits
486  < data_type
487  , array_layout
488  , typename SrcTraits::device_type
489  , typename SrcTraits::memory_traits > traits_type ;
490 
491  typedef Kokkos::View
492  < data_type
493  , array_layout
494  , typename SrcTraits::device_type
495  , typename SrcTraits::memory_traits > type ;
496 
497 
498  template< class MemoryTraits >
499  struct apply {
500 
502 
503  typedef Kokkos::ViewTraits
504  < data_type
505  , array_layout
506  , typename SrcTraits::device_type
507  , MemoryTraits > traits_type ;
508 
509  typedef Kokkos::View
510  < data_type
511  , array_layout
512  , typename SrcTraits::device_type
513  , MemoryTraits > type ;
514  };
515 
516  template < class Arg0 = int, class Arg1 = int, class Arg2 = int, class Arg3 = int, class Arg4 = int, class Arg5 = int, class Arg6 = int >
517  struct ExtentGenerator {
518  template <typename dimension>
519  KOKKOS_INLINE_FUNCTION
520  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() )
521  {
522  return SubviewExtents< 7 , rank >( dim , arg0 , arg1 , arg2 , arg3 ,
523  arg4 , arg5 , arg6 );
524  }
525  };
526 
527  template < class Arg0 = int, class Arg1 = int, class Arg2 = int, class Arg3 = int, class Arg4 = int, class Arg5 = int, class Arg6 = int >
528  struct ArrayExtentGenerator {
529  template <typename dimension>
530  KOKKOS_INLINE_FUNCTION
531  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() )
532  {
533  return SubviewExtents< 8 , rank+1 >( dim , Kokkos::ALL() , arg0 , arg1 ,
534  arg2 , arg3 , arg4 , arg5 , arg6 );
535  }
536  };
537 
538  typedef DynRankView< value_type , array_layout , typename SrcTraits::device_type , typename SrcTraits::memory_traits > ret_type;
539 
540  template < typename T , class ... P >
541  KOKKOS_INLINE_FUNCTION
542  static ret_type subview( const unsigned src_rank , Kokkos::DynRankView< T , P...> const & src , Args ... args )
543  {
544 
545  typedef ViewMapping< traits_type, typename traits_type::specialize > DstType ;
546  typedef typename std::conditional< (rank==0) , ViewDimension<>
547  , typename std::conditional< (rank==1) , ViewDimension<0>
548  , typename std::conditional< (rank==2) , ViewDimension<0,0>
549  , typename std::conditional< (rank==3) , ViewDimension<0,0,0>
550  , typename std::conditional< (rank==4) , ViewDimension<0,0,0,0>
551  , typename std::conditional< (rank==5) , ViewDimension<0,0,0,0,0>
552  , typename std::conditional< (rank==6) , ViewDimension<0,0,0,0,0,0>
553  , ViewDimension<0,0,0,0,0,0,0>
554  >::type >::type >::type >::type >::type >::type >::type DstDimType ;
555  typedef typename std::conditional< (rank==0) , ViewDimension<0>
556  , typename std::conditional< (rank==1) , ViewDimension<0,0>
557  , typename std::conditional< (rank==2) , ViewDimension<0,0,0>
558  , typename std::conditional< (rank==3) , ViewDimension<0,0,0,0>
559  , typename std::conditional< (rank==4) , ViewDimension<0,0,0,0,0>
560  , typename std::conditional< (rank==5) , ViewDimension<0,0,0,0,0,0>
561  , typename std::conditional< (rank==6) , ViewDimension<0,0,0,0,0,0,0>
562  , ViewDimension<0,0,0,0,0,0,0,0>
563  >::type >::type >::type >::type >::type >::type >::type DstArrayDimType ;
564 
565  typedef ViewOffset< DstDimType , Kokkos::LayoutStride > dst_offset_type ;
566  typedef ViewOffset< DstArrayDimType , Kokkos::LayoutStride > dst_array_offset_type ;
567  typedef typename DstType::handle_type dst_handle_type ;
568 
569  ret_type dst ;
570 
571  const SubviewExtents< 7 , rank > extents =
572  ExtentGenerator< Args ... >::generator(
573  src.m_map.m_impl_offset.m_dim , args... ) ;
574  const SubviewExtents< 8 , rank+1 > array_extents =
575  ArrayExtentGenerator< Args ... >::generator(
576  src.m_map.m_array_offset.m_dim , args... ) ;
577 
578  dst_offset_type tempdst( src.m_map.m_impl_offset , extents ) ;
579  dst_array_offset_type temparraydst(
580  src.m_map.m_array_offset , array_extents ) ;
581 
582  dst.m_track = src.m_track ;
583 
584  dst.m_map.m_impl_offset.m_dim.N0 = tempdst.m_dim.N0 ;
585  dst.m_map.m_impl_offset.m_dim.N1 = tempdst.m_dim.N1 ;
586  dst.m_map.m_impl_offset.m_dim.N2 = tempdst.m_dim.N2 ;
587  dst.m_map.m_impl_offset.m_dim.N3 = tempdst.m_dim.N3 ;
588  dst.m_map.m_impl_offset.m_dim.N4 = tempdst.m_dim.N4 ;
589  dst.m_map.m_impl_offset.m_dim.N5 = tempdst.m_dim.N5 ;
590  dst.m_map.m_impl_offset.m_dim.N6 = tempdst.m_dim.N6 ;
591 
592  dst.m_map.m_impl_offset.m_stride.S0 = tempdst.m_stride.S0;
593  dst.m_map.m_impl_offset.m_stride.S1 = tempdst.m_stride.S1;
594  dst.m_map.m_impl_offset.m_stride.S2 = tempdst.m_stride.S2;
595  dst.m_map.m_impl_offset.m_stride.S3 = tempdst.m_stride.S3;
596  dst.m_map.m_impl_offset.m_stride.S4 = tempdst.m_stride.S4;
597  dst.m_map.m_impl_offset.m_stride.S5 = tempdst.m_stride.S5;
598  dst.m_map.m_impl_offset.m_stride.S6 = tempdst.m_stride.S6;
599 
600  // dst is always LayoutStride, which uses the last (rank-8) index for
601  // the fad dimension, thus we need to move its stride/dimension from the
602  // first to the last
603 
604  dst.m_map.m_array_offset.m_dim.N0 = temparraydst.m_dim.N1 ;
605  dst.m_map.m_array_offset.m_dim.N1 = temparraydst.m_dim.N2 ;
606  dst.m_map.m_array_offset.m_dim.N2 = temparraydst.m_dim.N3 ;
607  dst.m_map.m_array_offset.m_dim.N3 = temparraydst.m_dim.N4 ;
608  dst.m_map.m_array_offset.m_dim.N4 = temparraydst.m_dim.N5 ;
609  dst.m_map.m_array_offset.m_dim.N5 = temparraydst.m_dim.N6 ;
610  dst.m_map.m_array_offset.m_dim.N6 = temparraydst.m_dim.N7 ;
611  dst.m_map.m_array_offset.m_dim.N7 = temparraydst.m_dim.N0 ;
612 
613  dst.m_map.m_array_offset.m_stride.S0 = temparraydst.m_stride.S1;
614  dst.m_map.m_array_offset.m_stride.S1 = temparraydst.m_stride.S2;
615  dst.m_map.m_array_offset.m_stride.S2 = temparraydst.m_stride.S3;
616  dst.m_map.m_array_offset.m_stride.S3 = temparraydst.m_stride.S4;
617  dst.m_map.m_array_offset.m_stride.S4 = temparraydst.m_stride.S5;
618  dst.m_map.m_array_offset.m_stride.S5 = temparraydst.m_stride.S6;
619  dst.m_map.m_array_offset.m_stride.S6 = temparraydst.m_stride.S7;
620  dst.m_map.m_array_offset.m_stride.S7 = temparraydst.m_stride.S0;
621 
622  dst.m_track = src.m_track ;
623 
624  dst.m_map.m_impl_handle =
625  dst_handle_type(
626  src.m_map.m_impl_handle +
627  src.m_map.m_array_offset( array_extents.domain_offset(0)
628  , array_extents.domain_offset(1)
629  , array_extents.domain_offset(2)
630  , array_extents.domain_offset(3)
631  , array_extents.domain_offset(4)
632  , array_extents.domain_offset(5)
633  , array_extents.domain_offset(6)
634  , array_extents.domain_offset(7)
635  ) );
636 
637  dst.m_map.m_fad_size = src.m_map.m_fad_size;
638  dst.m_map.m_original_fad_size = src.m_map.m_original_fad_size;
639  dst.m_map.m_fad_stride = src.m_map.m_fad_stride;
640  dst.m_map.m_fad_index = src.m_map.m_fad_index;
641 
642  dst.m_rank = ( src_rank > 0 ? unsigned(R0) : 0 )
643  + ( src_rank > 1 ? unsigned(R1) : 0 )
644  + ( src_rank > 2 ? unsigned(R2) : 0 )
645  + ( src_rank > 3 ? unsigned(R3) : 0 )
646  + ( src_rank > 4 ? unsigned(R4) : 0 )
647  + ( src_rank > 5 ? unsigned(R5) : 0 )
648  + ( src_rank > 6 ? unsigned(R6) : 0 ) ;
649 
650  return dst ;
651  }
652 };
653 
658 template< class DstTraits , class SrcTraits >
659 class ViewMapping< DstTraits , SrcTraits ,
660  typename std::enable_if<(
661  Kokkos::Impl::MemorySpaceAccess
662  < typename DstTraits::memory_space
663  , typename SrcTraits::memory_space >::assignable
664  &&
665  // Destination view has FAD only
666  std::is_same< typename DstTraits::specialize
667  , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value
668  &&
669  // Source view has FAD only
670  std::is_same< typename SrcTraits::specialize
671  , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value
672  ), Kokkos::Impl::ViewToDynRankViewTag >::type >
673 {
674 public:
675 
676  enum { is_assignable = true };
677  enum { is_assignable_data_type = true };
678 
679  typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
680  typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
681  typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcFadType ;
682 
683  template < typename DT , typename ... DP , typename ST , typename ... SP >
684  KOKKOS_INLINE_FUNCTION static
685  void assign( Kokkos::DynRankView< DT , DP... > & dst
686  , const Kokkos::View< ST , SP... >& src )
687  {
688  static_assert(
689  (
690  std::is_same< typename DstTraits::array_layout
691  , Kokkos::LayoutLeft >::value ||
692  std::is_same< typename DstTraits::array_layout
693  , Kokkos::LayoutRight >::value ||
694  std::is_same< typename DstTraits::array_layout
695  , Kokkos::LayoutStride >::value
696  )
697  &&
698  (
699  std::is_same< typename SrcTraits::array_layout
700  , Kokkos::LayoutLeft >::value ||
701  std::is_same< typename SrcTraits::array_layout
702  , Kokkos::LayoutRight >::value ||
703  std::is_same< typename SrcTraits::array_layout
704  , Kokkos::LayoutStride >::value
705  )
706  , "View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
707 
708  static_assert(
709  std::is_same< typename DstTraits::value_type
710  , typename SrcTraits::value_type >::value ||
711  std::is_same< typename DstTraits::value_type
712  , typename SrcTraits::const_value_type >::value ,
713  "View assignment must have same value type or const = non-const" );
714 
715  const bool is_left =
717  typedef typename DstType::offset_type dst_offset_type;
718  typedef typename DstType::array_offset_type dst_array_offset_type;
719  if (is_left) {
720  dst.m_map.m_array_offset =
721  dst_array_offset_type(std::integral_constant<unsigned,0>(),
722  src.m_map.m_array_offset.layout() );
723  }
724  else {
725  dst.m_map.m_array_offset =
726  dst_array_offset_type(std::integral_constant<unsigned,0>(),
727  permute_fad_layout(src.m_map.m_array_offset.layout(),
728  SrcTraits::rank) );
729  }
730  dst.m_map.m_impl_offset =
731  dst_offset_type(std::integral_constant<unsigned,0>(),
732  src.m_map.m_impl_offset.layout() );
733 
734  dst.m_map.m_impl_handle = src.m_map.m_impl_handle ;
735  dst.m_rank = src.rank ;
736 
737  dst.m_map.m_fad_size = src.m_map.m_fad_size ;
738  dst.m_map.m_original_fad_size = src.m_map.m_original_fad_size;
739  dst.m_map.m_fad_stride = src.m_map.m_fad_stride ;
740  dst.m_map.m_fad_index = src.m_map.m_fad_index;
741  }
742 };
743 
748 template< class DstTraits , class SrcTraits >
749 class ViewMapping< DstTraits , SrcTraits ,
750  typename std::enable_if<(
751  Kokkos::Impl::MemorySpaceAccess
752  < typename DstTraits::memory_space
753  , typename SrcTraits::memory_space >::assignable
754  &&
755  // Destination view has ordinary
756  std::is_same< typename DstTraits::specialize , void >::value
757  &&
758  // Source view has FAD only
759  std::is_same< typename SrcTraits::specialize
760  , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value
761  ), Kokkos::Impl::ViewToDynRankViewTag >::type >
762 {
763 public:
764 
765  enum { is_assignable = true };
766  enum { is_assignable_data_type = true };
767 
768  typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
769  typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
770  typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcFadType ;
771 
772  template < typename DT , typename ... DP , typename ST , typename ... SP >
773  KOKKOS_INLINE_FUNCTION static
774  void assign( Kokkos::DynRankView< DT , DP... > & dst
775  , const Kokkos::View< ST , SP... >& src )
776  {
777  static_assert(
778  (
779  std::is_same< typename DstTraits::array_layout
780  , Kokkos::LayoutLeft >::value ||
781  std::is_same< typename DstTraits::array_layout
782  , Kokkos::LayoutRight >::value ||
783  std::is_same< typename DstTraits::array_layout
784  , Kokkos::LayoutStride >::value
785  )
786  &&
787  (
788  std::is_same< typename SrcTraits::array_layout
789  , Kokkos::LayoutLeft >::value ||
790  std::is_same< typename SrcTraits::array_layout
791  , Kokkos::LayoutRight >::value ||
792  std::is_same< typename SrcTraits::array_layout
793  , Kokkos::LayoutStride >::value
794  )
795  , "View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
796 
797  static_assert(
798  std::is_same< typename DstTraits::value_type
799  , typename SrcTraits::value_type >::value ||
800  std::is_same< typename DstTraits::value_type
801  , typename SrcTraits::const_value_type >::value ,
802  "View assignment must have same value type or const = non-const" );
803 
804  dst.m_map.m_impl_offset.m_dim = src.m_map.m_array_offset.m_dim;
805  dst.m_map.m_impl_offset.m_stride = src.m_map.m_array_offset.m_stride ;
806 
807  dst.m_map.m_impl_handle = src.m_map.m_impl_handle ;
808  dst.m_rank = src.rank ;
809  }
810 };
811 
812 }} //end Kokkos::Impl
813 #endif
814 
815 #endif //defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
816 
817 #endif // defined(HAVE_SACADO_KOKKOS)
818 
819 #endif /* #ifndef KOKKOS_DYN_RANK_VIEW_SACADO_FAD_HPP */
KOKKOS_INLINE_FUNCTION auto subview(const View< D, Kokkos::LayoutContiguous< LayoutSrc, StrideSrc >, P...> &src, Args...args)
#define T
Definition: Sacado_rad.hpp:553
int value
const int fad_dim
expr expr expr bar false