Kokkos Core Kernels Package  Version of the Day
KokkosExp_View.hpp
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 
44 #ifndef KOKKOS_EXPERIMENTAL_VIEW_HPP
45 #define KOKKOS_EXPERIMENTAL_VIEW_HPP
46 
47 #include <string>
48 #include <type_traits>
49 #include <initializer_list>
50 
51 #include <Kokkos_Core_fwd.hpp>
52 #include <Kokkos_HostSpace.hpp>
53 #include <Kokkos_MemoryTraits.hpp>
54 
55 //----------------------------------------------------------------------------
56 //----------------------------------------------------------------------------
57 
58 namespace Kokkos {
59 namespace Experimental {
60 namespace Impl {
61 
62 template< class DataType >
63 struct ViewArrayAnalysis ;
64 
65 template< class DataType , class ValueType , class ArrayLayout >
66 struct ViewDataAnalysis ;
67 
68 template< class , class = void , typename Enable = void >
69 class ViewMapping { enum { is_assignable = false }; };
70 
71 template< class DstMemorySpace , class SrcMemorySpace >
72 struct DeepCopy ;
73 
74 } /* namespace Impl */
75 } /* namespace Experimental */
76 } /* namespace Kokkos */
77 
78 //----------------------------------------------------------------------------
79 //----------------------------------------------------------------------------
80 
81 namespace Kokkos {
82 namespace Experimental {
83 
102 template< class DataType ,
103  class Arg1 = void ,
104  class Arg2 = void ,
105  class Arg3 = void >
106 class ViewTraits {
107 private:
108 
109  // Layout, Space, and MemoryTraits are optional
110  // but need to appear in that order. That means Layout
111  // can only be Arg1, Space can be Arg1 or Arg2, and
112  // MemoryTraits can be Arg1, Arg2 or Arg3
113 
114  enum { Arg1IsLayout = Kokkos::Impl::is_array_layout<Arg1>::value };
115 
116  enum { Arg1IsSpace = Kokkos::Impl::is_space<Arg1>::value };
117  enum { Arg2IsSpace = Kokkos::Impl::is_space<Arg2>::value };
118 
119  enum { Arg1IsMemoryTraits = Kokkos::Impl::is_memory_traits<Arg1>::value };
120  enum { Arg2IsMemoryTraits = Kokkos::Impl::is_memory_traits<Arg2>::value };
121  enum { Arg3IsMemoryTraits = Kokkos::Impl::is_memory_traits<Arg3>::value };
122 
123  enum { Arg1IsVoid = std::is_same< Arg1 , void >::value };
124  enum { Arg2IsVoid = std::is_same< Arg2 , void >::value };
125  enum { Arg3IsVoid = std::is_same< Arg3 , void >::value };
126 
127  static_assert( 1 == Arg1IsLayout + Arg1IsSpace + Arg1IsMemoryTraits + Arg1IsVoid
128  , "Template argument #1 must be layout, space, traits, or void" );
129 
130  // If Arg1 is Layout then Arg2 is Space, MemoryTraits, or void
131  // If Arg1 is Space then Arg2 is MemoryTraits or void
132  // If Arg1 is MemoryTraits then Arg2 is void
133  // If Arg1 is Void then Arg2 is void
134 
135  static_assert( ( Arg1IsLayout && ( 1 == Arg2IsSpace + Arg2IsMemoryTraits + Arg2IsVoid ) ) ||
136  ( Arg1IsSpace && ( 0 == Arg2IsSpace ) && ( 1 == Arg2IsMemoryTraits + Arg2IsVoid ) ) ||
137  ( Arg1IsMemoryTraits && Arg2IsVoid ) ||
138  ( Arg1IsVoid && Arg2IsVoid )
139  , "Template argument #2 must be space, traits, or void" );
140 
141  // Arg3 is MemoryTraits or void and at most one argument is MemoryTraits
142  static_assert( ( 1 == Arg3IsMemoryTraits + Arg3IsVoid ) &&
143  ( Arg1IsMemoryTraits + Arg2IsMemoryTraits + Arg3IsMemoryTraits <= 1 )
144  , "Template argument #3 must be traits or void" );
145 
146  typedef
147  typename std::conditional< Arg1IsSpace , Arg1 ,
148  typename std::conditional< Arg2IsSpace , Arg2 , Kokkos::DefaultExecutionSpace
149  >::type >::type::execution_space
150  ExecutionSpace ;
151 
152  typedef
153  typename std::conditional< Arg1IsSpace , Arg1 ,
154  typename std::conditional< Arg2IsSpace , Arg2 , Kokkos::DefaultExecutionSpace
155  >::type >::type::memory_space
156  MemorySpace ;
157 
158  typedef
159  typename Kokkos::Impl::is_space<
160  typename std::conditional< Arg1IsSpace , Arg1 ,
161  typename std::conditional< Arg2IsSpace , Arg2 , Kokkos::DefaultExecutionSpace
162  >::type >::type >::host_mirror_space
163  HostMirrorSpace ;
164 
165  typedef
166  typename std::conditional< Arg1IsLayout , Arg1 , typename ExecutionSpace::array_layout >::type
167  ArrayLayout ;
168 
169  // Arg1, Arg2, or Arg3 may be memory traits
170  typedef
171  typename std::conditional< Arg1IsMemoryTraits , Arg1 ,
172  typename std::conditional< Arg2IsMemoryTraits , Arg2 ,
173  typename std::conditional< Arg3IsMemoryTraits , Arg3 , MemoryManaged
174  >::type >::type >::type
175  MemoryTraits ;
176 
177  // Analyze data type's array properties
178  typedef Kokkos::Experimental::Impl::ViewArrayAnalysis< DataType > array_analysis ;
179 
180  // Analyze data type's properties with opportunity to specialize based upon the array value type
181  typedef Kokkos::Experimental::Impl::
182  ViewDataAnalysis< DataType
183  , typename array_analysis::non_const_value_type
184  , ArrayLayout
185  > data_analysis ;
186 
187 public:
188 
189  //------------------------------------
190  // Data type traits:
191 
192  typedef typename data_analysis::type data_type ;
193  typedef typename data_analysis::const_type const_data_type ;
194  typedef typename data_analysis::non_const_type non_const_data_type ;
195 
196  //------------------------------------
197  // Compatible array of trivial type traits:
198 
199  typedef typename data_analysis::array_scalar_type array_scalar_type ;
200  typedef typename data_analysis::const_array_scalar_type const_array_scalar_type ;
201  typedef typename data_analysis::non_const_array_scalar_type non_const_array_scalar_type ;
202 
203  //------------------------------------
204  // Value type traits:
205 
206  typedef typename data_analysis::value_type value_type ;
207  typedef typename data_analysis::const_value_type const_value_type ;
208  typedef typename data_analysis::non_const_value_type non_const_value_type ;
209 
210  //------------------------------------
211  // Mapping traits:
212 
213  typedef ArrayLayout array_layout ;
214  typedef typename data_analysis::dimension dimension ;
215  typedef typename data_analysis::specialize specialize /* mapping specialization tag */ ;
216 
217  enum { rank = dimension::rank };
218  enum { rank_dynamic = dimension::rank_dynamic };
219 
220  //------------------------------------
221  // Execution space, memory space, memory access traits, and host mirror space.
222 
223  typedef ExecutionSpace execution_space ;
224  typedef MemorySpace memory_space ;
226  typedef MemoryTraits memory_traits ;
227  typedef HostMirrorSpace host_mirror_space ;
228 
229  typedef typename memory_space::size_type size_type ;
230 
231  enum { is_hostspace = std::is_same< memory_space , HostSpace >::value };
232  enum { is_managed = memory_traits::Unmanaged == 0 };
233  enum { is_random_access = memory_traits::RandomAccess == 1 };
234 
235  //------------------------------------
236 };
237 
318 template< class DataType
319  , class Arg1 = void /* ArrayLayout, SpaceType, or MemoryTraits */
320  , class Arg2 = void /* SpaceType or MemoryTraits */
321  , class Arg3 = void /* MemoryTraits */ >
322 class View ;
323 
324 } /* namespace Experimental */
325 } /* namespace Kokkos */
326 
327 //----------------------------------------------------------------------------
328 //----------------------------------------------------------------------------
329 
330 #include <impl/KokkosExp_ViewMapping.hpp>
331 #include <impl/KokkosExp_ViewAllocProp.hpp>
332 #include <impl/KokkosExp_ViewArray.hpp>
333 
334 //----------------------------------------------------------------------------
335 //----------------------------------------------------------------------------
336 
337 namespace Kokkos {
338 namespace Experimental {
339 
340 namespace {
341 
342 constexpr Kokkos::Experimental::Impl::ALL_t
343  ALL = Kokkos::Experimental::Impl::ALL_t();
344 
345 constexpr Kokkos::Experimental::Impl::WithoutInitializing_t
346  WithoutInitializing = Kokkos::Experimental::Impl::WithoutInitializing_t();
347 
348 constexpr Kokkos::Experimental::Impl::AllowPadding_t
349  AllowPadding = Kokkos::Experimental::Impl::AllowPadding_t();
350 
351 }
352 
362 template< class ... Args >
363 inline
364 Kokkos::Experimental::Impl::ViewAllocProp< Args ... >
365 view_alloc( Args ... args )
366 {
367  return Kokkos::Experimental::Impl::ViewAllocProp< Args ... >( args ... );
368 }
369 
370 } /* namespace Experimental */
371 } /* namespace Kokkos */
372 
373 //----------------------------------------------------------------------------
374 //----------------------------------------------------------------------------
375 
376 namespace Kokkos {
377 namespace Experimental {
378 
380 template< class V
381  , bool R0 = false , bool R1 = false , bool R2 = false , bool R3 = false
382  , bool R4 = false , bool R5 = false , bool R6 = false , bool R7 = false >
383 using Subview = typename Kokkos::Experimental::Impl::SubviewType< V, R0 , R1 , R2 , R3 , R4 , R5 , R6 , R7 >::type ;
384 
385 template< class DataType , class Arg1 , class Arg2 , class Arg3 >
386 class View : public ViewTraits< DataType , Arg1 , Arg2 , Arg3 > {
387 private:
388 
389  template< class , class , class , class > friend class View ;
390 
392  typedef Kokkos::Experimental::Impl::ViewMapping< traits > map_type ;
393  typedef Kokkos::Experimental::Impl::SharedAllocationTracker track_type ;
394 
395  track_type m_track ;
396  map_type m_map ;
397 
398 public:
399 
400  //----------------------------------------
402  typedef View< typename traits::array_scalar_type ,
403  typename traits::array_layout ,
404  typename traits::device_type ,
405  typename traits::memory_traits >
407 
409  typedef View< typename traits::const_data_type ,
410  typename traits::array_layout ,
411  typename traits::device_type ,
412  typename traits::memory_traits >
414 
416  typedef View< typename traits::non_const_data_type ,
417  typename traits::array_layout ,
418  typename traits::device_type ,
419  typename traits::memory_traits >
421 
423  typedef View< typename traits::non_const_data_type ,
424  typename traits::array_layout ,
425  typename traits::host_mirror_space ,
426  void >
428 
429  //----------------------------------------
430  // Domain dimensions
431 
432  enum { Rank = map_type::Rank };
433 
434  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_0() const { return m_map.dimension_0(); }
435  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_1() const { return m_map.dimension_1(); }
436  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_2() const { return m_map.dimension_2(); }
437  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_3() const { return m_map.dimension_3(); }
438  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_4() const { return m_map.dimension_4(); }
439  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_5() const { return m_map.dimension_5(); }
440  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_6() const { return m_map.dimension_6(); }
441  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_7() const { return m_map.dimension_7(); }
442 
443  KOKKOS_INLINE_FUNCTION constexpr size_t stride_0() const { return m_map.stride_0(); }
444  KOKKOS_INLINE_FUNCTION constexpr size_t stride_1() const { return m_map.stride_1(); }
445  KOKKOS_INLINE_FUNCTION constexpr size_t stride_2() const { return m_map.stride_2(); }
446  KOKKOS_INLINE_FUNCTION constexpr size_t stride_3() const { return m_map.stride_3(); }
447  KOKKOS_INLINE_FUNCTION constexpr size_t stride_4() const { return m_map.stride_4(); }
448  KOKKOS_INLINE_FUNCTION constexpr size_t stride_5() const { return m_map.stride_5(); }
449  KOKKOS_INLINE_FUNCTION constexpr size_t stride_6() const { return m_map.stride_6(); }
450  KOKKOS_INLINE_FUNCTION constexpr size_t stride_7() const { return m_map.stride_7(); }
451 
452  //----------------------------------------
453  // Range span is the span which contains all members.
454 
455  typedef typename map_type::reference_type reference_type ;
456 
457  enum { reference_type_is_lvalue_reference = std::is_lvalue_reference< reference_type >::value };
458 
459  KOKKOS_INLINE_FUNCTION constexpr size_t span() const { return m_map.span(); }
460  KOKKOS_INLINE_FUNCTION constexpr bool span_is_contiguous() const { return m_map.span_is_contiguous(); }
461  KOKKOS_INLINE_FUNCTION constexpr typename traits::value_type * data() const { return m_map.data(); }
462 
463  // Deprecated, use 'span_is_contigous()' instead
464  KOKKOS_INLINE_FUNCTION constexpr bool is_contiguous() const { return m_map.span_is_contiguous(); }
465  // Deprecated, use 'data()' instead
466  KOKKOS_INLINE_FUNCTION constexpr typename traits::value_type * ptr_on_device() const { return m_map.data(); }
467 
468  //----------------------------------------
469  // Allow specializations to query their specialized map
470 
471  KOKKOS_INLINE_FUNCTION
472  const map_type & implementation_map() const { return m_map ; }
473 
474  //----------------------------------------
475 
476 private:
477 
478  typedef typename
479  std::conditional< Rank == 0 , reference_type
480  , Kokkos::Experimental::Impl::Error_view_scalar_reference_to_non_scalar_view >::type
481  scalar_operator_reference_type ;
482 
483  typedef typename
484  std::conditional< Rank == 0 , const int
485  , Kokkos::Experimental::Impl::Error_view_scalar_reference_to_non_scalar_view >::type
486  scalar_operator_index_type ;
487 
488 public:
489 
490  // Rank == 0
491 
492  KOKKOS_FORCEINLINE_FUNCTION
493  scalar_operator_reference_type operator()() const
494  {
495  KOKKOS_ASSERT_VIEW_MAPPING_ACCESS( typename traits::memory_space, m_map, Rank, 0, 0, 0, 0, 0, 0, 0, 0 );
496  return scalar_operator_reference_type( m_map.reference() );
497  }
498 
499  KOKKOS_FORCEINLINE_FUNCTION
500  reference_type
501  operator()( scalar_operator_index_type i0
502  , const int i1 = 0 , const int i2 = 0 , const int i3 = 0
503  , const int i4 = 0 , const int i5 = 0 , const int i6 = 0 , const int i7 = 0 ) const
504  {
505  KOKKOS_ASSERT_VIEW_MAPPING_ACCESS( typename traits::memory_space, m_map, Rank, i0, i1, i2, i3, i4, i5, i6, i7 );
506  return m_map.reference();
507  }
508 
509  // Rank == 1
510 
511  template< typename I0 >
512  KOKKOS_FORCEINLINE_FUNCTION
513  typename std::enable_if<( Rank == 1 && std::is_integral<I0>::value
514  ), reference_type >::type
515  operator[]( const I0 & i0 ) const
516  {
517  KOKKOS_ASSERT_VIEW_MAPPING_ACCESS( typename traits::memory_space, m_map, Rank, i0, 0, 0, 0, 0, 0, 0, 0 );
518  return m_map.reference(i0);
519  }
520 
521  template< typename I0 >
522  KOKKOS_FORCEINLINE_FUNCTION
523  typename std::enable_if<( Rank == 1 && std::is_integral<I0>::value
524  ), reference_type >::type
525  operator()( const I0 & i0 ) const
526  {
527  KOKKOS_ASSERT_VIEW_MAPPING_ACCESS( typename traits::memory_space, m_map, Rank, i0, 0, 0, 0, 0, 0, 0, 0 );
528  return m_map.reference(i0);
529  }
530 
531  template< typename I0 >
532  KOKKOS_FORCEINLINE_FUNCTION
533  reference_type
534  operator()( const I0 & i0
535  , typename std::enable_if<( Rank == 1 && std::is_integral<I0>::value ), const int >::type i1
536  , const int i2 = 0 , const int i3 = 0
537  , const int i4 = 0 , const int i5 = 0 , const int i6 = 0 , const int i7 = 0 ) const
538  {
539  KOKKOS_ASSERT_VIEW_MAPPING_ACCESS( typename traits::memory_space, m_map, Rank, i0, i1, i2, i3, i4, i5, i6, i7 );
540  return m_map.reference(i0);
541  }
542 
543  // Rank == 2
544 
545  template< typename I0 , typename I1 >
546  KOKKOS_FORCEINLINE_FUNCTION
547  typename std::enable_if<( Rank == 2 &&
548  std::is_integral<I0>::value &&
549  std::is_integral<I1>::value
550  ), reference_type >::type
551  operator()( const I0 & i0 , const I1 & i1 ) const
552  {
553  KOKKOS_ASSERT_VIEW_MAPPING_ACCESS( typename traits::memory_space, m_map, Rank, i0, i1, 0, 0, 0, 0, 0, 0 );
554  return m_map.reference(i0,i1);
555  }
556 
557  template< typename I0 , typename I1 >
558  KOKKOS_FORCEINLINE_FUNCTION
559  reference_type
560  operator()( const I0 & i0 , const I1 & i1
561  , typename std::enable_if<( Rank == 2 &&
562  std::is_integral<I0>::value &&
563  std::is_integral<I1>::value
564  ), const int >::type i2
565  , const int i3 = 0
566  , const int i4 = 0 , const int i5 = 0 , const int i6 = 0 , const int i7 = 0 ) const
567  {
568  KOKKOS_ASSERT_VIEW_MAPPING_ACCESS( typename traits::memory_space, m_map, Rank, i0, i1, i2, i3, i4, i5, i6, i7 );
569  return m_map.reference(i0,i1);
570  }
571 
572  // Rank == 3
573 
574  template< typename I0 , typename I1 , typename I2 >
575  KOKKOS_FORCEINLINE_FUNCTION
576  typename std::enable_if<( Rank == 3 &&
577  std::is_integral<I0>::value &&
578  std::is_integral<I1>::value &&
579  std::is_integral<I2>::value
580  ), reference_type >::type
581  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 ) const
582  {
583  KOKKOS_ASSERT_VIEW_MAPPING_ACCESS( typename traits::memory_space, m_map, Rank, i0, i1, i2, 0, 0, 0, 0, 0 );
584  return m_map.reference(i0,i1,i2);
585  }
586 
587  template< typename I0 , typename I1 , typename I2 >
588  KOKKOS_FORCEINLINE_FUNCTION
589  reference_type
590  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2
591  , typename std::enable_if<( Rank == 3 &&
592  std::is_integral<I0>::value &&
593  std::is_integral<I1>::value &&
594  std::is_integral<I2>::value
595  ), const int >::type i3
596  , const int i4 = 0 , const int i5 = 0 , const int i6 = 0 , const int i7 = 0 ) const
597  {
598  KOKKOS_ASSERT_VIEW_MAPPING_ACCESS( typename traits::memory_space, m_map, Rank, i0, i1, i2, i3, i4, i5, i6, i7 );
599  return m_map.reference(i0,i1,i2);
600  }
601 
602  // Rank == 4
603 
604  template< typename I0 , typename I1 , typename I2 , typename I3 >
605  KOKKOS_FORCEINLINE_FUNCTION
606  typename std::enable_if<( Rank == 4 &&
607  std::is_integral<I0>::value &&
608  std::is_integral<I1>::value &&
609  std::is_integral<I2>::value &&
610  std::is_integral<I3>::value
611  ), reference_type >::type
612  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3 ) const
613  {
614  KOKKOS_ASSERT_VIEW_MAPPING_ACCESS( typename traits::memory_space, m_map, Rank, i0, i1, i2, i3, 0, 0, 0, 0 );
615  return m_map.reference(i0,i1,i2,i3);
616  }
617 
618  template< typename I0 , typename I1 , typename I2 , typename I3 >
619  KOKKOS_FORCEINLINE_FUNCTION
620  reference_type
621  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
622  , typename std::enable_if<( Rank == 4 &&
623  std::is_integral<I0>::value &&
624  std::is_integral<I1>::value &&
625  std::is_integral<I2>::value &&
626  std::is_integral<I3>::value
627  ), const int >::type i4
628  , const int i5 = 0 , const int i6 = 0 , const int i7 = 0 ) const
629  {
630  KOKKOS_ASSERT_VIEW_MAPPING_ACCESS( typename traits::memory_space, m_map, Rank, i0, i1, i2, i3, i4, i5, i6, i7 );
631  return m_map.reference(i0,i1,i2,i3);
632  }
633 
634  // Rank == 5
635 
636  template< typename I0 , typename I1 , typename I2 , typename I3
637  , typename I4 >
638  KOKKOS_FORCEINLINE_FUNCTION
639  typename std::enable_if<( Rank == 5 &&
640  std::is_integral<I0>::value &&
641  std::is_integral<I1>::value &&
642  std::is_integral<I2>::value &&
643  std::is_integral<I3>::value &&
644  std::is_integral<I4>::value
645  ), reference_type >::type
646  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
647  , const I4 & i4 ) const
648  {
649  KOKKOS_ASSERT_VIEW_MAPPING_ACCESS( typename traits::memory_space, m_map, Rank, i0, i1, i2, i3, i4, 0, 0, 0 );
650  return m_map.reference(i0,i1,i2,i3,i4);
651  }
652 
653  template< typename I0 , typename I1 , typename I2 , typename I3
654  , typename I4 >
655  KOKKOS_FORCEINLINE_FUNCTION
656  reference_type
657  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
658  , const I4 & i4
659  , typename std::enable_if<( Rank == 5 &&
660  std::is_integral<I0>::value &&
661  std::is_integral<I1>::value &&
662  std::is_integral<I2>::value &&
663  std::is_integral<I3>::value &&
664  std::is_integral<I4>::value
665  ), const int >::type i5
666  , const int i6 = 0 , const int i7 = 0 ) const
667  {
668  KOKKOS_ASSERT_VIEW_MAPPING_ACCESS( typename traits::memory_space, m_map, Rank, i0, i1, i2, i3, i4, i5, i6, i7 );
669  return m_map.reference(i0,i1,i2,i3,i4);
670  }
671 
672  // Rank == 6
673 
674  template< typename I0 , typename I1 , typename I2 , typename I3
675  , typename I4 , typename I5 >
676  KOKKOS_FORCEINLINE_FUNCTION
677  typename std::enable_if<( Rank == 6 &&
678  std::is_integral<I0>::value &&
679  std::is_integral<I1>::value &&
680  std::is_integral<I2>::value &&
681  std::is_integral<I3>::value &&
682  std::is_integral<I4>::value &&
683  std::is_integral<I5>::value
684  ), reference_type >::type
685  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
686  , const I4 & i4 , const I5 & i5 ) const
687  {
688  KOKKOS_ASSERT_VIEW_MAPPING_ACCESS( typename traits::memory_space, m_map, Rank, i0, i1, i2, i3, i4, i5, 0, 0 );
689  return m_map.reference(i0,i1,i2,i3,i4,i5);
690  }
691 
692  template< typename I0 , typename I1 , typename I2 , typename I3
693  , typename I4 , typename I5 >
694  KOKKOS_FORCEINLINE_FUNCTION
695  reference_type
696  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
697  , const I4 & i4 , const I5 & i5
698  , typename std::enable_if<( Rank == 6 &&
699  std::is_integral<I0>::value &&
700  std::is_integral<I1>::value &&
701  std::is_integral<I2>::value &&
702  std::is_integral<I3>::value &&
703  std::is_integral<I4>::value
704  ), const int >::type i6
705  , const int i7 = 0 ) const
706  {
707  KOKKOS_ASSERT_VIEW_MAPPING_ACCESS( typename traits::memory_space, m_map, Rank, i0, i1, i2, i3, i4, i5, i6, i7 );
708  return m_map.reference(i0,i1,i2,i3,i4,i5);
709  }
710 
711  // Rank == 7
712 
713  template< typename I0 , typename I1 , typename I2 , typename I3
714  , typename I4 , typename I5 , typename I6 >
715  KOKKOS_FORCEINLINE_FUNCTION
716  typename std::enable_if<( Rank == 7 &&
717  std::is_integral<I0>::value &&
718  std::is_integral<I1>::value &&
719  std::is_integral<I2>::value &&
720  std::is_integral<I3>::value &&
721  std::is_integral<I4>::value &&
722  std::is_integral<I5>::value &&
723  std::is_integral<I6>::value
724  ), reference_type >::type
725  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
726  , const I4 & i4 , const I5 & i5 , const I6 & i6 ) const
727  {
728  KOKKOS_ASSERT_VIEW_MAPPING_ACCESS( typename traits::memory_space, m_map, Rank, i0, i1, i2, i3, i4, i5, i6, 0 );
729  return m_map.reference(i0,i1,i2,i3,i4,i5,i6);
730  }
731 
732  template< typename I0 , typename I1 , typename I2 , typename I3
733  , typename I4 , typename I5 , typename I6 >
734  KOKKOS_FORCEINLINE_FUNCTION
735  reference_type
736  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
737  , const I4 & i4 , const I5 & i5 , const I6 & i6
738  , typename std::enable_if<( Rank == 7 &&
739  std::is_integral<I0>::value &&
740  std::is_integral<I1>::value &&
741  std::is_integral<I2>::value &&
742  std::is_integral<I3>::value &&
743  std::is_integral<I4>::value
744  ), const int >::type i7
745  ) const
746  {
747  KOKKOS_ASSERT_VIEW_MAPPING_ACCESS( typename traits::memory_space, m_map, Rank, i0, i1, i2, i3, i4, i5, i6, i7 );
748  return m_map.reference(i0,i1,i2,i3,i4,i5,i6);
749  }
750 
751  // Rank == 8
752 
753  template< typename I0 , typename I1 , typename I2 , typename I3
754  , typename I4 , typename I5 , typename I6 , typename I7 >
755  KOKKOS_FORCEINLINE_FUNCTION
756  typename std::enable_if<( Rank == 8 &&
757  std::is_integral<I0>::value &&
758  std::is_integral<I1>::value &&
759  std::is_integral<I2>::value &&
760  std::is_integral<I3>::value &&
761  std::is_integral<I4>::value &&
762  std::is_integral<I5>::value &&
763  std::is_integral<I6>::value &&
764  std::is_integral<I7>::value
765  ), reference_type >::type
766  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
767  , const I4 & i4 , const I5 & i5 , const I6 & i6 , const I7 & i7 ) const
768  {
769  KOKKOS_ASSERT_VIEW_MAPPING_ACCESS( typename traits::memory_space, m_map, Rank, i0, i1, i2, i3, i4, i5, i6, i7 );
770  return m_map.reference(i0,i1,i2,i3,i4,i5,i6,i7);
771  }
772 
773  //----------------------------------------
774 
775  KOKKOS_INLINE_FUNCTION
776  ~View() {}
777 
778  KOKKOS_INLINE_FUNCTION
779  View() : m_track(), m_map() {}
780 
781  KOKKOS_INLINE_FUNCTION
782  View( const View & rhs ) : m_track( rhs.m_track ), m_map( rhs.m_map ) {}
783 
784  KOKKOS_INLINE_FUNCTION
785  View( View && rhs ) : m_track( rhs.m_track ), m_map( rhs.m_map ) {}
786 
787  KOKKOS_INLINE_FUNCTION
788  View & operator = ( const View & rhs ) { m_track = rhs.m_track ; m_map = rhs.m_map ; return *this ; }
789 
790  KOKKOS_INLINE_FUNCTION
791  View & operator = ( View && rhs ) { m_track = rhs.m_track ; m_map = rhs.m_map ; return *this ; }
792 
793  //----------------------------------------
794 
795  template< class RT , class R1 , class R2 , class R3 >
796  KOKKOS_INLINE_FUNCTION
797  View( const View<RT,R1,R2,R3> & rhs )
798  : m_track( rhs.m_track )
799  , m_map()
800  {
801  typedef typename View<RT,R1,R2,R3>::traits SrcTraits ;
802  typedef Kokkos::Experimental::Impl::ViewMapping< traits , SrcTraits > Mapping ;
803  static_assert( Mapping::is_assignable , "Incompatible View copy construction" );
804  Mapping::assign( m_map , rhs.m_map , rhs.m_track );
805  }
806 
807  template< class RT , class R1 , class R2 , class R3 >
808  KOKKOS_INLINE_FUNCTION
809  View( View<RT,R1,R2,R3> && rhs )
810  : m_track( rhs.m_track )
811  , m_map()
812  {
813  typedef typename View<RT,R1,R2,R3>::traits SrcTraits ;
814  typedef Kokkos::Experimental::Impl::ViewMapping< traits , SrcTraits > Mapping ;
815  static_assert( Mapping::is_assignable , "Incompatible View move construction" );
816  Mapping::assign( m_map , rhs.m_map , rhs.m_track );
817  }
818 
819  template< class RT , class R1 , class R2 , class R3 >
820  KOKKOS_INLINE_FUNCTION
821  View & operator = ( const View<RT,R1,R2,R3> & rhs )
822  {
823  typedef typename View<RT,R1,R2,R3>::traits SrcTraits ;
824  typedef Kokkos::Experimental::Impl::ViewMapping< traits , SrcTraits > Mapping ;
825  static_assert( Mapping::is_assignable , "Incompatible View copy assignment" );
826  Mapping::assign( m_map , rhs.m_map , rhs.m_track );
827  m_track.operator=( rhs.m_track );
828  return *this ;
829  }
830 
831  template< class RT , class R1 , class R2 , class R3 >
832  KOKKOS_INLINE_FUNCTION
833  View & operator = ( View<RT,R1,R2,R3> && rhs )
834  {
835  typedef typename View<RT,R1,R2,R3>::traits SrcTraits ;
836  typedef Kokkos::Experimental::Impl::ViewMapping< traits , SrcTraits > Mapping ;
837  static_assert( Mapping::is_assignable , "Incompatible View move assignment" );
838  Mapping::assign( m_map , rhs.m_map , rhs.m_track );
839  m_track.operator=( rhs.m_track );
840  return *this ;
841  }
842 
843  //----------------------------------------
844  // Allocation according to allocation properties
845 
846 private:
847 
848  // Must call destructor for non-trivial types
849  template< class ExecSpace >
850  struct DestroyFunctor {
851  map_type m_map ;
852  ExecSpace m_space ;
853 
854  void destroy_shared_allocation() { m_map.destroy( m_space ); }
855  };
856 
857 public:
858 
859  inline
860  const std::string label() const { return m_track.template get_label< typename traits::memory_space >(); }
861 
862  template< class Prop >
863  explicit inline
864  View( const Prop & arg_prop
865  , const size_t arg_N0 = 0
866  , const size_t arg_N1 = 0
867  , const size_t arg_N2 = 0
868  , const size_t arg_N3 = 0
869  , const size_t arg_N4 = 0
870  , const size_t arg_N5 = 0
871  , const size_t arg_N6 = 0
872  , const size_t arg_N7 = 0
873  )
874  : m_track()
875  , m_map()
876  {
877  // Merge the < execution_space , memory_space > into the properties.
878  typedef Kokkos::Experimental::Impl::ViewAllocProp< typename traits::device_type , Prop > alloc_prop ;
879 
880  typedef typename alloc_prop::execution_space execution_space ;
881  typedef typename traits::memory_space memory_space ;
882  typedef DestroyFunctor< execution_space > destroy_functor ;
883  typedef Kokkos::Experimental::Impl::SharedAllocationRecord< memory_space , destroy_functor > record_type ;
884 
885  static_assert( traits::is_managed , "View allocation constructor requires managed memory" );
886 
887  const alloc_prop prop( arg_prop );
888 
889  // If initializing view data then the execution space must be initialized.
890  if ( prop.initialize.value && ! prop.execution.is_initialized() ) {
891  Kokkos::Impl::throw_runtime_exception("Constructing View and initializing data with uninitialized execution space");
892  }
893 
894  // Query the mapping for byte-size of allocation.
895  const size_t alloc_size = map_type::memory_span( prop.allow_padding
896  , arg_N0 , arg_N1 , arg_N2 , arg_N3
897  , arg_N4 , arg_N5 , arg_N6 , arg_N7 );
898 
899  // Allocate memory from the memory space.
900  record_type * const record = record_type::allocate( prop.memory , prop.label , alloc_size );
901 
902  // Construct the mapping object prior to start of tracking
903  // to assign destroy functor and possibly initialize.
904  m_map = map_type( record->data()
905  , prop.allow_padding
906  , arg_N0 , arg_N1 , arg_N2 , arg_N3
907  , arg_N4 , arg_N5 , arg_N6 , arg_N7 );
908 
909  // If constructing the plan for destructing as well
910  // Copy the destroy functor into the allocation record
911  // before initiating tracking.
912  if ( prop.initialize.value ) {
913  m_map.construct( prop.execution );
914 
915  record->m_destroy.m_map = m_map ;
916  record->m_destroy.m_space = prop.execution ;
917  }
918 
919  // Setup and initialization complete, start tracking
920  m_track = track_type( record );
921  }
922 
923  template< class Prop >
924  explicit inline
925  View( const Prop & arg_prop
926  , const typename traits::array_layout & arg_layout
927  )
928  : m_track()
929  , m_map()
930  {
931  // Merge the < execution_space , memory_space > into the properties.
932  typedef Kokkos::Experimental::Impl::ViewAllocProp< typename traits::device_type , Prop > alloc_prop ;
933 
934  typedef typename alloc_prop::execution_space execution_space ;
935  typedef typename traits::memory_space memory_space ;
936  typedef DestroyFunctor< execution_space > destroy_functor ;
937  typedef Kokkos::Experimental::Impl::SharedAllocationRecord< memory_space , destroy_functor > record_type ;
938 
939  static_assert( traits::is_managed , "View allocation constructor requires managed memory" );
940 
941  const alloc_prop prop( arg_prop );
942 
943  // If initializing view data then the execution space must be initialized.
944  if ( prop.initialize.value && ! prop.execution.is_initialized() ) {
945  Kokkos::Impl::throw_runtime_exception("Constructing View and initializing data with uninitialized execution space");
946  }
947 
948  // Query the mapping for byte-size of allocation.
949  const size_t alloc_size = map_type::memory_span( prop.allow_padding , arg_layout );
950 
951  // Allocate memory from the memory space.
952  record_type * const record = record_type::allocate( prop.memory , prop.label , alloc_size );
953 
954  // Construct the mapping object prior to start of tracking
955  // to assign destroy functor and possibly initialize.
956  m_map = map_type( record->data() , prop.allow_padding , arg_layout );
957 
958  // Copy the destroy functor into the allocation record before initiating tracking.
959 
960  if ( prop.initialize.value ) {
961  m_map.construct( prop.execution );
962 
963  record->m_destroy.m_map = m_map ;
964  record->m_destroy.m_space = prop.execution ;
965  }
966 
967  // Setup and initialization complete, start tracking
968  m_track = track_type( record );
969  }
970 
971  //----------------------------------------
972  // Memory span required to wrap these dimensions.
973  static constexpr size_t memory_span( const size_t arg_N0 = 0
974  , const size_t arg_N1 = 0
975  , const size_t arg_N2 = 0
976  , const size_t arg_N3 = 0
977  , const size_t arg_N4 = 0
978  , const size_t arg_N5 = 0
979  , const size_t arg_N6 = 0
980  , const size_t arg_N7 = 0
981  )
982  {
983  return map_type::memory_span( std::integral_constant<bool,false>()
984  , arg_N0 , arg_N1 , arg_N2 , arg_N3
985  , arg_N4 , arg_N5 , arg_N6 , arg_N7 );
986  }
987 
988  explicit inline
989  View( typename traits::value_type * const arg_ptr
990  , const size_t arg_N0 = 0
991  , const size_t arg_N1 = 0
992  , const size_t arg_N2 = 0
993  , const size_t arg_N3 = 0
994  , const size_t arg_N4 = 0
995  , const size_t arg_N5 = 0
996  , const size_t arg_N6 = 0
997  , const size_t arg_N7 = 0
998  )
999  : m_track() // No memory tracking
1000  , m_map( arg_ptr , std::integral_constant<bool,false>()
1001  , arg_N0 , arg_N1 , arg_N2 , arg_N3
1002  , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1003  {}
1004 
1005  explicit inline
1006  View( typename traits::value_type * const arg_ptr
1007  , typename traits::array_layout & arg_layout
1008  )
1009  : m_track() // No memory tracking
1010  , m_map( arg_ptr , std::integral_constant<bool,false>(), arg_layout )
1011  {}
1012 
1013  //----------------------------------------
1014  // Shared scratch memory constructor
1015 
1016  static inline
1017  size_t shmem_size( const size_t arg_N0 = 0 ,
1018  const size_t arg_N1 = 0 ,
1019  const size_t arg_N2 = 0 ,
1020  const size_t arg_N3 = 0 ,
1021  const size_t arg_N4 = 0 ,
1022  const size_t arg_N5 = 0 ,
1023  const size_t arg_N6 = 0 ,
1024  const size_t arg_N7 = 0 )
1025  {
1026  return map_type::memory_span( std::integral_constant<bool,false>()
1027  , arg_N0 , arg_N1 , arg_N2 , arg_N3
1028  , arg_N4 , arg_N5 , arg_N6 , arg_N7 );
1029  }
1030 
1031  explicit KOKKOS_INLINE_FUNCTION
1032  View( const typename traits::execution_space::scratch_memory_space & arg_space
1033  , const size_t arg_N0 = 0
1034  , const size_t arg_N1 = 0
1035  , const size_t arg_N2 = 0
1036  , const size_t arg_N3 = 0
1037  , const size_t arg_N4 = 0
1038  , const size_t arg_N5 = 0
1039  , const size_t arg_N6 = 0
1040  , const size_t arg_N7 = 0 )
1041  : m_track() // No memory tracking
1042  , m_map( arg_space.get_shmem( map_type::memory_span( std::integral_constant<bool,false>()
1043  , arg_N0 , arg_N1 , arg_N2 , arg_N3
1044  , arg_N4 , arg_N5 , arg_N6 , arg_N7 ) )
1045  , std::integral_constant<bool,false>()
1046  , arg_N0 , arg_N1 , arg_N2 , arg_N3
1047  , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1048  {}
1049 
1050  //----------------------------------------
1051  // Subviews
1052 
1053 private:
1054 
1056  KOKKOS_INLINE_FUNCTION
1057  View( const track_type & arg_track , const map_type & arg_map )
1058  : m_track( arg_track )
1059  , m_map( arg_map )
1060  {}
1061 
1062  explicit KOKKOS_INLINE_FUNCTION
1063  View( const track_type & rhs )
1064  : m_track( rhs )
1065  , m_map()
1066  {}
1067 
1068 public:
1069 
1070  template< class D , class A1 , class A2 , class A3
1071  , class T0 , class T1 , class T2 , class T3
1072  , class T4 , class T5 , class T6 , class T7 >
1073  friend
1074  KOKKOS_INLINE_FUNCTION
1075  Kokkos::Experimental::Subview< View< D , A1 , A2 , A3 >
1076  , Kokkos::Experimental::Impl::ViewOffsetRange<T0>::is_range
1077  , Kokkos::Experimental::Impl::ViewOffsetRange<T1>::is_range
1078  , Kokkos::Experimental::Impl::ViewOffsetRange<T2>::is_range
1079  , Kokkos::Experimental::Impl::ViewOffsetRange<T3>::is_range
1080  , Kokkos::Experimental::Impl::ViewOffsetRange<T4>::is_range
1081  , Kokkos::Experimental::Impl::ViewOffsetRange<T5>::is_range
1082  , Kokkos::Experimental::Impl::ViewOffsetRange<T6>::is_range
1083  , Kokkos::Experimental::Impl::ViewOffsetRange<T7>::is_range
1084  >
1085  subview( const View< D , A1 , A2 , A3 > & src
1086  , T0 const & arg0 , T1 const & arg1 , T2 const & arg2 , T3 const & arg3
1087  , T4 const & arg4 , T5 const & arg5 , T6 const & arg6 , T7 const & arg7
1088  );
1089 
1090  template< class D , class A1 , class A2 , class A3
1091  , class T0 , class T1 , class T2 , class T3
1092  , class T4 , class T5 , class T6 >
1093  friend
1094  KOKKOS_INLINE_FUNCTION
1095  Kokkos::Experimental::Subview< View< D , A1 , A2 , A3 >
1096  , Kokkos::Experimental::Impl::ViewOffsetRange<T0>::is_range
1097  , Kokkos::Experimental::Impl::ViewOffsetRange<T1>::is_range
1098  , Kokkos::Experimental::Impl::ViewOffsetRange<T2>::is_range
1099  , Kokkos::Experimental::Impl::ViewOffsetRange<T3>::is_range
1100  , Kokkos::Experimental::Impl::ViewOffsetRange<T4>::is_range
1101  , Kokkos::Experimental::Impl::ViewOffsetRange<T5>::is_range
1102  , Kokkos::Experimental::Impl::ViewOffsetRange<T6>::is_range
1103  >
1104  subview( const View< D , A1 , A2 , A3 > & src
1105  , T0 const & arg0 , T1 const & arg1 , T2 const & arg2 , T3 const & arg3
1106  , T4 const & arg4 , T5 const & arg5 , T6 const & arg6
1107  );
1108 
1109  template< class D , class A1 , class A2 , class A3
1110  , class T0 , class T1 , class T2 , class T3
1111  , class T4 , class T5 >
1112  friend
1113  KOKKOS_INLINE_FUNCTION
1114  Kokkos::Experimental::Subview< View< D , A1 , A2 , A3 >
1115  , Kokkos::Experimental::Impl::ViewOffsetRange<T0>::is_range
1116  , Kokkos::Experimental::Impl::ViewOffsetRange<T1>::is_range
1117  , Kokkos::Experimental::Impl::ViewOffsetRange<T2>::is_range
1118  , Kokkos::Experimental::Impl::ViewOffsetRange<T3>::is_range
1119  , Kokkos::Experimental::Impl::ViewOffsetRange<T4>::is_range
1120  , Kokkos::Experimental::Impl::ViewOffsetRange<T5>::is_range
1121  >
1122  subview( const View< D , A1 , A2 , A3 > & src
1123  , T0 const & arg0 , T1 const & arg1 , T2 const & arg2 , T3 const & arg3
1124  , T4 const & arg4 , T5 const & arg5
1125  );
1126 
1127  template< class D , class A1 , class A2 , class A3
1128  , class T0 , class T1 , class T2 , class T3
1129  , class T4 >
1130  friend
1131  KOKKOS_INLINE_FUNCTION
1132  Kokkos::Experimental::Subview< View< D , A1 , A2 , A3 >
1133  , Kokkos::Experimental::Impl::ViewOffsetRange<T0>::is_range
1134  , Kokkos::Experimental::Impl::ViewOffsetRange<T1>::is_range
1135  , Kokkos::Experimental::Impl::ViewOffsetRange<T2>::is_range
1136  , Kokkos::Experimental::Impl::ViewOffsetRange<T3>::is_range
1137  , Kokkos::Experimental::Impl::ViewOffsetRange<T4>::is_range
1138  >
1139  subview( const View< D , A1 , A2 , A3 > & src
1140  , T0 const & arg0 , T1 const & arg1 , T2 const & arg2 , T3 const & arg3
1141  , T4 const & arg4
1142  );
1143 
1144  template< class D , class A1 , class A2 , class A3
1145  , class T0 , class T1 , class T2 , class T3 >
1146  friend
1147  KOKKOS_INLINE_FUNCTION
1148  Kokkos::Experimental::Subview< View< D , A1 , A2 , A3 >
1149  , Kokkos::Experimental::Impl::ViewOffsetRange<T0>::is_range
1150  , Kokkos::Experimental::Impl::ViewOffsetRange<T1>::is_range
1151  , Kokkos::Experimental::Impl::ViewOffsetRange<T2>::is_range
1152  , Kokkos::Experimental::Impl::ViewOffsetRange<T3>::is_range
1153  >
1154  subview( const View< D , A1 , A2 , A3 > & src
1155  , T0 const & arg0 , T1 const & arg1 , T2 const & arg2 , T3 const & arg3
1156  );
1157 
1158  template< class D , class A1 , class A2 , class A3
1159  , class T0 , class T1 , class T2 >
1160  friend
1161  KOKKOS_INLINE_FUNCTION
1162  Kokkos::Experimental::Subview< View< D , A1 , A2 , A3 >
1163  , Kokkos::Experimental::Impl::ViewOffsetRange<T0>::is_range
1164  , Kokkos::Experimental::Impl::ViewOffsetRange<T1>::is_range
1165  , Kokkos::Experimental::Impl::ViewOffsetRange<T2>::is_range
1166  >
1167  subview( const View< D , A1 , A2 , A3 > & src
1168  , T0 const & arg0 , T1 const & arg1 , T2 const & arg2
1169  );
1170 
1171  template< class D , class A1 , class A2 , class A3
1172  , class T0 , class T1 >
1173  friend
1174  KOKKOS_INLINE_FUNCTION
1175  Kokkos::Experimental::Subview< View< D , A1 , A2 , A3 >
1176  , Kokkos::Experimental::Impl::ViewOffsetRange<T0>::is_range
1177  , Kokkos::Experimental::Impl::ViewOffsetRange<T1>::is_range
1178  >
1179  subview( const View< D , A1 , A2 , A3 > & src
1180  , T0 const & arg0 , T1 const & arg1
1181  );
1182 
1183  template< class D, class A1, class A2, class A3, class T0 >
1184  friend
1185  KOKKOS_INLINE_FUNCTION
1186  Kokkos::Experimental::Subview< View< D, A1, A2, A3 >
1187  , Kokkos::Experimental::Impl::ViewOffsetRange<T0>::is_range
1188  >
1189  subview( const View< D, A1, A2, A3 > & src , T0 const & arg0 );
1190 
1191 };
1192 
1193 template< class > struct is_view : public std::false_type {};
1194 
1195 template< class D, class A1, class A2, class A3 >
1196 struct is_view< View<D,A1,A2,A3> > : public std::true_type {};
1197 
1198 //----------------------------------------------------------------------------
1199 //----------------------------------------------------------------------------
1200 
1201 template< class D, class A1, class A2, class A3
1202  , class T0 , class T1 , class T2 , class T3
1203  , class T4 , class T5 , class T6 , class T7 >
1204 KOKKOS_INLINE_FUNCTION
1205 Kokkos::Experimental::Subview< View< D, A1, A2, A3 >
1206  , Kokkos::Experimental::Impl::ViewOffsetRange<T0>::is_range
1207  , Kokkos::Experimental::Impl::ViewOffsetRange<T1>::is_range
1208  , Kokkos::Experimental::Impl::ViewOffsetRange<T2>::is_range
1209  , Kokkos::Experimental::Impl::ViewOffsetRange<T3>::is_range
1210  , Kokkos::Experimental::Impl::ViewOffsetRange<T4>::is_range
1211  , Kokkos::Experimental::Impl::ViewOffsetRange<T5>::is_range
1212  , Kokkos::Experimental::Impl::ViewOffsetRange<T6>::is_range
1213  , Kokkos::Experimental::Impl::ViewOffsetRange<T7>::is_range
1214  >
1215 subview( const View< D, A1, A2, A3 > & src
1216  , T0 const & arg0 , T1 const & arg1 , T2 const & arg2 , T3 const & arg3
1217  , T4 const & arg4 , T5 const & arg5 , T6 const & arg6 , T7 const & arg7
1218  )
1219 {
1220  typedef View< D, A1, A2, A3 > SrcView ;
1221 
1222  typedef Kokkos::Experimental::Impl::SubviewMapping
1223  < typename SrcView::traits
1224  , Kokkos::Experimental::Impl::ViewOffsetRange<T0>::is_range
1225  , Kokkos::Experimental::Impl::ViewOffsetRange<T1>::is_range
1226  , Kokkos::Experimental::Impl::ViewOffsetRange<T2>::is_range
1227  , Kokkos::Experimental::Impl::ViewOffsetRange<T3>::is_range
1228  , Kokkos::Experimental::Impl::ViewOffsetRange<T4>::is_range
1229  , Kokkos::Experimental::Impl::ViewOffsetRange<T5>::is_range
1230  , Kokkos::Experimental::Impl::ViewOffsetRange<T6>::is_range
1231  , Kokkos::Experimental::Impl::ViewOffsetRange<T7>::is_range
1232  > Mapping ;
1233 
1234  typedef typename Mapping::type DstView ;
1235 
1236  static_assert( SrcView::Rank == 8 , "Subview of rank 8 View requires 8 arguments" );
1237 
1238  DstView dst( src.m_track );
1239 
1240  Mapping::assign( dst.m_map, src.m_map, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 );
1241 
1242  return dst ;
1243 }
1244 
1245 template< class D, class A1, class A2, class A3
1246  , class T0 , class T1 , class T2 , class T3
1247  , class T4 , class T5 , class T6 >
1248 KOKKOS_INLINE_FUNCTION
1249 Kokkos::Experimental::Subview< View< D, A1, A2, A3 >
1250  , Kokkos::Experimental::Impl::ViewOffsetRange<T0>::is_range
1251  , Kokkos::Experimental::Impl::ViewOffsetRange<T1>::is_range
1252  , Kokkos::Experimental::Impl::ViewOffsetRange<T2>::is_range
1253  , Kokkos::Experimental::Impl::ViewOffsetRange<T3>::is_range
1254  , Kokkos::Experimental::Impl::ViewOffsetRange<T4>::is_range
1255  , Kokkos::Experimental::Impl::ViewOffsetRange<T5>::is_range
1256  , Kokkos::Experimental::Impl::ViewOffsetRange<T6>::is_range
1257  >
1258 subview( const View< D, A1, A2, A3 > & src
1259  , T0 const & arg0 , T1 const & arg1 , T2 const & arg2 , T3 const & arg3
1260  , T4 const & arg4 , T5 const & arg5 , T6 const & arg6
1261  )
1262 {
1263  typedef View< D, A1, A2, A3 > SrcView ;
1264 
1265  typedef Kokkos::Experimental::Impl::SubviewMapping
1266  < typename SrcView::traits
1267  , Kokkos::Experimental::Impl::ViewOffsetRange<T0>::is_range
1268  , Kokkos::Experimental::Impl::ViewOffsetRange<T1>::is_range
1269  , Kokkos::Experimental::Impl::ViewOffsetRange<T2>::is_range
1270  , Kokkos::Experimental::Impl::ViewOffsetRange<T3>::is_range
1271  , Kokkos::Experimental::Impl::ViewOffsetRange<T4>::is_range
1272  , Kokkos::Experimental::Impl::ViewOffsetRange<T5>::is_range
1273  , Kokkos::Experimental::Impl::ViewOffsetRange<T6>::is_range
1274  > Mapping ;
1275 
1276  typedef typename Mapping::type DstView ;
1277 
1278  static_assert( SrcView::Rank == 7 , "Subview of rank 7 View requires 7 arguments" );
1279 
1280  DstView dst( src.m_track );
1281 
1282  Mapping::assign( dst.m_map, src.m_map, arg0, arg1, arg2, arg3, arg4, arg5, arg6, 0 );
1283 
1284  return dst ;
1285 }
1286 
1287 template< class D, class A1, class A2, class A3
1288  , class T0 , class T1 , class T2 , class T3
1289  , class T4 , class T5 >
1290 KOKKOS_INLINE_FUNCTION
1291 Kokkos::Experimental::Subview< View< D, A1, A2, A3 >
1292  , Kokkos::Experimental::Impl::ViewOffsetRange<T0>::is_range
1293  , Kokkos::Experimental::Impl::ViewOffsetRange<T1>::is_range
1294  , Kokkos::Experimental::Impl::ViewOffsetRange<T2>::is_range
1295  , Kokkos::Experimental::Impl::ViewOffsetRange<T3>::is_range
1296  , Kokkos::Experimental::Impl::ViewOffsetRange<T4>::is_range
1297  , Kokkos::Experimental::Impl::ViewOffsetRange<T5>::is_range
1298  >
1299 subview( const View< D, A1, A2, A3 > & src
1300  , T0 const & arg0 , T1 const & arg1 , T2 const & arg2 , T3 const & arg3
1301  , T4 const & arg4 , T5 const & arg5
1302  )
1303 {
1304  typedef View< D, A1, A2, A3 > SrcView ;
1305 
1306  typedef Kokkos::Experimental::Impl::SubviewMapping
1307  < typename SrcView::traits
1308  , Kokkos::Experimental::Impl::ViewOffsetRange<T0>::is_range
1309  , Kokkos::Experimental::Impl::ViewOffsetRange<T1>::is_range
1310  , Kokkos::Experimental::Impl::ViewOffsetRange<T2>::is_range
1311  , Kokkos::Experimental::Impl::ViewOffsetRange<T3>::is_range
1312  , Kokkos::Experimental::Impl::ViewOffsetRange<T4>::is_range
1313  , Kokkos::Experimental::Impl::ViewOffsetRange<T5>::is_range
1314  > Mapping ;
1315 
1316  typedef typename Mapping::type DstView ;
1317 
1318  static_assert( SrcView::Rank == 6 , "Subview of rank 6 View requires 6 arguments" );
1319 
1320  DstView dst( src.m_track );
1321 
1322  Mapping::assign( dst.m_map, src.m_map, arg0, arg1, arg2, arg3, arg4, arg5, 0, 0 );
1323 
1324  return dst ;
1325 }
1326 
1327 template< class D, class A1, class A2, class A3
1328  , class T0 , class T1 , class T2 , class T3
1329  , class T4 >
1330 KOKKOS_INLINE_FUNCTION
1331 Kokkos::Experimental::Subview< View< D, A1, A2, A3 >
1332  , Kokkos::Experimental::Impl::ViewOffsetRange<T0>::is_range
1333  , Kokkos::Experimental::Impl::ViewOffsetRange<T1>::is_range
1334  , Kokkos::Experimental::Impl::ViewOffsetRange<T2>::is_range
1335  , Kokkos::Experimental::Impl::ViewOffsetRange<T3>::is_range
1336  , Kokkos::Experimental::Impl::ViewOffsetRange<T4>::is_range
1337  >
1338 subview( const View< D, A1, A2, A3 > & src
1339  , T0 const & arg0 , T1 const & arg1 , T2 const & arg2 , T3 const & arg3
1340  , T4 const & arg4
1341  )
1342 {
1343  typedef View< D, A1, A2, A3 > SrcView ;
1344 
1345  typedef Kokkos::Experimental::Impl::SubviewMapping
1346  < typename SrcView::traits
1347  , Kokkos::Experimental::Impl::ViewOffsetRange<T0>::is_range
1348  , Kokkos::Experimental::Impl::ViewOffsetRange<T1>::is_range
1349  , Kokkos::Experimental::Impl::ViewOffsetRange<T2>::is_range
1350  , Kokkos::Experimental::Impl::ViewOffsetRange<T3>::is_range
1351  , Kokkos::Experimental::Impl::ViewOffsetRange<T4>::is_range
1352  > Mapping ;
1353 
1354  typedef typename Mapping::type DstView ;
1355 
1356  static_assert( SrcView::Rank == 5 , "Subview of rank 5 View requires 5 arguments" );
1357 
1358  DstView dst( src.m_track );
1359 
1360  Mapping::assign( dst.m_map, src.m_map, arg0, arg1, arg2, arg3, arg4, 0, 0, 0 );
1361 
1362  return dst ;
1363 }
1364 
1365 template< class D, class A1, class A2, class A3
1366  , class T0 , class T1 , class T2 , class T3 >
1367 KOKKOS_INLINE_FUNCTION
1368 Kokkos::Experimental::Subview< View< D, A1, A2, A3 >
1369  , Kokkos::Experimental::Impl::ViewOffsetRange<T0>::is_range
1370  , Kokkos::Experimental::Impl::ViewOffsetRange<T1>::is_range
1371  , Kokkos::Experimental::Impl::ViewOffsetRange<T2>::is_range
1372  , Kokkos::Experimental::Impl::ViewOffsetRange<T3>::is_range
1373  >
1374 subview( const View< D, A1, A2, A3 > & src
1375  , T0 const & arg0 , T1 const & arg1 , T2 const & arg2 , T3 const & arg3
1376  )
1377 {
1378  typedef View< D, A1, A2, A3 > SrcView ;
1379 
1380  typedef Kokkos::Experimental::Impl::SubviewMapping
1381  < typename SrcView::traits
1382  , Kokkos::Experimental::Impl::ViewOffsetRange<T0>::is_range
1383  , Kokkos::Experimental::Impl::ViewOffsetRange<T1>::is_range
1384  , Kokkos::Experimental::Impl::ViewOffsetRange<T2>::is_range
1385  , Kokkos::Experimental::Impl::ViewOffsetRange<T3>::is_range
1386  > Mapping ;
1387 
1388  typedef typename Mapping::type DstView ;
1389 
1390  static_assert( SrcView::Rank == 4 , "Subview of rank 4 View requires 4 arguments" );
1391 
1392  DstView dst( src.m_track );
1393 
1394  Mapping::assign( dst.m_map, src.m_map, arg0, arg1, arg2, arg3, 0, 0, 0, 0 );
1395 
1396  return dst ;
1397 }
1398 
1399 template< class D, class A1, class A2, class A3
1400  , class T0 , class T1 , class T2 >
1401 KOKKOS_INLINE_FUNCTION
1402 Kokkos::Experimental::Subview< View< D, A1, A2, A3 >
1403  , Kokkos::Experimental::Impl::ViewOffsetRange<T0>::is_range
1404  , Kokkos::Experimental::Impl::ViewOffsetRange<T1>::is_range
1405  , Kokkos::Experimental::Impl::ViewOffsetRange<T2>::is_range
1406  >
1407 subview( const View< D, A1, A2, A3 > & src
1408  , T0 const & arg0 , T1 const & arg1 , T2 const & arg2
1409  )
1410 {
1411  typedef View< D, A1, A2, A3 > SrcView ;
1412 
1413  typedef Kokkos::Experimental::Impl::SubviewMapping
1414  < typename SrcView::traits
1415  , Kokkos::Experimental::Impl::ViewOffsetRange<T0>::is_range
1416  , Kokkos::Experimental::Impl::ViewOffsetRange<T1>::is_range
1417  , Kokkos::Experimental::Impl::ViewOffsetRange<T2>::is_range
1418  > Mapping ;
1419 
1420  typedef typename Mapping::type DstView ;
1421 
1422  static_assert( SrcView::Rank == 3 , "Subview of rank 3 View requires 3 arguments" );
1423 
1424  DstView dst( src.m_track );
1425 
1426  Mapping::assign( dst.m_map, src.m_map, arg0, arg1, arg2, 0, 0, 0, 0, 0 );
1427 
1428  return dst ;
1429 }
1430 
1431 template< class D, class A1, class A2, class A3
1432  , class T0 , class T1 >
1433 KOKKOS_INLINE_FUNCTION
1434 Kokkos::Experimental::Subview< View< D, A1, A2, A3 >
1435  , Kokkos::Experimental::Impl::ViewOffsetRange<T0>::is_range
1436  , Kokkos::Experimental::Impl::ViewOffsetRange<T1>::is_range
1437  >
1438 subview( const View< D, A1, A2, A3 > & src
1439  , T0 const & arg0 , T1 const & arg1
1440  )
1441 {
1442  typedef View< D, A1, A2, A3 > SrcView ;
1443 
1444  typedef Kokkos::Experimental::Impl::SubviewMapping
1445  < typename SrcView::traits
1446  , Kokkos::Experimental::Impl::ViewOffsetRange<T0>::is_range
1447  , Kokkos::Experimental::Impl::ViewOffsetRange<T1>::is_range
1448  > Mapping ;
1449 
1450  typedef typename Mapping::type DstView ;
1451 
1452  static_assert( SrcView::Rank == 2 , "Subview of rank 2 View requires 2 arguments" );
1453 
1454  DstView dst( src.m_track );
1455 
1456  Mapping::assign( dst.m_map, src.m_map, arg0, arg1, 0, 0, 0, 0, 0, 0 );
1457 
1458  return dst ;
1459 }
1460 
1461 template< class D, class A1, class A2, class A3, class T0 >
1462 KOKKOS_INLINE_FUNCTION
1463 Kokkos::Experimental::Subview< View< D, A1, A2, A3 >
1464  , Kokkos::Experimental::Impl::ViewOffsetRange<T0>::is_range
1465  >
1466 subview( const View< D, A1, A2, A3 > & src , T0 const & arg0 )
1467 {
1468  typedef View< D, A1, A2, A3 > SrcView ;
1469 
1470  typedef Kokkos::Experimental::Impl::SubviewMapping
1471  < typename SrcView::traits
1472  , Kokkos::Experimental::Impl::ViewOffsetRange<T0>::is_range
1473  > Mapping ;
1474 
1475  typedef typename Mapping::type DstView ;
1476 
1477  static_assert( SrcView::Rank == 1 , "Subview of rank 1 View requires 1 arguments" );
1478 
1479  DstView dst( src.m_track );
1480 
1481  Mapping::assign( dst.m_map , src.m_map , arg0, 0, 0, 0, 0, 0, 0, 0 );
1482 
1483  return dst ;
1484 }
1485 
1486 } /* namespace Experimental */
1487 } /* namespace Kokkos */
1488 
1489 //----------------------------------------------------------------------------
1490 //----------------------------------------------------------------------------
1491 
1492 namespace Kokkos {
1493 namespace Experimental {
1494 
1495 template< class LT , class L1 , class L2 , class L3
1496  , class RT , class R1 , class R2 , class R3 >
1497 KOKKOS_INLINE_FUNCTION
1498 bool operator == ( const View<LT,L1,L2,L3> & lhs ,
1499  const View<RT,R1,R2,R3> & rhs )
1500 {
1501  // Same data, layout, dimensions
1502  typedef ViewTraits<LT,L1,L2,L3> lhs_traits ;
1503  typedef ViewTraits<RT,R1,R2,R3> rhs_traits ;
1504 
1505  return
1506  std::is_same< typename lhs_traits::const_value_type ,
1507  typename rhs_traits::const_value_type >::value &&
1508  std::is_same< typename lhs_traits::array_layout ,
1509  typename rhs_traits::array_layout >::value &&
1510  std::is_same< typename lhs_traits::memory_space ,
1511  typename rhs_traits::memory_space >::value &&
1512  lhs_traits::Rank == rhs_traits::Rank &&
1513  lhs.data() == rhs.data() &&
1514  lhs.span() == rhs.span() &&
1515  lhs.dimension_0() == rhs.dimension_0() &&
1516  lhs.dimension_1() == rhs.dimension_1() &&
1517  lhs.dimension_2() == rhs.dimension_2() &&
1518  lhs.dimension_3() == rhs.dimension_3() &&
1519  lhs.dimension_4() == rhs.dimension_4() &&
1520  lhs.dimension_5() == rhs.dimension_5() &&
1521  lhs.dimension_6() == rhs.dimension_6() &&
1522  lhs.dimension_7() == rhs.dimension_7();
1523 }
1524 
1525 template< class LT , class L1 , class L2 , class L3
1526  , class RT , class R1 , class R2 , class R3 >
1527 KOKKOS_INLINE_FUNCTION
1528 bool operator != ( const View<LT,L1,L2,L3> & lhs ,
1529  const View<RT,R1,R2,R3> & rhs )
1530 {
1531  return ! ( operator==(lhs,rhs) );
1532 }
1533 
1534 } /* namespace Experimental */
1535 } /* namespace Kokkos */
1536 
1537 //----------------------------------------------------------------------------
1538 //----------------------------------------------------------------------------
1539 
1540 namespace Kokkos {
1541 namespace Experimental {
1542 namespace Impl {
1543 
1544 template< class OutputView , typename Enable = void >
1545 struct ViewFill {
1546 
1547  typedef typename OutputView::const_value_type const_value_type ;
1548 
1549  const OutputView output ;
1550  const_value_type input ;
1551 
1552  KOKKOS_INLINE_FUNCTION
1553  void operator()( const size_t i0 ) const
1554  {
1555  const size_t n1 = output.dimension_1();
1556  const size_t n2 = output.dimension_2();
1557  const size_t n3 = output.dimension_3();
1558  const size_t n4 = output.dimension_4();
1559  const size_t n5 = output.dimension_5();
1560  const size_t n6 = output.dimension_6();
1561  const size_t n7 = output.dimension_7();
1562 
1563  for ( size_t i1 = 0 ; i1 < n1 ; ++i1 ) {
1564  for ( size_t i2 = 0 ; i2 < n2 ; ++i2 ) {
1565  for ( size_t i3 = 0 ; i3 < n3 ; ++i3 ) {
1566  for ( size_t i4 = 0 ; i4 < n4 ; ++i4 ) {
1567  for ( size_t i5 = 0 ; i5 < n5 ; ++i5 ) {
1568  for ( size_t i6 = 0 ; i6 < n6 ; ++i6 ) {
1569  for ( size_t i7 = 0 ; i7 < n7 ; ++i7 ) {
1570  output(i0,i1,i2,i3,i4,i5,i6,i7) = input ;
1571  }}}}}}}
1572  }
1573 
1574  ViewFill( const OutputView & arg_out , const_value_type & arg_in )
1575  : output( arg_out ), input( arg_in )
1576  {
1577  typedef typename OutputView::execution_space execution_space ;
1579 
1580  (void) Kokkos::Impl::ParallelFor< ViewFill , Policy >( *this , Policy( 0 , output.dimension_0() ) );
1581 
1582  execution_space::fence();
1583  }
1584 };
1585 
1586 template< class OutputView >
1587 struct ViewFill< OutputView , typename std::enable_if< OutputView::Rank == 0 >::type > {
1588  ViewFill( const OutputView & dst , const typename OutputView::const_value_type & src )
1589  {
1590  Kokkos::Impl::DeepCopy< typename OutputView::memory_space , Kokkos::HostSpace >
1591  ( dst.data() , & src , sizeof(typename OutputView::const_value_type) );
1592  }
1593 };
1594 
1595 template< class OutputView , class InputView >
1596 struct ViewRemap {
1597 
1598  const OutputView output ;
1599  const InputView input ;
1600  const size_t n0 ;
1601  const size_t n1 ;
1602  const size_t n2 ;
1603  const size_t n3 ;
1604  const size_t n4 ;
1605  const size_t n5 ;
1606  const size_t n6 ;
1607  const size_t n7 ;
1608 
1609  ViewRemap( const OutputView & arg_out , const InputView & arg_in )
1610  : output( arg_out ), input( arg_in )
1611  , n0( std::min( (size_t)arg_out.dimension_0() , (size_t)arg_in.dimension_0() ) )
1612  , n1( std::min( (size_t)arg_out.dimension_1() , (size_t)arg_in.dimension_1() ) )
1613  , n2( std::min( (size_t)arg_out.dimension_2() , (size_t)arg_in.dimension_2() ) )
1614  , n3( std::min( (size_t)arg_out.dimension_3() , (size_t)arg_in.dimension_3() ) )
1615  , n4( std::min( (size_t)arg_out.dimension_4() , (size_t)arg_in.dimension_4() ) )
1616  , n5( std::min( (size_t)arg_out.dimension_5() , (size_t)arg_in.dimension_5() ) )
1617  , n6( std::min( (size_t)arg_out.dimension_6() , (size_t)arg_in.dimension_6() ) )
1618  , n7( std::min( (size_t)arg_out.dimension_7() , (size_t)arg_in.dimension_7() ) )
1619  {
1620  typedef typename OutputView::execution_space execution_space ;
1622  (void) Kokkos::Impl::ParallelFor< ViewRemap , Policy >( *this , Policy( 0 , n0 ) );
1623  }
1624 
1625  KOKKOS_INLINE_FUNCTION
1626  void operator()( const size_t i0 ) const
1627  {
1628  for ( size_t i1 = 0 ; i1 < n1 ; ++i1 ) {
1629  for ( size_t i2 = 0 ; i2 < n2 ; ++i2 ) {
1630  for ( size_t i3 = 0 ; i3 < n3 ; ++i3 ) {
1631  for ( size_t i4 = 0 ; i4 < n4 ; ++i4 ) {
1632  for ( size_t i5 = 0 ; i5 < n5 ; ++i5 ) {
1633  for ( size_t i6 = 0 ; i6 < n6 ; ++i6 ) {
1634  for ( size_t i7 = 0 ; i7 < n7 ; ++i7 ) {
1635  output(i0,i1,i2,i3,i4,i5,i6,i7) = input(i0,i1,i2,i3,i4,i5,i6,i7);
1636  }}}}}}}
1637  }
1638 };
1639 
1640 } /* namespace Impl */
1641 } /* namespace Experimental */
1642 } /* namespace Kokkos */
1643 
1644 //----------------------------------------------------------------------------
1645 //----------------------------------------------------------------------------
1646 
1647 namespace Kokkos {
1648 namespace Experimental {
1649 
1651 template< class DT , class D1 , class D2 , class D3 >
1652 inline
1653 void deep_copy( const View<DT,D1,D2,D3> & dst
1654  , typename ViewTraits<DT,D1,D2,D3>::const_value_type & value )
1655 {
1656  static_assert( std::is_same< typename ViewTraits<DT,D1,D2,D3>::non_const_value_type ,
1657  typename ViewTraits<DT,D1,D2,D3>::value_type >::value
1658  , "ERROR: Incompatible deep_copy( View , value )" );
1659 
1660  Kokkos::Experimental::Impl::ViewFill< View<DT,D1,D2,D3> >( dst , value );
1661 }
1662 
1664 template< class ST , class S1 , class S2 , class S3 >
1665 inline
1666 void deep_copy( ST & dst , const View<ST,S1,S2,S3> & src )
1667 {
1668  static_assert( ViewTraits<ST,S1,S2,S3>::rank == 0
1669  , "ERROR: Non-rank-zero view in deep_copy( value , View )" );
1670 
1671  typedef ViewTraits<ST,S1,S2,S3> src_traits ;
1672  typedef typename src_traits::memory_space src_memory_space ;
1673  Kokkos::Impl::DeepCopy< HostSpace , src_memory_space >( & dst , src.data() , sizeof(ST) );
1674 }
1675 
1676 //----------------------------------------------------------------------------
1678 template< class DT , class D1 , class D2 , class D3
1679  , class ST , class S1 , class S2 , class S3 >
1680 inline
1681 void deep_copy( const View<DT,D1,D2,D3> & dst ,
1682  const View<ST,S1,S2,S3> & src ,
1683  typename std::enable_if<(
1684  // Rank zero:
1685  ( unsigned(ViewTraits<DT,D1,D2,D3>::rank) == unsigned(0) ) &&
1686  ( unsigned(ViewTraits<ST,S1,S2,S3>::rank) == unsigned(0) ) &&
1687  // Same type and destination is not constant:
1688  std::is_same< typename ViewTraits<DT,D1,D2,D3>::value_type ,
1689  typename ViewTraits<ST,S1,S2,S3>::non_const_value_type >::value
1690  )>::type * = 0 )
1691 {
1692  typedef View<DT,D1,D2,D3> dst_type ;
1693  typedef View<ST,S1,S2,S3> src_type ;
1694 
1695  typedef typename dst_type::value_type value_type ;
1696  typedef typename dst_type::memory_space dst_memory_space ;
1697  typedef typename src_type::memory_space src_memory_space ;
1698 
1699  if ( dst.data() != src.data() ) {
1700  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , sizeof(value_type) );
1701  }
1702 }
1703 
1704 //----------------------------------------------------------------------------
1708 template< class DT , class D1 , class D2 , class D3 ,
1709  class ST , class S1 , class S2 , class S3 >
1710 inline
1711 void deep_copy( const View<DT,D1,D2,D3> & dst ,
1712  const View<ST,S1,S2,S3> & src ,
1713  typename std::enable_if<(
1714  // destination is non-const.
1715  std::is_same< typename ViewTraits<DT,D1,D2,D3>::value_type ,
1716  typename ViewTraits<DT,D1,D2,D3>::non_const_value_type >::value
1717  &&
1718  // Same non-zero rank:
1719  ( unsigned(ViewTraits<DT,D1,D2,D3>::rank) != 0 )
1720  &&
1721  ( unsigned(ViewTraits<DT,D1,D2,D3>::rank) ==
1722  unsigned(ViewTraits<ST,S1,S2,S3>::rank) )
1723  &&
1724  // Not specialized, default ViewMapping
1725  std::is_same< typename ViewTraits<DT,D1,D2,D3>::specialize , void >::value
1726  &&
1727  std::is_same< typename ViewTraits<ST,S1,S2,S3>::specialize , void >::value
1728  )>::type * = 0 )
1729 {
1730  typedef View<DT,D1,D2,D3> dst_type ;
1731  typedef View<ST,S1,S2,S3> src_type ;
1732 
1733  typedef typename dst_type::execution_space dst_execution_space ;
1734  typedef typename dst_type::memory_space dst_memory_space ;
1735  typedef typename src_type::memory_space src_memory_space ;
1736 
1737  enum { DstExecCanAccessSrc =
1738  Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< typename dst_execution_space::memory_space , src_memory_space >::value };
1739 
1740  if ( (void *) dst.data() != (void*) src.data() ) {
1741 
1742  // Concern: If overlapping views then a parallel copy will be erroneous.
1743  // ...
1744 
1745  // If same type, equal layout, equal dimensions, equal span, and contiguous memory then can byte-wise copy
1746 
1747  if ( std::is_same< typename ViewTraits<DT,D1,D2,D3>::value_type ,
1748  typename ViewTraits<ST,S1,S2,S3>::non_const_value_type >::value &&
1749  std::is_same< typename ViewTraits<DT,D1,D2,D3>::array_layout ,
1750  typename ViewTraits<ST,S1,S2,S3>::array_layout >::value &&
1751  dst.span_is_contiguous() &&
1752  src.span_is_contiguous() &&
1753  dst.span() == src.span() &&
1754  dst.dimension_0() == src.dimension_0() &&
1755  dst.dimension_1() == src.dimension_1() &&
1756  dst.dimension_2() == src.dimension_2() &&
1757  dst.dimension_3() == src.dimension_3() &&
1758  dst.dimension_4() == src.dimension_4() &&
1759  dst.dimension_5() == src.dimension_5() &&
1760  dst.dimension_6() == src.dimension_6() &&
1761  dst.dimension_7() == src.dimension_7() ) {
1762 
1763  const size_t nbytes = sizeof(typename dst_type::value_type) * dst.span();
1764 
1765  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1766  }
1767  else if ( DstExecCanAccessSrc ) {
1768  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
1769  Kokkos::Experimental::Impl::ViewRemap< dst_type , src_type >( dst , src );
1770  }
1771  else {
1772  Kokkos::Impl::throw_runtime_exception("deep_copy given views that would require a temporary allocation");
1773  }
1774  }
1775 }
1776 
1777 } /* namespace Experimental */
1778 } /* namespace Kokkos */
1779 
1780 //----------------------------------------------------------------------------
1781 //----------------------------------------------------------------------------
1782 
1783 namespace Kokkos {
1784 namespace Experimental {
1785 
1786 template< class T , class A1, class A2, class A3 >
1787 inline
1789 create_mirror( const Kokkos::Experimental::View<T,A1,A2,A3> & src
1790  , typename std::enable_if<
1791  ! std::is_same< typename Kokkos::Experimental::ViewTraits<T,A1,A2,A3>::array_layout
1792  , Kokkos::LayoutStride >::value
1793  >::type * = 0
1794  )
1795 {
1796  typedef View<T,A1,A2,A3> src_type ;
1797  typedef typename src_type::HostMirror dst_type ;
1798 
1799  return dst_type( std::string( src.label() ).append("_mirror")
1800  , src.dimension_0()
1801  , src.dimension_1()
1802  , src.dimension_2()
1803  , src.dimension_3()
1804  , src.dimension_4()
1805  , src.dimension_5()
1806  , src.dimension_6()
1807  , src.dimension_7() );
1808 }
1809 
1810 template< class T , class A1, class A2, class A3 >
1811 inline
1813 create_mirror( const Kokkos::Experimental::View<T,A1,A2,A3> & src
1814  , typename std::enable_if<
1815  std::is_same< typename Kokkos::Experimental::ViewTraits<T,A1,A2,A3>::array_layout
1816  , Kokkos::LayoutStride >::value
1817  >::type * = 0
1818  )
1819 {
1820  typedef View<T,A1,A2,A3> src_type ;
1821  typedef typename src_type::HostMirror dst_type ;
1822 
1823  Kokkos::LayoutStride layout ;
1824 
1825  layout.dimension[0] = src.dimension_0();
1826  layout.dimension[1] = src.dimension_1();
1827  layout.dimension[2] = src.dimension_2();
1828  layout.dimension[3] = src.dimension_3();
1829  layout.dimension[4] = src.dimension_4();
1830  layout.dimension[5] = src.dimension_5();
1831  layout.dimension[6] = src.dimension_6();
1832  layout.dimension[7] = src.dimension_7();
1833 
1834  layout.stride[0] = src.stride_0();
1835  layout.stride[1] = src.stride_1();
1836  layout.stride[2] = src.stride_2();
1837  layout.stride[3] = src.stride_3();
1838  layout.stride[4] = src.stride_4();
1839  layout.stride[5] = src.stride_5();
1840  layout.stride[6] = src.stride_6();
1841  layout.stride[7] = src.stride_7();
1842 
1843  return dst_type( std::string( src.label() ).append("_mirror") , layout );
1844 }
1845 
1846 template< class T , class A1 , class A2 , class A3 >
1847 inline
1849 create_mirror_view( const Kokkos::Experimental::View<T,A1,A2,A3> & src
1850  , typename std::enable_if<(
1851  std::is_same< typename Kokkos::Experimental::View<T,A1,A2,A3>::memory_space
1852  , typename Kokkos::Experimental::View<T,A1,A2,A3>::HostMirror::memory_space
1853  >::value
1854  &&
1855  std::is_same< typename Kokkos::Experimental::View<T,A1,A2,A3>::data_type
1856  , typename Kokkos::Experimental::View<T,A1,A2,A3>::HostMirror::data_type
1857  >::value
1858  )>::type * = 0
1859  )
1860 {
1861  return src ;
1862 }
1863 
1864 template< class T , class A1 , class A2 , class A3 >
1865 inline
1867 create_mirror_view( const Kokkos::Experimental::View<T,A1,A2,A3> & src
1868  , typename std::enable_if< ! (
1869  std::is_same< typename Kokkos::Experimental::View<T,A1,A2,A3>::memory_space
1870  , typename Kokkos::Experimental::View<T,A1,A2,A3>::HostMirror::memory_space
1871  >::value
1872  &&
1873  std::is_same< typename Kokkos::Experimental::View<T,A1,A2,A3>::data_type
1874  , typename Kokkos::Experimental::View<T,A1,A2,A3>::HostMirror::data_type
1875  >::value
1876  )>::type * = 0
1877  )
1878 {
1879  return Kokkos::Experimental::create_mirror( src );
1880 }
1881 
1882 } /* namespace Experimental */
1883 } /* namespace Kokkos */
1884 
1885 //----------------------------------------------------------------------------
1886 //----------------------------------------------------------------------------
1887 
1888 namespace Kokkos {
1889 namespace Experimental {
1890 
1892 template< class T , class A1 , class A2 , class A3 >
1893 inline
1895  const size_t n0 = 0 ,
1896  const size_t n1 = 0 ,
1897  const size_t n2 = 0 ,
1898  const size_t n3 = 0 ,
1899  const size_t n4 = 0 ,
1900  const size_t n5 = 0 ,
1901  const size_t n6 = 0 ,
1902  const size_t n7 = 0 )
1903 {
1904  typedef Kokkos::Experimental::View<T,A1,A2,A3> view_type ;
1905 
1906  static_assert( Kokkos::Experimental::ViewTraits<T,A1,A2,A3>::is_managed , "Can only resize managed views" );
1907 
1908  view_type v_resized( v.label(), n0, n1, n2, n3, n4, n5, n6, n7 );
1909 
1910  Kokkos::Experimental::Impl::ViewRemap< view_type , view_type >( v_resized , v );
1911 
1912  v = v_resized ;
1913 }
1914 
1916 template< class T , class A1 , class A2 , class A3 >
1917 inline
1919  const size_t n0 = 0 ,
1920  const size_t n1 = 0 ,
1921  const size_t n2 = 0 ,
1922  const size_t n3 = 0 ,
1923  const size_t n4 = 0 ,
1924  const size_t n5 = 0 ,
1925  const size_t n6 = 0 ,
1926  const size_t n7 = 0 )
1927 {
1928  typedef Kokkos::Experimental::View<T,A1,A2,A3> view_type ;
1929 
1930  static_assert( Kokkos::Experimental::ViewTraits<T,A1,A2,A3>::is_managed , "Can only realloc managed views" );
1931 
1932  const std::string label = v.label();
1933 
1934  v = view_type(); // Deallocate first, if the only view to allocation
1935  v = view_type( label, n0, n1, n2, n3, n4, n5, n6, n7 );
1936 }
1937 
1938 } /* namespace Experimental */
1939 } /* namespace Kokkos */
1940 
1941 //----------------------------------------------------------------------------
1942 //----------------------------------------------------------------------------
1943 
1944 #if defined( KOKKOS_USING_EXPERIMENTAL_VIEW )
1945 
1946 namespace Kokkos {
1947 
1948 template< class D , class A1 = void , class A2 = void , class A3 = void >
1950 
1951 template< class D , class A1 = void , class A2 = void , class A3 = void , class S = void >
1953 
1954 using Kokkos::Experimental::deep_copy ;
1955 using Kokkos::Experimental::create_mirror ;
1956 using Kokkos::Experimental::create_mirror_view ;
1957 using Kokkos::Experimental::subview ;
1958 using Kokkos::Experimental::resize ;
1959 using Kokkos::Experimental::realloc ;
1960 
1961 namespace Impl {
1962 
1963 using Kokkos::Experimental::is_view ;
1964 
1965 class ViewDefault {};
1966 
1967 template< class SrcViewType
1968  , class Arg0Type
1969  , class Arg1Type
1970  , class Arg2Type
1971  , class Arg3Type
1972  , class Arg4Type
1973  , class Arg5Type
1974  , class Arg6Type
1975  , class Arg7Type
1976  >
1977 struct ViewSubview /* { typedef ... type ; } */ ;
1978 
1979 }
1980 
1981 } /* namespace Kokkos */
1982 
1983 #include <impl/Kokkos_Atomic_View.hpp>
1984 
1985 #endif /* #if defined( KOKKOS_USING_EXPERIMENTAL_VIEW ) */
1986 
1987 //----------------------------------------------------------------------------
1988 //----------------------------------------------------------------------------
1989 
1990 #endif
1991 
View< typename traits::const_data_type, typename traits::array_layout, typename traits::device_type, typename traits::memory_traits > const_type
Compatible view of const data type.
Tag denoting that a subview should capture all of a dimension.
void deep_copy(const View< DT, DL, DD, DM, DS > &dst, typename Impl::enable_if<(Impl::is_same< typename ViewTraits< DT, DL, DD, DM >::non_const_value_type, typename ViewTraits< DT, DL, DD, DM >::value_type >::value), typename ViewTraits< DT, DL, DD, DM >::const_value_type >::type &value)
Deep copy a value into a view.
View< typename traits::non_const_data_type, typename traits::array_layout, typename traits::host_mirror_space, void > HostMirror
Compatible HostMirror view.
KOKKOS_INLINE_FUNCTION bool operator!=(const complex< RealType > &x, const complex< RealType > &y)
Inequality operator for two complex numbers.
View< typename traits::non_const_data_type, typename traits::array_layout, typename traits::device_type, typename traits::memory_traits > non_const_type
Compatible view of non-const data type.
View< typename traits::array_scalar_type, typename traits::array_layout, typename traits::device_type, typename traits::memory_traits > array_type
Compatible view of array of scalar types.
Memory layout tag indicated arbitrarily strided multi-index mapping into contiguous memory...
Traits class for accessing attributes of a View.
Memory space for main process and CPU execution spaces.
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.
Execution policy for work over a range of an integral type.
void resize(View< T, L, D, M, S > &v, const typename Impl::enable_if< ViewTraits< T, L, D, M >::is_managed, size_t >::type n0, 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.
void realloc(View< T, L, D, M, S > &v, const typename Impl::enable_if< ViewTraits< T, L, D, M >::is_managed, size_t >::type n0, 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)
Reallocate a view without copying old data to new data.
View to an array of data.