Kokkos Core Kernels Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Kokkos_DynRankView.hpp
Go to the documentation of this file.
1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Kokkos v. 2.0
6 // Copyright (2014) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Christian R. Trott (crtrott@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 */
43 
49 
50 #ifndef KOKKOS_DYNRANKVIEW_HPP
51 #define KOKKOS_DYNRANKVIEW_HPP
52 
53 #include <Kokkos_Core.hpp>
54 #include <impl/Kokkos_Error.hpp>
55 #include <type_traits>
56 
57 namespace Kokkos {
58 
59 template< typename DataType , class ... Properties >
60 class DynRankView; //forward declare
61 
62 namespace Impl {
63 
64 template <typename Specialize>
65 struct DynRankDimTraits {
66 
67  enum : size_t{unspecified = KOKKOS_INVALID_INDEX};
68 
69  // Compute the rank of the view from the nonzero dimension arguments.
70  KOKKOS_INLINE_FUNCTION
71  static size_t computeRank( const size_t N0
72  , const size_t N1
73  , const size_t N2
74  , const size_t N3
75  , const size_t N4
76  , const size_t N5
77  , const size_t N6
78  , const size_t /* N7 */)
79  {
80  return
81  ( (N6 == unspecified && N5 == unspecified && N4 == unspecified && N3 == unspecified && N2 == unspecified && N1 == unspecified && N0 == unspecified) ? 0
82  : ( (N6 == unspecified && N5 == unspecified && N4 == unspecified && N3 == unspecified && N2 == unspecified && N1 == unspecified) ? 1
83  : ( (N6 == unspecified && N5 == unspecified && N4 == unspecified && N3 == unspecified && N2 == unspecified) ? 2
84  : ( (N6 == unspecified && N5 == unspecified && N4 == unspecified && N3 == unspecified) ? 3
85  : ( (N6 == unspecified && N5 == unspecified && N4 == unspecified) ? 4
86  : ( (N6 == unspecified && N5 == unspecified) ? 5
87  : ( (N6 == unspecified) ? 6
88  : 7 ) ) ) ) ) ) );
89  }
90 
91  // Compute the rank of the view from the nonzero layout arguments.
92  template <typename Layout>
93  KOKKOS_INLINE_FUNCTION
94  static size_t computeRank( const Layout& layout )
95  {
96  return computeRank( layout.dimension[0]
97  , layout.dimension[1]
98  , layout.dimension[2]
99  , layout.dimension[3]
100  , layout.dimension[4]
101  , layout.dimension[5]
102  , layout.dimension[6]
103  , layout.dimension[7] );
104  }
105 
106  // Extra overload to match that for specialize types v2
107  template <typename Layout, typename ... P>
108  KOKKOS_INLINE_FUNCTION
109  static size_t computeRank( const Kokkos::Impl::ViewCtorProp<P...>& /* prop */, const Layout& layout )
110  {
111  return computeRank(layout);
112  }
113 
114  // Create the layout for the rank-7 view.
115  // Non-strided Layout
116  template <typename Layout>
117  KOKKOS_INLINE_FUNCTION
118  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 )
119  {
120  return Layout( layout.dimension[0] != unspecified ? layout.dimension[0] : 1
121  , layout.dimension[1] != unspecified ? layout.dimension[1] : 1
122  , layout.dimension[2] != unspecified ? layout.dimension[2] : 1
123  , layout.dimension[3] != unspecified ? layout.dimension[3] : 1
124  , layout.dimension[4] != unspecified ? layout.dimension[4] : 1
125  , layout.dimension[5] != unspecified ? layout.dimension[5] : 1
126  , layout.dimension[6] != unspecified ? layout.dimension[6] : 1
127  , layout.dimension[7] != unspecified ? layout.dimension[7] : 1
128  );
129  }
130 
131  // LayoutStride
132  template <typename Layout>
133  KOKKOS_INLINE_FUNCTION
134  static typename std::enable_if< (std::is_same<Layout , Kokkos::LayoutStride>::value) , Layout>::type createLayout( const Layout& layout )
135  {
136  return Layout( layout.dimension[0] != unspecified ? layout.dimension[0] : 1
137  , layout.stride[0]
138  , layout.dimension[1] != unspecified ? layout.dimension[1] : 1
139  , layout.stride[1]
140  , layout.dimension[2] != unspecified ? layout.dimension[2] : 1
141  , layout.stride[2]
142  , layout.dimension[3] != unspecified ? layout.dimension[3] : 1
143  , layout.stride[3]
144  , layout.dimension[4] != unspecified ? layout.dimension[4] : 1
145  , layout.stride[4]
146  , layout.dimension[5] != unspecified ? layout.dimension[5] : 1
147  , layout.stride[5]
148  , layout.dimension[6] != unspecified ? layout.dimension[6] : 1
149  , layout.stride[6]
150  , layout.dimension[7] != unspecified ? layout.dimension[7] : 1
151  , layout.stride[7]
152  );
153  }
154 
155  // Extra overload to match that for specialize types
156  template <typename Traits, typename ... P>
157  KOKKOS_INLINE_FUNCTION
158  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 || std::is_same<typename Traits::array_layout , Kokkos::LayoutStride>::value) , typename Traits::array_layout >::type createLayout( const Kokkos::Impl::ViewCtorProp<P...>& /* prop */, const typename Traits::array_layout& layout )
159  {
160  return createLayout( layout );
161  }
162 
163  // Create a view from the given dimension arguments.
164  // This is only necessary because the shmem constructor doesn't take a layout.
165  // NDE shmem View's are not compatible with the added view_alloc value_type / fad_dim deduction functionality
166  template <typename ViewType, typename ViewArg>
167  static ViewType createView( const ViewArg& arg
168  , const size_t N0
169  , const size_t N1
170  , const size_t N2
171  , const size_t N3
172  , const size_t N4
173  , const size_t N5
174  , const size_t N6
175  , const size_t N7 )
176  {
177  return ViewType( arg
178  , N0 != unspecified ? N0 : 1
179  , N1 != unspecified ? N1 : 1
180  , N2 != unspecified ? N2 : 1
181  , N3 != unspecified ? N3 : 1
182  , N4 != unspecified ? N4 : 1
183  , N5 != unspecified ? N5 : 1
184  , N6 != unspecified ? N6 : 1
185  , N7 != unspecified ? N7 : 1 );
186  }
187 };
188 
189  // Non-strided Layout
190  template <typename Layout , typename iType>
191  KOKKOS_INLINE_FUNCTION
192  static typename std::enable_if< (std::is_same<Layout , Kokkos::LayoutRight>::value || std::is_same<Layout , Kokkos::LayoutLeft>::value) && std::is_integral<iType>::value , Layout >::type
193  reconstructLayout( const Layout& layout , iType dynrank )
194  {
195  return Layout( dynrank > 0 ? layout.dimension[0] :KOKKOS_INVALID_INDEX
196  , dynrank > 1 ? layout.dimension[1] :KOKKOS_INVALID_INDEX
197  , dynrank > 2 ? layout.dimension[2] :KOKKOS_INVALID_INDEX
198  , dynrank > 3 ? layout.dimension[3] :KOKKOS_INVALID_INDEX
199  , dynrank > 4 ? layout.dimension[4] :KOKKOS_INVALID_INDEX
200  , dynrank > 5 ? layout.dimension[5] :KOKKOS_INVALID_INDEX
201  , dynrank > 6 ? layout.dimension[6] :KOKKOS_INVALID_INDEX
202  , dynrank > 7 ? layout.dimension[7] :KOKKOS_INVALID_INDEX
203  );
204  }
205 
206  // LayoutStride
207  template <typename Layout , typename iType>
208  KOKKOS_INLINE_FUNCTION
209  static typename std::enable_if< (std::is_same<Layout , Kokkos::LayoutStride>::value) && std::is_integral<iType>::value , Layout >::type
210  reconstructLayout( const Layout& layout , iType dynrank )
211  {
212  return Layout( dynrank > 0 ? layout.dimension[0] :KOKKOS_INVALID_INDEX
213  , dynrank > 0 ? layout.stride[0] : (0)
214  , dynrank > 1 ? layout.dimension[1] :KOKKOS_INVALID_INDEX
215  , dynrank > 1 ? layout.stride[1] : (0)
216  , dynrank > 2 ? layout.dimension[2] :KOKKOS_INVALID_INDEX
217  , dynrank > 2 ? layout.stride[2] : (0)
218  , dynrank > 3 ? layout.dimension[3] :KOKKOS_INVALID_INDEX
219  , dynrank > 3 ? layout.stride[3] : (0)
220  , dynrank > 4 ? layout.dimension[4] :KOKKOS_INVALID_INDEX
221  , dynrank > 4 ? layout.stride[4] : (0)
222  , dynrank > 5 ? layout.dimension[5] :KOKKOS_INVALID_INDEX
223  , dynrank > 5 ? layout.stride[5] : (0)
224  , dynrank > 6 ? layout.dimension[6] :KOKKOS_INVALID_INDEX
225  , dynrank > 6 ? layout.stride[6] : (0)
226  , dynrank > 7 ? layout.dimension[7] :KOKKOS_INVALID_INDEX
227  , dynrank > 7 ? layout.stride[7] : (0)
228  );
229  }
230 
231 
233 // Enhanced debug checking - most infrastructure matches that of functions in
234 // Kokkos_ViewMapping; additional checks for extra arguments beyond rank are 0
235 template< unsigned , typename iType0 , class MapType >
236 KOKKOS_INLINE_FUNCTION
237 bool dyn_rank_view_verify_operator_bounds( const iType0 & , const MapType & )
238 { return true ; }
239 
240 template< unsigned R , typename iType0 , class MapType , typename iType1 , class ... Args >
241 KOKKOS_INLINE_FUNCTION
242 bool dyn_rank_view_verify_operator_bounds
243  ( const iType0 & rank
244  , const MapType & map
245  , const iType1 & i
246  , Args ... args
247  )
248 {
249  if ( static_cast<iType0>(R) < rank ) {
250  return ( size_t(i) < map.extent(R) )
251  && dyn_rank_view_verify_operator_bounds<R+1>( rank , map , args ... );
252  }
253  else if ( i != 0 ) {
254  printf("DynRankView Debug Bounds Checking Error: at rank %u\n Extra arguments beyond the rank must be zero \n",R);
255  return ( false )
256  && dyn_rank_view_verify_operator_bounds<R+1>( rank , map , args ... );
257  }
258  else {
259  return ( true )
260  && dyn_rank_view_verify_operator_bounds<R+1>( rank , map , args ... );
261  }
262 }
263 
264 template< unsigned , class MapType >
265 inline
266 void dyn_rank_view_error_operator_bounds( char * , int , const MapType & )
267 {}
268 
269 template< unsigned R , class MapType , class iType , class ... Args >
270 inline
271 void dyn_rank_view_error_operator_bounds
272  ( char * buf
273  , int len
274  , const MapType & map
275  , const iType & i
276  , Args ... args
277  )
278 {
279  const int n =
280  snprintf(buf,len," %ld < %ld %c"
281  , static_cast<unsigned long>(i)
282  , static_cast<unsigned long>( map.extent(R) )
283  , ( sizeof...(Args) ? ',' : ')' )
284  );
285  dyn_rank_view_error_operator_bounds<R+1>(buf+n,len-n,map,args...);
286 }
287 
288 // op_rank = rank of the operator version that was called
289 template< typename MemorySpace
290  , typename iType0 , typename iType1 , class MapType , class ... Args >
291 KOKKOS_INLINE_FUNCTION
292 void dyn_rank_view_verify_operator_bounds
293  ( const iType0 & op_rank , const iType1 & rank
294  , const Kokkos::Impl::SharedAllocationTracker & tracker
295  , const MapType & map , Args ... args )
296 {
297  if ( static_cast<iType0>(rank) > op_rank ) {
298  Kokkos::abort( "DynRankView Bounds Checking Error: Need at least rank arguments to the operator()" );
299  }
300 
301  if ( ! dyn_rank_view_verify_operator_bounds<0>( rank , map , args ... ) ) {
302 #if defined( KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST )
303  enum { LEN = 1024 };
304  char buffer[ LEN ];
305  const std::string label = tracker.template get_label<MemorySpace>();
306  int n = snprintf(buffer,LEN,"DynRankView bounds error of view %s (", label.c_str());
307  dyn_rank_view_error_operator_bounds<0>( buffer + n , LEN - n , map , args ... );
308  Kokkos::Impl::throw_runtime_exception(std::string(buffer));
309 #else
310  Kokkos::abort("DynRankView bounds error");
311 #endif
312  }
313 }
314 
315 
318 
319 } // namespace Impl
320 
321 namespace Impl {
322 
323 template< class DstTraits , class SrcTraits >
324 class ViewMapping< DstTraits , SrcTraits ,
325  typename std::enable_if<(
326  std::is_same< typename DstTraits::memory_space , typename SrcTraits::memory_space >::value
327  &&
328  std::is_same< typename DstTraits::specialize , void >::value
329  &&
330  std::is_same< typename SrcTraits::specialize , void >::value
331  &&
332  (
333  std::is_same< typename DstTraits::array_layout , typename SrcTraits::array_layout >::value
334  ||
335  (
336  (
337  std::is_same< typename DstTraits::array_layout , Kokkos::LayoutLeft >::value ||
338  std::is_same< typename DstTraits::array_layout , Kokkos::LayoutRight >::value ||
339  std::is_same< typename DstTraits::array_layout , Kokkos::LayoutStride >::value
340  )
341  &&
342  (
343  std::is_same< typename SrcTraits::array_layout , Kokkos::LayoutLeft >::value ||
344  std::is_same< typename SrcTraits::array_layout , Kokkos::LayoutRight >::value ||
345  std::is_same< typename SrcTraits::array_layout , Kokkos::LayoutStride >::value
346  )
347  )
348  )
349  ) , Kokkos::Impl::ViewToDynRankViewTag >::type >
350 {
351 private:
352 
353  enum { is_assignable_value_type =
354  std::is_same< typename DstTraits::value_type
355  , typename SrcTraits::value_type >::value ||
356  std::is_same< typename DstTraits::value_type
357  , typename SrcTraits::const_value_type >::value };
358 
359  enum { is_assignable_layout =
360  std::is_same< typename DstTraits::array_layout
361  , typename SrcTraits::array_layout >::value ||
362  std::is_same< typename DstTraits::array_layout
363  , Kokkos::LayoutStride >::value
364  };
365 
366 public:
367 
368  enum { is_assignable = is_assignable_value_type &&
369  is_assignable_layout };
370 
371  typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
372  typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcType ;
373 
374  template < typename DT , typename ... DP , typename ST , typename ... SP >
375  KOKKOS_INLINE_FUNCTION
376  static void assign( Kokkos::DynRankView< DT , DP...> & dst , const Kokkos::View< ST , SP... > & src )
377  {
378  static_assert( is_assignable_value_type
379  , "View assignment must have same value type or const = non-const" );
380 
381  static_assert( is_assignable_layout
382  , "View assignment must have compatible layout or have rank <= 1" );
383 
384  // Removed dimension checks...
385 
386  typedef typename DstType::offset_type dst_offset_type ;
387  dst.m_map.m_impl_offset = dst_offset_type(std::integral_constant<unsigned,0>() , src.layout() ); //Check this for integer input1 for padding, etc
388  dst.m_map.m_impl_handle = Kokkos::Impl::ViewDataHandle< DstTraits >::assign( src.m_map.m_impl_handle , src.m_track );
389  dst.m_track.assign( src.m_track , DstTraits::is_managed );
390  dst.m_rank = src.Rank ;
391  }
392 };
393 
394 } //end Impl
395 
396 /* \class DynRankView
397  * \brief Container that creates a Kokkos view with rank determined at runtime.
398  * Essentially this is a rank 7 view
399  *
400  * Changes from View
401  * 1. The rank of the DynRankView is returned by the method rank()
402  * 2. Max rank of a DynRankView is 7
403  * 3. subview called with 'subview(...)' or 'subdynrankview(...)' (backward compatibility)
404  * 4. Every subview is returned with LayoutStride
405  * 5. Copy and Copy-Assign View to DynRankView
406  * 6. deep_copy between Views and DynRankViews
407  * 7. rank( view ); returns the rank of View or DynRankView
408  *
409  */
410 
411 template< class > struct is_dyn_rank_view : public std::false_type {};
412 
413 template< class D, class ... P >
414 struct is_dyn_rank_view< Kokkos::DynRankView<D,P...> > : public std::true_type {};
415 
416 
417 template< typename DataType , class ... Properties >
418 class DynRankView : public ViewTraits< DataType , Properties ... >
419 {
420  static_assert( !std::is_array<DataType>::value && !std::is_pointer<DataType>::value , "Cannot template DynRankView with array or pointer datatype - must be pod" );
421 
422 private:
423  template < class , class ... > friend class DynRankView ;
424  template < class , class ... > friend class Kokkos::Impl::ViewMapping ;
425 
426 public:
427  typedef ViewTraits< DataType , Properties ... > drvtraits ;
428 
429  typedef View< DataType******* , Properties...> view_type ;
430 
431  typedef ViewTraits< DataType******* , Properties ... > traits ;
432 
433 
434 private:
435  typedef Kokkos::Impl::ViewMapping< traits , typename traits::specialize > map_type ;
436  typedef Kokkos::Impl::SharedAllocationTracker track_type ;
437 
438  track_type m_track ;
439  map_type m_map ;
440  unsigned m_rank;
441 
442 public:
443  KOKKOS_INLINE_FUNCTION
444  view_type & DownCast() const { return ( view_type & ) (*this); }
445  KOKKOS_INLINE_FUNCTION
446  const view_type & ConstDownCast() const { return (const view_type & ) (*this); }
447 
448  //Types below - at least the HostMirror requires the value_type, NOT the rank 7 data_type of the traits
449 
451  typedef DynRankView< typename drvtraits::scalar_array_type ,
452  typename drvtraits::array_layout ,
453  typename drvtraits::device_type ,
454  typename drvtraits::memory_traits >
455  array_type ;
456 
458  typedef DynRankView< typename drvtraits::const_data_type ,
459  typename drvtraits::array_layout ,
460  typename drvtraits::device_type ,
461  typename drvtraits::memory_traits >
462  const_type ;
463 
465  typedef DynRankView< typename drvtraits::non_const_data_type ,
466  typename drvtraits::array_layout ,
467  typename drvtraits::device_type ,
468  typename drvtraits::memory_traits >
469  non_const_type ;
470 
472  typedef DynRankView< typename drvtraits::non_const_data_type ,
473  typename drvtraits::array_layout ,
474  typename drvtraits::host_mirror_space >
475  HostMirror ;
476 
477 
478  //----------------------------------------
479  // Domain rank and extents
480 
481 // enum { Rank = map_type::Rank }; //Will be dyn rank of 7 always, keep the enum?
482 
483  template< typename iType >
484  KOKKOS_INLINE_FUNCTION constexpr
485  typename std::enable_if< std::is_integral<iType>::value , size_t >::type
486  extent( const iType & r ) const
487  { return m_map.extent(r); }
488 
489  template< typename iType >
490  KOKKOS_INLINE_FUNCTION constexpr
491  typename std::enable_if< std::is_integral<iType>::value , int >::type
492  extent_int( const iType & r ) const
493  { return static_cast<int>(m_map.extent(r)); }
494 
495  KOKKOS_INLINE_FUNCTION constexpr
496  typename traits::array_layout layout() const
497  { return m_map.layout(); }
498 
499  //----------------------------------------
500  /* Deprecate all 'dimension' functions in favor of
501  * ISO/C++ vocabulary 'extent'.
502  */
503 
504 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
505  template< typename iType >
506  KOKKOS_INLINE_FUNCTION constexpr
507  typename std::enable_if< std::is_integral<iType>::value , size_t >::type
508  dimension( const iType & r ) const { return extent( r ); }
509 
510  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_0() const { return m_map.dimension_0(); }
511  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_1() const { return m_map.dimension_1(); }
512  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_2() const { return m_map.dimension_2(); }
513  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_3() const { return m_map.dimension_3(); }
514  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_4() const { return m_map.dimension_4(); }
515  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_5() const { return m_map.dimension_5(); }
516  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_6() const { return m_map.dimension_6(); }
517  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_7() const { return m_map.dimension_7(); }
518 #endif
519 
520  //----------------------------------------
521 
522  KOKKOS_INLINE_FUNCTION constexpr size_t size() const { return m_map.extent(0) *
523  m_map.extent(1) *
524  m_map.extent(2) *
525  m_map.extent(3) *
526  m_map.extent(4) *
527  m_map.extent(5) *
528  m_map.extent(6) *
529  m_map.extent(7); }
530 
531  KOKKOS_INLINE_FUNCTION constexpr size_t stride_0() const { return m_map.stride_0(); }
532  KOKKOS_INLINE_FUNCTION constexpr size_t stride_1() const { return m_map.stride_1(); }
533  KOKKOS_INLINE_FUNCTION constexpr size_t stride_2() const { return m_map.stride_2(); }
534  KOKKOS_INLINE_FUNCTION constexpr size_t stride_3() const { return m_map.stride_3(); }
535  KOKKOS_INLINE_FUNCTION constexpr size_t stride_4() const { return m_map.stride_4(); }
536  KOKKOS_INLINE_FUNCTION constexpr size_t stride_5() const { return m_map.stride_5(); }
537  KOKKOS_INLINE_FUNCTION constexpr size_t stride_6() const { return m_map.stride_6(); }
538  KOKKOS_INLINE_FUNCTION constexpr size_t stride_7() const { return m_map.stride_7(); }
539 
540  template< typename iType >
541  KOKKOS_INLINE_FUNCTION void stride( iType * const s ) const { m_map.stride(s); }
542 
543  //----------------------------------------
544  // Range span is the span which contains all members.
545 
546  typedef typename map_type::reference_type reference_type ;
547  typedef typename map_type::pointer_type pointer_type ;
548 
549  enum { reference_type_is_lvalue_reference = std::is_lvalue_reference< reference_type >::value };
550 
551  KOKKOS_INLINE_FUNCTION constexpr size_t span() const { return m_map.span(); }
552 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
553  // Deprecated, use 'span()' instead
554  KOKKOS_INLINE_FUNCTION constexpr size_t capacity() const { return m_map.span(); }
555 #endif
556  KOKKOS_INLINE_FUNCTION constexpr bool span_is_contiguous() const { return m_map.span_is_contiguous(); }
557  KOKKOS_INLINE_FUNCTION constexpr pointer_type data() const { return m_map.data(); }
558 
559 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
560  // Deprecated, use 'span_is_contigous()' instead
561  KOKKOS_INLINE_FUNCTION constexpr bool is_contiguous() const { return m_map.span_is_contiguous(); }
562  // Deprecated, use 'data()' instead
563  KOKKOS_INLINE_FUNCTION constexpr pointer_type ptr_on_device() const { return m_map.data(); }
564 #endif
565 
566  //----------------------------------------
567  // Allow specializations to query their specialized map
568 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
569  KOKKOS_INLINE_FUNCTION
570  const Kokkos::Impl::ViewMapping< traits , typename traits::specialize > &
571  implementation_map() const { return m_map ; }
572 #endif
573  KOKKOS_INLINE_FUNCTION
574  const Kokkos::Impl::ViewMapping< traits , typename traits::specialize > &
575  impl_map() const { return m_map ; }
576 
577  //----------------------------------------
578 
579 private:
580 
581  enum {
582  is_layout_left = std::is_same< typename traits::array_layout
583  , Kokkos::LayoutLeft >::value ,
584 
585  is_layout_right = std::is_same< typename traits::array_layout
586  , Kokkos::LayoutRight >::value ,
587 
588  is_layout_stride = std::is_same< typename traits::array_layout
589  , Kokkos::LayoutStride >::value ,
590 
591  is_default_map =
592  std::is_same< typename traits::specialize , void >::value &&
593  ( is_layout_left || is_layout_right || is_layout_stride )
594  };
595 
596  template< class Space , bool = Kokkos::Impl::MemorySpaceAccess< Space , typename traits::memory_space >::accessible > struct verify_space
597  { KOKKOS_FORCEINLINE_FUNCTION static void check() {} };
598 
599  template< class Space > struct verify_space<Space,false>
600  { KOKKOS_FORCEINLINE_FUNCTION static void check()
601  { Kokkos::abort("Kokkos::DynRankView ERROR: attempt to access inaccessible memory space"); };
602  };
603 
604 // Bounds checking macros
605 #if defined( KOKKOS_ENABLE_DEBUG_BOUNDS_CHECK )
606 
607 // rank of the calling operator - included as first argument in ARG
608 #define KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( ARG ) \
609  DynRankView::template verify_space< Kokkos::Impl::ActiveExecutionMemorySpace >::check(); \
610  Kokkos::Impl::dyn_rank_view_verify_operator_bounds< typename traits::memory_space > ARG ;
611 
612 #else
613 
614 #define KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( ARG ) \
615  DynRankView::template verify_space< Kokkos::Impl::ActiveExecutionMemorySpace >::check();
616 
617 #endif
618 
619 public:
620 
621  KOKKOS_INLINE_FUNCTION
622  constexpr unsigned rank() const { return m_rank; }
623 
624 
625  //operators ()
626  // Rank 0
627  KOKKOS_INLINE_FUNCTION
628  reference_type operator()() const
629  {
630  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (0 , this->rank(), m_track, m_map) )
631  return impl_map().reference();
632  //return m_map.reference(0,0,0,0,0,0,0);
633  }
634 
635  // Rank 1
636  // This assumes a contiguous underlying memory (i.e. no padding, no striding...)
637  template< typename iType >
638  KOKKOS_INLINE_FUNCTION
639  typename std::enable_if< std::is_same<typename drvtraits::value_type, typename drvtraits::scalar_array_type>::value && std::is_integral<iType>::value, reference_type>::type
640  operator[](const iType & i0) const
641  {
642  //Phalanx is violating this, since they use the operator to access ALL elements in the allocation
643  //KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (1 , this->rank(), m_track, m_map) )
644  return data()[i0];
645  }
646 
647  // This assumes a contiguous underlying memory (i.e. no padding, no striding...
648  // AND a Trilinos/Sacado scalar type )
649  template< typename iType >
650  KOKKOS_INLINE_FUNCTION
651  typename std::enable_if< !std::is_same<typename drvtraits::value_type, typename drvtraits::scalar_array_type>::value && std::is_integral<iType>::value, reference_type>::type
652  operator[](const iType & i0) const
653  {
654 // auto map = impl_map();
655  const size_t dim_scalar = m_map.dimension_scalar();
656  const size_t bytes = this->span() / dim_scalar;
657 
659  tmp_view_type rankone_view(this->data(), bytes, dim_scalar);
660  return rankone_view(i0);
661  }
662 
663  // Rank 1 parenthesis
664  template< typename iType >
665  KOKKOS_INLINE_FUNCTION
666  typename std::enable_if< (std::is_same<typename traits::specialize , void>::value && std::is_integral<iType>::value), reference_type>::type
667  operator()(const iType & i0 ) const
668  {
669  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (1 , this->rank(), m_track, m_map, i0) )
670  return m_map.reference(i0);
671  }
672 
673  template< typename iType >
674  KOKKOS_INLINE_FUNCTION
675  typename std::enable_if< !(std::is_same<typename traits::specialize , void>::value && std::is_integral<iType>::value), reference_type>::type
676  operator()(const iType & i0 ) const
677  {
678  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (1 , this->rank(), m_track, m_map, i0) )
679  return m_map.reference(i0,0,0,0,0,0,0);
680  }
681 
682  // Rank 2
683  template< typename iType0 , typename iType1 >
684  KOKKOS_INLINE_FUNCTION
685  typename std::enable_if< (std::is_same<typename traits::specialize , void>::value && std::is_integral<iType0>::value && std::is_integral<iType1>::value), reference_type>::type
686  operator()(const iType0 & i0 , const iType1 & i1 ) const
687  {
688  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (2 , this->rank(), m_track, m_map, i0, i1) )
689  return m_map.reference(i0,i1);
690  }
691 
692  template< typename iType0 , typename iType1 >
693  KOKKOS_INLINE_FUNCTION
694  typename std::enable_if< !(std::is_same<typename drvtraits::specialize , void>::value && std::is_integral<iType0>::value), reference_type>::type
695  operator()(const iType0 & i0 , const iType1 & i1 ) const
696  {
697  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (2 , this->rank(), m_track, m_map, i0, i1) )
698  return m_map.reference(i0,i1,0,0,0,0,0);
699  }
700 
701  // Rank 3
702  template< typename iType0 , typename iType1 , typename iType2 >
703  KOKKOS_INLINE_FUNCTION
704  typename std::enable_if< (std::is_same<typename traits::specialize , void>::value && std::is_integral<iType0>::value && std::is_integral<iType1>::value && std::is_integral<iType2>::value), reference_type>::type
705  operator()(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 ) const
706  {
707  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (3 , this->rank(), m_track, m_map, i0, i1, i2) )
708  return m_map.reference(i0,i1,i2);
709  }
710 
711  template< typename iType0 , typename iType1 , typename iType2 >
712  KOKKOS_INLINE_FUNCTION
713  typename std::enable_if< !(std::is_same<typename drvtraits::specialize , void>::value && std::is_integral<iType0>::value), reference_type>::type
714  operator()(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 ) const
715  {
716  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (3 , this->rank(), m_track, m_map, i0, i1, i2) )
717  return m_map.reference(i0,i1,i2,0,0,0,0);
718  }
719 
720  // Rank 4
721  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 >
722  KOKKOS_INLINE_FUNCTION
723  typename std::enable_if< (std::is_same<typename traits::specialize , void>::value && std::is_integral<iType0>::value && std::is_integral<iType1>::value && std::is_integral<iType2>::value && std::is_integral<iType3>::value), reference_type>::type
724  operator()(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ) const
725  {
726  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (4 , this->rank(), m_track, m_map, i0, i1, i2, i3) )
727  return m_map.reference(i0,i1,i2,i3);
728  }
729 
730  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 >
731  KOKKOS_INLINE_FUNCTION
732  typename std::enable_if< !(std::is_same<typename drvtraits::specialize , void>::value && std::is_integral<iType0>::value), reference_type>::type
733  operator()(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ) const
734  {
735  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (4 , this->rank(), m_track, m_map, i0, i1, i2, i3) )
736  return m_map.reference(i0,i1,i2,i3,0,0,0);
737  }
738 
739  // Rank 5
740  template< typename iType0 , typename iType1 , typename iType2 , typename iType3, typename iType4 >
741  KOKKOS_INLINE_FUNCTION
742  typename std::enable_if< (std::is_same<typename traits::specialize , void>::value && std::is_integral<iType0>::value && std::is_integral<iType1>::value && std::is_integral<iType2>::value && std::is_integral<iType3>::value && std::is_integral<iType4>::value), reference_type>::type
743  operator()(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 , const iType4 & i4 ) const
744  {
745  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (5 , this->rank(), m_track, m_map, i0, i1, i2, i3, i4) )
746  return m_map.reference(i0,i1,i2,i3,i4);
747  }
748 
749  template< typename iType0 , typename iType1 , typename iType2 , typename iType3, typename iType4 >
750  KOKKOS_INLINE_FUNCTION
751  typename std::enable_if< !(std::is_same<typename drvtraits::specialize , void>::value && std::is_integral<iType0>::value), reference_type>::type
752  operator()(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 , const iType4 & i4 ) const
753  {
754  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (5 , this->rank(), m_track, m_map, i0, i1, i2, i3, i4) )
755  return m_map.reference(i0,i1,i2,i3,i4,0,0);
756  }
757 
758  // Rank 6
759  template< typename iType0 , typename iType1 , typename iType2 , typename iType3, typename iType4 , typename iType5 >
760  KOKKOS_INLINE_FUNCTION
761  typename std::enable_if< (std::is_same<typename traits::specialize , void>::value && std::is_integral<iType0>::value && std::is_integral<iType1>::value && std::is_integral<iType2>::value && std::is_integral<iType3>::value && std::is_integral<iType4>::value && std::is_integral<iType5>::value), reference_type>::type
762  operator()(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 , const iType4 & i4 , const iType5 & i5 ) const
763  {
764  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (6 , this->rank(), m_track, m_map, i0, i1, i2, i3, i4, i5) )
765  return m_map.reference(i0,i1,i2,i3,i4,i5);
766  }
767 
768  template< typename iType0 , typename iType1 , typename iType2 , typename iType3, typename iType4 , typename iType5 >
769  KOKKOS_INLINE_FUNCTION
770  typename std::enable_if< !(std::is_same<typename drvtraits::specialize , void>::value && std::is_integral<iType0>::value), reference_type>::type
771  operator()(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 , const iType4 & i4 , const iType5 & i5 ) const
772  {
773  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (6 , this->rank(), m_track, m_map, i0, i1, i2, i3, i4, i5) )
774  return m_map.reference(i0,i1,i2,i3,i4,i5,0);
775  }
776 
777  // Rank 7
778  template< typename iType0 , typename iType1 , typename iType2 , typename iType3, typename iType4 , typename iType5 , typename iType6 >
779  KOKKOS_INLINE_FUNCTION
780  typename std::enable_if< (std::is_integral<iType0>::value && std::is_integral<iType1>::value && std::is_integral<iType2>::value && std::is_integral<iType3>::value && std::is_integral<iType4>::value && std::is_integral<iType5>::value && std::is_integral<iType6>::value), reference_type>::type
781  operator()(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 , const iType4 & i4 , const iType5 & i5 , const iType6 & i6 ) const
782  {
783  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (7 , this->rank(), m_track, m_map, i0, i1, i2, i3, i4, i5, i6) )
784  return m_map.reference(i0,i1,i2,i3,i4,i5,i6);
785  }
786 
787  // Rank 0
788  KOKKOS_INLINE_FUNCTION
789  reference_type access() const
790  {
791  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (0 , this->rank(), m_track, m_map) )
792  return impl_map().reference();
793  //return m_map.reference(0,0,0,0,0,0,0);
794  }
795 
796  // Rank 1
797  // Rank 1 parenthesis
798  template< typename iType >
799  KOKKOS_INLINE_FUNCTION
800  typename std::enable_if< (std::is_same<typename traits::specialize , void>::value && std::is_integral<iType>::value), reference_type>::type
801  access(const iType & i0 ) const
802  {
803  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (1 , this->rank(), m_track, m_map, i0) )
804  return m_map.reference(i0);
805  }
806 
807  template< typename iType >
808  KOKKOS_INLINE_FUNCTION
809  typename std::enable_if< !(std::is_same<typename traits::specialize , void>::value && std::is_integral<iType>::value), reference_type>::type
810  access(const iType & i0 ) const
811  {
812  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (1 , this->rank(), m_track, m_map, i0) )
813  return m_map.reference(i0,0,0,0,0,0,0);
814  }
815 
816  // Rank 2
817  template< typename iType0 , typename iType1 >
818  KOKKOS_INLINE_FUNCTION
819  typename std::enable_if< (std::is_same<typename traits::specialize , void>::value && std::is_integral<iType0>::value && std::is_integral<iType1>::value), reference_type>::type
820  access(const iType0 & i0 , const iType1 & i1 ) const
821  {
822  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (2 , this->rank(), m_track, m_map, i0, i1) )
823  return m_map.reference(i0,i1);
824  }
825 
826  template< typename iType0 , typename iType1 >
827  KOKKOS_INLINE_FUNCTION
828  typename std::enable_if< !(std::is_same<typename drvtraits::specialize , void>::value && std::is_integral<iType0>::value), reference_type>::type
829  access(const iType0 & i0 , const iType1 & i1 ) const
830  {
831  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (2 , this->rank(), m_track, m_map, i0, i1) )
832  return m_map.reference(i0,i1,0,0,0,0,0);
833  }
834 
835  // Rank 3
836  template< typename iType0 , typename iType1 , typename iType2 >
837  KOKKOS_INLINE_FUNCTION
838  typename std::enable_if< (std::is_same<typename traits::specialize , void>::value && std::is_integral<iType0>::value && std::is_integral<iType1>::value && std::is_integral<iType2>::value), reference_type>::type
839  access(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 ) const
840  {
841  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (3 , this->rank(), m_track, m_map, i0, i1, i2) )
842  return m_map.reference(i0,i1,i2);
843  }
844 
845  template< typename iType0 , typename iType1 , typename iType2 >
846  KOKKOS_INLINE_FUNCTION
847  typename std::enable_if< !(std::is_same<typename drvtraits::specialize , void>::value && std::is_integral<iType0>::value), reference_type>::type
848  access(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 ) const
849  {
850  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (3 , this->rank(), m_track, m_map, i0, i1, i2) )
851  return m_map.reference(i0,i1,i2,0,0,0,0);
852  }
853 
854  // Rank 4
855  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 >
856  KOKKOS_INLINE_FUNCTION
857  typename std::enable_if< (std::is_same<typename traits::specialize , void>::value && std::is_integral<iType0>::value && std::is_integral<iType1>::value && std::is_integral<iType2>::value && std::is_integral<iType3>::value), reference_type>::type
858  access(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ) const
859  {
860  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (4 , this->rank(), m_track, m_map, i0, i1, i2, i3) )
861  return m_map.reference(i0,i1,i2,i3);
862  }
863 
864  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 >
865  KOKKOS_INLINE_FUNCTION
866  typename std::enable_if< !(std::is_same<typename drvtraits::specialize , void>::value && std::is_integral<iType0>::value), reference_type>::type
867  access(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ) const
868  {
869  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (4 , this->rank(), m_track, m_map, i0, i1, i2, i3) )
870  return m_map.reference(i0,i1,i2,i3,0,0,0);
871  }
872 
873  // Rank 5
874  template< typename iType0 , typename iType1 , typename iType2 , typename iType3, typename iType4 >
875  KOKKOS_INLINE_FUNCTION
876  typename std::enable_if< (std::is_same<typename traits::specialize , void>::value && std::is_integral<iType0>::value && std::is_integral<iType1>::value && std::is_integral<iType2>::value && std::is_integral<iType3>::value && std::is_integral<iType4>::value), reference_type>::type
877  access(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 , const iType4 & i4 ) const
878  {
879  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (5 , this->rank(), m_track, m_map, i0, i1, i2, i3, i4) )
880  return m_map.reference(i0,i1,i2,i3,i4);
881  }
882 
883  template< typename iType0 , typename iType1 , typename iType2 , typename iType3, typename iType4 >
884  KOKKOS_INLINE_FUNCTION
885  typename std::enable_if< !(std::is_same<typename drvtraits::specialize , void>::value && std::is_integral<iType0>::value), reference_type>::type
886  access(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 , const iType4 & i4 ) const
887  {
888  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (5 , this->rank(), m_track, m_map, i0, i1, i2, i3, i4) )
889  return m_map.reference(i0,i1,i2,i3,i4,0,0);
890  }
891 
892  // Rank 6
893  template< typename iType0 , typename iType1 , typename iType2 , typename iType3, typename iType4 , typename iType5 >
894  KOKKOS_INLINE_FUNCTION
895  typename std::enable_if< (std::is_same<typename traits::specialize , void>::value && std::is_integral<iType0>::value && std::is_integral<iType1>::value && std::is_integral<iType2>::value && std::is_integral<iType3>::value && std::is_integral<iType4>::value && std::is_integral<iType5>::value), reference_type>::type
896  access(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 , const iType4 & i4 , const iType5 & i5 ) const
897  {
898  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (6 , this->rank(), m_track, m_map, i0, i1, i2, i3, i4, i5) )
899  return m_map.reference(i0,i1,i2,i3,i4,i5);
900  }
901 
902  template< typename iType0 , typename iType1 , typename iType2 , typename iType3, typename iType4 , typename iType5 >
903  KOKKOS_INLINE_FUNCTION
904  typename std::enable_if< !(std::is_same<typename drvtraits::specialize , void>::value && std::is_integral<iType0>::value), reference_type>::type
905  access(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 , const iType4 & i4 , const iType5 & i5 ) const
906  {
907  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (6 , this->rank(), m_track, m_map, i0, i1, i2, i3, i4, i5) )
908  return m_map.reference(i0,i1,i2,i3,i4,i5,0);
909  }
910 
911  // Rank 7
912  template< typename iType0 , typename iType1 , typename iType2 , typename iType3, typename iType4 , typename iType5 , typename iType6 >
913  KOKKOS_INLINE_FUNCTION
914  typename std::enable_if< (std::is_integral<iType0>::value && std::is_integral<iType1>::value && std::is_integral<iType2>::value && std::is_integral<iType3>::value && std::is_integral<iType4>::value && std::is_integral<iType5>::value && std::is_integral<iType6>::value), reference_type>::type
915  access(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 , const iType4 & i4 , const iType5 & i5 , const iType6 & i6 ) const
916  {
917  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (7 , this->rank(), m_track, m_map, i0, i1, i2, i3, i4, i5, i6) )
918  return m_map.reference(i0,i1,i2,i3,i4,i5,i6);
919  }
920 
921 #undef KOKKOS_IMPL_VIEW_OPERATOR_VERIFY
922 
923  //----------------------------------------
924  // Standard constructor, destructor, and assignment operators...
925 
926  KOKKOS_INLINE_FUNCTION
927  ~DynRankView() {}
928 
929  KOKKOS_INLINE_FUNCTION
930  DynRankView() : m_track(), m_map(), m_rank() {} //Default ctor
931 
932  KOKKOS_INLINE_FUNCTION
933  DynRankView( const DynRankView & rhs ) : m_track( rhs.m_track ), m_map( rhs.m_map ), m_rank(rhs.m_rank) {}
934 
935  KOKKOS_INLINE_FUNCTION
936  DynRankView( DynRankView && rhs ) : m_track( rhs.m_track ), m_map( rhs.m_map ), m_rank(rhs.m_rank) {}
937 
938  KOKKOS_INLINE_FUNCTION
939  DynRankView & operator = ( const DynRankView & rhs ) { m_track = rhs.m_track; m_map = rhs.m_map; m_rank = rhs.m_rank; return *this; }
940 
941  KOKKOS_INLINE_FUNCTION
942  DynRankView & operator = ( DynRankView && rhs ) { m_track = rhs.m_track; m_map = rhs.m_map; m_rank = rhs.m_rank; return *this; }
943 
944  //----------------------------------------
945  // Compatible view copy constructor and assignment
946  // may assign unmanaged from managed.
947  template< class RT , class ... RP >
948  KOKKOS_INLINE_FUNCTION
949  DynRankView( const DynRankView<RT,RP...> & rhs )
950  : m_track( rhs.m_track , traits::is_managed )
951  , m_map()
952  , m_rank(rhs.m_rank)
953  {
954  typedef typename DynRankView<RT,RP...> ::traits SrcTraits ;
955  typedef Kokkos::Impl::ViewMapping< traits , SrcTraits , typename traits::specialize > Mapping ;
956  static_assert( Mapping::is_assignable , "Incompatible DynRankView copy construction" );
957  Mapping::assign( m_map , rhs.m_map , rhs.m_track );
958  }
959 
960  template< class RT , class ... RP >
961  KOKKOS_INLINE_FUNCTION
962  DynRankView & operator = (const DynRankView<RT,RP...> & rhs )
963  {
964  typedef typename DynRankView<RT,RP...> ::traits SrcTraits ;
965  typedef Kokkos::Impl::ViewMapping< traits , SrcTraits , typename traits::specialize > Mapping ;
966  static_assert( Mapping::is_assignable , "Incompatible DynRankView copy construction" );
967  Mapping::assign( m_map , rhs.m_map , rhs.m_track );
968  m_track.assign( rhs.m_track , traits::is_managed );
969  m_rank = rhs.rank();
970  return *this;
971  }
972 
973 // Copy/Assign View to DynRankView
974  template< class RT , class ... RP >
975  KOKKOS_INLINE_FUNCTION
976  DynRankView( const View<RT,RP...> & rhs )
977  : m_track()
978  , m_map()
979  , m_rank( rhs.Rank )
980  {
981  typedef typename View<RT,RP...>::traits SrcTraits ;
982  typedef Kokkos::Impl::ViewMapping< traits , SrcTraits , Kokkos::Impl::ViewToDynRankViewTag > Mapping ;
983  static_assert( Mapping::is_assignable , "Incompatible View to DynRankView copy construction" );
984  Mapping::assign( *this , rhs );
985  }
986 
987  template< class RT , class ... RP >
988  KOKKOS_INLINE_FUNCTION
989  DynRankView & operator = ( const View<RT,RP...> & rhs )
990  {
991  typedef typename View<RT,RP...>::traits SrcTraits ;
992  typedef Kokkos::Impl::ViewMapping< traits , SrcTraits , Kokkos::Impl::ViewToDynRankViewTag > Mapping ;
993  static_assert( Mapping::is_assignable , "Incompatible View to DynRankView copy assignment" );
994  Mapping::assign( *this , rhs );
995  return *this ;
996  }
997 
998  //----------------------------------------
999  // Allocation tracking properties
1000 
1001  KOKKOS_INLINE_FUNCTION
1002  int use_count() const
1003  { return m_track.use_count(); }
1004 
1005  inline
1006  const std::string label() const
1007  { return m_track.template get_label< typename traits::memory_space >(); }
1008 
1009  //----------------------------------------
1010  // Allocation according to allocation properties and array layout
1011  // unused arg_layout dimensions must be set to KOKKOS_INVALID_INDEX so that rank deduction can properly take place
1012  template< class ... P >
1013  explicit inline
1014  DynRankView( const Kokkos::Impl::ViewCtorProp< P ... > & arg_prop
1015  , typename std::enable_if< ! Kokkos::Impl::ViewCtorProp< P... >::has_pointer
1016  , typename traits::array_layout
1017  >::type const & arg_layout
1018  )
1019  : m_track()
1020  , m_map()
1021  , m_rank( Impl::DynRankDimTraits<typename traits::specialize>::template computeRank< typename traits::array_layout, P...>(arg_prop, arg_layout) )
1022  {
1023  // Append layout and spaces if not input
1024  typedef Kokkos::Impl::ViewCtorProp< P ... > alloc_prop_input ;
1025 
1026  // use 'std::integral_constant<unsigned,I>' for non-types
1027  // to avoid duplicate class error.
1028  typedef Kokkos::Impl::ViewCtorProp
1029  < P ...
1030  , typename std::conditional
1031  < alloc_prop_input::has_label
1032  , std::integral_constant<unsigned,0>
1033  , typename std::string
1034  >::type
1035  , typename std::conditional
1036  < alloc_prop_input::has_memory_space
1037  , std::integral_constant<unsigned,1>
1038  , typename traits::device_type::memory_space
1039  >::type
1040  , typename std::conditional
1041  < alloc_prop_input::has_execution_space
1042  , std::integral_constant<unsigned,2>
1043  , typename traits::device_type::execution_space
1044  >::type
1045  > alloc_prop ;
1046 
1047  static_assert( traits::is_managed
1048  , "View allocation constructor requires managed memory" );
1049 
1050  if ( alloc_prop::initialize &&
1051 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
1052  ! alloc_prop::execution_space::is_initialized()
1053 #else
1054  ! alloc_prop::execution_space::impl_is_initialized()
1055 #endif
1056  ) {
1057  // If initializing view data then
1058  // the execution space must be initialized.
1059  Kokkos::Impl::throw_runtime_exception("Constructing DynRankView and initializing data with uninitialized execution space");
1060  }
1061 
1062  // Copy the input allocation properties with possibly defaulted properties
1063  alloc_prop prop_copy( arg_prop );
1064 
1065 //------------------------------------------------------------
1066 #if defined( KOKKOS_ENABLE_CUDA )
1067  // If allocating in CudaUVMSpace must fence before and after
1068  // the allocation to protect against possible concurrent access
1069  // on the CPU and the GPU.
1070  // Fence using the trait's executon space (which will be Kokkos::Cuda)
1071  // to avoid incomplete type errors from usng Kokkos::Cuda directly.
1072  if ( std::is_same< Kokkos::CudaUVMSpace , typename traits::device_type::memory_space >::value ) {
1073  typename traits::device_type::memory_space::execution_space().fence();
1074  }
1075 #endif
1076 //------------------------------------------------------------
1077 
1078  Kokkos::Impl::SharedAllocationRecord<> *
1079  record = m_map.allocate_shared( prop_copy, Impl::DynRankDimTraits<typename traits::specialize>::template createLayout<traits, P...>(arg_prop, arg_layout) );
1080 
1081 //------------------------------------------------------------
1082 #if defined( KOKKOS_ENABLE_CUDA )
1083  if ( std::is_same< Kokkos::CudaUVMSpace , typename traits::device_type::memory_space >::value ) {
1084  typename traits::device_type::memory_space::execution_space().fence();
1085  }
1086 #endif
1087 //------------------------------------------------------------
1088 
1089  // Setup and initialization complete, start tracking
1090  m_track.assign_allocated_record_to_uninitialized( record );
1091  }
1092 
1093 
1094  // Wrappers
1095  template< class ... P >
1096  explicit KOKKOS_INLINE_FUNCTION
1097  DynRankView( const Kokkos::Impl::ViewCtorProp< P ... > & arg_prop
1098  , typename std::enable_if< Kokkos::Impl::ViewCtorProp< P... >::has_pointer
1099  , typename traits::array_layout
1100  >::type const & arg_layout
1101  )
1102  : m_track() // No memory tracking
1103  , m_map( arg_prop , Impl::DynRankDimTraits<typename traits::specialize>::template createLayout<traits, P...>(arg_prop, arg_layout) )
1104  , m_rank( Impl::DynRankDimTraits<typename traits::specialize>::template computeRank< typename traits::array_layout, P...>(arg_prop, arg_layout) )
1105  {
1106  static_assert(
1107  std::is_same< pointer_type
1108  , typename Impl::ViewCtorProp< P... >::pointer_type
1109  >::value ,
1110  "Constructing DynRankView to wrap user memory must supply matching pointer type" );
1111  }
1112 
1113  //----------------------------------------
1114  //Constructor(s)
1115 
1116  // Simple dimension-only layout
1117  template< class ... P >
1118  explicit inline
1119  DynRankView( const Kokkos::Impl::ViewCtorProp< P ... > & arg_prop
1120  , typename std::enable_if< ! Kokkos::Impl::ViewCtorProp< P... >::has_pointer
1121  , size_t
1122  >::type const arg_N0 =KOKKOS_INVALID_INDEX
1123  , const size_t arg_N1 =KOKKOS_INVALID_INDEX
1124  , const size_t arg_N2 =KOKKOS_INVALID_INDEX
1125  , const size_t arg_N3 =KOKKOS_INVALID_INDEX
1126  , const size_t arg_N4 =KOKKOS_INVALID_INDEX
1127  , const size_t arg_N5 =KOKKOS_INVALID_INDEX
1128  , const size_t arg_N6 =KOKKOS_INVALID_INDEX
1129  , const size_t arg_N7 =KOKKOS_INVALID_INDEX
1130  )
1131  : DynRankView( arg_prop
1132  , typename traits::array_layout
1133  ( arg_N0 , arg_N1 , arg_N2 , arg_N3 , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1134  )
1135  {}
1136 
1137  template< class ... P >
1138  explicit KOKKOS_INLINE_FUNCTION
1139  DynRankView( const Kokkos::Impl::ViewCtorProp< P ... > & arg_prop
1140  , typename std::enable_if< Kokkos::Impl::ViewCtorProp< P... >::has_pointer
1141  , size_t
1142  >::type const arg_N0 =KOKKOS_INVALID_INDEX
1143  , const size_t arg_N1 =KOKKOS_INVALID_INDEX
1144  , const size_t arg_N2 =KOKKOS_INVALID_INDEX
1145  , const size_t arg_N3 =KOKKOS_INVALID_INDEX
1146  , const size_t arg_N4 =KOKKOS_INVALID_INDEX
1147  , const size_t arg_N5 =KOKKOS_INVALID_INDEX
1148  , const size_t arg_N6 =KOKKOS_INVALID_INDEX
1149  , const size_t arg_N7 =KOKKOS_INVALID_INDEX
1150  )
1151  : DynRankView( arg_prop
1152  , typename traits::array_layout
1153  ( arg_N0 , arg_N1 , arg_N2 , arg_N3 , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1154  )
1155  {}
1156 
1157  // Allocate with label and layout
1158  template< typename Label >
1159  explicit inline
1160  DynRankView( const Label & arg_label
1161  , typename std::enable_if<
1162  Kokkos::Impl::is_view_label<Label>::value ,
1163  typename traits::array_layout >::type const & arg_layout
1164  )
1165  : DynRankView( Kokkos::Impl::ViewCtorProp< std::string >( arg_label ) , arg_layout )
1166  {}
1167 
1168  // Allocate label and layout, must disambiguate from subview constructor
1169  template< typename Label >
1170  explicit inline
1171  DynRankView( const Label & arg_label
1172  , typename std::enable_if<
1173  Kokkos::Impl::is_view_label<Label>::value ,
1174  const size_t >::type arg_N0 =KOKKOS_INVALID_INDEX
1175  , const size_t arg_N1 =KOKKOS_INVALID_INDEX
1176  , const size_t arg_N2 =KOKKOS_INVALID_INDEX
1177  , const size_t arg_N3 =KOKKOS_INVALID_INDEX
1178  , const size_t arg_N4 =KOKKOS_INVALID_INDEX
1179  , const size_t arg_N5 =KOKKOS_INVALID_INDEX
1180  , const size_t arg_N6 =KOKKOS_INVALID_INDEX
1181  , const size_t arg_N7 =KOKKOS_INVALID_INDEX
1182  )
1183  : DynRankView( Kokkos::Impl::ViewCtorProp< std::string >( arg_label )
1184  , typename traits::array_layout
1185  ( arg_N0 , arg_N1 , arg_N2 , arg_N3 , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1186  )
1187  {}
1188 
1189  // For backward compatibility
1190  // NDE This ctor does not take ViewCtorProp argument - should not use alternative createLayout call
1191  explicit inline
1192  DynRankView( const ViewAllocateWithoutInitializing & arg_prop
1193  , const typename traits::array_layout & arg_layout
1194  )
1195  : DynRankView( Kokkos::Impl::ViewCtorProp< std::string , Kokkos::Impl::WithoutInitializing_t >( arg_prop.label , Kokkos::WithoutInitializing )
1196  , arg_layout
1197  )
1198  {}
1199 
1200  explicit inline
1201  DynRankView( const ViewAllocateWithoutInitializing & arg_prop
1202  , const size_t arg_N0 =KOKKOS_INVALID_INDEX
1203  , const size_t arg_N1 =KOKKOS_INVALID_INDEX
1204  , const size_t arg_N2 =KOKKOS_INVALID_INDEX
1205  , const size_t arg_N3 =KOKKOS_INVALID_INDEX
1206  , const size_t arg_N4 =KOKKOS_INVALID_INDEX
1207  , const size_t arg_N5 =KOKKOS_INVALID_INDEX
1208  , const size_t arg_N6 =KOKKOS_INVALID_INDEX
1209  , const size_t arg_N7 =KOKKOS_INVALID_INDEX
1210  )
1211  : DynRankView(Kokkos::Impl::ViewCtorProp< std::string , Kokkos::Impl::WithoutInitializing_t >( arg_prop.label , Kokkos::WithoutInitializing )
1212  , typename traits::array_layout(arg_N0, arg_N1, arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7)
1213  )
1214  {}
1215 
1216  //----------------------------------------
1217  // Memory span required to wrap these dimensions.
1218  static constexpr size_t required_allocation_size(
1219  const size_t arg_N0 = 0
1220  , const size_t arg_N1 = 0
1221  , const size_t arg_N2 = 0
1222  , const size_t arg_N3 = 0
1223  , const size_t arg_N4 = 0
1224  , const size_t arg_N5 = 0
1225  , const size_t arg_N6 = 0
1226  , const size_t arg_N7 = 0
1227  )
1228  {
1229  return map_type::memory_span(
1230  typename traits::array_layout
1231  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1232  , arg_N4 , arg_N5 , arg_N6 , arg_N7 ) );
1233  }
1234 
1235  explicit KOKKOS_INLINE_FUNCTION
1236  DynRankView( pointer_type arg_ptr
1237  , const size_t arg_N0 =KOKKOS_INVALID_INDEX
1238  , const size_t arg_N1 =KOKKOS_INVALID_INDEX
1239  , const size_t arg_N2 =KOKKOS_INVALID_INDEX
1240  , const size_t arg_N3 =KOKKOS_INVALID_INDEX
1241  , const size_t arg_N4 =KOKKOS_INVALID_INDEX
1242  , const size_t arg_N5 =KOKKOS_INVALID_INDEX
1243  , const size_t arg_N6 =KOKKOS_INVALID_INDEX
1244  , const size_t arg_N7 =KOKKOS_INVALID_INDEX
1245  )
1246  : DynRankView( Kokkos::Impl::ViewCtorProp<pointer_type>(arg_ptr) , arg_N0, arg_N1, arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7 )
1247  {}
1248 
1249  explicit KOKKOS_INLINE_FUNCTION
1250  DynRankView( pointer_type arg_ptr
1251  , typename traits::array_layout & arg_layout
1252  )
1253  : DynRankView( Kokkos::Impl::ViewCtorProp<pointer_type>(arg_ptr) , arg_layout )
1254  {}
1255 
1256 
1257  //----------------------------------------
1258  // Shared scratch memory constructor
1259 
1260  static inline
1261  size_t shmem_size( const size_t arg_N0 =KOKKOS_INVALID_INDEX ,
1262  const size_t arg_N1 =KOKKOS_INVALID_INDEX ,
1263  const size_t arg_N2 =KOKKOS_INVALID_INDEX ,
1264  const size_t arg_N3 =KOKKOS_INVALID_INDEX ,
1265  const size_t arg_N4 =KOKKOS_INVALID_INDEX ,
1266  const size_t arg_N5 =KOKKOS_INVALID_INDEX ,
1267  const size_t arg_N6 =KOKKOS_INVALID_INDEX ,
1268  const size_t arg_N7 =KOKKOS_INVALID_INDEX )
1269  {
1270  const size_t num_passed_args =
1271  ( arg_N0 !=KOKKOS_INVALID_INDEX ) + ( arg_N1 !=KOKKOS_INVALID_INDEX ) + ( arg_N2 !=KOKKOS_INVALID_INDEX ) +
1272  ( arg_N3 !=KOKKOS_INVALID_INDEX ) + ( arg_N4 !=KOKKOS_INVALID_INDEX ) + ( arg_N5 !=KOKKOS_INVALID_INDEX ) +
1273  ( arg_N6 !=KOKKOS_INVALID_INDEX ) + ( arg_N7 !=KOKKOS_INVALID_INDEX );
1274 
1275  if ( std::is_same<typename traits::specialize , void>::value && num_passed_args != traits::rank_dynamic ) {
1276  Kokkos::abort( "Kokkos::View::shmem_size() rank_dynamic != number of arguments.\n" );
1277  }
1278  {}
1279 
1280  return map_type::memory_span(
1281  typename traits::array_layout
1282  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1283  , arg_N4 , arg_N5 , arg_N6 , arg_N7 ) );
1284  }
1285 
1286  explicit KOKKOS_INLINE_FUNCTION
1287  DynRankView( const typename traits::execution_space::scratch_memory_space & arg_space
1288  , const typename traits::array_layout & arg_layout )
1289  : DynRankView( Kokkos::Impl::ViewCtorProp<pointer_type>(
1290  reinterpret_cast<pointer_type>(
1291  arg_space.get_shmem( map_type::memory_span(
1292  Impl::DynRankDimTraits<typename traits::specialize>::createLayout( arg_layout ) //is this correct?
1293  ) ) ) )
1294  , arg_layout )
1295  {}
1296 
1297  explicit KOKKOS_INLINE_FUNCTION
1298  DynRankView( const typename traits::execution_space::scratch_memory_space & arg_space
1299  , const size_t arg_N0 =KOKKOS_INVALID_INDEX
1300  , const size_t arg_N1 =KOKKOS_INVALID_INDEX
1301  , const size_t arg_N2 =KOKKOS_INVALID_INDEX
1302  , const size_t arg_N3 =KOKKOS_INVALID_INDEX
1303  , const size_t arg_N4 =KOKKOS_INVALID_INDEX
1304  , const size_t arg_N5 =KOKKOS_INVALID_INDEX
1305  , const size_t arg_N6 =KOKKOS_INVALID_INDEX
1306  , const size_t arg_N7 =KOKKOS_INVALID_INDEX )
1307 
1308  : DynRankView( Kokkos::Impl::ViewCtorProp<pointer_type>(
1309  reinterpret_cast<pointer_type>(
1310  arg_space.get_shmem(
1311  map_type::memory_span(
1312  Impl::DynRankDimTraits<typename traits::specialize>::createLayout(
1313  typename traits::array_layout
1314  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1315  , arg_N4 , arg_N5 , arg_N6 , arg_N7 ) ) ) ) )
1316  )
1317  , typename traits::array_layout
1318  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1319  , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1320  )
1321  {}
1322 
1323 };
1324 
1325 
1326  template < typename D , class ... P >
1327  KOKKOS_INLINE_FUNCTION
1328  constexpr unsigned rank( const DynRankView<D , P...> & DRV ) { return DRV.rank(); } //needed for transition to common constexpr method in view and dynrankview to return rank
1329 
1330 //----------------------------------------------------------------------------
1331 // Subview mapping.
1332 // Deduce destination view type from source view traits and subview arguments
1333 
1334 namespace Impl {
1335 
1336 struct DynRankSubviewTag {};
1337 
1338 } // namespace Impl
1339 
1340 namespace Impl {
1341 
1342 template< class SrcTraits , class ... Args >
1343 struct ViewMapping
1344  < typename std::enable_if<(
1345  std::is_same< typename SrcTraits::specialize , void >::value
1346  &&
1347  (
1348  std::is_same< typename SrcTraits::array_layout
1349  , Kokkos::LayoutLeft >::value ||
1350  std::is_same< typename SrcTraits::array_layout
1351  , Kokkos::LayoutRight >::value ||
1352  std::is_same< typename SrcTraits::array_layout
1353  , Kokkos::LayoutStride >::value
1354  )
1355  ), Kokkos::Impl::DynRankSubviewTag >::type
1356  , SrcTraits
1357  , Args ... >
1358 {
1359 private:
1360 
1361  enum
1362  { RZ = false
1363  , R0 = bool(is_integral_extent<0,Args...>::value)
1364  , R1 = bool(is_integral_extent<1,Args...>::value)
1365  , R2 = bool(is_integral_extent<2,Args...>::value)
1366  , R3 = bool(is_integral_extent<3,Args...>::value)
1367  , R4 = bool(is_integral_extent<4,Args...>::value)
1368  , R5 = bool(is_integral_extent<5,Args...>::value)
1369  , R6 = bool(is_integral_extent<6,Args...>::value)
1370  };
1371 
1372  enum { rank = unsigned(R0) + unsigned(R1) + unsigned(R2) + unsigned(R3)
1373  + unsigned(R4) + unsigned(R5) + unsigned(R6) };
1374 
1375  typedef Kokkos::LayoutStride array_layout ;
1376 
1377  typedef typename SrcTraits::value_type value_type ;
1378 
1379  typedef value_type******* data_type ;
1380 
1381 public:
1382 
1383  typedef Kokkos::ViewTraits
1384  < data_type
1385  , array_layout
1386  , typename SrcTraits::device_type
1387  , typename SrcTraits::memory_traits > traits_type ;
1388 
1389  typedef Kokkos::View
1390  < data_type
1391  , array_layout
1392  , typename SrcTraits::device_type
1393  , typename SrcTraits::memory_traits > type ;
1394 
1395 
1396  template< class MemoryTraits >
1397  struct apply {
1398 
1399  static_assert( Kokkos::Impl::is_memory_traits< MemoryTraits >::value , "" );
1400 
1401  typedef Kokkos::ViewTraits
1402  < data_type
1403  , array_layout
1404  , typename SrcTraits::device_type
1405  , MemoryTraits > traits_type ;
1406 
1407  typedef Kokkos::View
1408  < data_type
1409  , array_layout
1410  , typename SrcTraits::device_type
1411  , MemoryTraits > type ;
1412  };
1413 
1414 
1415  typedef typename SrcTraits::dimension dimension ;
1416 
1417  template < class Arg0 = int, class Arg1 = int, class Arg2 = int, class Arg3 = int, class Arg4 = int, class Arg5 = int, class Arg6 = int >
1418  struct ExtentGenerator {
1419  KOKKOS_INLINE_FUNCTION
1420  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() )
1421  {
1422  return SubviewExtents< 7 , rank>( dim , arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 );
1423  }
1424  };
1425 
1426 
1427  typedef Kokkos::DynRankView< value_type , array_layout , typename SrcTraits::device_type , typename SrcTraits::memory_traits > ret_type;
1428 
1429  template < typename T , class ... P >
1430  KOKKOS_INLINE_FUNCTION
1431  static ret_type subview( const unsigned src_rank , Kokkos::DynRankView< T , P...> const & src
1432  , Args ... args )
1433  {
1434 
1435  typedef ViewMapping< traits_type, typename traits_type::specialize > DstType ;
1436 
1437  typedef typename std::conditional< (rank==0) , ViewDimension<>
1438  , typename std::conditional< (rank==1) , ViewDimension<0>
1439  , typename std::conditional< (rank==2) , ViewDimension<0,0>
1440  , typename std::conditional< (rank==3) , ViewDimension<0,0,0>
1441  , typename std::conditional< (rank==4) , ViewDimension<0,0,0,0>
1442  , typename std::conditional< (rank==5) , ViewDimension<0,0,0,0,0>
1443  , typename std::conditional< (rank==6) , ViewDimension<0,0,0,0,0,0>
1444  , ViewDimension<0,0,0,0,0,0,0>
1445  >::type >::type >::type >::type >::type >::type >::type DstDimType ;
1446 
1447  typedef ViewOffset< DstDimType , Kokkos::LayoutStride > dst_offset_type ;
1448  typedef typename DstType::handle_type dst_handle_type ;
1449 
1450  ret_type dst ;
1451 
1452  const SubviewExtents< 7 , rank > extents =
1453  ExtentGenerator< Args ... >::generator( src.m_map.m_impl_offset.m_dim , args... ) ;
1454 
1455  dst_offset_type tempdst( src.m_map.m_impl_offset , extents ) ;
1456 
1457  dst.m_track = src.m_track ;
1458 
1459  dst.m_map.m_impl_offset.m_dim.N0 = tempdst.m_dim.N0 ;
1460  dst.m_map.m_impl_offset.m_dim.N1 = tempdst.m_dim.N1 ;
1461  dst.m_map.m_impl_offset.m_dim.N2 = tempdst.m_dim.N2 ;
1462  dst.m_map.m_impl_offset.m_dim.N3 = tempdst.m_dim.N3 ;
1463  dst.m_map.m_impl_offset.m_dim.N4 = tempdst.m_dim.N4 ;
1464  dst.m_map.m_impl_offset.m_dim.N5 = tempdst.m_dim.N5 ;
1465  dst.m_map.m_impl_offset.m_dim.N6 = tempdst.m_dim.N6 ;
1466 
1467  dst.m_map.m_impl_offset.m_stride.S0 = tempdst.m_stride.S0 ;
1468  dst.m_map.m_impl_offset.m_stride.S1 = tempdst.m_stride.S1 ;
1469  dst.m_map.m_impl_offset.m_stride.S2 = tempdst.m_stride.S2 ;
1470  dst.m_map.m_impl_offset.m_stride.S3 = tempdst.m_stride.S3 ;
1471  dst.m_map.m_impl_offset.m_stride.S4 = tempdst.m_stride.S4 ;
1472  dst.m_map.m_impl_offset.m_stride.S5 = tempdst.m_stride.S5 ;
1473  dst.m_map.m_impl_offset.m_stride.S6 = tempdst.m_stride.S6 ;
1474 
1475  dst.m_map.m_impl_handle = dst_handle_type( src.m_map.m_impl_handle +
1476  src.m_map.m_impl_offset( extents.domain_offset(0)
1477  , extents.domain_offset(1)
1478  , extents.domain_offset(2)
1479  , extents.domain_offset(3)
1480  , extents.domain_offset(4)
1481  , extents.domain_offset(5)
1482  , extents.domain_offset(6)
1483  ) );
1484 
1485  dst.m_rank = ( src_rank > 0 ? unsigned(R0) : 0 )
1486  + ( src_rank > 1 ? unsigned(R1) : 0 )
1487  + ( src_rank > 2 ? unsigned(R2) : 0 )
1488  + ( src_rank > 3 ? unsigned(R3) : 0 )
1489  + ( src_rank > 4 ? unsigned(R4) : 0 )
1490  + ( src_rank > 5 ? unsigned(R5) : 0 )
1491  + ( src_rank > 6 ? unsigned(R6) : 0 ) ;
1492 
1493  return dst ;
1494  }
1495 };
1496 
1497 } // end Impl
1498 
1499 
1500 template< class V , class ... Args >
1501 using Subdynrankview = typename Kokkos::Impl::ViewMapping< Kokkos::Impl::DynRankSubviewTag , V , Args... >::ret_type ;
1502 
1503 template< class D , class ... P , class ...Args >
1504 KOKKOS_INLINE_FUNCTION
1505 Subdynrankview< ViewTraits<D******* , P...> , Args... >
1506 subdynrankview( const Kokkos::DynRankView< D , P... > &src , Args...args)
1507  {
1508  if ( src.rank() > sizeof...(Args) ) //allow sizeof...(Args) >= src.rank(), ignore the remaining args
1509  { Kokkos::abort("subdynrankview: num of args must be >= rank of the source DynRankView"); }
1510 
1511  typedef Kokkos::Impl::ViewMapping< Kokkos::Impl::DynRankSubviewTag , Kokkos::ViewTraits< D*******, P... > , Args... > metafcn ;
1512 
1513  return metafcn::subview( src.rank() , src , args... );
1514  }
1515 
1516 //Wrapper to allow subview function name
1517 template< class D , class ... P , class ...Args >
1518 KOKKOS_INLINE_FUNCTION
1519 Subdynrankview< ViewTraits<D******* , P...> , Args... >
1520 subview( const Kokkos::DynRankView< D , P... > &src , Args...args)
1521  {
1522  return subdynrankview( src , args... );
1523  }
1524 
1525 } // namespace Kokkos
1526 
1527 namespace Kokkos {
1528 
1529 // overload == and !=
1530 template< class LT , class ... LP , class RT , class ... RP >
1531 KOKKOS_INLINE_FUNCTION
1532 bool operator == ( const DynRankView<LT,LP...> & lhs ,
1533  const DynRankView<RT,RP...> & rhs )
1534 {
1535  // Same data, layout, dimensions
1536  typedef ViewTraits<LT,LP...> lhs_traits ;
1537  typedef ViewTraits<RT,RP...> rhs_traits ;
1538 
1539  return
1540  std::is_same< typename lhs_traits::const_value_type ,
1541  typename rhs_traits::const_value_type >::value &&
1542  std::is_same< typename lhs_traits::array_layout ,
1543  typename rhs_traits::array_layout >::value &&
1544  std::is_same< typename lhs_traits::memory_space ,
1545  typename rhs_traits::memory_space >::value &&
1546  lhs.rank() == rhs.rank() &&
1547  lhs.data() == rhs.data() &&
1548  lhs.span() == rhs.span() &&
1549  lhs.extent(0) == rhs.extent(0) &&
1550  lhs.extent(1) == rhs.extent(1) &&
1551  lhs.extent(2) == rhs.extent(2) &&
1552  lhs.extent(3) == rhs.extent(3) &&
1553  lhs.extent(4) == rhs.extent(4) &&
1554  lhs.extent(5) == rhs.extent(5) &&
1555  lhs.extent(6) == rhs.extent(6) &&
1556  lhs.extent(7) == rhs.extent(7);
1557 }
1558 
1559 template< class LT , class ... LP , class RT , class ... RP >
1560 KOKKOS_INLINE_FUNCTION
1561 bool operator != ( const DynRankView<LT,LP...> & lhs ,
1562  const DynRankView<RT,RP...> & rhs )
1563 {
1564  return ! ( operator==(lhs,rhs) );
1565 }
1566 
1567 } //end Kokkos
1568 
1569 //----------------------------------------------------------------------------
1570 //----------------------------------------------------------------------------
1571 namespace Kokkos {
1572 namespace Impl {
1573 
1574 template< class OutputView , typename Enable = void >
1575 struct DynRankViewFill {
1576 
1577  typedef typename OutputView::traits::const_value_type const_value_type ;
1578 
1579  const OutputView output ;
1580  const_value_type input ;
1581 
1582  KOKKOS_INLINE_FUNCTION
1583  void operator()( const size_t i0 ) const
1584  {
1585  const size_t n1 = output.extent(1);
1586  const size_t n2 = output.extent(2);
1587  const size_t n3 = output.extent(3);
1588  const size_t n4 = output.extent(4);
1589  const size_t n5 = output.extent(5);
1590  const size_t n6 = output.extent(6);
1591 
1592  for ( size_t i1 = 0 ; i1 < n1 ; ++i1 ) {
1593  for ( size_t i2 = 0 ; i2 < n2 ; ++i2 ) {
1594  for ( size_t i3 = 0 ; i3 < n3 ; ++i3 ) {
1595  for ( size_t i4 = 0 ; i4 < n4 ; ++i4 ) {
1596  for ( size_t i5 = 0 ; i5 < n5 ; ++i5 ) {
1597  for ( size_t i6 = 0 ; i6 < n6 ; ++i6 ) {
1598  output.access(i0,i1,i2,i3,i4,i5,i6) = input ;
1599  }}}}}}
1600  }
1601 
1602  DynRankViewFill( const OutputView & arg_out , const_value_type & arg_in )
1603  : output( arg_out ), input( arg_in )
1604  {
1605  typedef typename OutputView::execution_space execution_space ;
1607 
1608  const Kokkos::Impl::ParallelFor< DynRankViewFill , Policy > closure( *this , Policy( 0 , output.extent(0) ) );
1609 
1610  closure.execute();
1611 
1612  execution_space().fence();
1613  }
1614 };
1615 
1616 template< class OutputView >
1617 struct DynRankViewFill< OutputView , typename std::enable_if< OutputView::Rank == 0 >::type > {
1618  DynRankViewFill( const OutputView & dst , const typename OutputView::const_value_type & src )
1619  {
1620  Kokkos::Impl::DeepCopy< typename OutputView::memory_space , Kokkos::HostSpace >
1621  ( dst.data() , & src , sizeof(typename OutputView::const_value_type) );
1622  }
1623 };
1624 
1625 template< class OutputView , class InputView , class ExecSpace = typename OutputView::execution_space >
1626 struct DynRankViewRemap {
1627 
1628  const OutputView output ;
1629  const InputView input ;
1630  const size_t n0 ;
1631  const size_t n1 ;
1632  const size_t n2 ;
1633  const size_t n3 ;
1634  const size_t n4 ;
1635  const size_t n5 ;
1636  const size_t n6 ;
1637  const size_t n7 ;
1638 
1639  DynRankViewRemap( const OutputView & arg_out , const InputView & arg_in )
1640  : output( arg_out ), input( arg_in )
1641  , n0( std::min( (size_t)arg_out.extent(0) , (size_t)arg_in.extent(0) ) )
1642  , n1( std::min( (size_t)arg_out.extent(1) , (size_t)arg_in.extent(1) ) )
1643  , n2( std::min( (size_t)arg_out.extent(2) , (size_t)arg_in.extent(2) ) )
1644  , n3( std::min( (size_t)arg_out.extent(3) , (size_t)arg_in.extent(3) ) )
1645  , n4( std::min( (size_t)arg_out.extent(4) , (size_t)arg_in.extent(4) ) )
1646  , n5( std::min( (size_t)arg_out.extent(5) , (size_t)arg_in.extent(5) ) )
1647  , n6( std::min( (size_t)arg_out.extent(6) , (size_t)arg_in.extent(6) ) )
1648  , n7( std::min( (size_t)arg_out.extent(7) , (size_t)arg_in.extent(7) ) )
1649  {
1650  typedef Kokkos::RangePolicy< ExecSpace > Policy ;
1651  const Kokkos::Impl::ParallelFor< DynRankViewRemap , Policy > closure( *this , Policy( 0 , n0 ) );
1652  closure.execute();
1653  // Kokkos::fence(); // ??
1654  }
1655 
1656  KOKKOS_INLINE_FUNCTION
1657  void operator()( const size_t i0 ) const
1658  {
1659  for ( size_t i1 = 0 ; i1 < n1 ; ++i1 ) {
1660  for ( size_t i2 = 0 ; i2 < n2 ; ++i2 ) {
1661  for ( size_t i3 = 0 ; i3 < n3 ; ++i3 ) {
1662  for ( size_t i4 = 0 ; i4 < n4 ; ++i4 ) {
1663  for ( size_t i5 = 0 ; i5 < n5 ; ++i5 ) {
1664  for ( size_t i6 = 0 ; i6 < n6 ; ++i6 ) {
1665  output.access(i0,i1,i2,i3,i4,i5,i6) = input.access(i0,i1,i2,i3,i4,i5,i6);
1666  }}}}}}
1667  }
1668 };
1669 
1670 } /* namespace Impl */
1671 } /* namespace Kokkos */
1672 
1673 
1674 namespace Kokkos {
1675 
1677 template< class DT , class ... DP >
1678 inline
1679 void deep_copy
1680  ( const DynRankView<DT,DP...> & dst
1681  , typename ViewTraits<DT,DP...>::const_value_type & value
1682  , typename std::enable_if<
1683  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value
1684  >::type * = 0 )
1685 {
1686  static_assert(
1687  std::is_same< typename ViewTraits<DT,DP...>::non_const_value_type ,
1688  typename ViewTraits<DT,DP...>::value_type >::value
1689  , "deep_copy requires non-const type" );
1690 
1691  Kokkos::Impl::DynRankViewFill< DynRankView<DT,DP...> >( dst , value );
1692 }
1693 
1695 template< class ST , class ... SP >
1696 inline
1697 void deep_copy
1698  ( typename ViewTraits<ST,SP...>::non_const_value_type & dst
1699  , const DynRankView<ST,SP...> & src
1700  , typename std::enable_if<
1701  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value
1702  >::type * = 0 )
1703 {
1704  if ( src.rank() != 0 )
1705  {
1706  Kokkos::abort("");
1707  }
1708 
1709  typedef ViewTraits<ST,SP...> src_traits ;
1710  typedef typename src_traits::memory_space src_memory_space ;
1711  Kokkos::Impl::DeepCopy< HostSpace , src_memory_space >( & dst , src.data() , sizeof(ST) );
1712 }
1713 
1714 //----------------------------------------------------------------------------
1718 template< class DstType , class SrcType >
1719 inline
1720 void deep_copy
1721  ( const DstType & dst
1722  , const SrcType & src
1723  , typename std::enable_if<(
1724  std::is_same< typename DstType::traits::specialize , void >::value &&
1725  std::is_same< typename SrcType::traits::specialize , void >::value
1726  &&
1727  ( Kokkos::is_dyn_rank_view<DstType>::value || Kokkos::is_dyn_rank_view<SrcType>::value)
1728  )>::type * = 0 )
1729 {
1730  static_assert(
1731  std::is_same< typename DstType::traits::value_type ,
1732  typename DstType::traits::non_const_value_type >::value
1733  , "deep_copy requires non-const destination type" );
1734 
1735  typedef DstType dst_type ;
1736  typedef SrcType src_type ;
1737 
1738  typedef typename dst_type::execution_space dst_execution_space ;
1739  typedef typename src_type::execution_space src_execution_space ;
1740  typedef typename dst_type::memory_space dst_memory_space ;
1741  typedef typename src_type::memory_space src_memory_space ;
1742 
1743  enum { DstExecCanAccessSrc =
1745 
1746  enum { SrcExecCanAccessDst =
1748 
1749  if ( (void *) dst.data() != (void*) src.data() ) {
1750 
1751  // Concern: If overlapping views then a parallel copy will be erroneous.
1752  // ...
1753 
1754  // If same type, equal layout, equal dimensions, equal span, and contiguous memory then can byte-wise copy
1755  if ( rank(src) == 0 && rank(dst) == 0 )
1756  {
1757  typedef typename dst_type::value_type value_type ;
1758  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , sizeof(value_type) );
1759  }
1760  else if ( std::is_same< typename DstType::traits::value_type ,
1761  typename SrcType::traits::non_const_value_type >::value &&
1762  (
1763  ( std::is_same< typename DstType::traits::array_layout ,
1764  typename SrcType::traits::array_layout >::value
1765  &&
1766  ( std::is_same< typename DstType::traits::array_layout ,
1767  typename Kokkos::LayoutLeft>::value
1768  ||
1769  std::is_same< typename DstType::traits::array_layout ,
1770  typename Kokkos::LayoutRight>::value
1771  )
1772  )
1773  ||
1774  (
1775  rank(dst) == 1
1776  &&
1777  rank(src) == 1
1778  )
1779  ) &&
1780  dst.span_is_contiguous() &&
1781  src.span_is_contiguous() &&
1782  dst.span() == src.span() &&
1783  dst.extent(0) == src.extent(0) &&
1784 
1785  dst.extent(1) == src.extent(1) &&
1786  dst.extent(2) == src.extent(2) &&
1787  dst.extent(3) == src.extent(3) &&
1788  dst.extent(4) == src.extent(4) &&
1789  dst.extent(5) == src.extent(5) &&
1790  dst.extent(6) == src.extent(6) &&
1791  dst.extent(7) == src.extent(7) ) {
1792 
1793  const size_t nbytes = sizeof(typename dst_type::value_type) * dst.span();
1794 
1795  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1796  }
1797  else if ( std::is_same< typename DstType::traits::value_type ,
1798  typename SrcType::traits::non_const_value_type >::value &&
1799  (
1800  ( std::is_same< typename DstType::traits::array_layout ,
1801  typename SrcType::traits::array_layout >::value
1802  &&
1803  std::is_same< typename DstType::traits::array_layout ,
1804  typename Kokkos::LayoutStride>::value
1805  )
1806  ||
1807  (
1808  rank(dst) == 1
1809  &&
1810  rank(src) == 1
1811  )
1812  ) &&
1813  dst.span_is_contiguous() &&
1814  src.span_is_contiguous() &&
1815  dst.span() == src.span() &&
1816  dst.extent(0) == src.extent(0) &&
1817  dst.extent(1) == src.extent(1) &&
1818  dst.extent(2) == src.extent(2) &&
1819  dst.extent(3) == src.extent(3) &&
1820  dst.extent(4) == src.extent(4) &&
1821  dst.extent(5) == src.extent(5) &&
1822  dst.extent(6) == src.extent(6) &&
1823  dst.extent(7) == src.extent(7) &&
1824  dst.stride_0() == src.stride_0() &&
1825  dst.stride_1() == src.stride_1() &&
1826  dst.stride_2() == src.stride_2() &&
1827  dst.stride_3() == src.stride_3() &&
1828  dst.stride_4() == src.stride_4() &&
1829  dst.stride_5() == src.stride_5() &&
1830  dst.stride_6() == src.stride_6() &&
1831  dst.stride_7() == src.stride_7()
1832  ) {
1833 
1834  const size_t nbytes = sizeof(typename dst_type::value_type) * dst.span();
1835 
1836  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1837  }
1838  else if ( DstExecCanAccessSrc ) {
1839  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
1840  Kokkos::Impl::DynRankViewRemap< dst_type , src_type >( dst , src );
1841  }
1842  else if ( SrcExecCanAccessDst ) {
1843  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
1844  Kokkos::Impl::DynRankViewRemap< dst_type , src_type , src_execution_space >( dst , src );
1845  }
1846  else {
1847  Kokkos::Impl::throw_runtime_exception("deep_copy given views that would require a temporary allocation");
1848  }
1849  }
1850 }
1851 
1852 } //end Kokkos
1853 
1854 
1855 //----------------------------------------------------------------------------
1856 //----------------------------------------------------------------------------
1857 
1858 namespace Kokkos {
1859 namespace Impl {
1860 
1861 
1862 // Deduce Mirror Types
1863 template<class Space, class T, class ... P>
1864 struct MirrorDRViewType {
1865  // The incoming view_type
1866  typedef typename Kokkos::DynRankView<T,P...> src_view_type;
1867  // The memory space for the mirror view
1868  typedef typename Space::memory_space memory_space;
1869  // Check whether it is the same memory space
1870  enum { is_same_memspace = std::is_same<memory_space,typename src_view_type::memory_space>::value };
1871  // The array_layout
1872  typedef typename src_view_type::array_layout array_layout;
1873  // The data type (we probably want it non-const since otherwise we can't even deep_copy to it.
1874  typedef typename src_view_type::non_const_data_type data_type;
1875  // The destination view type if it is not the same memory space
1876  typedef Kokkos::DynRankView<data_type,array_layout,Space> dest_view_type;
1877  // If it is the same memory_space return the existsing view_type
1878  // This will also keep the unmanaged trait if necessary
1879  typedef typename std::conditional<is_same_memspace,src_view_type,dest_view_type>::type view_type;
1880 };
1881 
1882 template<class Space, class T, class ... P>
1883 struct MirrorDRVType {
1884  // The incoming view_type
1885  typedef typename Kokkos::DynRankView<T,P...> src_view_type;
1886  // The memory space for the mirror view
1887  typedef typename Space::memory_space memory_space;
1888  // Check whether it is the same memory space
1889  enum { is_same_memspace = std::is_same<memory_space,typename src_view_type::memory_space>::value };
1890  // The array_layout
1891  typedef typename src_view_type::array_layout array_layout;
1892  // The data type (we probably want it non-const since otherwise we can't even deep_copy to it.
1893  typedef typename src_view_type::non_const_data_type data_type;
1894  // The destination view type if it is not the same memory space
1895  typedef Kokkos::DynRankView<data_type,array_layout,Space> view_type;
1896 };
1897 
1898 }
1899 
1900 template< class T , class ... P >
1901 inline
1902 typename DynRankView<T,P...>::HostMirror
1903 create_mirror( const DynRankView<T,P...> & src
1904  , typename std::enable_if<
1905  std::is_same< typename ViewTraits<T,P...>::specialize , void >::value &&
1906  ! std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
1907  , Kokkos::LayoutStride >::value
1908  >::type * = 0
1909  )
1910 {
1911  typedef DynRankView<T,P...> src_type ;
1912  typedef typename src_type::HostMirror dst_type ;
1913 
1914  return dst_type( std::string( src.label() ).append("_mirror")
1915  , Impl::reconstructLayout(src.layout(), src.rank()) );
1916 }
1917 
1918 
1919 template< class T , class ... P >
1920 inline
1921 typename DynRankView<T,P...>::HostMirror
1922 create_mirror( const DynRankView<T,P...> & src
1923  , typename std::enable_if<
1924  std::is_same< typename ViewTraits<T,P...>::specialize , void >::value &&
1925  std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
1926  , Kokkos::LayoutStride >::value
1927  >::type * = 0
1928  )
1929 {
1930  typedef DynRankView<T,P...> src_type ;
1931  typedef typename src_type::HostMirror dst_type ;
1932 
1933  return dst_type( std::string( src.label() ).append("_mirror")
1934  , Impl::reconstructLayout(src.layout(), src.rank()) );
1935 }
1936 
1937 
1938 // Create a mirror in a new space (specialization for different space)
1939 template<class Space, class T, class ... P>
1940 typename Impl::MirrorDRVType<Space,T,P ...>::view_type
1941 create_mirror(const Space& , const Kokkos::DynRankView<T,P...> & src
1942  , typename std::enable_if<
1943  std::is_same< typename ViewTraits<T,P...>::specialize , void >::value
1944  >::type * = 0) {
1945  return typename Impl::MirrorDRVType<Space,T,P ...>::view_type(src.label(), Impl::reconstructLayout(src.layout(), src.rank()) );
1946 }
1947 
1948 template< class T , class ... P >
1949 inline
1950 typename DynRankView<T,P...>::HostMirror
1951 create_mirror_view( const DynRankView<T,P...> & src
1952  , typename std::enable_if<(
1953  std::is_same< typename DynRankView<T,P...>::memory_space
1954  , typename DynRankView<T,P...>::HostMirror::memory_space
1955  >::value
1956  &&
1957  std::is_same< typename DynRankView<T,P...>::data_type
1958  , typename DynRankView<T,P...>::HostMirror::data_type
1959  >::value
1960  )>::type * = 0
1961  )
1962 {
1963  return src ;
1964 }
1965 
1966 template< class T , class ... P >
1967 inline
1968 typename DynRankView<T,P...>::HostMirror
1969 create_mirror_view( const DynRankView<T,P...> & src
1970  , typename std::enable_if< ! (
1971  std::is_same< typename DynRankView<T,P...>::memory_space
1972  , typename DynRankView<T,P...>::HostMirror::memory_space
1973  >::value
1974  &&
1975  std::is_same< typename DynRankView<T,P...>::data_type
1976  , typename DynRankView<T,P...>::HostMirror::data_type
1977  >::value
1978  )>::type * = 0
1979  )
1980 {
1981  return Kokkos::create_mirror( src );
1982 }
1983 
1984 // Create a mirror view in a new space (specialization for same space)
1985 template<class Space, class T, class ... P>
1986 typename Impl::MirrorDRViewType<Space,T,P ...>::view_type
1987 create_mirror_view(const Space& , const Kokkos::DynRankView<T,P...> & src
1988  , typename std::enable_if<Impl::MirrorDRViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
1989  return src;
1990 }
1991 
1992 // Create a mirror view in a new space (specialization for different space)
1993 template<class Space, class T, class ... P>
1994 typename Impl::MirrorDRViewType<Space,T,P ...>::view_type
1995 create_mirror_view(const Space& , const Kokkos::DynRankView<T,P...> & src
1996  , typename std::enable_if<!Impl::MirrorDRViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
1997  return typename Impl::MirrorDRViewType<Space,T,P ...>::view_type(src.label(), Impl::reconstructLayout(src.layout(), src.rank()) );
1998 }
1999 
2000 // Create a mirror view and deep_copy in a new space (specialization for same space)
2001 template<class Space, class T, class ... P>
2002 typename Impl::MirrorDRViewType<Space,T,P ...>::view_type
2003 create_mirror_view_and_copy(const Space& , const Kokkos::DynRankView<T,P...> & src
2004  , std::string const& name = ""
2005  , typename std::enable_if<Impl::MirrorDRViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2006  (void)name;
2007  return src;
2008 }
2009 
2010 // Create a mirror view and deep_copy in a new space (specialization for different space)
2011 template<class Space, class T, class ... P>
2012 typename Impl::MirrorDRViewType<Space,T,P ...>::view_type
2013 create_mirror_view_and_copy(const Space& , const Kokkos::DynRankView<T,P...> & src
2014  , std::string const& name = ""
2015  , typename std::enable_if<!Impl::MirrorDRViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2016  using Mirror = typename Impl::MirrorDRViewType<Space,T,P ...>::view_type;
2017  std::string label = name.empty() ? src.label() : name;
2018  auto mirror = Mirror( Kokkos::ViewAllocateWithoutInitializing(label), Impl::reconstructLayout(src.layout(), src.rank()) );
2019  deep_copy(mirror, src);
2020  return mirror;
2021 }
2022 
2023 } //end Kokkos
2024 
2025 
2026 //----------------------------------------------------------------------------
2027 //----------------------------------------------------------------------------
2028 
2029 namespace Kokkos {
2031 template< class T , class ... P >
2032 inline
2033 void resize( DynRankView<T,P...> & v ,
2034  const size_t n0 =KOKKOS_INVALID_INDEX ,
2035  const size_t n1 =KOKKOS_INVALID_INDEX ,
2036  const size_t n2 =KOKKOS_INVALID_INDEX ,
2037  const size_t n3 =KOKKOS_INVALID_INDEX ,
2038  const size_t n4 =KOKKOS_INVALID_INDEX ,
2039  const size_t n5 =KOKKOS_INVALID_INDEX ,
2040  const size_t n6 =KOKKOS_INVALID_INDEX ,
2041  const size_t n7 =KOKKOS_INVALID_INDEX )
2042 {
2043  typedef DynRankView<T,P...> drview_type ;
2044 
2045  static_assert( Kokkos::ViewTraits<T,P...>::is_managed , "Can only resize managed views" );
2046 
2047  drview_type v_resized( v.label(), n0, n1, n2, n3, n4, n5, n6 );
2048 
2049  Kokkos::Impl::DynRankViewRemap< drview_type , drview_type >( v_resized, v );
2050 
2051  v = v_resized ;
2052 }
2053 
2055 template< class T , class ... P >
2056 inline
2057 void realloc( DynRankView<T,P...> & v ,
2058  const size_t n0 =KOKKOS_INVALID_INDEX ,
2059  const size_t n1 =KOKKOS_INVALID_INDEX ,
2060  const size_t n2 =KOKKOS_INVALID_INDEX ,
2061  const size_t n3 =KOKKOS_INVALID_INDEX ,
2062  const size_t n4 =KOKKOS_INVALID_INDEX ,
2063  const size_t n5 =KOKKOS_INVALID_INDEX ,
2064  const size_t n6 =KOKKOS_INVALID_INDEX ,
2065  const size_t n7 =KOKKOS_INVALID_INDEX )
2066 {
2067  typedef DynRankView<T,P...> drview_type ;
2068 
2069  static_assert( Kokkos::ViewTraits<T,P...>::is_managed , "Can only realloc managed views" );
2070 
2071  const std::string label = v.label();
2072 
2073  v = drview_type(); // Deallocate first, if the only view to allocation
2074  v = drview_type( label, n0, n1, n2, n3, n4, n5, n6 );
2075 }
2076 
2077 } //end Kokkos
2078 
2079 #endif
2080 
KOKKOS_INLINE_FUNCTION bool operator==(const complex< RealType1 > &x, const complex< RealType2 > &y)
Equality operator for two complex numbers.
KOKKOS_INLINE_FUNCTION bool operator!=(const complex< RealType1 > &x, const complex< RealType2 > &y)
Inequality operator for two complex numbers.
Memory layout tag indicating left-to-right (Fortran scheme) striding of multi-indices.
Can AccessSpace access MemorySpace ?
std::enable_if< std::is_same< typename Kokkos::View< T, P...>::array_layout, Kokkos::LayoutLeft >::value||std::is_same< typename Kokkos::View< T, P...>::array_layout, Kokkos::LayoutRight >::value >::type resize(Kokkos::View< T, P...> &v, const size_t n0=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n1=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n2=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n3=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n4=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n5=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n6=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n7=KOKKOS_IMPL_CTOR_DEFAULT_ARG)
Resize a view with copying old data to new data at the corresponding indices.
Memory layout tag indicated arbitrarily strided multi-index mapping into contiguous memory...
void deep_copy(const View< DT, DP...> &dst, typename ViewTraits< DT, DP...>::const_value_type &value, typename std::enable_if< std::is_same< typename ViewTraits< DT, DP...>::specialize, void >::value >::type *=0)
Deep copy a value from Host memory into a view.
View to an array of data.
Memory layout tag indicating right-to-left (C or lexigraphical scheme) striding of multi-indices...
Assign compatible default mappings.
Implementation of the ParallelFor operator that has a partial specialization for the device...
std::enable_if< std::is_same< typename Kokkos::View< T, P...>::array_layout, Kokkos::LayoutLeft >::value||std::is_same< typename Kokkos::View< T, P...>::array_layout, Kokkos::LayoutRight >::value >::type realloc(Kokkos::View< T, P...> &v, const size_t n0=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n1=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n2=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n3=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n4=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n5=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n6=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n7=KOKKOS_IMPL_CTOR_DEFAULT_ARG)
Resize a view with discarding old data.
Execution policy for work over a range of an integral type.
KOKKOS_INLINE_FUNCTION constexpr unsigned rank(const View< D, P...> &V)
Temporary free function rank() until rank() is implemented in the View.
Traits class for accessing attributes of a View.