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