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