Kokkos Core Kernels Package  Version of the Day
Kokkos_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_VIEW_HPP
45 #define KOKKOS_VIEW_HPP
46 
47 #include <type_traits>
48 #include <string>
49 #include <Kokkos_Core_fwd.hpp>
50 #include <Kokkos_HostSpace.hpp>
51 #include <Kokkos_MemoryTraits.hpp>
52 
53 #if ! defined( KOKKOS_USING_EXPERIMENTAL_VIEW )
54 
55 #include <impl/Kokkos_StaticAssert.hpp>
56 #include <impl/Kokkos_Traits.hpp>
57 #include <impl/Kokkos_Shape.hpp>
58 #include <impl/Kokkos_AnalyzeShape.hpp>
59 #include <impl/Kokkos_Tags.hpp>
60 
61 // Must define before includng <impl/Kokkos_ViewOffset.hpp>
62 namespace Kokkos { struct ALL ; }
63 
64 #include <impl/Kokkos_ViewOffset.hpp>
65 #include <impl/Kokkos_ViewSupport.hpp>
66 
67 //----------------------------------------------------------------------------
68 //----------------------------------------------------------------------------
69 
70 namespace Kokkos {
71 namespace Impl {
72 
74 template< class ValueType ,
75  class ArraySpecialize ,
76  class ArrayLayout ,
77  class MemorySpace ,
78  class MemoryTraits >
80 
84 template< class SrcViewType
85  , class Arg0Type
86  , class Arg1Type
87  , class Arg2Type
88  , class Arg3Type
89  , class Arg4Type
90  , class Arg5Type
91  , class Arg6Type
92  , class Arg7Type
93  >
94 struct ViewSubview /* { typedef ... type ; } */ ;
95 
96 template< class DstViewSpecialize ,
97  class SrcViewSpecialize = void ,
98  class Enable = void >
99 struct ViewAssignment ;
100 
101 template< class DstMemorySpace , class SrcMemorySpace , class ExecutionSpace>
102 struct DeepCopy ;
103 
104 } /* namespace Impl */
105 } // namespace Kokkos
106 
107 //----------------------------------------------------------------------------
108 //----------------------------------------------------------------------------
109 
110 namespace Kokkos {
111 
130 template< class DataType ,
131  class Arg1 = void ,
132  class Arg2 = void ,
133  class Arg3 = void >
134 class ViewTraits {
135 private:
136 
137  // Layout, Space, and MemoryTraits are optional
138  // but need to appear in that order. That means Layout
139  // can only be Arg1, Space can be Arg1 or Arg2, and
140  // MemoryTraits can be Arg1, Arg2 or Arg3
141 
142  enum { Arg1IsLayout = Impl::is_array_layout<Arg1>::value };
143 
144  enum { Arg1IsSpace = Impl::is_space<Arg1>::value };
145  enum { Arg2IsSpace = Impl::is_space<Arg2>::value };
146 
147  enum { Arg1IsMemoryTraits = Impl::is_memory_traits<Arg1>::value };
148  enum { Arg2IsMemoryTraits = Impl::is_memory_traits<Arg2>::value };
149  enum { Arg3IsMemoryTraits = Impl::is_memory_traits<Arg3>::value };
150 
151  enum { Arg1IsVoid = Impl::is_same< Arg1 , void >::value };
152  enum { Arg2IsVoid = Impl::is_same< Arg2 , void >::value };
153  enum { Arg3IsVoid = Impl::is_same< Arg3 , void >::value };
154 
155  // Arg1 is Layout, Space, MemoryTraits, or void
156  typedef typename
157  Impl::StaticAssert<
158  ( 1 == Arg1IsLayout + Arg1IsSpace + Arg1IsMemoryTraits + Arg1IsVoid )
159  , Arg1 >::type Arg1Verified ;
160 
161  // If Arg1 is Layout then Arg2 is Space, MemoryTraits, or void
162  // If Arg1 is Space then Arg2 is MemoryTraits or void
163  // If Arg1 is MemoryTraits then Arg2 is void
164  // If Arg1 is Void then Arg2 is void
165  typedef typename
166  Impl::StaticAssert<
167  ( Arg1IsLayout && ( 1 == Arg2IsSpace + Arg2IsMemoryTraits + Arg2IsVoid ) ) ||
168  ( Arg1IsSpace && ( 0 == Arg2IsSpace ) && ( 1 == Arg2IsMemoryTraits + Arg2IsVoid ) ) ||
169  ( Arg1IsMemoryTraits && Arg2IsVoid ) ||
170  ( Arg1IsVoid && Arg2IsVoid )
171  , Arg2 >::type Arg2Verified ;
172 
173  // Arg3 is MemoryTraits or void and at most one argument is MemoryTraits
174  typedef typename
175  Impl::StaticAssert<
176  ( 1 == Arg3IsMemoryTraits + Arg3IsVoid ) &&
177  ( Arg1IsMemoryTraits + Arg2IsMemoryTraits + Arg3IsMemoryTraits <= 1 )
178  , Arg3 >::type Arg3Verified ;
179 
180  // Arg1 or Arg2 may have execution and memory spaces
181  typedef typename Impl::if_c<( Arg1IsSpace ), Arg1Verified ,
182  typename Impl::if_c<( Arg2IsSpace ), Arg2Verified ,
183  Kokkos::DefaultExecutionSpace
184  >::type >::type::execution_space ExecutionSpace ;
185 
186  typedef typename Impl::if_c<( Arg1IsSpace ), Arg1Verified ,
187  typename Impl::if_c<( Arg2IsSpace ), Arg2Verified ,
188  Kokkos::DefaultExecutionSpace
189  >::type >::type::memory_space MemorySpace ;
190 
191  typedef typename Impl::is_space<
192  typename Impl::if_c<( Arg1IsSpace ), Arg1Verified ,
193  typename Impl::if_c<( Arg2IsSpace ), Arg2Verified ,
194  Kokkos::DefaultExecutionSpace
195  >::type >::type >::host_mirror_space HostMirrorSpace ;
196 
197  // Arg1 may be array layout
198  typedef typename Impl::if_c< Arg1IsLayout , Arg1Verified ,
199  typename ExecutionSpace::array_layout
200  >::type ArrayLayout ;
201 
202  // Arg1, Arg2, or Arg3 may be memory traits
203  typedef typename Impl::if_c< Arg1IsMemoryTraits , Arg1Verified ,
204  typename Impl::if_c< Arg2IsMemoryTraits , Arg2Verified ,
205  typename Impl::if_c< Arg3IsMemoryTraits , Arg3Verified ,
206  MemoryManaged
207  >::type >::type >::type MemoryTraits ;
208 
209  typedef Impl::AnalyzeShape<DataType> analysis ;
210 
211 public:
212 
213  //------------------------------------
214  // Data type traits:
215 
216  typedef DataType data_type ;
217  typedef typename analysis::const_type const_data_type ;
218  typedef typename analysis::non_const_type non_const_data_type ;
219 
220  //------------------------------------
221  // Array of intrinsic scalar type traits:
222 
223  typedef typename analysis::array_intrinsic_type array_intrinsic_type ;
224  typedef typename analysis::const_array_intrinsic_type const_array_intrinsic_type ;
225  typedef typename analysis::non_const_array_intrinsic_type non_const_array_intrinsic_type ;
226 
227  //------------------------------------
228  // Value type traits:
229 
230  typedef typename analysis::value_type value_type ;
231  typedef typename analysis::const_value_type const_value_type ;
232  typedef typename analysis::non_const_value_type non_const_value_type ;
233 
234  //------------------------------------
235  // Layout and shape traits:
236 
237  typedef ArrayLayout array_layout ;
238  typedef typename analysis::shape shape_type ;
239 
240  enum { rank = shape_type::rank };
241  enum { rank_dynamic = shape_type::rank_dynamic };
242 
243  //------------------------------------
244  // Execution space, memory space, memory access traits, and host mirror space.
245 
246  typedef ExecutionSpace execution_space ;
247  typedef MemorySpace memory_space ;
249  typedef MemoryTraits memory_traits ;
250  typedef HostMirrorSpace host_mirror_space ;
251 
252  typedef typename memory_space::size_type size_type ;
253 
254  enum { is_hostspace = Impl::is_same< memory_space , HostSpace >::value };
255  enum { is_managed = memory_traits::Unmanaged == 0 };
256  enum { is_random_access = memory_traits::RandomAccess == 1 };
257 
258  //------------------------------------
259 
260 
261  //------------------------------------
262  // Specialization tag:
263 
264  typedef typename
265  Impl::ViewSpecialize< value_type
266  , typename analysis::specialize
267  , array_layout
268  , memory_space
269  , memory_traits
270  >::type specialize ;
271 };
272 
273 } /* namespace Kokkos */
274 
275 //----------------------------------------------------------------------------
276 //----------------------------------------------------------------------------
277 
278 namespace Kokkos {
279 namespace Impl {
280 
281 class ViewDefault {};
282 
285 template< class ValueType , class MemorySpace , class MemoryTraits >
286 struct ViewSpecialize< ValueType , void , LayoutLeft , MemorySpace , MemoryTraits >
287 { typedef ViewDefault type ; };
288 
289 template< class ValueType , class MemorySpace , class MemoryTraits >
290 struct ViewSpecialize< ValueType , void , LayoutRight , MemorySpace , MemoryTraits >
291 { typedef ViewDefault type ; };
292 
293 template< class ValueType , class MemorySpace , class MemoryTraits >
294 struct ViewSpecialize< ValueType , void , LayoutStride , MemorySpace , MemoryTraits >
295 { typedef ViewDefault type ; };
296 
297 } /* namespace Impl */
298 } /* namespace Kokkos */
299 
300 //----------------------------------------------------------------------------
301 //----------------------------------------------------------------------------
302 
303 namespace Kokkos {
304 namespace Impl {
305 
307 namespace ViewError {
308 
309 struct allocation_constructor_requires_managed {};
310 struct allocation_constructor_requires_nonconst {};
311 struct user_pointer_constructor_requires_unmanaged {};
312 struct device_shmem_constructor_requires_unmanaged {};
313 
314 struct scalar_operator_called_from_non_scalar_view {};
315 
316 } /* namespace ViewError */
317 
318 //----------------------------------------------------------------------------
324 template< class ReturnType , class Traits , class Layout , unsigned Rank ,
325  typename iType0 = int , typename iType1 = int ,
326  typename iType2 = int , typename iType3 = int ,
327  typename iType4 = int , typename iType5 = int ,
328  typename iType6 = int , typename iType7 = int ,
329  class Enable = void >
331 
332 template< class ReturnType , class Traits , class Layout , unsigned Rank ,
333  typename iType0 , typename iType1 ,
334  typename iType2 , typename iType3 ,
335  typename iType4 , typename iType5 ,
336  typename iType6 , typename iType7 >
337 struct ViewEnableArrayOper<
338  ReturnType , Traits , Layout , Rank ,
339  iType0 , iType1 , iType2 , iType3 ,
340  iType4 , iType5 , iType6 , iType7 ,
341  typename enable_if<
342  iType0(0) == 0 && iType1(0) == 0 && iType2(0) == 0 && iType3(0) == 0 &&
343  iType4(0) == 0 && iType5(0) == 0 && iType6(0) == 0 && iType7(0) == 0 &&
344  is_same< typename Traits::array_layout , Layout >::value &&
345  ( unsigned(Traits::rank) == Rank )
346  >::type >
347 {
348  typedef ReturnType type ;
349 };
350 
351 } /* namespace Impl */
352 } /* namespace Kokkos */
353 
354 //----------------------------------------------------------------------------
355 //----------------------------------------------------------------------------
356 
357 namespace Kokkos {
358 
439 template< class DataType ,
440  class Arg1Type = void , /* ArrayLayout, SpaceType, or MemoryTraits */
441  class Arg2Type = void , /* SpaceType or MemoryTraits */
442  class Arg3Type = void , /* MemoryTraits */
443  class Specialize =
445 class View ;
446 
447 namespace Impl {
448 
449 template< class C >
450 struct is_view : public bool_< false > {};
451 
452 template< class D , class A1 , class A2 , class A3 , class S >
453 struct is_view< View< D , A1 , A2 , A3 , S > > : public bool_< true > {};
454 
455 }
456 
457 //----------------------------------------------------------------------------
458 
459 template< class DataType ,
460  class Arg1Type ,
461  class Arg2Type ,
462  class Arg3Type >
463 class View< DataType , Arg1Type , Arg2Type , Arg3Type , Impl::ViewDefault >
464  : public ViewTraits< DataType , Arg1Type , Arg2Type, Arg3Type >
465 {
466 public:
467 
469 
470 private:
471 
472  // Assignment of compatible views requirement:
473  template< class , class , class , class , class > friend class View ;
474 
475  // Assignment of compatible subview requirement:
476  template< class , class , class > friend struct Impl::ViewAssignment ;
477 
478  // Dimensions, cardinality, capacity, and offset computation for
479  // multidimensional array view of contiguous memory.
480  // Inherits from Impl::Shape
481  typedef Impl::ViewOffset< typename traits::shape_type
482  , typename traits::array_layout
483  > offset_map_type ;
484 
485  // Intermediary class for data management and access
486  typedef Impl::ViewDataManagement< traits > view_data_management ;
487 
488  //----------------------------------------
489  // Data members:
490 
491  typename view_data_management::handle_type m_ptr_on_device ;
492  offset_map_type m_offset_map ;
493  view_data_management m_management ;
494  Impl::AllocationTracker m_tracker ;
495 
496  //----------------------------------------
497 
498 public:
499 
501  typedef typename view_data_management::return_type reference_type ;
502 
503  enum { reference_type_is_lvalue = view_data_management::ReturnTypeIsReference };
504 
505  typedef View< typename traits::array_intrinsic_type ,
506  typename traits::array_layout ,
507  typename traits::device_type ,
508  typename traits::memory_traits > array_type ;
509 
510  typedef View< typename traits::const_data_type ,
511  typename traits::array_layout ,
512  typename traits::device_type ,
513  typename traits::memory_traits > const_type ;
514 
515  typedef View< typename traits::non_const_data_type ,
516  typename traits::array_layout ,
517  typename traits::device_type ,
518  typename traits::memory_traits > non_const_type ;
519 
520  typedef View< typename traits::non_const_data_type ,
521  typename traits::array_layout ,
522  typename traits::host_mirror_space ,
523  void > HostMirror ;
524 
525  //------------------------------------
526  // Shape
527 
528  enum { Rank = traits::rank };
529 
530  KOKKOS_INLINE_FUNCTION offset_map_type shape() const { return m_offset_map ; }
531  KOKKOS_INLINE_FUNCTION typename traits::size_type dimension_0() const { return m_offset_map.N0 ; }
532  KOKKOS_INLINE_FUNCTION typename traits::size_type dimension_1() const { return m_offset_map.N1 ; }
533  KOKKOS_INLINE_FUNCTION typename traits::size_type dimension_2() const { return m_offset_map.N2 ; }
534  KOKKOS_INLINE_FUNCTION typename traits::size_type dimension_3() const { return m_offset_map.N3 ; }
535  KOKKOS_INLINE_FUNCTION typename traits::size_type dimension_4() const { return m_offset_map.N4 ; }
536  KOKKOS_INLINE_FUNCTION typename traits::size_type dimension_5() const { return m_offset_map.N5 ; }
537  KOKKOS_INLINE_FUNCTION typename traits::size_type dimension_6() const { return m_offset_map.N6 ; }
538  KOKKOS_INLINE_FUNCTION typename traits::size_type dimension_7() const { return m_offset_map.N7 ; }
539  KOKKOS_INLINE_FUNCTION typename traits::size_type size() const { return m_offset_map.cardinality(); }
540 
541  template< typename iType >
542  KOKKOS_INLINE_FUNCTION
543  typename traits::size_type dimension( const iType & i ) const
544  { return Impl::dimension( m_offset_map , i ); }
545 
546  //------------------------------------
547  // Destructor, constructors, assignment operators:
548 
549  KOKKOS_INLINE_FUNCTION
550  ~View() {}
551 
552  KOKKOS_INLINE_FUNCTION
553  View()
554  : m_ptr_on_device()
555  , m_offset_map()
556  , m_management()
557  , m_tracker()
558  { m_offset_map.assign(0, 0,0,0,0,0,0,0,0); }
559 
560  KOKKOS_INLINE_FUNCTION
561  View( const View & rhs )
562  : m_ptr_on_device()
563  , m_offset_map()
564  , m_management()
565  , m_tracker()
566  {
567  (void) Impl::ViewAssignment<
568  typename traits::specialize ,
569  typename traits::specialize >( *this , rhs );
570  }
571 
572  KOKKOS_INLINE_FUNCTION
573  View & operator = ( const View & rhs )
574  {
575  (void) Impl::ViewAssignment<
576  typename traits::specialize ,
577  typename traits::specialize >( *this , rhs );
578  return *this ;
579  }
580 
581  //------------------------------------
582  // Construct or assign compatible view:
583 
584  template< class RT , class RL , class RD , class RM , class RS >
585  KOKKOS_INLINE_FUNCTION
586  View( const View<RT,RL,RD,RM,RS> & rhs )
587  : m_ptr_on_device()
588  , m_offset_map()
589  , m_management()
590  , m_tracker()
591  {
592  (void) Impl::ViewAssignment<
593  typename traits::specialize , RS >( *this , rhs );
594  }
595 
596  template< class RT , class RL , class RD , class RM , class RS >
597  KOKKOS_INLINE_FUNCTION
598  View & operator = ( const View<RT,RL,RD,RM,RS> & rhs )
599  {
600  (void) Impl::ViewAssignment<
601  typename traits::specialize , RS >( *this , rhs );
602  return *this ;
603  }
604 
605  //------------------------------------
618  template< class AllocationProperties >
619  explicit inline
620  View( const AllocationProperties & prop ,
621  // Impl::ViewAllocProp::size_type exists when the traits and allocation properties
622  // are valid for allocating viewed memory.
623  const typename Impl::ViewAllocProp< traits , AllocationProperties >::size_type n0 = 0 ,
624  const size_t n1 = 0 ,
625  const size_t n2 = 0 ,
626  const size_t n3 = 0 ,
627  const size_t n4 = 0 ,
628  const size_t n5 = 0 ,
629  const size_t n6 = 0 ,
630  const size_t n7 = 0 ,
631  const size_t n8 = 0 )
632  : m_ptr_on_device()
633  , m_offset_map()
634  , m_management()
635  , m_tracker()
636  {
637  typedef Impl::ViewAllocProp< traits , AllocationProperties > Alloc ;
638 
639  static_assert(!std::is_same<typename traits::array_layout, LayoutStride>::value,
640  "LayoutStride does not support View constructor which takes dimensions directly!");
641 
642  m_offset_map.assign( n0, n1, n2, n3, n4, n5, n6, n7, n8 );
643  if(Alloc::AllowPadding)
644  m_offset_map.set_padding();
645 
646  m_ptr_on_device = view_data_management::template allocate< Alloc::Initialize >( Alloc::label(prop) , m_offset_map, m_tracker );
647 
648  }
649 
650  template< class AllocationProperties >
651  explicit inline
652  View( const AllocationProperties & prop ,
653  const typename traits::array_layout & layout ,
654  // Impl::ViewAllocProp::size_type exists when the traits and allocation properties
655  // are valid for allocating viewed memory.
656  const typename Impl::ViewAllocProp< traits , AllocationProperties >::size_type = 0 )
657  : m_ptr_on_device()
658  , m_offset_map()
659  , m_management()
660  , m_tracker()
661  {
662  typedef Impl::ViewAllocProp< traits , AllocationProperties > Alloc ;
663 
664  m_offset_map.assign( layout );
665  if(Alloc::AllowPadding)
666  m_offset_map.set_padding();
667 
668  m_ptr_on_device = view_data_management::template allocate< Alloc::Initialize >( Alloc::label(prop) , m_offset_map, m_tracker );
669 
670  m_management.set_noncontiguous();
671  }
672 
673  //------------------------------------
674  // Assign an unmanaged View from pointer, can be called in functors.
675  // No alignment padding is performed.
676 
677  template< class Type >
678  explicit KOKKOS_INLINE_FUNCTION
679  View( Type * ptr ,
680  typename Impl::ViewRawPointerProp< traits , Type >::size_type n0 = 0 ,
681  const size_t n1 = 0 ,
682  const size_t n2 = 0 ,
683  const size_t n3 = 0 ,
684  const size_t n4 = 0 ,
685  const size_t n5 = 0 ,
686  const size_t n6 = 0 ,
687  const size_t n7 = 0 ,
688  const size_t n8 = 0 )
689  : m_ptr_on_device(ptr)
690  , m_offset_map()
691  , m_management()
692  , m_tracker()
693  {
694  m_offset_map.assign( n0, n1, n2, n3, n4, n5, n6, n7, n8 );
695  m_management.set_unmanaged();
696  }
697 
698  template< class Type >
699  explicit KOKKOS_INLINE_FUNCTION
700  View( Type * ptr ,
701  typename traits::array_layout const & layout ,
702  typename Impl::ViewRawPointerProp< traits , Type >::size_type = 0 )
703  : m_ptr_on_device(ptr)
704  , m_offset_map()
705  , m_management()
706  , m_tracker()
707  {
708  m_offset_map.assign( layout );
709  m_management.set_unmanaged();
710  m_management.set_noncontiguous();
711  }
712 
713 
714 
715  //------------------------------------
716  // Assign a View from an AllocationTracker,
717  // The allocator used must be compatiable with the memory space of the view
718  // No alignment padding is performed.
719  // TODO: Should these allow padding??? DJS 01/15/15
720  explicit
721  View( Impl::AllocationTracker const &arg_tracker ,
722  const size_t n0 = 0 ,
723  const size_t n1 = 0 ,
724  const size_t n2 = 0 ,
725  const size_t n3 = 0 ,
726  const size_t n4 = 0 ,
727  const size_t n5 = 0 ,
728  const size_t n6 = 0 ,
729  const size_t n7 = 0 ,
730  const size_t n8 = 0 )
731  : m_ptr_on_device(reinterpret_cast<typename traits::value_type*>(arg_tracker.alloc_ptr()))
732  , m_offset_map()
733  , m_management()
734  , m_tracker(arg_tracker)
735  {
736  m_offset_map.assign( n0, n1, n2, n3, n4, n5, n6, n7, n8 );
737 
738  const size_t req_size = m_offset_map.capacity() * sizeof(typename traits::value_type);
739  if ( m_tracker.alloc_size() < req_size ) {
740  Impl::throw_runtime_exception("Error: tracker.alloc_size() < req_size");
741  }
742  }
743 
744  explicit
745  View( Impl::AllocationTracker const & arg_tracker
746  , typename traits::array_layout const & layout )
747  : m_ptr_on_device(reinterpret_cast<typename traits::value_type*>(arg_tracker.alloc_ptr()))
748  , m_offset_map()
749  , m_management()
750  , m_tracker(arg_tracker)
751  {
752  m_offset_map.assign( layout );
753 
754  const size_t req_size = m_offset_map.capacity() * sizeof(typename traits::value_type);
755  if ( m_tracker.alloc_size() < req_size ) {
756  Impl::throw_runtime_exception("Error: tracker.alloc_size() < req_size");
757  }
758 
759  m_management.set_noncontiguous();
760  }
761 
762  //------------------------------------
772  template< class D , class A1 , class A2 , class A3
773  , class SubArg0_type , class SubArg1_type , class SubArg2_type , class SubArg3_type
774  , class SubArg4_type , class SubArg5_type , class SubArg6_type , class SubArg7_type
775  >
776  KOKKOS_INLINE_FUNCTION
777  View( const View<D,A1,A2,A3,Impl::ViewDefault> & src
778  , const SubArg0_type & arg0 , const SubArg1_type & arg1
779  , const SubArg2_type & arg2 , const SubArg3_type & arg3
780  , const SubArg4_type & arg4 , const SubArg5_type & arg5
781  , const SubArg6_type & arg6 , const SubArg7_type & arg7
782  );
783 
784  template< class D , class A1 , class A2 , class A3
785  , class SubArg0_type , class SubArg1_type , class SubArg2_type , class SubArg3_type
786  , class SubArg4_type , class SubArg5_type , class SubArg6_type
787  >
788  KOKKOS_INLINE_FUNCTION
789  View( const View<D,A1,A2,A3,Impl::ViewDefault> & src
790  , const SubArg0_type & arg0 , const SubArg1_type & arg1
791  , const SubArg2_type & arg2 , const SubArg3_type & arg3
792  , const SubArg4_type & arg4 , const SubArg5_type & arg5
793  , const SubArg6_type & arg6
794  );
795 
796  template< class D , class A1 , class A2 , class A3
797  , class SubArg0_type , class SubArg1_type , class SubArg2_type , class SubArg3_type
798  , class SubArg4_type , class SubArg5_type
799  >
800  KOKKOS_INLINE_FUNCTION
801  View( const View<D,A1,A2,A3,Impl::ViewDefault> & src
802  , const SubArg0_type & arg0 , const SubArg1_type & arg1
803  , const SubArg2_type & arg2 , const SubArg3_type & arg3
804  , const SubArg4_type & arg4 , const SubArg5_type & arg5
805  );
806 
807  template< class D , class A1 , class A2 , class A3
808  , class SubArg0_type , class SubArg1_type , class SubArg2_type , class SubArg3_type
809  , class SubArg4_type
810  >
811  KOKKOS_INLINE_FUNCTION
812  View( const View<D,A1,A2,A3,Impl::ViewDefault> & src
813  , const SubArg0_type & arg0 , const SubArg1_type & arg1
814  , const SubArg2_type & arg2 , const SubArg3_type & arg3
815  , const SubArg4_type & arg4
816  );
817 
818  template< class D , class A1 , class A2 , class A3
819  , class SubArg0_type , class SubArg1_type , class SubArg2_type , class SubArg3_type
820  >
821  KOKKOS_INLINE_FUNCTION
822  View( const View<D,A1,A2,A3,Impl::ViewDefault> & src
823  , const SubArg0_type & arg0 , const SubArg1_type & arg1
824  , const SubArg2_type & arg2 , const SubArg3_type & arg3
825  );
826 
827  template< class D , class A1 , class A2 , class A3
828  , class SubArg0_type , class SubArg1_type , class SubArg2_type
829  >
830  KOKKOS_INLINE_FUNCTION
831  View( const View<D,A1,A2,A3,Impl::ViewDefault> & src
832  , const SubArg0_type & arg0 , const SubArg1_type & arg1
833  , const SubArg2_type & arg2
834  );
835 
836  template< class D , class A1 , class A2 , class A3
837  , class SubArg0_type , class SubArg1_type
838  >
839  KOKKOS_INLINE_FUNCTION
840  View( const View<D,A1,A2,A3,Impl::ViewDefault> & src
841  , const SubArg0_type & arg0 , const SubArg1_type & arg1
842  );
843 
844  template< class D , class A1 , class A2 , class A3
845  , class SubArg0_type
846  >
847  KOKKOS_INLINE_FUNCTION
848  View( const View<D,A1,A2,A3,Impl::ViewDefault> & src
849  , const SubArg0_type & arg0
850  );
851 
852  //------------------------------------
853  // Assign unmanaged View to portion of execution space's shared memory
854 
855  typedef Impl::if_c< ! traits::is_managed ,
856  const typename traits::execution_space::scratch_memory_space & ,
857  Impl::ViewError::device_shmem_constructor_requires_unmanaged >
858  if_scratch_memory_constructor ;
859 
860  explicit KOKKOS_INLINE_FUNCTION
861  View( typename if_scratch_memory_constructor::type space ,
862  const unsigned n0 = 0 ,
863  const unsigned n1 = 0 ,
864  const unsigned n2 = 0 ,
865  const unsigned n3 = 0 ,
866  const unsigned n4 = 0 ,
867  const unsigned n5 = 0 ,
868  const unsigned n6 = 0 ,
869  const unsigned n7 = 0 )
870  : m_ptr_on_device()
871  , m_offset_map()
872  , m_management()
873  , m_tracker()
874  {
875  typedef typename traits::value_type value_type_ ;
876 
877  enum { align = 8 };
878  enum { mask = align - 1 };
879 
880  m_offset_map.assign( n0, n1, n2, n3, n4, n5, n6, n7 );
881 
882  typedef Impl::if_c< ! traits::is_managed ,
883  value_type_ * ,
884  Impl::ViewError::device_shmem_constructor_requires_unmanaged >
885  if_device_shmem_pointer ;
886 
887  // Select the first argument:
888  m_ptr_on_device = if_device_shmem_pointer::select(
889  (value_type_*) space.get_shmem( unsigned( sizeof(value_type_) * m_offset_map.capacity() + unsigned(mask) ) & ~unsigned(mask) ) );
890  }
891 
892  explicit KOKKOS_INLINE_FUNCTION
893  View( typename if_scratch_memory_constructor::type space ,
894  typename traits::array_layout const & layout)
895  : m_ptr_on_device()
896  , m_offset_map()
897  , m_management()
898  , m_tracker()
899  {
900  typedef typename traits::value_type value_type_ ;
901 
902  typedef Impl::if_c< ! traits::is_managed ,
903  value_type_ * ,
904  Impl::ViewError::device_shmem_constructor_requires_unmanaged >
905  if_device_shmem_pointer ;
906 
907  m_offset_map.assign( layout );
908  m_management.set_unmanaged();
909  m_management.set_noncontiguous();
910 
911  enum { align = 8 };
912  enum { mask = align - 1 };
913 
914  // Select the first argument:
915  m_ptr_on_device = if_device_shmem_pointer::select(
916  (value_type_*) space.get_shmem( unsigned( sizeof(value_type_) * m_offset_map.capacity() + unsigned(mask) ) & ~unsigned(mask) ) );
917  }
918 
919  static inline
920  unsigned shmem_size( const unsigned n0 = 0 ,
921  const unsigned n1 = 0 ,
922  const unsigned n2 = 0 ,
923  const unsigned n3 = 0 ,
924  const unsigned n4 = 0 ,
925  const unsigned n5 = 0 ,
926  const unsigned n6 = 0 ,
927  const unsigned n7 = 0 )
928  {
929  enum { align = 8 };
930  enum { mask = align - 1 };
931 
932  typedef typename traits::value_type value_type_ ;
933 
934  offset_map_type offset_map ;
935 
936  offset_map.assign( n0, n1, n2, n3, n4, n5, n6, n7 );
937 
938  return unsigned( sizeof(value_type_) * offset_map.capacity() + unsigned(mask) ) & ~unsigned(mask) ;
939  }
940 
941  //------------------------------------
942  // Is not allocated
943 
944  KOKKOS_FORCEINLINE_FUNCTION
945  bool is_null() const { return 0 == ptr_on_device() ; }
946 
947  //------------------------------------
948  // Operators for scalar (rank zero) views.
949 
950  typedef Impl::if_c< traits::rank == 0 ,
951  typename traits::value_type ,
952  Impl::ViewError::scalar_operator_called_from_non_scalar_view >
953  if_scalar_operator ;
954 
955  typedef Impl::if_c< traits::rank == 0 ,
956  reference_type ,
957  Impl::ViewError::scalar_operator_called_from_non_scalar_view >
958  if_scalar_operator_return ;
959  KOKKOS_INLINE_FUNCTION
960  const View & operator = ( const typename if_scalar_operator::type & rhs ) const
961  {
962  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
963  m_ptr_on_device[ 0 ] = if_scalar_operator::select( rhs );
964  return *this ;
965  }
966 
967  KOKKOS_FORCEINLINE_FUNCTION
968  operator typename if_scalar_operator_return::type () const
969  {
970  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
971  return if_scalar_operator_return::select( m_ptr_on_device[ 0 ] );
972  }
973 
974  KOKKOS_FORCEINLINE_FUNCTION
975  typename if_scalar_operator_return::type operator()() const
976  {
977  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
978  return if_scalar_operator_return::select( m_ptr_on_device[ 0 ] );
979  }
980 
981  KOKKOS_FORCEINLINE_FUNCTION
982  typename if_scalar_operator_return::type operator*() const
983  {
984  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
985  return if_scalar_operator_return::select( m_ptr_on_device[ 0 ] );
986  }
987 
988  //------------------------------------
989  // Array member access operators enabled if
990  // (1) a zero value of all argument types are compile-time comparable to zero
991  // (2) the rank matches the number of arguments
992  // (3) the memory space is valid for the access
993  //------------------------------------
994  // rank 1:
995  // Specialisation for LayoutLeft and LayoutRight since we know its stride 1
996 
997  template< typename iType0 >
998  KOKKOS_FORCEINLINE_FUNCTION
1000  operator[] ( const iType0 & i0 ) const
1001  {
1002  KOKKOS_ASSERT_SHAPE_BOUNDS_1( m_offset_map, i0 );
1003  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
1004 
1005  return m_ptr_on_device[ i0 ];
1006  }
1007 
1008  template< typename iType0 >
1009  KOKKOS_FORCEINLINE_FUNCTION
1011  operator() ( const iType0 & i0 ) const
1012  {
1013  KOKKOS_ASSERT_SHAPE_BOUNDS_1( m_offset_map, i0 );
1014  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
1015 
1016  return m_ptr_on_device[ i0 ];
1017  }
1018 
1019  template< typename iType0 >
1020  KOKKOS_FORCEINLINE_FUNCTION
1022  at( const iType0 & i0 , const int , const int , const int ,
1023  const int , const int , const int , const int ) const
1024  {
1025  KOKKOS_ASSERT_SHAPE_BOUNDS_1( m_offset_map, i0 );
1026  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
1027 
1028  return m_ptr_on_device[ i0 ];
1029  }
1030 
1031  template< typename iType0 >
1032  KOKKOS_FORCEINLINE_FUNCTION
1034  operator[] ( const iType0 & i0 ) const
1035  {
1036  KOKKOS_ASSERT_SHAPE_BOUNDS_1( m_offset_map, i0 );
1037  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
1038 
1039  return m_ptr_on_device[ i0 ];
1040  }
1041 
1042  template< typename iType0 >
1043  KOKKOS_FORCEINLINE_FUNCTION
1045  operator() ( const iType0 & i0 ) const
1046  {
1047  KOKKOS_ASSERT_SHAPE_BOUNDS_1( m_offset_map, i0 );
1048  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
1049 
1050  return m_ptr_on_device[ i0 ];
1051  }
1052 
1053  template< typename iType0 >
1054  KOKKOS_FORCEINLINE_FUNCTION
1056  at( const iType0 & i0 , const int , const int , const int ,
1057  const int , const int , const int , const int ) const
1058  {
1059  KOKKOS_ASSERT_SHAPE_BOUNDS_1( m_offset_map, i0 );
1060  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
1061 
1062  return m_ptr_on_device[ i0 ];
1063  }
1064 
1065  template< typename iType0 >
1066  KOKKOS_FORCEINLINE_FUNCTION
1067  typename Impl::ViewEnableArrayOper< reference_type , traits,
1068  typename Impl::if_c<
1069  Impl::is_same<typename traits::array_layout, LayoutRight>::value ||
1070  Impl::is_same<typename traits::array_layout, LayoutLeft>::value ,
1071  void, typename traits::array_layout>::type,
1072  1, iType0 >::type
1073  operator[] ( const iType0 & i0 ) const
1074  {
1075  KOKKOS_ASSERT_SHAPE_BOUNDS_1( m_offset_map, i0 );
1076  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
1077 
1078  return m_ptr_on_device[ m_offset_map(i0) ];
1079  }
1080 
1081  template< typename iType0 >
1082  KOKKOS_FORCEINLINE_FUNCTION
1083  typename Impl::ViewEnableArrayOper< reference_type , traits,
1084  typename Impl::if_c<
1085  Impl::is_same<typename traits::array_layout, LayoutRight>::value ||
1086  Impl::is_same<typename traits::array_layout, LayoutLeft>::value ,
1087  void, typename traits::array_layout>::type,
1088  1, iType0 >::type
1089  operator() ( const iType0 & i0 ) const
1090  {
1091  KOKKOS_ASSERT_SHAPE_BOUNDS_1( m_offset_map, i0 );
1092  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
1093 
1094  return m_ptr_on_device[ m_offset_map(i0) ];
1095  }
1096 
1097  template< typename iType0 >
1098  KOKKOS_FORCEINLINE_FUNCTION
1099  typename Impl::ViewEnableArrayOper< reference_type , traits,
1100  typename Impl::if_c<
1101  Impl::is_same<typename traits::array_layout, LayoutRight>::value ||
1102  Impl::is_same<typename traits::array_layout, LayoutLeft>::value ,
1103  void, typename traits::array_layout>::type,
1104  1, iType0 >::type
1105  at( const iType0 & i0 , const int , const int , const int ,
1106  const int , const int , const int , const int ) const
1107  {
1108  KOKKOS_ASSERT_SHAPE_BOUNDS_1( m_offset_map, i0 );
1109  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
1110 
1111  return m_ptr_on_device[ m_offset_map(i0) ];
1112  }
1113 
1114  // rank 2:
1115 
1116  template< typename iType0 , typename iType1 >
1117  KOKKOS_FORCEINLINE_FUNCTION
1118  typename Impl::ViewEnableArrayOper< reference_type ,
1119  traits, typename traits::array_layout, 2, iType0, iType1 >::type
1120  operator() ( const iType0 & i0 , const iType1 & i1 ) const
1121  {
1122  KOKKOS_ASSERT_SHAPE_BOUNDS_2( m_offset_map, i0,i1 );
1123  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
1124 
1125  return m_ptr_on_device[ m_offset_map(i0,i1) ];
1126  }
1127 
1128  template< typename iType0 , typename iType1 >
1129  KOKKOS_FORCEINLINE_FUNCTION
1130  typename Impl::ViewEnableArrayOper< reference_type ,
1131  traits, typename traits::array_layout, 2, iType0, iType1 >::type
1132  at( const iType0 & i0 , const iType1 & i1 , const int , const int ,
1133  const int , const int , const int , const int ) const
1134  {
1135  KOKKOS_ASSERT_SHAPE_BOUNDS_2( m_offset_map, i0,i1 );
1136  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
1137 
1138  return m_ptr_on_device[ m_offset_map(i0,i1) ];
1139  }
1140 
1141  // rank 3:
1142 
1143  template< typename iType0 , typename iType1 , typename iType2 >
1144  KOKKOS_FORCEINLINE_FUNCTION
1145  typename Impl::ViewEnableArrayOper< reference_type ,
1146  traits, typename traits::array_layout, 3, iType0, iType1, iType2 >::type
1147  operator() ( const iType0 & i0 , const iType1 & i1 , const iType2 & i2 ) const
1148  {
1149  KOKKOS_ASSERT_SHAPE_BOUNDS_3( m_offset_map, i0,i1,i2 );
1150  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
1151 
1152  return m_ptr_on_device[ m_offset_map(i0,i1,i2) ];
1153  }
1154 
1155  template< typename iType0 , typename iType1 , typename iType2 >
1156  KOKKOS_FORCEINLINE_FUNCTION
1157  typename Impl::ViewEnableArrayOper< reference_type ,
1158  traits, typename traits::array_layout, 3, iType0, iType1, iType2 >::type
1159  at( const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const int ,
1160  const int , const int , const int , const int ) const
1161  {
1162  KOKKOS_ASSERT_SHAPE_BOUNDS_3( m_offset_map, i0,i1,i2 );
1163  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
1164 
1165  return m_ptr_on_device[ m_offset_map(i0,i1,i2) ];
1166  }
1167 
1168  // rank 4:
1169 
1170  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 >
1171  KOKKOS_FORCEINLINE_FUNCTION
1172  typename Impl::ViewEnableArrayOper< reference_type ,
1173  traits, typename traits::array_layout, 4, iType0, iType1, iType2, iType3 >::type
1174  operator() ( const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ) const
1175  {
1176  KOKKOS_ASSERT_SHAPE_BOUNDS_4( m_offset_map, i0,i1,i2,i3 );
1177  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
1178 
1179  return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3) ];
1180  }
1181 
1182  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 >
1183  KOKKOS_FORCEINLINE_FUNCTION
1184  typename Impl::ViewEnableArrayOper< reference_type ,
1185  traits, typename traits::array_layout, 4, iType0, iType1, iType2, iType3 >::type
1186  at( const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ,
1187  const int , const int , const int , const int ) const
1188  {
1189  KOKKOS_ASSERT_SHAPE_BOUNDS_4( m_offset_map, i0,i1,i2,i3 );
1190  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
1191 
1192  return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3) ];
1193  }
1194 
1195  // rank 5:
1196 
1197  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 ,
1198  typename iType4 >
1199  KOKKOS_FORCEINLINE_FUNCTION
1200  typename Impl::ViewEnableArrayOper< reference_type ,
1201  traits, typename traits::array_layout, 5, iType0, iType1, iType2, iType3 , iType4 >::type
1202  operator() ( const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ,
1203  const iType4 & i4 ) const
1204  {
1205  KOKKOS_ASSERT_SHAPE_BOUNDS_5( m_offset_map, i0,i1,i2,i3,i4 );
1206  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
1207 
1208  return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3,i4) ];
1209  }
1210 
1211  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 ,
1212  typename iType4 >
1213  KOKKOS_FORCEINLINE_FUNCTION
1214  typename Impl::ViewEnableArrayOper< reference_type ,
1215  traits, typename traits::array_layout, 5, iType0, iType1, iType2, iType3 , iType4 >::type
1216  at( const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ,
1217  const iType4 & i4 , const int , const int , const int ) const
1218  {
1219  KOKKOS_ASSERT_SHAPE_BOUNDS_5( m_offset_map, i0,i1,i2,i3,i4 );
1220  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
1221 
1222  return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3,i4) ];
1223  }
1224 
1225  // rank 6:
1226 
1227  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 ,
1228  typename iType4 , typename iType5 >
1229  KOKKOS_FORCEINLINE_FUNCTION
1230  typename Impl::ViewEnableArrayOper< reference_type ,
1231  traits, typename traits::array_layout, 6,
1232  iType0, iType1, iType2, iType3 , iType4, iType5 >::type
1233  operator() ( const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ,
1234  const iType4 & i4 , const iType5 & i5 ) const
1235  {
1236  KOKKOS_ASSERT_SHAPE_BOUNDS_6( m_offset_map, i0,i1,i2,i3,i4,i5 );
1237  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
1238 
1239  return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3,i4,i5) ];
1240  }
1241 
1242  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 ,
1243  typename iType4 , typename iType5 >
1244  KOKKOS_FORCEINLINE_FUNCTION
1245  typename Impl::ViewEnableArrayOper< reference_type ,
1246  traits, typename traits::array_layout, 6,
1247  iType0, iType1, iType2, iType3 , iType4, iType5 >::type
1248  at( const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ,
1249  const iType4 & i4 , const iType5 & i5 , const int , const int ) const
1250  {
1251  KOKKOS_ASSERT_SHAPE_BOUNDS_6( m_offset_map, i0,i1,i2,i3,i4,i5 );
1252  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
1253 
1254  return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3,i4,i5) ];
1255  }
1256 
1257  // rank 7:
1258 
1259  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 ,
1260  typename iType4 , typename iType5 , typename iType6 >
1261  KOKKOS_FORCEINLINE_FUNCTION
1262  typename Impl::ViewEnableArrayOper< reference_type ,
1263  traits, typename traits::array_layout, 7,
1264  iType0, iType1, iType2, iType3 , iType4, iType5, iType6 >::type
1265  operator() ( const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ,
1266  const iType4 & i4 , const iType5 & i5 , const iType6 & i6 ) const
1267  {
1268  KOKKOS_ASSERT_SHAPE_BOUNDS_7( m_offset_map, i0,i1,i2,i3,i4,i5,i6 );
1269  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
1270 
1271  return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3,i4,i5,i6) ];
1272  }
1273 
1274  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 ,
1275  typename iType4 , typename iType5 , typename iType6 >
1276  KOKKOS_FORCEINLINE_FUNCTION
1277  typename Impl::ViewEnableArrayOper< reference_type ,
1278  traits, typename traits::array_layout, 7,
1279  iType0, iType1, iType2, iType3 , iType4, iType5, iType6 >::type
1280  at( const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ,
1281  const iType4 & i4 , const iType5 & i5 , const iType6 & i6 , const int ) const
1282  {
1283  KOKKOS_ASSERT_SHAPE_BOUNDS_7( m_offset_map, i0,i1,i2,i3,i4,i5,i6 );
1284  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
1285 
1286  return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3,i4,i5,i6) ];
1287  }
1288 
1289  // rank 8:
1290 
1291  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 ,
1292  typename iType4 , typename iType5 , typename iType6 , typename iType7 >
1293  KOKKOS_FORCEINLINE_FUNCTION
1294  typename Impl::ViewEnableArrayOper< reference_type ,
1295  traits, typename traits::array_layout, 8,
1296  iType0, iType1, iType2, iType3 , iType4, iType5, iType6, iType7 >::type
1297  operator() ( const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ,
1298  const iType4 & i4 , const iType5 & i5 , const iType6 & i6 , const iType7 & i7 ) const
1299  {
1300  KOKKOS_ASSERT_SHAPE_BOUNDS_8( m_offset_map, i0,i1,i2,i3,i4,i5,i6,i7 );
1301  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
1302 
1303  return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3,i4,i5,i6,i7) ];
1304  }
1305 
1306  template< typename iType0 , typename iType1 , typename iType2 , typename iType3 ,
1307  typename iType4 , typename iType5 , typename iType6 , typename iType7 >
1308  KOKKOS_FORCEINLINE_FUNCTION
1309  typename Impl::ViewEnableArrayOper< reference_type ,
1310  traits, typename traits::array_layout, 8,
1311  iType0, iType1, iType2, iType3 , iType4, iType5, iType6, iType7 >::type
1312  at( const iType0 & i0 , const iType1 & i1 , const iType2 & i2 , const iType3 & i3 ,
1313  const iType4 & i4 , const iType5 & i5 , const iType6 & i6 , const iType7 & i7 ) const
1314  {
1315  KOKKOS_ASSERT_SHAPE_BOUNDS_8( m_offset_map, i0,i1,i2,i3,i4,i5,i6,i7 );
1316  KOKKOS_RESTRICT_EXECUTION_TO_DATA( typename traits::memory_space , ptr_on_device() );
1317 
1318  return m_ptr_on_device[ m_offset_map(i0,i1,i2,i3,i4,i5,i6,i7) ];
1319  }
1320 
1321  //------------------------------------
1322  // Access to the underlying contiguous storage of this view specialization.
1323  // These methods are specific to specialization of a view.
1324 
1325  KOKKOS_FORCEINLINE_FUNCTION
1326  typename traits::value_type * ptr_on_device() const
1327  { return (typename traits::value_type *) m_ptr_on_device ; }
1328 
1329  // Stride of physical storage, dimensioned to at least Rank
1330  template< typename iType >
1331  KOKKOS_INLINE_FUNCTION
1332  void stride( iType * const s ) const
1333  { m_offset_map.stride(s); }
1334 
1335  // Count of contiguously allocated data members including padding.
1336  KOKKOS_INLINE_FUNCTION
1337  typename traits::size_type capacity() const
1338  { return m_offset_map.capacity(); }
1339 
1340  // If the view data can be treated (deep copied)
1341  // as a contiguous block of memory.
1342  KOKKOS_INLINE_FUNCTION
1343  bool is_contiguous() const
1344  { return m_management.is_contiguous(); }
1345 
1346  const Impl::AllocationTracker & tracker() const { return m_tracker; }
1347 };
1348 
1349 } /* namespace Kokkos */
1350 
1351 //----------------------------------------------------------------------------
1352 //----------------------------------------------------------------------------
1353 
1354 namespace Kokkos {
1355 
1356 template< class LT , class LL , class LD , class LM , class LS ,
1357  class RT , class RL , class RD , class RM , class RS >
1358 KOKKOS_INLINE_FUNCTION
1359 typename Impl::enable_if<( Impl::is_same< LS , RS >::value ), bool >::type
1360 operator == ( const View<LT,LL,LD,LM,LS> & lhs ,
1361  const View<RT,RL,RD,RM,RS> & rhs )
1362 {
1363  // Same data, layout, dimensions
1364  typedef ViewTraits<LT,LL,LD,LM> lhs_traits ;
1365  typedef ViewTraits<RT,RL,RD,RM> rhs_traits ;
1366 
1367  return
1368  Impl::is_same< typename lhs_traits::const_data_type ,
1369  typename rhs_traits::const_data_type >::value &&
1370  Impl::is_same< typename lhs_traits::array_layout ,
1371  typename rhs_traits::array_layout >::value &&
1372  Impl::is_same< typename lhs_traits::memory_space ,
1373  typename rhs_traits::memory_space >::value &&
1374  Impl::is_same< typename lhs_traits::specialize ,
1375  typename rhs_traits::specialize >::value &&
1376  lhs.ptr_on_device() == rhs.ptr_on_device() &&
1377  lhs.shape() == rhs.shape() ;
1378 }
1379 
1380 template< class LT , class LL , class LD , class LM , class LS ,
1381  class RT , class RL , class RD , class RM , class RS >
1382 KOKKOS_INLINE_FUNCTION
1383 bool operator != ( const View<LT,LL,LD,LM,LS> & lhs ,
1384  const View<RT,RL,RD,RM,RS> & rhs )
1385 {
1386  return ! operator==( lhs , rhs );
1387 }
1388 
1389 //----------------------------------------------------------------------------
1390 
1391 
1392 } // namespace Kokkos
1393 
1394 //----------------------------------------------------------------------------
1395 //----------------------------------------------------------------------------
1396 
1397 namespace Kokkos {
1398 
1399 //----------------------------------------------------------------------------
1402 template< class DT , class DL , class DD , class DM , class DS >
1403 inline
1404 void deep_copy( const View<DT,DL,DD,DM,DS> & dst ,
1405  typename Impl::enable_if<(
1406  Impl::is_same< typename ViewTraits<DT,DL,DD,DM>::non_const_value_type ,
1407  typename ViewTraits<DT,DL,DD,DM>::value_type >::value
1408  ), typename ViewTraits<DT,DL,DD,DM>::const_value_type >::type & value )
1409 {
1410  Impl::ViewFill< View<DT,DL,DD,DM,DS> >( dst , value );
1411 }
1412 
1413 template< class ST , class SL , class SD , class SM , class SS >
1414 inline
1415 typename Impl::enable_if<( ViewTraits<ST,SL,SD,SM>::rank == 0 )>::type
1416 deep_copy( ST & dst , const View<ST,SL,SD,SM,SS> & src )
1417 {
1418  typedef ViewTraits<ST,SL,SD,SM> src_traits ;
1419  typedef typename src_traits::memory_space src_memory_space ;
1420  Impl::DeepCopy< HostSpace , src_memory_space >( & dst , src.ptr_on_device() , sizeof(ST) );
1421 }
1422 
1423 //----------------------------------------------------------------------------
1426 template< class DT , class DL , class DD , class DM , class DS ,
1427  class ST , class SL , class SD , class SM , class SS >
1428 inline
1429 void deep_copy( const View<DT,DL,DD,DM,DS> & dst ,
1430  const View<ST,SL,SD,SM,SS> & src ,
1431  typename Impl::enable_if<(
1432  // Same type and destination is not constant:
1433  Impl::is_same< typename View<DT,DL,DD,DM,DS>::value_type ,
1435  &&
1436  // Rank zero:
1437  ( unsigned(View<DT,DL,DD,DM,DS>::rank) == unsigned(0) ) &&
1438  ( unsigned(View<ST,SL,SD,SM,SS>::rank) == unsigned(0) )
1439  )>::type * = 0 )
1440 {
1441  typedef View<DT,DL,DD,DM,DS> dst_type ;
1442  typedef View<ST,SL,SD,SM,SS> src_type ;
1443 
1444  typedef typename dst_type::memory_space dst_memory_space ;
1445  typedef typename src_type::memory_space src_memory_space ;
1446  typedef typename src_type::value_type value_type ;
1447 
1448  if ( dst.ptr_on_device() != src.ptr_on_device() ) {
1449  Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.ptr_on_device() , src.ptr_on_device() , sizeof(value_type) );
1450  }
1451 }
1452 
1453 //----------------------------------------------------------------------------
1457 template< class DT , class DL , class DD , class DM ,
1458  class ST , class SL , class SD , class SM >
1459 inline
1462  typename Impl::enable_if<(
1463  // Same type and destination is not constant:
1464  Impl::is_same< typename View<DT,DL,DD,DM,Impl::ViewDefault>::value_type ,
1466  &&
1467  // Same non-zero rank:
1470  &&
1472  &&
1473  // Same layout:
1474  Impl::is_same< typename View<DT,DL,DD,DM,Impl::ViewDefault>::array_layout ,
1476  )>::type * = 0 )
1477 {
1478  typedef View<DT,DL,DD,DM,Impl::ViewDefault> dst_type ;
1479  typedef View<ST,SL,SD,SM,Impl::ViewDefault> src_type ;
1480 
1481  typedef typename dst_type::memory_space dst_memory_space ;
1482  typedef typename src_type::memory_space src_memory_space ;
1483 
1484  enum { is_contiguous = // Contiguous (e.g., non-strided, non-tiled) layout
1485  Impl::is_same< typename View<DT,DL,DD,DM,Impl::ViewDefault>::array_layout , LayoutLeft >::value ||
1486  Impl::is_same< typename View<DT,DL,DD,DM,Impl::ViewDefault>::array_layout , LayoutRight >::value };
1487 
1488  if ( dst.ptr_on_device() != src.ptr_on_device() ) {
1489 
1490  // Same shape (dimensions)
1491 
1492  const bool shapes_are_equal = dst.shape() == src.shape();
1493 
1494  if ( shapes_are_equal && is_contiguous && dst.capacity() == src.capacity() ) {
1495 
1496  // Views span equal length contiguous range.
1497  // Assuming can perform a straight memory copy over this range.
1498 
1499  const size_t nbytes = sizeof(typename dst_type::value_type) * dst.capacity();
1500 
1501  Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.ptr_on_device() , src.ptr_on_device() , nbytes );
1502  }
1503  else {
1504  // Destination view's execution space must be able to directly access source memory space
1505  // in order for the ViewRemap functor run in the destination memory space's execution space.
1506  size_t stride[8];
1507  src.stride(stride);
1508  size_t size_stride = stride[0]*src.dimension_0();
1509  size_t size_dim = src.dimension_0();
1510  for(int i = 1; i<src.rank; i++) {
1511  if(stride[i]*src.dimension(i)>size_stride)
1512  size_stride = stride[i]*src.dimension(i);
1513  size_dim*=src.dimension(i);
1514  }
1515 
1516  if( shapes_are_equal && size_stride == size_dim) {
1517  const size_t nbytes = sizeof(typename dst_type::value_type) * dst.capacity();
1518 
1519  Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.ptr_on_device() , src.ptr_on_device() , nbytes );
1520  } else {
1521  Impl::ViewRemap< dst_type , src_type >( dst , src );
1522  }
1523  }
1524  }
1525 }
1526 
1527 
1531 template< class DT , class DL , class DD , class DM , class DS ,
1532  class ST , class SL , class SD , class SM , class SS >
1533 inline
1535  const View< ST, SL, SD, SM, SS > & src ,
1536  const typename Impl::enable_if<(
1537  // Same type and destination is not constant:
1538  Impl::is_same< typename View<DT,DL,DD,DM,DS>::value_type ,
1540  &&
1541  // Source memory space is accessible to destination memory space
1542  Impl::VerifyExecutionCanAccessMemorySpace< typename View<DT,DL,DD,DM,DS>::memory_space
1543  , typename View<ST,SL,SD,SM,SS>::memory_space >::value
1544  &&
1545  // Same non-zero rank
1546  ( unsigned( View<DT,DL,DD,DM,DS>::rank ) ==
1547  unsigned( View<ST,SL,SD,SM,SS>::rank ) )
1548  &&
1549  ( 0 < unsigned( View<DT,DL,DD,DM,DS>::rank ) )
1550  &&
1551  // Different layout or different specialization:
1552  ( ( ! Impl::is_same< typename View<DT,DL,DD,DM,DS>::array_layout ,
1553  typename View<ST,SL,SD,SM,SS>::array_layout >::value )
1554  ||
1555  ( ! Impl::is_same< DS , SS >::value )
1556  )
1557  )>::type * = 0 )
1558 {
1559  typedef View< DT, DL, DD, DM, DS > dst_type ;
1560  typedef View< ST, SL, SD, SM, SS > src_type ;
1561 
1562  assert_shapes_equal_dimension( dst.shape() , src.shape() );
1563 
1564  Impl::ViewRemap< dst_type , src_type >( dst , src );
1565 }
1566 
1567 }
1568 
1569 //----------------------------------------------------------------------------
1570 //----------------------------------------------------------------------------
1571 
1572 namespace Kokkos {
1573 
1574 //----------------------------------------------------------------------------
1577 template< class ExecSpace, class DT , class DL , class DD , class DM , class DS >
1578 inline
1579 void deep_copy( const ExecSpace&, const View<DT,DL,DD,DM,DS> & dst ,
1580  typename Impl::enable_if<(
1581  Impl::is_same< typename ViewTraits<DT,DL,DD,DM>::non_const_value_type ,
1582  typename ViewTraits<DT,DL,DD,DM>::value_type >::value
1583  ), typename ViewTraits<DT,DL,DD,DM>::const_value_type >::type & value )
1584 {
1585  Impl::ViewFill< View<DT,DL,DD,DM,DS> >( dst , value );
1586 }
1587 
1588 template< class ExecSpace, class ST , class SL , class SD , class SM , class SS >
1589 inline
1590 typename Impl::enable_if<( ViewTraits<ST,SL,SD,SM>::rank == 0 )>::type
1591 deep_copy( const ExecSpace& exec, ST & dst , const View<ST,SL,SD,SM,SS> & src )
1592 {
1593  typedef ViewTraits<ST,SL,SD,SM> src_traits ;
1594  typedef typename src_traits::memory_space src_memory_space ;
1595  Impl::DeepCopy< HostSpace , src_memory_space , ExecSpace >( exec , & dst , src.ptr_on_device() , sizeof(ST) );
1596 }
1597 
1598 //----------------------------------------------------------------------------
1601 template< class ExecSpace ,
1602  class DT , class DL , class DD , class DM , class DS ,
1603  class ST , class SL , class SD , class SM , class SS >
1604 inline
1605 void deep_copy( const ExecSpace& exec,
1606  const View<DT,DL,DD,DM,DS> & dst ,
1607  const View<ST,SL,SD,SM,SS> & src ,
1608  typename Impl::enable_if<(
1609  // Same type and destination is not constant:
1610  Impl::is_same< typename View<DT,DL,DD,DM,DS>::value_type ,
1612  &&
1613  // Rank zero:
1614  ( unsigned(View<DT,DL,DD,DM,DS>::rank) == unsigned(0) ) &&
1615  ( unsigned(View<ST,SL,SD,SM,SS>::rank) == unsigned(0) )
1616  )>::type * = 0 )
1617 {
1618  typedef View<DT,DL,DD,DM,DS> dst_type ;
1619  typedef View<ST,SL,SD,SM,SS> src_type ;
1620 
1621  typedef typename dst_type::memory_space dst_memory_space ;
1622  typedef typename src_type::memory_space src_memory_space ;
1623  typedef typename src_type::value_type value_type ;
1624 
1625  if ( dst.ptr_on_device() != src.ptr_on_device() ) {
1626  Impl::DeepCopy< dst_memory_space , src_memory_space , ExecSpace >( exec , dst.ptr_on_device() , src.ptr_on_device() , sizeof(value_type) );
1627  }
1628 }
1629 
1630 //----------------------------------------------------------------------------
1634 template< class ExecSpace ,
1635  class DT , class DL , class DD , class DM ,
1636  class ST , class SL , class SD , class SM >
1637 inline
1638 void deep_copy( const ExecSpace & exec,
1641  typename Impl::enable_if<(
1642  // Same type and destination is not constant:
1643  Impl::is_same< typename View<DT,DL,DD,DM,Impl::ViewDefault>::value_type ,
1645  &&
1646  // Same non-zero rank:
1649  &&
1651  &&
1652  // Same layout:
1653  Impl::is_same< typename View<DT,DL,DD,DM,Impl::ViewDefault>::array_layout ,
1655  )>::type * = 0 )
1656 {
1657  typedef View<DT,DL,DD,DM,Impl::ViewDefault> dst_type ;
1658  typedef View<ST,SL,SD,SM,Impl::ViewDefault> src_type ;
1659 
1660  typedef typename dst_type::memory_space dst_memory_space ;
1661  typedef typename src_type::memory_space src_memory_space ;
1662 
1663  enum { is_contiguous = // Contiguous (e.g., non-strided, non-tiled) layout
1664  Impl::is_same< typename View<DT,DL,DD,DM,Impl::ViewDefault>::array_layout , LayoutLeft >::value ||
1665  Impl::is_same< typename View<DT,DL,DD,DM,Impl::ViewDefault>::array_layout , LayoutRight >::value };
1666 
1667  if ( dst.ptr_on_device() != src.ptr_on_device() ) {
1668 
1669  // Same shape (dimensions)
1670 
1671  const bool shapes_are_equal = dst.shape() == src.shape();
1672 
1673  if ( shapes_are_equal && is_contiguous && dst.capacity() == src.capacity() ) {
1674 
1675  // Views span equal length contiguous range.
1676  // Assuming can perform a straight memory copy over this range.
1677 
1678  const size_t nbytes = sizeof(typename dst_type::value_type) * dst.capacity();
1679 
1680  Impl::DeepCopy< dst_memory_space , src_memory_space , ExecSpace >( exec , dst.ptr_on_device() , src.ptr_on_device() , nbytes );
1681  }
1682  else {
1683  // Destination view's execution space must be able to directly access source memory space
1684  // in order for the ViewRemap functor run in the destination memory space's execution space.
1685  size_t stride[8];
1686  src.stride(stride);
1687  size_t size_stride = stride[0]*src.dimension_0();
1688  size_t size_dim = src.dimension_0();
1689  for(int i = 1; i<src.rank; i++) {
1690  if(stride[i]*src.dimension(i)>size_stride)
1691  size_stride = stride[i]*src.dimension(i);
1692  size_dim*=src.dimension(i);
1693  }
1694 
1695  if( shapes_are_equal && size_stride == size_dim) {
1696  const size_t nbytes = sizeof(typename dst_type::value_type) * dst.capacity();
1697 
1698  Impl::DeepCopy< dst_memory_space , src_memory_space , ExecSpace >( exec , dst.ptr_on_device() , src.ptr_on_device() , nbytes );
1699  } else {
1700  Impl::ViewRemap< dst_type , src_type >( dst , src );
1701  }
1702  }
1703  }
1704 }
1705 
1706 
1710 template< class ExecSpace ,
1711  class DT , class DL , class DD , class DM , class DS ,
1712  class ST , class SL , class SD , class SM , class SS >
1713 inline
1714 void deep_copy( const ExecSpace& ,
1715  const View< DT, DL, DD, DM, DS > & dst ,
1716  const View< ST, SL, SD, SM, SS > & src ,
1717  const typename Impl::enable_if<(
1718  // Same type and destination is not constant:
1719  Impl::is_same< typename View<DT,DL,DD,DM,DS>::value_type ,
1721  &&
1722  // Source memory space is accessible to destination memory space
1723  Impl::VerifyExecutionCanAccessMemorySpace< typename View<DT,DL,DD,DM,DS>::memory_space
1724  , typename View<ST,SL,SD,SM,SS>::memory_space >::value
1725  &&
1726  // Same non-zero rank
1727  ( unsigned( View<DT,DL,DD,DM,DS>::rank ) ==
1728  unsigned( View<ST,SL,SD,SM,SS>::rank ) )
1729  &&
1730  ( 0 < unsigned( View<DT,DL,DD,DM,DS>::rank ) )
1731  &&
1732  // Different layout or different specialization:
1733  ( ( ! Impl::is_same< typename View<DT,DL,DD,DM,DS>::array_layout ,
1734  typename View<ST,SL,SD,SM,SS>::array_layout >::value )
1735  ||
1736  ( ! Impl::is_same< DS , SS >::value )
1737  )
1738  )>::type * = 0 )
1739 {
1740  typedef View< DT, DL, DD, DM, DS > dst_type ;
1741  typedef View< ST, SL, SD, SM, SS > src_type ;
1742 
1743  assert_shapes_equal_dimension( dst.shape() , src.shape() );
1744 
1745  Impl::ViewRemap< dst_type , src_type >( dst , src );
1746 }
1747 
1748 }
1749 //----------------------------------------------------------------------------
1750 //----------------------------------------------------------------------------
1751 
1752 namespace Kokkos {
1753 
1754 template< class T , class L , class D , class M , class S >
1755 typename Impl::enable_if<(
1757  !Impl::is_same<L,LayoutStride>::value
1758  ), typename View<T,L,D,M,S>::HostMirror >::type
1759 inline
1760 create_mirror( const View<T,L,D,M,S> & src )
1761 {
1762  typedef View<T,L,D,M,S> view_type ;
1763  typedef typename view_type::HostMirror host_view_type ;
1764 
1765  // 'view' is managed therefore we can allocate a
1766  // compatible host_view through the ordinary constructor.
1767 
1768  std::string label = src.tracker().label();
1769  label.append("_mirror");
1770 
1771  return host_view_type( label ,
1772  src.dimension_0() ,
1773  src.dimension_1() ,
1774  src.dimension_2() ,
1775  src.dimension_3() ,
1776  src.dimension_4() ,
1777  src.dimension_5() ,
1778  src.dimension_6() ,
1779  src.dimension_7() );
1780 }
1781 
1782 template< class T , class L , class D , class M , class S >
1783 typename Impl::enable_if<(
1785  Impl::is_same<L,LayoutStride>::value
1786  ), typename View<T,L,D,M,S>::HostMirror >::type
1787 inline
1788 create_mirror( const View<T,L,D,M,S> & src )
1789 {
1790  typedef View<T,L,D,M,S> view_type ;
1791  typedef typename view_type::HostMirror host_view_type ;
1792 
1793  // 'view' is managed therefore we can allocate a
1794  // compatible host_view through the ordinary constructor.
1795 
1796  std::string label = src.tracker().label();
1797  label.append("_mirror");
1798  LayoutStride layout;
1799  src.stride(layout.stride);
1800  layout.dimension[0] = src.dimension_0();
1801  layout.dimension[1] = src.dimension_1();
1802  layout.dimension[2] = src.dimension_2();
1803  layout.dimension[3] = src.dimension_3();
1804  layout.dimension[4] = src.dimension_4();
1805  layout.dimension[5] = src.dimension_5();
1806  layout.dimension[6] = src.dimension_6();
1807  layout.dimension[7] = src.dimension_7();
1808 
1809  return host_view_type( label , layout );
1810 }
1811 template< class T , class L , class D , class M , class S >
1812 typename Impl::enable_if<(
1814  Impl::ViewAssignable< typename View<T,L,D,M,S>::HostMirror , View<T,L,D,M,S> >::value
1815  ), typename View<T,L,D,M,S>::HostMirror >::type
1816 inline
1817 create_mirror_view( const View<T,L,D,M,S> & src )
1818 {
1819  return src ;
1820 }
1821 
1822 template< class T , class L , class D , class M , class S >
1823 typename Impl::enable_if<(
1825  ! Impl::ViewAssignable< typename View<T,L,D,M,S>::HostMirror , View<T,L,D,M,S> >::value
1826  ), typename View<T,L,D,M,S>::HostMirror >::type
1827 inline
1828 create_mirror_view( const View<T,L,D,M,S> & src )
1829 {
1830  return create_mirror( src );
1831 }
1832 
1833 //----------------------------------------------------------------------------
1834 
1836 template< class T , class L , class D , class M , class S >
1837 inline
1839  const typename Impl::enable_if< ViewTraits<T,L,D,M>::is_managed , size_t >::type n0 ,
1840  const size_t n1 = 0 ,
1841  const size_t n2 = 0 ,
1842  const size_t n3 = 0 ,
1843  const size_t n4 = 0 ,
1844  const size_t n5 = 0 ,
1845  const size_t n6 = 0 ,
1846  const size_t n7 = 0 )
1847 {
1848  typedef View<T,L,D,M,S> view_type ;
1849 
1850  const std::string label = v.tracker().label();
1851 
1852  view_type v_resized( label, n0, n1, n2, n3, n4, n5, n6, n7 );
1853 
1854  Impl::ViewRemap< view_type , view_type >( v_resized , v );
1855 
1856  v = v_resized ;
1857 }
1858 
1860 template< class T , class L , class D , class M , class S >
1861 inline
1863  const typename Impl::enable_if< ViewTraits<T,L,D,M>::is_managed , size_t >::type n0 ,
1864  const size_t n1 = 0 ,
1865  const size_t n2 = 0 ,
1866  const size_t n3 = 0 ,
1867  const size_t n4 = 0 ,
1868  const size_t n5 = 0 ,
1869  const size_t n6 = 0 ,
1870  const size_t n7 = 0 )
1871 {
1872  typedef View<T,L,D,M,S> view_type ;
1873 
1874  // Query the current label and reuse it.
1875  const std::string label = v.tracker().label();
1876 
1877  v = view_type(); // deallocate first, if the only view to memory.
1878  v = view_type( label, n0, n1, n2, n3, n4, n5, n6, n7 );
1879 }
1880 
1881 } // namespace Kokkos
1882 
1883 //----------------------------------------------------------------------------
1884 //----------------------------------------------------------------------------
1885 
1886 namespace Kokkos {
1887 
1888 template< class D , class A1 , class A2 , class A3 , class S ,
1889  class ArgType0 , class ArgType1 , class ArgType2 , class ArgType3 ,
1890  class ArgType4 , class ArgType5 , class ArgType6 , class ArgType7 >
1891 KOKKOS_INLINE_FUNCTION
1892 typename Impl::ViewSubview< View<D,A1,A2,A3,S>
1893  , ArgType0 , ArgType1 , ArgType2 , ArgType3
1894  , ArgType4 , ArgType5 , ArgType6 , ArgType7
1895  >::type
1896 subview( const View<D,A1,A2,A3,S> & src ,
1897  const ArgType0 & arg0 ,
1898  const ArgType1 & arg1 ,
1899  const ArgType2 & arg2 ,
1900  const ArgType3 & arg3 ,
1901  const ArgType4 & arg4 ,
1902  const ArgType5 & arg5 ,
1903  const ArgType6 & arg6 ,
1904  const ArgType7 & arg7 )
1905 {
1906  typedef typename
1907  Impl::ViewSubview< View<D,A1,A2,A3,S>
1908  , ArgType0 , ArgType1 , ArgType2 , ArgType3
1909  , ArgType4 , ArgType5 , ArgType6 , ArgType7
1910  >::type
1911  DstViewType ;
1912 
1913  return DstViewType( src, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 );
1914 }
1915 
1916 template< class D , class A1 , class A2 , class A3 , class S ,
1917  class ArgType0 , class ArgType1 , class ArgType2 , class ArgType3 ,
1918  class ArgType4 , class ArgType5 , class ArgType6 >
1919 KOKKOS_INLINE_FUNCTION
1920 typename Impl::ViewSubview< View<D,A1,A2,A3,S>
1921  , ArgType0 , ArgType1 , ArgType2 , ArgType3
1922  , ArgType4 , ArgType5 , ArgType6 , void
1923  >::type
1924 subview( const View<D,A1,A2,A3,S> & src ,
1925  const ArgType0 & arg0 ,
1926  const ArgType1 & arg1 ,
1927  const ArgType2 & arg2 ,
1928  const ArgType3 & arg3 ,
1929  const ArgType4 & arg4 ,
1930  const ArgType5 & arg5 ,
1931  const ArgType6 & arg6 )
1932 {
1933  typedef typename
1934  Impl::ViewSubview< View<D,A1,A2,A3,S>
1935  , ArgType0 , ArgType1 , ArgType2 , ArgType3
1936  , ArgType4 , ArgType5 , ArgType6 , void
1937  >::type
1938  DstViewType ;
1939 
1940  return DstViewType( src, arg0, arg1, arg2, arg3, arg4, arg5, arg6 );
1941 }
1942 
1943 template< class D , class A1 , class A2 , class A3 , class S ,
1944  class ArgType0 , class ArgType1 , class ArgType2 , class ArgType3 ,
1945  class ArgType4 , class ArgType5 >
1946 KOKKOS_INLINE_FUNCTION
1947 typename Impl::ViewSubview< View<D,A1,A2,A3,S>
1948  , ArgType0 , ArgType1 , ArgType2 , ArgType3
1949  , ArgType4 , ArgType5 , void , void
1950  >::type
1951 subview( const View<D,A1,A2,A3,S> & src ,
1952  const ArgType0 & arg0 ,
1953  const ArgType1 & arg1 ,
1954  const ArgType2 & arg2 ,
1955  const ArgType3 & arg3 ,
1956  const ArgType4 & arg4 ,
1957  const ArgType5 & arg5 )
1958 {
1959  typedef typename
1960  Impl::ViewSubview< View<D,A1,A2,A3,S>
1961  , ArgType0 , ArgType1 , ArgType2 , ArgType3
1962  , ArgType4 , ArgType5 , void , void
1963  >::type
1964  DstViewType ;
1965 
1966  return DstViewType( src, arg0, arg1, arg2, arg3, arg4, arg5 );
1967 }
1968 
1969 template< class D , class A1 , class A2 , class A3 , class S ,
1970  class ArgType0 , class ArgType1 , class ArgType2 , class ArgType3 ,
1971  class ArgType4 >
1972 KOKKOS_INLINE_FUNCTION
1973 typename Impl::ViewSubview< View<D,A1,A2,A3,S>
1974  , ArgType0 , ArgType1 , ArgType2 , ArgType3
1975  , ArgType4 , void , void , void
1976  >::type
1977 subview( const View<D,A1,A2,A3,S> & src ,
1978  const ArgType0 & arg0 ,
1979  const ArgType1 & arg1 ,
1980  const ArgType2 & arg2 ,
1981  const ArgType3 & arg3 ,
1982  const ArgType4 & arg4 )
1983 {
1984  typedef typename
1985  Impl::ViewSubview< View<D,A1,A2,A3,S>
1986  , ArgType0 , ArgType1 , ArgType2 , ArgType3
1987  , ArgType4 , void , void , void
1988  >::type
1989  DstViewType ;
1990 
1991  return DstViewType( src, arg0, arg1, arg2, arg3, arg4 );
1992 }
1993 
1994 template< class D , class A1 , class A2 , class A3 , class S ,
1995  class ArgType0 , class ArgType1 , class ArgType2 , class ArgType3 >
1996 KOKKOS_INLINE_FUNCTION
1997 typename Impl::ViewSubview< View<D,A1,A2,A3,S>
1998  , ArgType0 , ArgType1 , ArgType2 , ArgType3
1999  , void , void , void , void
2000  >::type
2001 subview( const View<D,A1,A2,A3,S> & src ,
2002  const ArgType0 & arg0 ,
2003  const ArgType1 & arg1 ,
2004  const ArgType2 & arg2 ,
2005  const ArgType3 & arg3 )
2006 {
2007  typedef typename
2008  Impl::ViewSubview< View<D,A1,A2,A3,S>
2009  , ArgType0 , ArgType1 , ArgType2 , ArgType3
2010  , void , void , void , void
2011  >::type
2012  DstViewType ;
2013 
2014  return DstViewType( src, arg0, arg1, arg2, arg3 );
2015 }
2016 
2017 template< class D , class A1 , class A2 , class A3 , class S ,
2018  class ArgType0 , class ArgType1 , class ArgType2 >
2019 KOKKOS_INLINE_FUNCTION
2020 typename Impl::ViewSubview< View<D,A1,A2,A3,S>
2021  , ArgType0 , ArgType1 , ArgType2 , void
2022  , void , void , void , void
2023  >::type
2024 subview( const View<D,A1,A2,A3,S> & src ,
2025  const ArgType0 & arg0 ,
2026  const ArgType1 & arg1 ,
2027  const ArgType2 & arg2 )
2028 {
2029  typedef typename
2030  Impl::ViewSubview< View<D,A1,A2,A3,S>
2031  , ArgType0 , ArgType1 , ArgType2 , void
2032  , void , void , void , void
2033  >::type
2034  DstViewType ;
2035 
2036  return DstViewType( src, arg0, arg1, arg2 );
2037 }
2038 
2039 template< class D , class A1 , class A2 , class A3 , class S ,
2040  class ArgType0 , class ArgType1 >
2041 KOKKOS_INLINE_FUNCTION
2042 typename Impl::ViewSubview< View<D,A1,A2,A3,S>
2043  , ArgType0 , ArgType1 , void , void
2044  , void , void , void , void
2045  >::type
2046 subview( const View<D,A1,A2,A3,S> & src ,
2047  const ArgType0 & arg0 ,
2048  const ArgType1 & arg1 )
2049 {
2050  typedef typename
2051  Impl::ViewSubview< View<D,A1,A2,A3,S>
2052  , ArgType0 , ArgType1 , void , void
2053  , void , void , void , void
2054  >::type
2055  DstViewType ;
2056 
2057  return DstViewType( src, arg0, arg1 );
2058 }
2059 
2060 template< class D , class A1 , class A2 , class A3 , class S ,
2061  class ArgType0 >
2062 KOKKOS_INLINE_FUNCTION
2063 typename Impl::ViewSubview< View<D,A1,A2,A3,S>
2064  , ArgType0 , void , void , void
2065  , void , void , void , void
2066  >::type
2067 subview( const View<D,A1,A2,A3,S> & src ,
2068  const ArgType0 & arg0 )
2069 {
2070  typedef typename
2071  Impl::ViewSubview< View<D,A1,A2,A3,S>
2072  , ArgType0 , void , void , void
2073  , void , void , void , void
2074  >::type
2075  DstViewType ;
2076 
2077  return DstViewType( src, arg0 );
2078 }
2079 
2080 } // namespace Kokkos
2081 
2082 //----------------------------------------------------------------------------
2083 //----------------------------------------------------------------------------
2084 
2085 #include <impl/Kokkos_ViewDefault.hpp>
2086 #include <impl/Kokkos_Atomic_View.hpp>
2087 
2088 #include <impl/Kokkos_ViewOffset.hpp>
2089 #include <impl/Kokkos_ViewSupport.hpp>
2090 
2091 namespace Kokkos {
2093 struct ALL { KOKKOS_INLINE_FUNCTION ALL(){} };
2094 }
2095 
2096 //----------------------------------------------------------------------------
2097 //----------------------------------------------------------------------------
2098 
2099 #include <KokkosExp_View.hpp>
2100 
2101 #else
2102 
2103 // Must define before includng <impl/Kokkos_ViewOffset.hpp>
2104 namespace Kokkos {
2105 namespace Experimental {
2106 namespace Impl {
2107 struct ALL_t ;
2108 }
2109 }
2110 using ALL = Experimental::Impl::ALL_t ;
2111 }
2112 
2113 #include <impl/Kokkos_ViewOffset.hpp>
2114 #include <impl/Kokkos_ViewSupport.hpp>
2115 
2116 #include <KokkosExp_View.hpp>
2117 
2118 #endif /* #if defined( KOKKOS_USING_EXPERIMENTAL_VIEW ) */
2119 
2120 //----------------------------------------------------------------------------
2121 //----------------------------------------------------------------------------
2122 
2123 #endif
2124 
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.
Memory layout tag indicating left-to-right (Fortran scheme) striding of multi-indices.
KOKKOS_INLINE_FUNCTION complex< RealType > operator*(const complex< RealType > &x, const complex< RealType > &y)
Binary * operator for complex.
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 space for main process and CPU execution spaces.
Memory layout tag indicating right-to-left (C or lexigraphical scheme) striding of multi-indices...
ReturnType
View specialization mapping of view traits to a specialization tag.
Definition: Kokkos_View.hpp:79
Traits class for accessing attributes of a View.
KOKKOS_INLINE_FUNCTION bool operator==(const complex< RealType > &x, const complex< RealType > &y)
Equality operator for two complex numbers.
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.
Enable view parentheses operator for match of layout and integral arguments. If correct rank define t...
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.