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