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