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