Kokkos Core Kernels Package  Version of the Day
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
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 , void > DstType ;
372  typedef ViewMapping< SrcTraits , void > 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_offset = dst_offset_type(std::integral_constant<unsigned,0>() , src.layout() ); //Check this for integer input1 for padding, etc
388  dst.m_map.m_handle = Kokkos::Impl::ViewDataHandle< DstTraits >::assign( src.m_map.m_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 , void > 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 
569  KOKKOS_INLINE_FUNCTION
570  const Kokkos::Impl::ViewMapping< traits , void > &
571  implementation_map() const { return m_map ; }
572 
573  //----------------------------------------
574 
575 private:
576 
577  enum {
578  is_layout_left = std::is_same< typename traits::array_layout
579  , Kokkos::LayoutLeft >::value ,
580 
581  is_layout_right = std::is_same< typename traits::array_layout
582  , Kokkos::LayoutRight >::value ,
583 
584  is_layout_stride = std::is_same< typename traits::array_layout
585  , Kokkos::LayoutStride >::value ,
586 
587  is_default_map =
588  std::is_same< typename traits::specialize , void >::value &&
589  ( is_layout_left || is_layout_right || is_layout_stride )
590  };
591 
592  template< class Space , bool = Kokkos::Impl::MemorySpaceAccess< Space , typename traits::memory_space >::accessible > struct verify_space
593  { KOKKOS_FORCEINLINE_FUNCTION static void check() {} };
594 
595  template< class Space > struct verify_space<Space,false>
596  { KOKKOS_FORCEINLINE_FUNCTION static void check()
597  { Kokkos::abort("Kokkos::DynRankView ERROR: attempt to access inaccessible memory space"); };
598  };
599 
600 // Bounds checking macros
601 #if defined( KOKKOS_ENABLE_DEBUG_BOUNDS_CHECK )
602 
603 // rank of the calling operator - included as first argument in ARG
604 #define KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( ARG ) \
605  DynRankView::template verify_space< Kokkos::Impl::ActiveExecutionMemorySpace >::check(); \
606  Kokkos::Impl::dyn_rank_view_verify_operator_bounds< typename traits::memory_space > ARG ;
607 
608 #else
609 
610 #define KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( ARG ) \
611  DynRankView::template verify_space< Kokkos::Impl::ActiveExecutionMemorySpace >::check();
612 
613 #endif
614 
615 public:
616 
617  KOKKOS_INLINE_FUNCTION
618  constexpr unsigned rank() const { return m_rank; }
619 
620 
621  //operators ()
622  // Rank 0
623  KOKKOS_INLINE_FUNCTION
624  reference_type operator()() const
625  {
626  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (0 , this->rank(), m_track, m_map) )
627  return implementation_map().reference();
628  //return m_map.reference(0,0,0,0,0,0,0);
629  }
630 
631  // Rank 1
632  // This assumes a contiguous underlying memory (i.e. no padding, no striding...)
633  template< typename iType >
634  KOKKOS_INLINE_FUNCTION
635  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
636  operator[](const iType & i0) const
637  {
638  //Phalanx is violating this, since they use the operator to access ALL elements in the allocation
639  //KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (1 , this->rank(), m_track, m_map) )
640  return data()[i0];
641  }
642 
643  // This assumes a contiguous underlying memory (i.e. no padding, no striding...
644  // AND a Trilinos/Sacado scalar type )
645  template< typename iType >
646  KOKKOS_INLINE_FUNCTION
647  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
648  operator[](const iType & i0) const
649  {
650 // auto map = implementation_map();
651  const size_t dim_scalar = m_map.dimension_scalar();
652  const size_t bytes = this->span() / dim_scalar;
653 
655  tmp_view_type rankone_view(this->data(), bytes, dim_scalar);
656  return rankone_view(i0);
657  }
658 
659  // Rank 1 parenthesis
660  template< typename iType >
661  KOKKOS_INLINE_FUNCTION
662  typename std::enable_if< (std::is_same<typename traits::specialize , void>::value && std::is_integral<iType>::value), reference_type>::type
663  operator()(const iType & i0 ) const
664  {
665  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (1 , this->rank(), m_track, m_map, i0) )
666  return m_map.reference(i0);
667  }
668 
669  template< typename iType >
670  KOKKOS_INLINE_FUNCTION
671  typename std::enable_if< !(std::is_same<typename traits::specialize , void>::value && std::is_integral<iType>::value), reference_type>::type
672  operator()(const iType & i0 ) const
673  {
674  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (1 , this->rank(), m_track, m_map, i0) )
675  return m_map.reference(i0,0,0,0,0,0,0);
676  }
677 
678  // Rank 2
679  template< typename iType0 , typename iType1 >
680  KOKKOS_INLINE_FUNCTION
681  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
682  operator()(const iType0 & i0 , const iType1 & i1 ) const
683  {
684  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (2 , this->rank(), m_track, m_map, i0, i1) )
685  return m_map.reference(i0,i1);
686  }
687 
688  template< typename iType0 , typename iType1 >
689  KOKKOS_INLINE_FUNCTION
690  typename std::enable_if< !(std::is_same<typename drvtraits::specialize , void>::value && std::is_integral<iType0>::value), reference_type>::type
691  operator()(const iType0 & i0 , const iType1 & i1 ) const
692  {
693  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (2 , this->rank(), m_track, m_map, i0, i1) )
694  return m_map.reference(i0,i1,0,0,0,0,0);
695  }
696 
697  // Rank 3
698  template< typename iType0 , typename iType1 , typename iType2 >
699  KOKKOS_INLINE_FUNCTION
700  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
701  operator()(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 ) const
702  {
703  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (3 , this->rank(), m_track, m_map, i0, i1, i2) )
704  return m_map.reference(i0,i1,i2);
705  }
706 
707  template< typename iType0 , typename iType1 , typename iType2 >
708  KOKKOS_INLINE_FUNCTION
709  typename std::enable_if< !(std::is_same<typename drvtraits::specialize , void>::value && std::is_integral<iType0>::value), reference_type>::type
710  operator()(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 ) const
711  {
712  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (3 , this->rank(), m_track, m_map, i0, i1, i2) )
713  return m_map.reference(i0,i1,i2,0,0,0,0);
714  }
715 
716  // Rank 4
717  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 >
718  KOKKOS_INLINE_FUNCTION
719  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
720  operator()(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ) const
721  {
722  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (4 , this->rank(), m_track, m_map, i0, i1, i2, i3) )
723  return m_map.reference(i0,i1,i2,i3);
724  }
725 
726  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 >
727  KOKKOS_INLINE_FUNCTION
728  typename std::enable_if< !(std::is_same<typename drvtraits::specialize , void>::value && std::is_integral<iType0>::value), reference_type>::type
729  operator()(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ) const
730  {
731  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (4 , this->rank(), m_track, m_map, i0, i1, i2, i3) )
732  return m_map.reference(i0,i1,i2,i3,0,0,0);
733  }
734 
735  // Rank 5
736  template< typename iType0 , typename iType1 , typename iType2 , typename iType3, typename iType4 >
737  KOKKOS_INLINE_FUNCTION
738  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
739  operator()(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 , const iType4 & i4 ) const
740  {
741  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (5 , this->rank(), m_track, m_map, i0, i1, i2, i3, i4) )
742  return m_map.reference(i0,i1,i2,i3,i4);
743  }
744 
745  template< typename iType0 , typename iType1 , typename iType2 , typename iType3, typename iType4 >
746  KOKKOS_INLINE_FUNCTION
747  typename std::enable_if< !(std::is_same<typename drvtraits::specialize , void>::value && std::is_integral<iType0>::value), reference_type>::type
748  operator()(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 , const iType4 & i4 ) const
749  {
750  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (5 , this->rank(), m_track, m_map, i0, i1, i2, i3, i4) )
751  return m_map.reference(i0,i1,i2,i3,i4,0,0);
752  }
753 
754  // Rank 6
755  template< typename iType0 , typename iType1 , typename iType2 , typename iType3, typename iType4 , typename iType5 >
756  KOKKOS_INLINE_FUNCTION
757  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
758  operator()(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 , const iType4 & i4 , const iType5 & i5 ) const
759  {
760  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (6 , this->rank(), m_track, m_map, i0, i1, i2, i3, i4, i5) )
761  return m_map.reference(i0,i1,i2,i3,i4,i5);
762  }
763 
764  template< typename iType0 , typename iType1 , typename iType2 , typename iType3, typename iType4 , typename iType5 >
765  KOKKOS_INLINE_FUNCTION
766  typename std::enable_if< !(std::is_same<typename drvtraits::specialize , void>::value && std::is_integral<iType0>::value), reference_type>::type
767  operator()(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 , const iType4 & i4 , const iType5 & i5 ) const
768  {
769  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (6 , this->rank(), m_track, m_map, i0, i1, i2, i3, i4, i5) )
770  return m_map.reference(i0,i1,i2,i3,i4,i5,0);
771  }
772 
773  // Rank 7
774  template< typename iType0 , typename iType1 , typename iType2 , typename iType3, typename iType4 , typename iType5 , typename iType6 >
775  KOKKOS_INLINE_FUNCTION
776  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
777  operator()(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 , const iType4 & i4 , const iType5 & i5 , const iType6 & i6 ) const
778  {
779  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (7 , this->rank(), m_track, m_map, i0, i1, i2, i3, i4, i5, i6) )
780  return m_map.reference(i0,i1,i2,i3,i4,i5,i6);
781  }
782 
783  // Rank 0
784  KOKKOS_INLINE_FUNCTION
785  reference_type access() const
786  {
787  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (0 , this->rank(), m_track, m_map) )
788  return implementation_map().reference();
789  //return m_map.reference(0,0,0,0,0,0,0);
790  }
791 
792  // Rank 1
793  // Rank 1 parenthesis
794  template< typename iType >
795  KOKKOS_INLINE_FUNCTION
796  typename std::enable_if< (std::is_same<typename traits::specialize , void>::value && std::is_integral<iType>::value), reference_type>::type
797  access(const iType & i0 ) const
798  {
799  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (1 , this->rank(), m_track, m_map, i0) )
800  return m_map.reference(i0);
801  }
802 
803  template< typename iType >
804  KOKKOS_INLINE_FUNCTION
805  typename std::enable_if< !(std::is_same<typename traits::specialize , void>::value && std::is_integral<iType>::value), reference_type>::type
806  access(const iType & i0 ) const
807  {
808  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (1 , this->rank(), m_track, m_map, i0) )
809  return m_map.reference(i0,0,0,0,0,0,0);
810  }
811 
812  // Rank 2
813  template< typename iType0 , typename iType1 >
814  KOKKOS_INLINE_FUNCTION
815  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
816  access(const iType0 & i0 , const iType1 & i1 ) const
817  {
818  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (2 , this->rank(), m_track, m_map, i0, i1) )
819  return m_map.reference(i0,i1);
820  }
821 
822  template< typename iType0 , typename iType1 >
823  KOKKOS_INLINE_FUNCTION
824  typename std::enable_if< !(std::is_same<typename drvtraits::specialize , void>::value && std::is_integral<iType0>::value), reference_type>::type
825  access(const iType0 & i0 , const iType1 & i1 ) const
826  {
827  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (2 , this->rank(), m_track, m_map, i0, i1) )
828  return m_map.reference(i0,i1,0,0,0,0,0);
829  }
830 
831  // Rank 3
832  template< typename iType0 , typename iType1 , typename iType2 >
833  KOKKOS_INLINE_FUNCTION
834  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
835  access(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 ) const
836  {
837  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (3 , this->rank(), m_track, m_map, i0, i1, i2) )
838  return m_map.reference(i0,i1,i2);
839  }
840 
841  template< typename iType0 , typename iType1 , typename iType2 >
842  KOKKOS_INLINE_FUNCTION
843  typename std::enable_if< !(std::is_same<typename drvtraits::specialize , void>::value && std::is_integral<iType0>::value), reference_type>::type
844  access(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 ) const
845  {
846  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (3 , this->rank(), m_track, m_map, i0, i1, i2) )
847  return m_map.reference(i0,i1,i2,0,0,0,0);
848  }
849 
850  // Rank 4
851  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 >
852  KOKKOS_INLINE_FUNCTION
853  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
854  access(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ) const
855  {
856  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (4 , this->rank(), m_track, m_map, i0, i1, i2, i3) )
857  return m_map.reference(i0,i1,i2,i3);
858  }
859 
860  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 >
861  KOKKOS_INLINE_FUNCTION
862  typename std::enable_if< !(std::is_same<typename drvtraits::specialize , void>::value && std::is_integral<iType0>::value), reference_type>::type
863  access(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ) const
864  {
865  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (4 , this->rank(), m_track, m_map, i0, i1, i2, i3) )
866  return m_map.reference(i0,i1,i2,i3,0,0,0);
867  }
868 
869  // Rank 5
870  template< typename iType0 , typename iType1 , typename iType2 , typename iType3, typename iType4 >
871  KOKKOS_INLINE_FUNCTION
872  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
873  access(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 , const iType4 & i4 ) const
874  {
875  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (5 , this->rank(), m_track, m_map, i0, i1, i2, i3, i4) )
876  return m_map.reference(i0,i1,i2,i3,i4);
877  }
878 
879  template< typename iType0 , typename iType1 , typename iType2 , typename iType3, typename iType4 >
880  KOKKOS_INLINE_FUNCTION
881  typename std::enable_if< !(std::is_same<typename drvtraits::specialize , void>::value && std::is_integral<iType0>::value), reference_type>::type
882  access(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 , const iType4 & i4 ) const
883  {
884  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (5 , this->rank(), m_track, m_map, i0, i1, i2, i3, i4) )
885  return m_map.reference(i0,i1,i2,i3,i4,0,0);
886  }
887 
888  // Rank 6
889  template< typename iType0 , typename iType1 , typename iType2 , typename iType3, typename iType4 , typename iType5 >
890  KOKKOS_INLINE_FUNCTION
891  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
892  access(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 , const iType4 & i4 , const iType5 & i5 ) const
893  {
894  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (6 , this->rank(), m_track, m_map, i0, i1, i2, i3, i4, i5) )
895  return m_map.reference(i0,i1,i2,i3,i4,i5);
896  }
897 
898  template< typename iType0 , typename iType1 , typename iType2 , typename iType3, typename iType4 , typename iType5 >
899  KOKKOS_INLINE_FUNCTION
900  typename std::enable_if< !(std::is_same<typename drvtraits::specialize , void>::value && std::is_integral<iType0>::value), reference_type>::type
901  access(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 , const iType4 & i4 , const iType5 & i5 ) const
902  {
903  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (6 , this->rank(), m_track, m_map, i0, i1, i2, i3, i4, i5) )
904  return m_map.reference(i0,i1,i2,i3,i4,i5,0);
905  }
906 
907  // Rank 7
908  template< typename iType0 , typename iType1 , typename iType2 , typename iType3, typename iType4 , typename iType5 , typename iType6 >
909  KOKKOS_INLINE_FUNCTION
910  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
911  access(const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 , const iType4 & i4 , const iType5 & i5 , const iType6 & i6 ) const
912  {
913  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (7 , this->rank(), m_track, m_map, i0, i1, i2, i3, i4, i5, i6) )
914  return m_map.reference(i0,i1,i2,i3,i4,i5,i6);
915  }
916 
917 #undef KOKKOS_IMPL_VIEW_OPERATOR_VERIFY
918 
919  //----------------------------------------
920  // Standard constructor, destructor, and assignment operators...
921 
922  KOKKOS_INLINE_FUNCTION
923  ~DynRankView() {}
924 
925  KOKKOS_INLINE_FUNCTION
926  DynRankView() : m_track(), m_map(), m_rank() {} //Default ctor
927 
928  KOKKOS_INLINE_FUNCTION
929  DynRankView( const DynRankView & rhs ) : m_track( rhs.m_track ), m_map( rhs.m_map ), m_rank(rhs.m_rank) {}
930 
931  KOKKOS_INLINE_FUNCTION
932  DynRankView( DynRankView && rhs ) : m_track( rhs.m_track ), m_map( rhs.m_map ), m_rank(rhs.m_rank) {}
933 
934  KOKKOS_INLINE_FUNCTION
935  DynRankView & operator = ( const DynRankView & rhs ) { m_track = rhs.m_track; m_map = rhs.m_map; m_rank = rhs.m_rank; return *this; }
936 
937  KOKKOS_INLINE_FUNCTION
938  DynRankView & operator = ( DynRankView && rhs ) { m_track = rhs.m_track; m_map = rhs.m_map; m_rank = rhs.m_rank; return *this; }
939 
940  //----------------------------------------
941  // Compatible view copy constructor and assignment
942  // may assign unmanaged from managed.
943  template< class RT , class ... RP >
944  KOKKOS_INLINE_FUNCTION
945  DynRankView( const DynRankView<RT,RP...> & rhs )
946  : m_track( rhs.m_track , traits::is_managed )
947  , m_map()
948  , m_rank(rhs.m_rank)
949  {
950  typedef typename DynRankView<RT,RP...> ::traits SrcTraits ;
951  typedef Kokkos::Impl::ViewMapping< traits , SrcTraits , void > Mapping ;
952  static_assert( Mapping::is_assignable , "Incompatible DynRankView copy construction" );
953  Mapping::assign( m_map , rhs.m_map , rhs.m_track );
954  }
955 
956  template< class RT , class ... RP >
957  KOKKOS_INLINE_FUNCTION
958  DynRankView & operator = (const DynRankView<RT,RP...> & rhs )
959  {
960  typedef typename DynRankView<RT,RP...> ::traits SrcTraits ;
961  typedef Kokkos::Impl::ViewMapping< traits , SrcTraits , void > Mapping ;
962  static_assert( Mapping::is_assignable , "Incompatible DynRankView copy construction" );
963  Mapping::assign( m_map , rhs.m_map , rhs.m_track );
964  m_track.assign( rhs.m_track , traits::is_managed );
965  m_rank = rhs.rank();
966  return *this;
967  }
968 
969 // Copy/Assign View to DynRankView
970  template< class RT , class ... RP >
971  KOKKOS_INLINE_FUNCTION
972  DynRankView( const View<RT,RP...> & rhs )
973  : m_track()
974  , m_map()
975  , m_rank( rhs.Rank )
976  {
977  typedef typename View<RT,RP...>::traits SrcTraits ;
978  typedef Kokkos::Impl::ViewMapping< traits , SrcTraits , Kokkos::Impl::ViewToDynRankViewTag > Mapping ;
979  static_assert( Mapping::is_assignable , "Incompatible DynRankView copy construction" );
980  Mapping::assign( *this , rhs );
981  }
982 
983  template< class RT , class ... RP >
984  KOKKOS_INLINE_FUNCTION
985  DynRankView & operator = ( const View<RT,RP...> & rhs )
986  {
987  typedef typename View<RT,RP...>::traits SrcTraits ;
988  typedef Kokkos::Impl::ViewMapping< traits , SrcTraits , Kokkos::Impl::ViewToDynRankViewTag > Mapping ;
989  static_assert( Mapping::is_assignable , "Incompatible View to DynRankView copy assignment" );
990  Mapping::assign( *this , rhs );
991  return *this ;
992  }
993 
994  //----------------------------------------
995  // Allocation tracking properties
996 
997  KOKKOS_INLINE_FUNCTION
998  int use_count() const
999  { return m_track.use_count(); }
1000 
1001  inline
1002  const std::string label() const
1003  { return m_track.template get_label< typename traits::memory_space >(); }
1004 
1005  //----------------------------------------
1006  // Allocation according to allocation properties and array layout
1007  // unused arg_layout dimensions must be set toKOKKOS_INVALID_INDEX so that rank deduction can properly take place
1008  template< class ... P >
1009  explicit inline
1010  DynRankView( const Kokkos::Impl::ViewCtorProp< P ... > & arg_prop
1011  , typename std::enable_if< ! Kokkos::Impl::ViewCtorProp< P... >::has_pointer
1012  , typename traits::array_layout
1013  >::type const & arg_layout
1014  )
1015  : m_track()
1016  , m_map()
1017  , m_rank( Impl::DynRankDimTraits<typename traits::specialize>::template computeRank< typename traits::array_layout, P...>(arg_prop, arg_layout) )
1018  {
1019  // Append layout and spaces if not input
1020  typedef Kokkos::Impl::ViewCtorProp< P ... > alloc_prop_input ;
1021 
1022  // use 'std::integral_constant<unsigned,I>' for non-types
1023  // to avoid duplicate class error.
1024  typedef Kokkos::Impl::ViewCtorProp
1025  < P ...
1026  , typename std::conditional
1027  < alloc_prop_input::has_label
1028  , std::integral_constant<unsigned,0>
1029  , typename std::string
1030  >::type
1031  , typename std::conditional
1032  < alloc_prop_input::has_memory_space
1033  , std::integral_constant<unsigned,1>
1034  , typename traits::device_type::memory_space
1035  >::type
1036  , typename std::conditional
1037  < alloc_prop_input::has_execution_space
1038  , std::integral_constant<unsigned,2>
1039  , typename traits::device_type::execution_space
1040  >::type
1041  > alloc_prop ;
1042 
1043  static_assert( traits::is_managed
1044  , "View allocation constructor requires managed memory" );
1045 
1046  if ( alloc_prop::initialize &&
1047 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
1048  ! alloc_prop::execution_space::is_initialized()
1049 #else
1050  ! alloc_prop::execution_space::impl_is_initialized()
1051 #endif
1052  ) {
1053  // If initializing view data then
1054  // the execution space must be initialized.
1055  Kokkos::Impl::throw_runtime_exception("Constructing DynRankView and initializing data with uninitialized execution space");
1056  }
1057 
1058  // Copy the input allocation properties with possibly defaulted properties
1059  alloc_prop prop( arg_prop );
1060 
1061 //------------------------------------------------------------
1062 #if defined( KOKKOS_ENABLE_CUDA )
1063  // If allocating in CudaUVMSpace must fence before and after
1064  // the allocation to protect against possible concurrent access
1065  // on the CPU and the GPU.
1066  // Fence using the trait's executon space (which will be Kokkos::Cuda)
1067  // to avoid incomplete type errors from usng Kokkos::Cuda directly.
1068  if ( std::is_same< Kokkos::CudaUVMSpace , typename traits::device_type::memory_space >::value ) {
1069  traits::device_type::memory_space::execution_space::fence();
1070  }
1071 #endif
1072 //------------------------------------------------------------
1073 
1074  Kokkos::Impl::SharedAllocationRecord<> *
1075  record = m_map.allocate_shared( prop , Impl::DynRankDimTraits<typename traits::specialize>::template createLayout<traits, P...>(arg_prop, arg_layout) );
1076 
1077 //------------------------------------------------------------
1078 #if defined( KOKKOS_ENABLE_CUDA )
1079  if ( std::is_same< Kokkos::CudaUVMSpace , typename traits::device_type::memory_space >::value ) {
1080  traits::device_type::memory_space::execution_space::fence();
1081  }
1082 #endif
1083 //------------------------------------------------------------
1084 
1085  // Setup and initialization complete, start tracking
1086  m_track.assign_allocated_record_to_uninitialized( record );
1087  }
1088 
1089 
1090  // Wrappers
1091  template< class ... P >
1092  explicit KOKKOS_INLINE_FUNCTION
1093  DynRankView( const Kokkos::Impl::ViewCtorProp< P ... > & arg_prop
1094  , typename std::enable_if< Kokkos::Impl::ViewCtorProp< P... >::has_pointer
1095  , typename traits::array_layout
1096  >::type const & arg_layout
1097  )
1098  : m_track() // No memory tracking
1099  , m_map( arg_prop , Impl::DynRankDimTraits<typename traits::specialize>::template createLayout<traits, P...>(arg_prop, arg_layout) )
1100  , m_rank( Impl::DynRankDimTraits<typename traits::specialize>::template computeRank< typename traits::array_layout, P...>(arg_prop, arg_layout) )
1101  {
1102  static_assert(
1103  std::is_same< pointer_type
1104  , typename Impl::ViewCtorProp< P... >::pointer_type
1105  >::value ,
1106  "Constructing DynRankView to wrap user memory must supply matching pointer type" );
1107  }
1108 
1109  //----------------------------------------
1110  //Constructor(s)
1111 
1112  // Simple dimension-only layout
1113  template< class ... P >
1114  explicit inline
1115  DynRankView( const Kokkos::Impl::ViewCtorProp< P ... > & arg_prop
1116  , typename std::enable_if< ! Kokkos::Impl::ViewCtorProp< P... >::has_pointer
1117  , size_t
1118  >::type const arg_N0 =KOKKOS_INVALID_INDEX
1119  , const size_t arg_N1 =KOKKOS_INVALID_INDEX
1120  , const size_t arg_N2 =KOKKOS_INVALID_INDEX
1121  , const size_t arg_N3 =KOKKOS_INVALID_INDEX
1122  , const size_t arg_N4 =KOKKOS_INVALID_INDEX
1123  , const size_t arg_N5 =KOKKOS_INVALID_INDEX
1124  , const size_t arg_N6 =KOKKOS_INVALID_INDEX
1125  , const size_t arg_N7 =KOKKOS_INVALID_INDEX
1126  )
1127  : DynRankView( arg_prop
1128  , typename traits::array_layout
1129  ( arg_N0 , arg_N1 , arg_N2 , arg_N3 , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1130  )
1131  {}
1132 
1133  template< class ... P >
1134  explicit KOKKOS_INLINE_FUNCTION
1135  DynRankView( const Kokkos::Impl::ViewCtorProp< P ... > & arg_prop
1136  , typename std::enable_if< Kokkos::Impl::ViewCtorProp< P... >::has_pointer
1137  , size_t
1138  >::type const arg_N0 =KOKKOS_INVALID_INDEX
1139  , const size_t arg_N1 =KOKKOS_INVALID_INDEX
1140  , const size_t arg_N2 =KOKKOS_INVALID_INDEX
1141  , const size_t arg_N3 =KOKKOS_INVALID_INDEX
1142  , const size_t arg_N4 =KOKKOS_INVALID_INDEX
1143  , const size_t arg_N5 =KOKKOS_INVALID_INDEX
1144  , const size_t arg_N6 =KOKKOS_INVALID_INDEX
1145  , const size_t arg_N7 =KOKKOS_INVALID_INDEX
1146  )
1147  : DynRankView( arg_prop
1148  , typename traits::array_layout
1149  ( arg_N0 , arg_N1 , arg_N2 , arg_N3 , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1150  )
1151  {}
1152 
1153  // Allocate with label and layout
1154  template< typename Label >
1155  explicit inline
1156  DynRankView( const Label & arg_label
1157  , typename std::enable_if<
1158  Kokkos::Impl::is_view_label<Label>::value ,
1159  typename traits::array_layout >::type const & arg_layout
1160  )
1161  : DynRankView( Kokkos::Impl::ViewCtorProp< std::string >( arg_label ) , arg_layout )
1162  {}
1163 
1164  // Allocate label and layout, must disambiguate from subview constructor
1165  template< typename Label >
1166  explicit inline
1167  DynRankView( const Label & arg_label
1168  , typename std::enable_if<
1169  Kokkos::Impl::is_view_label<Label>::value ,
1170  const size_t >::type arg_N0 =KOKKOS_INVALID_INDEX
1171  , const size_t arg_N1 =KOKKOS_INVALID_INDEX
1172  , const size_t arg_N2 =KOKKOS_INVALID_INDEX
1173  , const size_t arg_N3 =KOKKOS_INVALID_INDEX
1174  , const size_t arg_N4 =KOKKOS_INVALID_INDEX
1175  , const size_t arg_N5 =KOKKOS_INVALID_INDEX
1176  , const size_t arg_N6 =KOKKOS_INVALID_INDEX
1177  , const size_t arg_N7 =KOKKOS_INVALID_INDEX
1178  )
1179  : DynRankView( Kokkos::Impl::ViewCtorProp< std::string >( arg_label )
1180  , typename traits::array_layout
1181  ( arg_N0 , arg_N1 , arg_N2 , arg_N3 , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1182  )
1183  {}
1184 
1185  // For backward compatibility
1186  // NDE This ctor does not take ViewCtorProp argument - should not use alternative createLayout call
1187  explicit inline
1188  DynRankView( const ViewAllocateWithoutInitializing & arg_prop
1189  , const typename traits::array_layout & arg_layout
1190  )
1191  : DynRankView( Kokkos::Impl::ViewCtorProp< std::string , Kokkos::Impl::WithoutInitializing_t >( arg_prop.label , Kokkos::WithoutInitializing )
1192 
1193  , Impl::DynRankDimTraits<typename traits::specialize>::createLayout(arg_layout)
1194  )
1195  {}
1196 
1197  explicit inline
1198  DynRankView( const ViewAllocateWithoutInitializing & arg_prop
1199  , const size_t arg_N0 =KOKKOS_INVALID_INDEX
1200  , const size_t arg_N1 =KOKKOS_INVALID_INDEX
1201  , const size_t arg_N2 =KOKKOS_INVALID_INDEX
1202  , const size_t arg_N3 =KOKKOS_INVALID_INDEX
1203  , const size_t arg_N4 =KOKKOS_INVALID_INDEX
1204  , const size_t arg_N5 =KOKKOS_INVALID_INDEX
1205  , const size_t arg_N6 =KOKKOS_INVALID_INDEX
1206  , const size_t arg_N7 =KOKKOS_INVALID_INDEX
1207  )
1208  : DynRankView(Kokkos::Impl::ViewCtorProp< std::string , Kokkos::Impl::WithoutInitializing_t >( arg_prop.label , Kokkos::WithoutInitializing ), arg_N0, arg_N1, arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7 )
1209  {}
1210 
1211  //----------------------------------------
1212  // Memory span required to wrap these dimensions.
1213  static constexpr size_t required_allocation_size(
1214  const size_t arg_N0 = 0
1215  , const size_t arg_N1 = 0
1216  , const size_t arg_N2 = 0
1217  , const size_t arg_N3 = 0
1218  , const size_t arg_N4 = 0
1219  , const size_t arg_N5 = 0
1220  , const size_t arg_N6 = 0
1221  , const size_t arg_N7 = 0
1222  )
1223  {
1224  return map_type::memory_span(
1225  typename traits::array_layout
1226  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1227  , arg_N4 , arg_N5 , arg_N6 , arg_N7 ) );
1228  }
1229 
1230  explicit KOKKOS_INLINE_FUNCTION
1231  DynRankView( pointer_type arg_ptr
1232  , const size_t arg_N0 =KOKKOS_INVALID_INDEX
1233  , const size_t arg_N1 =KOKKOS_INVALID_INDEX
1234  , const size_t arg_N2 =KOKKOS_INVALID_INDEX
1235  , const size_t arg_N3 =KOKKOS_INVALID_INDEX
1236  , const size_t arg_N4 =KOKKOS_INVALID_INDEX
1237  , const size_t arg_N5 =KOKKOS_INVALID_INDEX
1238  , const size_t arg_N6 =KOKKOS_INVALID_INDEX
1239  , const size_t arg_N7 =KOKKOS_INVALID_INDEX
1240  )
1241  : DynRankView( Kokkos::Impl::ViewCtorProp<pointer_type>(arg_ptr) , arg_N0, arg_N1, arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7 )
1242  {}
1243 
1244  explicit KOKKOS_INLINE_FUNCTION
1245  DynRankView( pointer_type arg_ptr
1246  , typename traits::array_layout & arg_layout
1247  )
1248  : DynRankView( Kokkos::Impl::ViewCtorProp<pointer_type>(arg_ptr) , arg_layout )
1249  {}
1250 
1251 
1252  //----------------------------------------
1253  // Shared scratch memory constructor
1254 
1255  static inline
1256  size_t shmem_size( const size_t arg_N0 =KOKKOS_INVALID_INDEX ,
1257  const size_t arg_N1 =KOKKOS_INVALID_INDEX ,
1258  const size_t arg_N2 =KOKKOS_INVALID_INDEX ,
1259  const size_t arg_N3 =KOKKOS_INVALID_INDEX ,
1260  const size_t arg_N4 =KOKKOS_INVALID_INDEX ,
1261  const size_t arg_N5 =KOKKOS_INVALID_INDEX ,
1262  const size_t arg_N6 =KOKKOS_INVALID_INDEX ,
1263  const size_t arg_N7 =KOKKOS_INVALID_INDEX )
1264  {
1265  const size_t num_passed_args =
1266  ( arg_N0 !=KOKKOS_INVALID_INDEX ) + ( arg_N1 !=KOKKOS_INVALID_INDEX ) + ( arg_N2 !=KOKKOS_INVALID_INDEX ) +
1267  ( arg_N3 !=KOKKOS_INVALID_INDEX ) + ( arg_N4 !=KOKKOS_INVALID_INDEX ) + ( arg_N5 !=KOKKOS_INVALID_INDEX ) +
1268  ( arg_N6 !=KOKKOS_INVALID_INDEX ) + ( arg_N7 !=KOKKOS_INVALID_INDEX );
1269 
1270  if ( std::is_same<typename traits::specialize , void>::value && num_passed_args != traits::rank_dynamic ) {
1271  Kokkos::abort( "Kokkos::View::shmem_size() rank_dynamic != number of arguments.\n" );
1272  }
1273  {}
1274 
1275  return map_type::memory_span(
1276  typename traits::array_layout
1277  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1278  , arg_N4 , arg_N5 , arg_N6 , arg_N7 ) );
1279  }
1280 
1281  explicit KOKKOS_INLINE_FUNCTION
1282  DynRankView( const typename traits::execution_space::scratch_memory_space & arg_space
1283  , const typename traits::array_layout & arg_layout )
1284  : DynRankView( Kokkos::Impl::ViewCtorProp<pointer_type>(
1285  reinterpret_cast<pointer_type>(
1286  arg_space.get_shmem( map_type::memory_span(
1287  Impl::DynRankDimTraits<typename traits::specialize>::createLayout( arg_layout ) //is this correct?
1288  ) ) ) )
1289  , arg_layout )
1290  {}
1291 
1292  explicit KOKKOS_INLINE_FUNCTION
1293  DynRankView( const typename traits::execution_space::scratch_memory_space & arg_space
1294  , const size_t arg_N0 =KOKKOS_INVALID_INDEX
1295  , const size_t arg_N1 =KOKKOS_INVALID_INDEX
1296  , const size_t arg_N2 =KOKKOS_INVALID_INDEX
1297  , const size_t arg_N3 =KOKKOS_INVALID_INDEX
1298  , const size_t arg_N4 =KOKKOS_INVALID_INDEX
1299  , const size_t arg_N5 =KOKKOS_INVALID_INDEX
1300  , const size_t arg_N6 =KOKKOS_INVALID_INDEX
1301  , const size_t arg_N7 =KOKKOS_INVALID_INDEX )
1302 
1303  : DynRankView( Kokkos::Impl::ViewCtorProp<pointer_type>(
1304  reinterpret_cast<pointer_type>(
1305  arg_space.get_shmem(
1306  map_type::memory_span(
1307  Impl::DynRankDimTraits<typename traits::specialize>::createLayout(
1308  typename traits::array_layout
1309  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1310  , arg_N4 , arg_N5 , arg_N6 , arg_N7 ) ) ) ) )
1311  )
1312  , typename traits::array_layout
1313  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1314  , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1315  )
1316  {}
1317 
1318 };
1319 
1320 
1321  template < typename D , class ... P >
1322  KOKKOS_INLINE_FUNCTION
1323  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
1324 
1325 //----------------------------------------------------------------------------
1326 // Subview mapping.
1327 // Deduce destination view type from source view traits and subview arguments
1328 
1329 namespace Impl {
1330 
1331 struct DynRankSubviewTag {};
1332 
1333 } // namespace Impl
1334 
1335 namespace Impl {
1336 
1337 template< class SrcTraits , class ... Args >
1338 struct ViewMapping
1339  < typename std::enable_if<(
1340  std::is_same< typename SrcTraits::specialize , void >::value
1341  &&
1342  (
1343  std::is_same< typename SrcTraits::array_layout
1344  , Kokkos::LayoutLeft >::value ||
1345  std::is_same< typename SrcTraits::array_layout
1346  , Kokkos::LayoutRight >::value ||
1347  std::is_same< typename SrcTraits::array_layout
1348  , Kokkos::LayoutStride >::value
1349  )
1350  ), Kokkos::Impl::DynRankSubviewTag >::type
1351  , SrcTraits
1352  , Args ... >
1353 {
1354 private:
1355 
1356  enum
1357  { RZ = false
1358  , R0 = bool(is_integral_extent<0,Args...>::value)
1359  , R1 = bool(is_integral_extent<1,Args...>::value)
1360  , R2 = bool(is_integral_extent<2,Args...>::value)
1361  , R3 = bool(is_integral_extent<3,Args...>::value)
1362  , R4 = bool(is_integral_extent<4,Args...>::value)
1363  , R5 = bool(is_integral_extent<5,Args...>::value)
1364  , R6 = bool(is_integral_extent<6,Args...>::value)
1365  };
1366 
1367  enum { rank = unsigned(R0) + unsigned(R1) + unsigned(R2) + unsigned(R3)
1368  + unsigned(R4) + unsigned(R5) + unsigned(R6) };
1369 
1370  typedef Kokkos::LayoutStride array_layout ;
1371 
1372  typedef typename SrcTraits::value_type value_type ;
1373 
1374  typedef value_type******* data_type ;
1375 
1376 public:
1377 
1378  typedef Kokkos::ViewTraits
1379  < data_type
1380  , array_layout
1381  , typename SrcTraits::device_type
1382  , typename SrcTraits::memory_traits > traits_type ;
1383 
1384  typedef Kokkos::View
1385  < data_type
1386  , array_layout
1387  , typename SrcTraits::device_type
1388  , typename SrcTraits::memory_traits > type ;
1389 
1390 
1391  template< class MemoryTraits >
1392  struct apply {
1393 
1394  static_assert( Kokkos::Impl::is_memory_traits< MemoryTraits >::value , "" );
1395 
1396  typedef Kokkos::ViewTraits
1397  < data_type
1398  , array_layout
1399  , typename SrcTraits::device_type
1400  , MemoryTraits > traits_type ;
1401 
1402  typedef Kokkos::View
1403  < data_type
1404  , array_layout
1405  , typename SrcTraits::device_type
1406  , MemoryTraits > type ;
1407  };
1408 
1409 
1410  typedef typename SrcTraits::dimension dimension ;
1411 
1412  template < class Arg0 = int, class Arg1 = int, class Arg2 = int, class Arg3 = int, class Arg4 = int, class Arg5 = int, class Arg6 = int >
1413  struct ExtentGenerator {
1414  KOKKOS_INLINE_FUNCTION
1415  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() )
1416  {
1417  return SubviewExtents< 7 , rank>( dim , arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 );
1418  }
1419  };
1420 
1421 
1422  typedef Kokkos::DynRankView< value_type , array_layout , typename SrcTraits::device_type , typename SrcTraits::memory_traits > ret_type;
1423 
1424  template < typename T , class ... P >
1425  KOKKOS_INLINE_FUNCTION
1426  static ret_type subview( const unsigned src_rank , Kokkos::DynRankView< T , P...> const & src
1427  , Args ... args )
1428  {
1429 
1430  typedef ViewMapping< traits_type, void > DstType ;
1431 
1432  typedef typename std::conditional< (rank==0) , ViewDimension<>
1433  , typename std::conditional< (rank==1) , ViewDimension<0>
1434  , typename std::conditional< (rank==2) , ViewDimension<0,0>
1435  , typename std::conditional< (rank==3) , ViewDimension<0,0,0>
1436  , typename std::conditional< (rank==4) , ViewDimension<0,0,0,0>
1437  , typename std::conditional< (rank==5) , ViewDimension<0,0,0,0,0>
1438  , typename std::conditional< (rank==6) , ViewDimension<0,0,0,0,0,0>
1439  , ViewDimension<0,0,0,0,0,0,0>
1440  >::type >::type >::type >::type >::type >::type >::type DstDimType ;
1441 
1442  typedef ViewOffset< DstDimType , Kokkos::LayoutStride > dst_offset_type ;
1443  typedef typename DstType::handle_type dst_handle_type ;
1444 
1445  ret_type dst ;
1446 
1447  const SubviewExtents< 7 , rank > extents =
1448  ExtentGenerator< Args ... >::generator( src.m_map.m_offset.m_dim , args... ) ;
1449 
1450  dst_offset_type tempdst( src.m_map.m_offset , extents ) ;
1451 
1452  dst.m_track = src.m_track ;
1453 
1454  dst.m_map.m_offset.m_dim.N0 = tempdst.m_dim.N0 ;
1455  dst.m_map.m_offset.m_dim.N1 = tempdst.m_dim.N1 ;
1456  dst.m_map.m_offset.m_dim.N2 = tempdst.m_dim.N2 ;
1457  dst.m_map.m_offset.m_dim.N3 = tempdst.m_dim.N3 ;
1458  dst.m_map.m_offset.m_dim.N4 = tempdst.m_dim.N4 ;
1459  dst.m_map.m_offset.m_dim.N5 = tempdst.m_dim.N5 ;
1460  dst.m_map.m_offset.m_dim.N6 = tempdst.m_dim.N6 ;
1461 
1462  dst.m_map.m_offset.m_stride.S0 = tempdst.m_stride.S0 ;
1463  dst.m_map.m_offset.m_stride.S1 = tempdst.m_stride.S1 ;
1464  dst.m_map.m_offset.m_stride.S2 = tempdst.m_stride.S2 ;
1465  dst.m_map.m_offset.m_stride.S3 = tempdst.m_stride.S3 ;
1466  dst.m_map.m_offset.m_stride.S4 = tempdst.m_stride.S4 ;
1467  dst.m_map.m_offset.m_stride.S5 = tempdst.m_stride.S5 ;
1468  dst.m_map.m_offset.m_stride.S6 = tempdst.m_stride.S6 ;
1469 
1470  dst.m_map.m_handle = dst_handle_type( src.m_map.m_handle +
1471  src.m_map.m_offset( extents.domain_offset(0)
1472  , extents.domain_offset(1)
1473  , extents.domain_offset(2)
1474  , extents.domain_offset(3)
1475  , extents.domain_offset(4)
1476  , extents.domain_offset(5)
1477  , extents.domain_offset(6)
1478  ) );
1479 
1480  dst.m_rank = ( src_rank > 0 ? unsigned(R0) : 0 )
1481  + ( src_rank > 1 ? unsigned(R1) : 0 )
1482  + ( src_rank > 2 ? unsigned(R2) : 0 )
1483  + ( src_rank > 3 ? unsigned(R3) : 0 )
1484  + ( src_rank > 4 ? unsigned(R4) : 0 )
1485  + ( src_rank > 5 ? unsigned(R5) : 0 )
1486  + ( src_rank > 6 ? unsigned(R6) : 0 ) ;
1487 
1488  return dst ;
1489  }
1490 };
1491 
1492 } // end Impl
1493 
1494 
1495 template< class V , class ... Args >
1496 using Subdynrankview = typename Kokkos::Impl::ViewMapping< Kokkos::Impl::DynRankSubviewTag , V , Args... >::ret_type ;
1497 
1498 template< class D , class ... P , class ...Args >
1499 KOKKOS_INLINE_FUNCTION
1500 Subdynrankview< ViewTraits<D******* , P...> , Args... >
1501 subdynrankview( const Kokkos::DynRankView< D , P... > &src , Args...args)
1502  {
1503  if ( src.rank() > sizeof...(Args) ) //allow sizeof...(Args) >= src.rank(), ignore the remaining args
1504  { Kokkos::abort("subdynrankview: num of args must be >= rank of the source DynRankView"); }
1505 
1506  typedef Kokkos::Impl::ViewMapping< Kokkos::Impl::DynRankSubviewTag , Kokkos::ViewTraits< D*******, P... > , Args... > metafcn ;
1507 
1508  return metafcn::subview( src.rank() , src , args... );
1509  }
1510 
1511 //Wrapper to allow subview function name
1512 template< class D , class ... P , class ...Args >
1513 KOKKOS_INLINE_FUNCTION
1514 Subdynrankview< ViewTraits<D******* , P...> , Args... >
1515 subview( const Kokkos::DynRankView< D , P... > &src , Args...args)
1516  {
1517  return subdynrankview( src , args... );
1518  }
1519 
1520 } // namespace Kokkos
1521 
1522 namespace Kokkos {
1523 
1524 // overload == and !=
1525 template< class LT , class ... LP , class RT , class ... RP >
1526 KOKKOS_INLINE_FUNCTION
1527 bool operator == ( const DynRankView<LT,LP...> & lhs ,
1528  const DynRankView<RT,RP...> & rhs )
1529 {
1530  // Same data, layout, dimensions
1531  typedef ViewTraits<LT,LP...> lhs_traits ;
1532  typedef ViewTraits<RT,RP...> rhs_traits ;
1533 
1534  return
1535  std::is_same< typename lhs_traits::const_value_type ,
1536  typename rhs_traits::const_value_type >::value &&
1537  std::is_same< typename lhs_traits::array_layout ,
1538  typename rhs_traits::array_layout >::value &&
1539  std::is_same< typename lhs_traits::memory_space ,
1540  typename rhs_traits::memory_space >::value &&
1541  lhs.rank() == rhs.rank() &&
1542  lhs.data() == rhs.data() &&
1543  lhs.span() == rhs.span() &&
1544  lhs.extent(0) == rhs.extent(0) &&
1545  lhs.extent(1) == rhs.extent(1) &&
1546  lhs.extent(2) == rhs.extent(2) &&
1547  lhs.extent(3) == rhs.extent(3) &&
1548  lhs.extent(4) == rhs.extent(4) &&
1549  lhs.extent(5) == rhs.extent(5) &&
1550  lhs.extent(6) == rhs.extent(6) &&
1551  lhs.extent(7) == rhs.extent(7);
1552 }
1553 
1554 template< class LT , class ... LP , class RT , class ... RP >
1555 KOKKOS_INLINE_FUNCTION
1556 bool operator != ( const DynRankView<LT,LP...> & lhs ,
1557  const DynRankView<RT,RP...> & rhs )
1558 {
1559  return ! ( operator==(lhs,rhs) );
1560 }
1561 
1562 } //end Kokkos
1563 
1564 //----------------------------------------------------------------------------
1565 //----------------------------------------------------------------------------
1566 namespace Kokkos {
1567 namespace Impl {
1568 
1569 template< class OutputView , typename Enable = void >
1570 struct DynRankViewFill {
1571 
1572  typedef typename OutputView::traits::const_value_type const_value_type ;
1573 
1574  const OutputView output ;
1575  const_value_type input ;
1576 
1577  KOKKOS_INLINE_FUNCTION
1578  void operator()( const size_t i0 ) const
1579  {
1580  const size_t n1 = output.extent(1);
1581  const size_t n2 = output.extent(2);
1582  const size_t n3 = output.extent(3);
1583  const size_t n4 = output.extent(4);
1584  const size_t n5 = output.extent(5);
1585  const size_t n6 = output.extent(6);
1586 
1587  for ( size_t i1 = 0 ; i1 < n1 ; ++i1 ) {
1588  for ( size_t i2 = 0 ; i2 < n2 ; ++i2 ) {
1589  for ( size_t i3 = 0 ; i3 < n3 ; ++i3 ) {
1590  for ( size_t i4 = 0 ; i4 < n4 ; ++i4 ) {
1591  for ( size_t i5 = 0 ; i5 < n5 ; ++i5 ) {
1592  for ( size_t i6 = 0 ; i6 < n6 ; ++i6 ) {
1593  output.access(i0,i1,i2,i3,i4,i5,i6) = input ;
1594  }}}}}}
1595  }
1596 
1597  DynRankViewFill( const OutputView & arg_out , const_value_type & arg_in )
1598  : output( arg_out ), input( arg_in )
1599  {
1600  typedef typename OutputView::execution_space execution_space ;
1602 
1603  const Kokkos::Impl::ParallelFor< DynRankViewFill , Policy > closure( *this , Policy( 0 , output.extent(0) ) );
1604 
1605  closure.execute();
1606 
1607  execution_space::fence();
1608  }
1609 };
1610 
1611 template< class OutputView >
1612 struct DynRankViewFill< OutputView , typename std::enable_if< OutputView::Rank == 0 >::type > {
1613  DynRankViewFill( const OutputView & dst , const typename OutputView::const_value_type & src )
1614  {
1615  Kokkos::Impl::DeepCopy< typename OutputView::memory_space , Kokkos::HostSpace >
1616  ( dst.data() , & src , sizeof(typename OutputView::const_value_type) );
1617  }
1618 };
1619 
1620 template< class OutputView , class InputView , class ExecSpace = typename OutputView::execution_space >
1621 struct DynRankViewRemap {
1622 
1623  const OutputView output ;
1624  const InputView input ;
1625  const size_t n0 ;
1626  const size_t n1 ;
1627  const size_t n2 ;
1628  const size_t n3 ;
1629  const size_t n4 ;
1630  const size_t n5 ;
1631  const size_t n6 ;
1632  const size_t n7 ;
1633 
1634  DynRankViewRemap( const OutputView & arg_out , const InputView & arg_in )
1635  : output( arg_out ), input( arg_in )
1636  , n0( std::min( (size_t)arg_out.extent(0) , (size_t)arg_in.extent(0) ) )
1637  , n1( std::min( (size_t)arg_out.extent(1) , (size_t)arg_in.extent(1) ) )
1638  , n2( std::min( (size_t)arg_out.extent(2) , (size_t)arg_in.extent(2) ) )
1639  , n3( std::min( (size_t)arg_out.extent(3) , (size_t)arg_in.extent(3) ) )
1640  , n4( std::min( (size_t)arg_out.extent(4) , (size_t)arg_in.extent(4) ) )
1641  , n5( std::min( (size_t)arg_out.extent(5) , (size_t)arg_in.extent(5) ) )
1642  , n6( std::min( (size_t)arg_out.extent(6) , (size_t)arg_in.extent(6) ) )
1643  , n7( std::min( (size_t)arg_out.extent(7) , (size_t)arg_in.extent(7) ) )
1644  {
1645  typedef Kokkos::RangePolicy< ExecSpace > Policy ;
1646  const Kokkos::Impl::ParallelFor< DynRankViewRemap , Policy > closure( *this , Policy( 0 , n0 ) );
1647  closure.execute();
1648  }
1649 
1650  KOKKOS_INLINE_FUNCTION
1651  void operator()( const size_t i0 ) const
1652  {
1653  for ( size_t i1 = 0 ; i1 < n1 ; ++i1 ) {
1654  for ( size_t i2 = 0 ; i2 < n2 ; ++i2 ) {
1655  for ( size_t i3 = 0 ; i3 < n3 ; ++i3 ) {
1656  for ( size_t i4 = 0 ; i4 < n4 ; ++i4 ) {
1657  for ( size_t i5 = 0 ; i5 < n5 ; ++i5 ) {
1658  for ( size_t i6 = 0 ; i6 < n6 ; ++i6 ) {
1659  output.access(i0,i1,i2,i3,i4,i5,i6) = input.access(i0,i1,i2,i3,i4,i5,i6);
1660  }}}}}}
1661  }
1662 };
1663 
1664 } /* namespace Impl */
1665 } /* namespace Kokkos */
1666 
1667 
1668 namespace Kokkos {
1669 
1671 template< class DT , class ... DP >
1672 inline
1673 void deep_copy
1674  ( const DynRankView<DT,DP...> & dst
1675  , typename ViewTraits<DT,DP...>::const_value_type & value
1676  , typename std::enable_if<
1677  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value
1678  >::type * = 0 )
1679 {
1680  static_assert(
1681  std::is_same< typename ViewTraits<DT,DP...>::non_const_value_type ,
1682  typename ViewTraits<DT,DP...>::value_type >::value
1683  , "deep_copy requires non-const type" );
1684 
1685  Kokkos::Impl::DynRankViewFill< DynRankView<DT,DP...> >( dst , value );
1686 }
1687 
1689 template< class ST , class ... SP >
1690 inline
1691 void deep_copy
1692  ( typename ViewTraits<ST,SP...>::non_const_value_type & dst
1693  , const DynRankView<ST,SP...> & src
1694  , typename std::enable_if<
1695  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value
1696  >::type * = 0 )
1697 {
1698  if ( src.rank() != 0 )
1699  {
1700  Kokkos::abort("");
1701  }
1702 
1703  typedef ViewTraits<ST,SP...> src_traits ;
1704  typedef typename src_traits::memory_space src_memory_space ;
1705  Kokkos::Impl::DeepCopy< HostSpace , src_memory_space >( & dst , src.data() , sizeof(ST) );
1706 }
1707 
1708 //----------------------------------------------------------------------------
1712 template< class DstType , class SrcType >
1713 inline
1714 void deep_copy
1715  ( const DstType & dst
1716  , const SrcType & src
1717  , typename std::enable_if<(
1718  std::is_same< typename DstType::traits::specialize , void >::value &&
1719  std::is_same< typename SrcType::traits::specialize , void >::value
1720  &&
1721  ( Kokkos::is_dyn_rank_view<DstType>::value || Kokkos::is_dyn_rank_view<SrcType>::value)
1722  )>::type * = 0 )
1723 {
1724  static_assert(
1725  std::is_same< typename DstType::traits::value_type ,
1726  typename DstType::traits::non_const_value_type >::value
1727  , "deep_copy requires non-const destination type" );
1728 
1729  typedef DstType dst_type ;
1730  typedef SrcType src_type ;
1731 
1732  typedef typename dst_type::execution_space dst_execution_space ;
1733  typedef typename src_type::execution_space src_execution_space ;
1734  typedef typename dst_type::memory_space dst_memory_space ;
1735  typedef typename src_type::memory_space src_memory_space ;
1736 
1737  enum { DstExecCanAccessSrc =
1739 
1740  enum { SrcExecCanAccessDst =
1742 
1743  if ( (void *) dst.data() != (void*) src.data() ) {
1744 
1745  // Concern: If overlapping views then a parallel copy will be erroneous.
1746  // ...
1747 
1748  // If same type, equal layout, equal dimensions, equal span, and contiguous memory then can byte-wise copy
1749  if ( rank(src) == 0 && rank(dst) == 0 )
1750  {
1751  typedef typename dst_type::value_type value_type ;
1752  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , sizeof(value_type) );
1753  }
1754  else if ( std::is_same< typename DstType::traits::value_type ,
1755  typename SrcType::traits::non_const_value_type >::value &&
1756  (
1757  ( std::is_same< typename DstType::traits::array_layout ,
1758  typename SrcType::traits::array_layout >::value
1759  &&
1760  ( std::is_same< typename DstType::traits::array_layout ,
1761  typename Kokkos::LayoutLeft>::value
1762  ||
1763  std::is_same< typename DstType::traits::array_layout ,
1764  typename Kokkos::LayoutRight>::value
1765  )
1766  )
1767  ||
1768  (
1769  rank(dst) == 1
1770  &&
1771  rank(src) == 1
1772  )
1773  ) &&
1774  dst.span_is_contiguous() &&
1775  src.span_is_contiguous() &&
1776  dst.span() == src.span() &&
1777  dst.extent(0) == src.extent(0) &&
1778 
1779  dst.extent(1) == src.extent(1) &&
1780  dst.extent(2) == src.extent(2) &&
1781  dst.extent(3) == src.extent(3) &&
1782  dst.extent(4) == src.extent(4) &&
1783  dst.extent(5) == src.extent(5) &&
1784  dst.extent(6) == src.extent(6) &&
1785  dst.extent(7) == src.extent(7) ) {
1786 
1787  const size_t nbytes = sizeof(typename dst_type::value_type) * dst.span();
1788 
1789  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1790  }
1791  else if ( std::is_same< typename DstType::traits::value_type ,
1792  typename SrcType::traits::non_const_value_type >::value &&
1793  (
1794  ( std::is_same< typename DstType::traits::array_layout ,
1795  typename SrcType::traits::array_layout >::value
1796  &&
1797  std::is_same< typename DstType::traits::array_layout ,
1798  typename Kokkos::LayoutStride>::value
1799  )
1800  ||
1801  (
1802  rank(dst) == 1
1803  &&
1804  rank(src) == 1
1805  )
1806  ) &&
1807  dst.span_is_contiguous() &&
1808  src.span_is_contiguous() &&
1809  dst.span() == src.span() &&
1810  dst.extent(0) == src.extent(0) &&
1811  dst.extent(1) == src.extent(1) &&
1812  dst.extent(2) == src.extent(2) &&
1813  dst.extent(3) == src.extent(3) &&
1814  dst.extent(4) == src.extent(4) &&
1815  dst.extent(5) == src.extent(5) &&
1816  dst.extent(6) == src.extent(6) &&
1817  dst.extent(7) == src.extent(7) &&
1818  dst.stride_0() == src.stride_0() &&
1819  dst.stride_1() == src.stride_1() &&
1820  dst.stride_2() == src.stride_2() &&
1821  dst.stride_3() == src.stride_3() &&
1822  dst.stride_4() == src.stride_4() &&
1823  dst.stride_5() == src.stride_5() &&
1824  dst.stride_6() == src.stride_6() &&
1825  dst.stride_7() == src.stride_7()
1826  ) {
1827 
1828  const size_t nbytes = sizeof(typename dst_type::value_type) * dst.span();
1829 
1830  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1831  }
1832  else if ( DstExecCanAccessSrc ) {
1833  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
1834  Kokkos::Impl::DynRankViewRemap< dst_type , src_type >( dst , src );
1835  }
1836  else if ( SrcExecCanAccessDst ) {
1837  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
1838  Kokkos::Impl::DynRankViewRemap< dst_type , src_type , src_execution_space >( dst , src );
1839  }
1840  else {
1841  Kokkos::Impl::throw_runtime_exception("deep_copy given views that would require a temporary allocation");
1842  }
1843  }
1844 }
1845 
1846 } //end Kokkos
1847 
1848 
1849 //----------------------------------------------------------------------------
1850 //----------------------------------------------------------------------------
1851 
1852 namespace Kokkos {
1853 namespace Impl {
1854 
1855 
1856 // Deduce Mirror Types
1857 template<class Space, class T, class ... P>
1858 struct MirrorDRViewType {
1859  // The incoming view_type
1860  typedef typename Kokkos::DynRankView<T,P...> src_view_type;
1861  // The memory space for the mirror view
1862  typedef typename Space::memory_space memory_space;
1863  // Check whether it is the same memory space
1864  enum { is_same_memspace = std::is_same<memory_space,typename src_view_type::memory_space>::value };
1865  // The array_layout
1866  typedef typename src_view_type::array_layout array_layout;
1867  // The data type (we probably want it non-const since otherwise we can't even deep_copy to it.
1868  typedef typename src_view_type::non_const_data_type data_type;
1869  // The destination view type if it is not the same memory space
1870  typedef Kokkos::DynRankView<data_type,array_layout,Space> dest_view_type;
1871  // If it is the same memory_space return the existsing view_type
1872  // This will also keep the unmanaged trait if necessary
1873  typedef typename std::conditional<is_same_memspace,src_view_type,dest_view_type>::type view_type;
1874 };
1875 
1876 template<class Space, class T, class ... P>
1877 struct MirrorDRVType {
1878  // The incoming view_type
1879  typedef typename Kokkos::DynRankView<T,P...> src_view_type;
1880  // The memory space for the mirror view
1881  typedef typename Space::memory_space memory_space;
1882  // Check whether it is the same memory space
1883  enum { is_same_memspace = std::is_same<memory_space,typename src_view_type::memory_space>::value };
1884  // The array_layout
1885  typedef typename src_view_type::array_layout array_layout;
1886  // The data type (we probably want it non-const since otherwise we can't even deep_copy to it.
1887  typedef typename src_view_type::non_const_data_type data_type;
1888  // The destination view type if it is not the same memory space
1889  typedef Kokkos::DynRankView<data_type,array_layout,Space> view_type;
1890 };
1891 
1892 }
1893 
1894 template< class T , class ... P >
1895 inline
1896 typename DynRankView<T,P...>::HostMirror
1897 create_mirror( const DynRankView<T,P...> & src
1898  , typename std::enable_if<
1899  std::is_same< typename ViewTraits<T,P...>::specialize , void >::value &&
1900  ! std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
1901  , Kokkos::LayoutStride >::value
1902  >::type * = 0
1903  )
1904 {
1905  typedef DynRankView<T,P...> src_type ;
1906  typedef typename src_type::HostMirror dst_type ;
1907 
1908  return dst_type( std::string( src.label() ).append("_mirror")
1909  , Impl::reconstructLayout(src.layout(), src.rank()) );
1910 }
1911 
1912 
1913 template< class T , class ... P >
1914 inline
1915 typename DynRankView<T,P...>::HostMirror
1916 create_mirror( const DynRankView<T,P...> & src
1917  , typename std::enable_if<
1918  std::is_same< typename ViewTraits<T,P...>::specialize , void >::value &&
1919  std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
1920  , Kokkos::LayoutStride >::value
1921  >::type * = 0
1922  )
1923 {
1924  typedef DynRankView<T,P...> src_type ;
1925  typedef typename src_type::HostMirror dst_type ;
1926 
1927  return dst_type( std::string( src.label() ).append("_mirror")
1928  , Impl::reconstructLayout(src.layout(), src.rank()) );
1929 }
1930 
1931 
1932 // Create a mirror in a new space (specialization for different space)
1933 template<class Space, class T, class ... P>
1934 typename Impl::MirrorDRVType<Space,T,P ...>::view_type
1935 create_mirror(const Space& , const Kokkos::DynRankView<T,P...> & src
1936  , typename std::enable_if<
1937  std::is_same< typename ViewTraits<T,P...>::specialize , void >::value
1938  >::type * = 0) {
1939  return typename Impl::MirrorDRVType<Space,T,P ...>::view_type(src.label(), Impl::reconstructLayout(src.layout(), src.rank()) );
1940 }
1941 
1942 template< class T , class ... P >
1943 inline
1944 typename DynRankView<T,P...>::HostMirror
1945 create_mirror_view( const DynRankView<T,P...> & src
1946  , typename std::enable_if<(
1947  std::is_same< typename DynRankView<T,P...>::memory_space
1948  , typename DynRankView<T,P...>::HostMirror::memory_space
1949  >::value
1950  &&
1951  std::is_same< typename DynRankView<T,P...>::data_type
1952  , typename DynRankView<T,P...>::HostMirror::data_type
1953  >::value
1954  )>::type * = 0
1955  )
1956 {
1957  return src ;
1958 }
1959 
1960 template< class T , class ... P >
1961 inline
1962 typename DynRankView<T,P...>::HostMirror
1963 create_mirror_view( const DynRankView<T,P...> & src
1964  , typename std::enable_if< ! (
1965  std::is_same< typename DynRankView<T,P...>::memory_space
1966  , typename DynRankView<T,P...>::HostMirror::memory_space
1967  >::value
1968  &&
1969  std::is_same< typename DynRankView<T,P...>::data_type
1970  , typename DynRankView<T,P...>::HostMirror::data_type
1971  >::value
1972  )>::type * = 0
1973  )
1974 {
1975  return Kokkos::create_mirror( src );
1976 }
1977 
1978 // Create a mirror view in a new space (specialization for same space)
1979 template<class Space, class T, class ... P>
1980 typename Impl::MirrorDRViewType<Space,T,P ...>::view_type
1981 create_mirror_view(const Space& , const Kokkos::DynRankView<T,P...> & src
1982  , typename std::enable_if<Impl::MirrorDRViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
1983  return src;
1984 }
1985 
1986 // Create a mirror view in a new space (specialization for different space)
1987 template<class Space, class T, class ... P>
1988 typename Impl::MirrorDRViewType<Space,T,P ...>::view_type
1989 create_mirror_view(const Space& , const Kokkos::DynRankView<T,P...> & src
1990  , typename std::enable_if<!Impl::MirrorDRViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
1991  return typename Impl::MirrorDRViewType<Space,T,P ...>::view_type(src.label(), Impl::reconstructLayout(src.layout(), src.rank()) );
1992 }
1993 
1994 } //end Kokkos
1995 
1996 
1997 //----------------------------------------------------------------------------
1998 //----------------------------------------------------------------------------
1999 
2000 namespace Kokkos {
2002 template< class T , class ... P >
2003 inline
2004 void resize( DynRankView<T,P...> & v ,
2005  const size_t n0 =KOKKOS_INVALID_INDEX ,
2006  const size_t n1 =KOKKOS_INVALID_INDEX ,
2007  const size_t n2 =KOKKOS_INVALID_INDEX ,
2008  const size_t n3 =KOKKOS_INVALID_INDEX ,
2009  const size_t n4 =KOKKOS_INVALID_INDEX ,
2010  const size_t n5 =KOKKOS_INVALID_INDEX ,
2011  const size_t n6 =KOKKOS_INVALID_INDEX ,
2012  const size_t n7 =KOKKOS_INVALID_INDEX )
2013 {
2014  typedef DynRankView<T,P...> drview_type ;
2015 
2016  static_assert( Kokkos::ViewTraits<T,P...>::is_managed , "Can only resize managed views" );
2017 
2018  drview_type v_resized( v.label(), n0, n1, n2, n3, n4, n5, n6 );
2019 
2020  Kokkos::Impl::DynRankViewRemap< drview_type , drview_type >( v_resized, v );
2021 
2022  v = v_resized ;
2023 }
2024 
2026 template< class T , class ... P >
2027 inline
2028 void realloc( DynRankView<T,P...> & v ,
2029  const size_t n0 =KOKKOS_INVALID_INDEX ,
2030  const size_t n1 =KOKKOS_INVALID_INDEX ,
2031  const size_t n2 =KOKKOS_INVALID_INDEX ,
2032  const size_t n3 =KOKKOS_INVALID_INDEX ,
2033  const size_t n4 =KOKKOS_INVALID_INDEX ,
2034  const size_t n5 =KOKKOS_INVALID_INDEX ,
2035  const size_t n6 =KOKKOS_INVALID_INDEX ,
2036  const size_t n7 =KOKKOS_INVALID_INDEX )
2037 {
2038  typedef DynRankView<T,P...> drview_type ;
2039 
2040  static_assert( Kokkos::ViewTraits<T,P...>::is_managed , "Can only realloc managed views" );
2041 
2042  const std::string label = v.label();
2043 
2044  v = drview_type(); // Deallocate first, if the only view to allocation
2045  v = drview_type( label, n0, n1, n2, n3, n4, n5, n6 );
2046 }
2047 
2048 } //end Kokkos
2049 
2050 #endif
2051 
KOKKOS_INLINE_FUNCTION bool operator==(const complex< RealType1 > &x, const complex< RealType2 > &y)
Equality operator for two complex numbers.
View
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 ?
Memory layout tag indicated arbitrarily strided multi-index mapping into contiguous memory...
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.
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.
Implementation of the ParallelFor operator that has a partial specialization for the device...
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.
Execution policy for work over a range of an integral type.
KOKKOS_INLINE_FUNCTION bool dyn_rank_view_verify_operator_bounds(const iType0 &, const MapType &)
Debug bounds-checking routines.
Traits class for accessing attributes of a View.
KOKKOS_INLINE_FUNCTION constexpr unsigned rank(const View< D, P... > &V)
Temporary free function rank() until rank() is implemented in the View.
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.