44 #ifndef KOKKOS_VIEW_HPP 45 #define KOKKOS_VIEW_HPP 47 #include <type_traits> 50 #include <initializer_list> 52 #include <Kokkos_Core_fwd.hpp> 53 #include <Kokkos_HostSpace.hpp> 54 #include <Kokkos_MemoryTraits.hpp> 55 #include <Kokkos_ExecPolicy.hpp> 64 template<
class DataType >
65 struct ViewArrayAnalysis ;
67 template<
class DataType ,
class ArrayLayout
68 ,
typename ValueType =
69 typename ViewArrayAnalysis< DataType >::non_const_value_type
71 struct ViewDataAnalysis ;
73 template< class ,
class ... >
74 class ViewMapping {
public:
enum { is_assignable =
false }; };
83 using Kokkos::Experimental::Impl::ViewMapping ;
84 using Kokkos::Experimental::Impl::ViewDataAnalysis ;
111 template<
class DataType ,
class ... Properties >
117 typedef void execution_space ;
118 typedef void memory_space ;
119 typedef void HostMirrorSpace ;
120 typedef void array_layout ;
121 typedef void memory_traits ;
124 template<
class ... Prop >
128 typedef typename ViewTraits<void,Prop...>::execution_space execution_space ;
129 typedef typename ViewTraits<void,Prop...>::memory_space memory_space ;
130 typedef typename ViewTraits<void,Prop...>::HostMirrorSpace HostMirrorSpace ;
131 typedef typename ViewTraits<void,Prop...>::array_layout array_layout ;
132 typedef typename ViewTraits<void,Prop...>::memory_traits memory_traits ;
135 template<
class ArrayLayout ,
class ... Prop >
136 struct ViewTraits< typename std::enable_if< Kokkos::Impl::is_array_layout<ArrayLayout>::value >::type , ArrayLayout , Prop ... >
140 typedef typename ViewTraits<void,Prop...>::execution_space execution_space ;
141 typedef typename ViewTraits<void,Prop...>::memory_space memory_space ;
142 typedef typename ViewTraits<void,Prop...>::HostMirrorSpace HostMirrorSpace ;
143 typedef ArrayLayout array_layout ;
144 typedef typename ViewTraits<void,Prop...>::memory_traits memory_traits ;
147 template<
class Space ,
class ... Prop >
148 struct ViewTraits< typename std::enable_if< Kokkos::Impl::is_space<Space>::value >::type , Space , Prop ... >
152 static_assert( std::is_same<
typename ViewTraits<void,Prop...>::execution_space ,
void >::value &&
153 std::is_same<
typename ViewTraits<void,Prop...>::memory_space ,
void >::value &&
154 std::is_same<
typename ViewTraits<void,Prop...>::HostMirrorSpace ,
void >::value &&
155 std::is_same<
typename ViewTraits<void,Prop...>::array_layout ,
void >::value
156 ,
"Only one View Execution or Memory Space template argument" );
158 typedef typename Space::execution_space execution_space ;
159 typedef typename Space::memory_space memory_space ;
160 typedef typename Kokkos::Impl::HostMirror< Space >::Space HostMirrorSpace ;
161 typedef typename execution_space::array_layout array_layout ;
162 typedef typename ViewTraits<void,Prop...>::memory_traits memory_traits ;
165 template<
class MemoryTraits ,
class ... Prop >
166 struct ViewTraits< typename std::enable_if< Kokkos::Impl::is_memory_traits<MemoryTraits>::value >::type , MemoryTraits , Prop ... >
170 static_assert( std::is_same<
typename ViewTraits<void,Prop...>::execution_space ,
void >::value &&
171 std::is_same<
typename ViewTraits<void,Prop...>::memory_space ,
void >::value &&
172 std::is_same<
typename ViewTraits<void,Prop...>::array_layout ,
void >::value &&
173 std::is_same<
typename ViewTraits<void,Prop...>::memory_traits ,
void >::value
174 ,
"MemoryTrait is the final optional template argument for a View" );
176 typedef void execution_space ;
177 typedef void memory_space ;
178 typedef void HostMirrorSpace ;
179 typedef void array_layout ;
180 typedef MemoryTraits memory_traits ;
184 template<
class DataType ,
class ... Properties >
192 std::conditional< ! std::is_same< typename prop::execution_space , void >::value
193 ,
typename prop::execution_space
194 , Kokkos::DefaultExecutionSpace
199 std::conditional< ! std::is_same< typename prop::memory_space , void >::value
200 ,
typename prop::memory_space
201 ,
typename ExecutionSpace::memory_space
206 std::conditional< ! std::is_same< typename prop::array_layout , void >::value
207 ,
typename prop::array_layout
208 ,
typename ExecutionSpace::array_layout
214 < ! std::is_same< typename prop::HostMirrorSpace , void >::value
215 ,
typename prop::HostMirrorSpace
216 ,
typename Kokkos::Impl::HostMirror< ExecutionSpace >::Space
221 std::conditional< ! std::is_same< typename prop::memory_traits , void >::value
222 ,
typename prop::memory_traits
223 ,
typename Kokkos::MemoryManaged
229 typedef Kokkos::Impl::ViewDataAnalysis< DataType , ArrayLayout > data_analysis ;
236 typedef typename data_analysis::type data_type ;
237 typedef typename data_analysis::const_type const_data_type ;
238 typedef typename data_analysis::non_const_type non_const_data_type ;
243 typedef typename data_analysis::scalar_array_type scalar_array_type ;
244 typedef typename data_analysis::const_scalar_array_type const_scalar_array_type ;
245 typedef typename data_analysis::non_const_scalar_array_type non_const_scalar_array_type ;
250 typedef typename data_analysis::value_type value_type ;
251 typedef typename data_analysis::const_value_type const_value_type ;
252 typedef typename data_analysis::non_const_value_type non_const_value_type ;
257 typedef ArrayLayout array_layout ;
258 typedef typename data_analysis::dimension dimension ;
259 typedef typename data_analysis::specialize specialize ;
261 enum {
rank = dimension::rank };
262 enum { rank_dynamic = dimension::rank_dynamic };
267 typedef ExecutionSpace execution_space ;
268 typedef MemorySpace memory_space ;
270 typedef MemoryTraits memory_traits ;
271 typedef HostMirrorSpace host_mirror_space ;
273 typedef typename MemorySpace::size_type size_type ;
275 enum { is_hostspace = std::is_same< MemorySpace , HostSpace >::value };
276 enum { is_managed = MemoryTraits::Unmanaged == 0 };
277 enum { is_random_access = MemoryTraits::RandomAccess == 1 };
364 template<
class DataType ,
class ... Properties >
372 #include <impl/Kokkos_ViewMapping.hpp> 373 #include <impl/Kokkos_ViewArray.hpp> 382 constexpr Kokkos::Impl::ALL_t
383 ALL = Kokkos::Impl::ALL_t();
385 constexpr Kokkos::Impl::WithoutInitializing_t
386 WithoutInitializing = Kokkos::Impl::WithoutInitializing_t();
388 constexpr Kokkos::Impl::AllowPadding_t
389 AllowPadding = Kokkos::Impl::AllowPadding_t();
402 template<
class ... Args >
404 Impl::ViewCtorProp< typename Impl::ViewCtorProp< void , Args >::type ... >
408 Impl::ViewCtorProp< typename Impl::ViewCtorProp< void , Args >::type ... >
411 static_assert( ! return_type::has_pointer
412 ,
"Cannot give pointer-to-memory for view allocation" );
414 return return_type( args... );
417 template<
class ... Args >
419 Impl::ViewCtorProp< typename Impl::ViewCtorProp< void , Args >::type ... >
420 view_wrap( Args
const & ... args )
423 Impl::ViewCtorProp< typename Impl::ViewCtorProp< void , Args >::type ... >
426 static_assert( ! return_type::has_memory_space &&
427 ! return_type::has_execution_space &&
428 ! return_type::has_label &&
429 return_type::has_pointer
430 ,
"Must only give pointer-to-memory for view wrapping" );
432 return return_type( args... );
442 template<
class DataType ,
class ... Properties >
445 template<
class >
struct is_view :
public std::false_type {};
447 template<
class D,
class ... P >
448 struct is_view< View<D,P...> > :
public std::true_type {};
450 template<
class D,
class ... P >
451 struct is_view< const View<D,P...> > :
public std::true_type {};
453 template<
class DataType ,
class ... Properties >
454 class View :
public ViewTraits< DataType , Properties ... > {
457 template< class ,
class ... >
friend class View ;
458 template< class ,
class ... >
friend class Kokkos::Impl::ViewMapping ;
462 typedef ViewTraits< DataType , Properties ... > traits ;
466 typedef Kokkos::Impl::ViewMapping< traits , void > map_type ;
467 typedef Kokkos::Impl::SharedAllocationTracker track_type ;
476 typedef View<
typename traits::scalar_array_type ,
477 typename traits::array_layout ,
478 typename traits::device_type ,
479 typename traits::memory_traits >
483 typedef View<
typename traits::const_data_type ,
484 typename traits::array_layout ,
485 typename traits::device_type ,
486 typename traits::memory_traits >
490 typedef View<
typename traits::non_const_data_type ,
491 typename traits::array_layout ,
492 typename traits::device_type ,
493 typename traits::memory_traits >
497 typedef View<
typename traits::non_const_data_type ,
498 typename traits::array_layout ,
499 typename traits::host_mirror_space >
505 enum { Rank = map_type::Rank };
513 template<
typename iType >
514 KOKKOS_INLINE_FUNCTION constexpr
515 typename std::enable_if< std::is_integral<iType>::value ,
size_t >::type
517 {
return m_map.extent(r); }
519 template<
typename iType >
520 KOKKOS_INLINE_FUNCTION constexpr
521 typename std::enable_if< std::is_integral<iType>::value ,
int >::type
522 extent_int(
const iType & r )
const 523 {
return static_cast<int>(m_map.extent(r)); }
525 KOKKOS_INLINE_FUNCTION constexpr
526 typename traits::array_layout layout()
const 527 {
return m_map.layout(); }
534 template<
typename iType >
535 KOKKOS_INLINE_FUNCTION constexpr
536 typename std::enable_if< std::is_integral<iType>::value ,
size_t >::type
537 dimension(
const iType & r )
const {
return extent( r ); }
539 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_0()
const {
return m_map.dimension_0(); }
540 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_1()
const {
return m_map.dimension_1(); }
541 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_2()
const {
return m_map.dimension_2(); }
542 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_3()
const {
return m_map.dimension_3(); }
543 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_4()
const {
return m_map.dimension_4(); }
544 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_5()
const {
return m_map.dimension_5(); }
545 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_6()
const {
return m_map.dimension_6(); }
546 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_7()
const {
return m_map.dimension_7(); }
550 KOKKOS_INLINE_FUNCTION constexpr
size_t size()
const {
return m_map.dimension_0() *
551 m_map.dimension_1() *
552 m_map.dimension_2() *
553 m_map.dimension_3() *
554 m_map.dimension_4() *
555 m_map.dimension_5() *
556 m_map.dimension_6() *
557 m_map.dimension_7(); }
559 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_0()
const {
return m_map.stride_0(); }
560 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_1()
const {
return m_map.stride_1(); }
561 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_2()
const {
return m_map.stride_2(); }
562 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_3()
const {
return m_map.stride_3(); }
563 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_4()
const {
return m_map.stride_4(); }
564 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_5()
const {
return m_map.stride_5(); }
565 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_6()
const {
return m_map.stride_6(); }
566 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_7()
const {
return m_map.stride_7(); }
568 template<
typename iType >
569 KOKKOS_INLINE_FUNCTION
void stride( iType *
const s )
const { m_map.stride(s); }
574 typedef typename map_type::reference_type reference_type ;
575 typedef typename map_type::pointer_type pointer_type ;
577 enum { reference_type_is_lvalue_reference = std::is_lvalue_reference< reference_type >::value };
579 KOKKOS_INLINE_FUNCTION constexpr
size_t span()
const {
return m_map.span(); }
581 KOKKOS_INLINE_FUNCTION constexpr
size_t capacity()
const {
return m_map.span(); }
582 KOKKOS_INLINE_FUNCTION constexpr
bool span_is_contiguous()
const {
return m_map.span_is_contiguous(); }
583 KOKKOS_INLINE_FUNCTION constexpr pointer_type data()
const {
return m_map.data(); }
586 KOKKOS_INLINE_FUNCTION constexpr
bool is_contiguous()
const {
return m_map.span_is_contiguous(); }
588 KOKKOS_INLINE_FUNCTION constexpr pointer_type ptr_on_device()
const {
return m_map.data(); }
593 KOKKOS_INLINE_FUNCTION
594 const Kokkos::Impl::ViewMapping< traits , void > &
595 implementation_map()
const {
return m_map ; }
602 is_layout_left = std::is_same<
typename traits::array_layout
605 is_layout_right = std::is_same<
typename traits::array_layout
608 is_layout_stride = std::is_same<
typename traits::array_layout
612 std::is_same< typename traits::specialize , void >::value &&
613 ( is_layout_left || is_layout_right || is_layout_stride )
616 template< class Space , bool = Kokkos::Impl::MemorySpaceAccess< Space , typename traits::memory_space >::accessible >
struct verify_space
617 { KOKKOS_FORCEINLINE_FUNCTION
static void check() {} };
619 template<
class Space >
struct verify_space<Space,false>
620 { KOKKOS_FORCEINLINE_FUNCTION
static void check()
621 { Kokkos::abort(
"Kokkos::View ERROR: attempt to access inaccessible memory space"); };
624 #if defined( KOKKOS_ENABLE_DEBUG_BOUNDS_CHECK ) 626 #define KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( ARG ) \ 627 View::template verify_space< Kokkos::Impl::ActiveExecutionMemorySpace >::check(); \ 628 Kokkos::Impl::view_verify_operator_bounds< typename traits::memory_space > ARG ; 632 #define KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( ARG ) \ 633 View::template verify_space< Kokkos::Impl::ActiveExecutionMemorySpace >::check(); 642 template<
class ... Args >
643 KOKKOS_FORCEINLINE_FUNCTION
644 typename std::enable_if<( Kokkos::Impl::are_integral<Args...>::value
646 ), reference_type >::type
647 operator()( Args ... args )
const 649 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,args...) )
650 return m_map.reference();
656 template<
typename I0
658 KOKKOS_FORCEINLINE_FUNCTION
659 typename std::enable_if<
660 ( Kokkos::Impl::are_integral<I0,Args...>::value
663 ), reference_type >::type
664 operator()(
const I0 & i0
665 , Args ... args )
const 667 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,args...) )
668 return m_map.reference(i0);
671 template<
typename I0
673 KOKKOS_FORCEINLINE_FUNCTION
674 typename std::enable_if<
675 ( Kokkos::Impl::are_integral<I0,Args...>::value
678 && ! is_layout_stride
679 ), reference_type >::type
680 operator()(
const I0 & i0
681 , Args ... args )
const 683 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,args...) )
684 return m_map.m_handle[ i0 ];
687 template<
typename I0
689 KOKKOS_FORCEINLINE_FUNCTION
690 typename std::enable_if<
691 ( Kokkos::Impl::are_integral<I0,Args...>::value
695 ), reference_type >::type
696 operator()(
const I0 & i0
697 , Args ... args )
const 699 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,args...) )
700 return m_map.m_handle[ m_map.m_offset.m_stride.S0 * i0 ];
706 template<
typename I0 >
707 KOKKOS_FORCEINLINE_FUNCTION
708 typename std::enable_if<
709 ( Kokkos::Impl::are_integral<I0>::value
712 ), reference_type >::type
713 operator[](
const I0 & i0 )
const 715 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0) )
716 return m_map.reference(i0);
719 template<
typename I0 >
720 KOKKOS_FORCEINLINE_FUNCTION
721 typename std::enable_if<
722 ( Kokkos::Impl::are_integral<I0>::value
725 && ! is_layout_stride
726 ), reference_type >::type
727 operator[](
const I0 & i0 )
const 729 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0) )
730 return m_map.m_handle[ i0 ];
733 template<
typename I0 >
734 KOKKOS_FORCEINLINE_FUNCTION
735 typename std::enable_if<
736 ( Kokkos::Impl::are_integral<I0>::value
740 ), reference_type >::type
741 operator[](
const I0 & i0 )
const 743 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0) )
744 return m_map.m_handle[ m_map.m_offset.m_stride.S0 * i0 ];
750 template<
typename I0 ,
typename I1
752 KOKKOS_FORCEINLINE_FUNCTION
753 typename std::enable_if<
754 ( Kokkos::Impl::are_integral<I0,I1,Args...>::value
757 ), reference_type >::type
758 operator()(
const I0 & i0 ,
const I1 & i1
759 , Args ... args )
const 761 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,args...) )
762 return m_map.reference(i0,i1);
765 template<
typename I0 ,
typename I1
767 KOKKOS_FORCEINLINE_FUNCTION
768 typename std::enable_if<
769 ( Kokkos::Impl::are_integral<I0,I1,Args...>::value
772 && is_layout_left && ( traits::rank_dynamic == 0 )
773 ), reference_type >::type
774 operator()(
const I0 & i0 ,
const I1 & i1
775 , Args ... args )
const 777 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,args...) )
778 return m_map.m_handle[ i0 + m_map.m_offset.m_dim.N0 * i1 ];
781 template<
typename I0 ,
typename I1
783 KOKKOS_FORCEINLINE_FUNCTION
784 typename std::enable_if<
785 ( Kokkos::Impl::are_integral<I0,I1,Args...>::value
788 && is_layout_left && ( traits::rank_dynamic != 0 )
789 ), reference_type >::type
790 operator()(
const I0 & i0 ,
const I1 & i1
791 , Args ... args )
const 793 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,args...) )
794 return m_map.m_handle[ i0 + m_map.m_offset.m_stride * i1 ];
797 template<
typename I0 ,
typename I1
799 KOKKOS_FORCEINLINE_FUNCTION
800 typename std::enable_if<
801 ( Kokkos::Impl::are_integral<I0,I1,Args...>::value
804 && is_layout_right && ( traits::rank_dynamic == 0 )
805 ), reference_type >::type
806 operator()(
const I0 & i0 ,
const I1 & i1
807 , Args ... args )
const 809 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,args...) )
810 return m_map.m_handle[ i1 + m_map.m_offset.m_dim.N1 * i0 ];
813 template<
typename I0 ,
typename I1
815 KOKKOS_FORCEINLINE_FUNCTION
816 typename std::enable_if<
817 ( Kokkos::Impl::are_integral<I0,I1,Args...>::value
820 && is_layout_right && ( traits::rank_dynamic != 0 )
821 ), reference_type >::type
822 operator()(
const I0 & i0 ,
const I1 & i1
823 , Args ... args )
const 825 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,args...) )
826 return m_map.m_handle[ i1 + m_map.m_offset.m_stride * i0 ];
829 template<
typename I0 ,
typename I1
831 KOKKOS_FORCEINLINE_FUNCTION
832 typename std::enable_if<
833 ( Kokkos::Impl::are_integral<I0,I1,Args...>::value
837 ), reference_type >::type
838 operator()(
const I0 & i0 ,
const I1 & i1
839 , Args ... args )
const 841 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,args...) )
842 return m_map.m_handle[ i0 * m_map.m_offset.m_stride.S0 +
843 i1 * m_map.m_offset.m_stride.S1 ];
849 template<
typename I0 ,
typename I1 ,
typename I2
851 KOKKOS_FORCEINLINE_FUNCTION
852 typename std::enable_if<
853 ( Kokkos::Impl::are_integral<I0,I1,I2,Args...>::value
856 ), reference_type >::type
857 operator()(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2
858 , Args ... args )
const 860 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,i2,args...) )
861 return m_map.m_handle[ m_map.m_offset(i0,i1,i2) ];
864 template<
typename I0 ,
typename I1 ,
typename I2
866 KOKKOS_FORCEINLINE_FUNCTION
867 typename std::enable_if<
868 ( Kokkos::Impl::are_integral<I0,I1,I2,Args...>::value
871 ), reference_type >::type
872 operator()(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2
873 , Args ... args )
const 875 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,i2,args...) )
876 return m_map.reference(i0,i1,i2);
882 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
884 KOKKOS_FORCEINLINE_FUNCTION
885 typename std::enable_if<
886 ( Kokkos::Impl::are_integral<I0,I1,I2,I3,Args...>::value
889 ), reference_type >::type
890 operator()(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
891 , Args ... args )
const 893 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,i2,i3,args...) )
894 return m_map.m_handle[ m_map.m_offset(i0,i1,i2,i3) ];
897 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
899 KOKKOS_FORCEINLINE_FUNCTION
900 typename std::enable_if<
901 ( Kokkos::Impl::are_integral<I0,I1,I2,I3,Args...>::value
904 ), reference_type >::type
905 operator()(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
906 , Args ... args )
const 908 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,i2,i3,args...) )
909 return m_map.reference(i0,i1,i2,i3);
915 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
918 KOKKOS_FORCEINLINE_FUNCTION
919 typename std::enable_if<
920 ( Kokkos::Impl::are_integral<I0,I1,I2,I3,I4,Args...>::value
923 ), reference_type >::type
924 operator()(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
926 , Args ... args )
const 928 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,i2,i3,i4,args...) )
929 return m_map.m_handle[ m_map.m_offset(i0,i1,i2,i3,i4) ];
932 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
935 KOKKOS_FORCEINLINE_FUNCTION
936 typename std::enable_if<
937 ( Kokkos::Impl::are_integral<I0,I1,I2,I3,I4,Args...>::value
940 ), reference_type >::type
941 operator()(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
943 , Args ... args )
const 945 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,i2,i3,i4,args...) )
946 return m_map.reference(i0,i1,i2,i3,i4);
952 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
953 ,
typename I4 ,
typename I5
955 KOKKOS_FORCEINLINE_FUNCTION
956 typename std::enable_if<
957 ( Kokkos::Impl::are_integral<I0,I1,I2,I3,I4,I5,Args...>::value
960 ), reference_type >::type
961 operator()(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
962 ,
const I4 & i4 ,
const I5 & i5
963 , Args ... args )
const 965 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,i2,i3,i4,i5,args...) )
966 return m_map.m_handle[ m_map.m_offset(i0,i1,i2,i3,i4,i5) ];
969 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
970 ,
typename I4 ,
typename I5
972 KOKKOS_FORCEINLINE_FUNCTION
973 typename std::enable_if<
974 ( Kokkos::Impl::are_integral<I0,I1,I2,I3,I4,I5,Args...>::value
977 ), reference_type >::type
978 operator()(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
979 ,
const I4 & i4 ,
const I5 & i5
980 , Args ... args )
const 982 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,i2,i3,i4,i5,args...) )
983 return m_map.reference(i0,i1,i2,i3,i4,i5);
989 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
990 ,
typename I4 ,
typename I5 ,
typename I6
992 KOKKOS_FORCEINLINE_FUNCTION
993 typename std::enable_if<
994 ( Kokkos::Impl::are_integral<I0,I1,I2,I3,I4,I5,I6,Args...>::value
997 ), reference_type >::type
998 operator()(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
999 ,
const I4 & i4 ,
const I5 & i5 ,
const I6 & i6
1000 , Args ... args )
const 1002 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,i2,i3,i4,i5,i6,args...) )
1003 return m_map.m_handle[ m_map.m_offset(i0,i1,i2,i3,i4,i5,i6) ];
1006 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
1007 ,
typename I4 ,
typename I5 ,
typename I6
1009 KOKKOS_FORCEINLINE_FUNCTION
1010 typename std::enable_if<
1011 ( Kokkos::Impl::are_integral<I0,I1,I2,I3,I4,I5,I6,Args...>::value
1014 ), reference_type >::type
1015 operator()(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
1016 ,
const I4 & i4 ,
const I5 & i5 ,
const I6 & i6
1017 , Args ... args )
const 1019 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,i2,i3,i4,i5,i6,args...) )
1020 return m_map.reference(i0,i1,i2,i3,i4,i5,i6);
1026 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
1027 ,
typename I4 ,
typename I5 ,
typename I6 ,
typename I7
1029 KOKKOS_FORCEINLINE_FUNCTION
1030 typename std::enable_if<
1031 ( Kokkos::Impl::are_integral<I0,I1,I2,I3,I4,I5,I6,I7,Args...>::value
1034 ), reference_type >::type
1035 operator()(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
1036 ,
const I4 & i4 ,
const I5 & i5 ,
const I6 & i6 ,
const I7 & i7
1037 , Args ... args )
const 1039 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,i2,i3,i4,i5,i6,i7,args...) )
1040 return m_map.m_handle[ m_map.m_offset(i0,i1,i2,i3,i4,i5,i6,i7) ];
1043 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
1044 ,
typename I4 ,
typename I5 ,
typename I6 ,
typename I7
1046 KOKKOS_FORCEINLINE_FUNCTION
1047 typename std::enable_if<
1048 ( Kokkos::Impl::are_integral<I0,I1,I2,I3,I4,I5,I6,I7,Args...>::value
1051 ), reference_type >::type
1052 operator()(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
1053 ,
const I4 & i4 ,
const I5 & i5 ,
const I6 & i6 ,
const I7 & i7
1054 , Args ... args )
const 1056 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,i2,i3,i4,i5,i6,i7,args...) )
1057 return m_map.reference(i0,i1,i2,i3,i4,i5,i6,i7);
1060 #undef KOKKOS_IMPL_VIEW_OPERATOR_VERIFY 1065 KOKKOS_INLINE_FUNCTION
1068 KOKKOS_INLINE_FUNCTION
1069 View() : m_track(), m_map() {}
1071 KOKKOS_INLINE_FUNCTION
1072 View(
const View & rhs ) : m_track( rhs.m_track ), m_map( rhs.m_map ) {}
1074 KOKKOS_INLINE_FUNCTION
1075 View( View && rhs ) : m_track( rhs.m_track ), m_map( rhs.m_map ) {}
1077 KOKKOS_INLINE_FUNCTION
1078 View & operator = (
const View & rhs ) { m_track = rhs.m_track ; m_map = rhs.m_map ;
return *this ; }
1080 KOKKOS_INLINE_FUNCTION
1081 View & operator = ( View && rhs ) { m_track = rhs.m_track ; m_map = rhs.m_map ;
return *this ; }
1087 template<
class RT ,
class ... RP >
1088 KOKKOS_INLINE_FUNCTION
1090 : m_track( rhs.m_track , traits::is_managed )
1093 typedef typename View<RT,RP...>
::traits SrcTraits ;
1094 typedef Kokkos::Impl::ViewMapping< traits , SrcTraits , void > Mapping ;
1095 static_assert( Mapping::is_assignable ,
"Incompatible View copy construction" );
1096 Mapping::assign( m_map , rhs.m_map , rhs.m_track );
1099 template<
class RT ,
class ... RP >
1100 KOKKOS_INLINE_FUNCTION
1103 typedef typename View<RT,RP...>
::traits SrcTraits ;
1104 typedef Kokkos::Impl::ViewMapping< traits , SrcTraits , void > Mapping ;
1105 static_assert( Mapping::is_assignable ,
"Incompatible View copy assignment" );
1106 Mapping::assign( m_map , rhs.m_map , rhs.m_track );
1107 m_track.assign( rhs.m_track , traits::is_managed );
1115 template<
class RT ,
class ... RP ,
class Arg0 ,
class ... Args >
1116 KOKKOS_INLINE_FUNCTION
1118 ,
const Arg0 & arg0 , Args ... args )
1119 : m_track( src_view.m_track , traits::is_managed )
1122 typedef View< RT , RP... > SrcType ;
1124 typedef Kokkos::Impl::ViewMapping
1126 ,
typename SrcType::traits
1127 , Arg0 , Args... > Mapping ;
1129 typedef typename Mapping::type DstType ;
1131 static_assert( Kokkos::Impl::ViewMapping< traits , typename DstType::traits , void >::is_assignable
1132 ,
"Subview construction requires compatible view and subview arguments" );
1134 Mapping::assign( m_map, src_view.m_map, arg0 , args... );
1140 KOKKOS_INLINE_FUNCTION
1141 int use_count()
const 1142 {
return m_track.use_count(); }
1145 const std::string label()
const 1146 {
return m_track.template get_label< typename traits::memory_space >(); }
1151 template<
class ... P >
1153 View(
const Impl::ViewCtorProp< P ... > & arg_prop
1154 ,
typename std::enable_if< ! Impl::ViewCtorProp< P... >::has_pointer
1155 ,
typename traits::array_layout
1156 >::type
const & arg_layout
1162 typedef Impl::ViewCtorProp< P ... > alloc_prop_input ;
1166 typedef Impl::ViewCtorProp
1168 ,
typename std::conditional
1169 < alloc_prop_input::has_label
1170 , std::integral_constant<unsigned,0>
1171 ,
typename std::string
1173 ,
typename std::conditional
1174 < alloc_prop_input::has_memory_space
1175 , std::integral_constant<unsigned,1>
1176 ,
typename traits::device_type::memory_space
1178 ,
typename std::conditional
1179 < alloc_prop_input::has_execution_space
1180 , std::integral_constant<unsigned,2>
1181 ,
typename traits::device_type::execution_space
1185 static_assert( traits::is_managed
1186 ,
"View allocation constructor requires managed memory" );
1188 if ( alloc_prop::initialize &&
1189 ! alloc_prop::execution_space::is_initialized() ) {
1192 Kokkos::Impl::throw_runtime_exception(
"Constructing View and initializing data with uninitialized execution space");
1196 alloc_prop
prop( arg_prop );
1199 #if defined( KOKKOS_ENABLE_CUDA ) 1205 if ( std::is_same< Kokkos::CudaUVMSpace , typename traits::device_type::memory_space >::value ) {
1206 traits::device_type::memory_space::execution_space::fence();
1211 Kokkos::Impl::SharedAllocationRecord<> *
1212 record = m_map.allocate_shared( prop , arg_layout );
1215 #if defined( KOKKOS_ENABLE_CUDA ) 1216 if ( std::is_same< Kokkos::CudaUVMSpace , typename traits::device_type::memory_space >::value ) {
1217 traits::device_type::memory_space::execution_space::fence();
1223 m_track.assign_allocated_record_to_uninitialized( record );
1227 template<
class ... P >
1228 explicit KOKKOS_INLINE_FUNCTION
1229 View(
const Impl::ViewCtorProp< P ... > & arg_prop
1230 ,
typename std::enable_if< Impl::ViewCtorProp< P... >::has_pointer
1231 ,
typename traits::array_layout
1232 >::type
const & arg_layout
1235 , m_map( arg_prop , arg_layout )
1238 std::is_same< pointer_type
1239 ,
typename Impl::ViewCtorProp< P... >::pointer_type
1241 "Constructing View to wrap user memory must supply matching pointer type" );
1245 template<
class ... P >
1247 View(
const Impl::ViewCtorProp< P ... > & arg_prop
1248 ,
typename std::enable_if< ! Impl::ViewCtorProp< P... >::has_pointer
1250 >::type
const arg_N0 = 0
1251 ,
const size_t arg_N1 = 0
1252 ,
const size_t arg_N2 = 0
1253 ,
const size_t arg_N3 = 0
1254 ,
const size_t arg_N4 = 0
1255 ,
const size_t arg_N5 = 0
1256 ,
const size_t arg_N6 = 0
1257 ,
const size_t arg_N7 = 0
1260 ,
typename traits::array_layout
1261 ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1262 , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1266 template<
class ... P >
1267 explicit KOKKOS_INLINE_FUNCTION
1268 View(
const Impl::ViewCtorProp< P ... > & arg_prop
1269 ,
typename std::enable_if< Impl::ViewCtorProp< P... >::has_pointer
1271 >::type
const arg_N0 = 0
1272 ,
const size_t arg_N1 = 0
1273 ,
const size_t arg_N2 = 0
1274 ,
const size_t arg_N3 = 0
1275 ,
const size_t arg_N4 = 0
1276 ,
const size_t arg_N5 = 0
1277 ,
const size_t arg_N6 = 0
1278 ,
const size_t arg_N7 = 0
1281 ,
typename traits::array_layout
1282 ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1283 , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1288 template<
typename Label >
1290 View(
const Label & arg_label
1291 ,
typename std::enable_if<
1292 Kokkos::Impl::is_view_label<Label>::value ,
1293 typename traits::array_layout >::type
const & arg_layout
1295 : View( Impl::ViewCtorProp< std::string >( arg_label ) , arg_layout )
1299 template<
typename Label >
1301 View(
const Label & arg_label
1302 ,
typename std::enable_if<
1303 Kokkos::Impl::is_view_label<Label>::value ,
1304 const size_t >::type arg_N0 = 0
1305 ,
const size_t arg_N1 = 0
1306 ,
const size_t arg_N2 = 0
1307 ,
const size_t arg_N3 = 0
1308 ,
const size_t arg_N4 = 0
1309 ,
const size_t arg_N5 = 0
1310 ,
const size_t arg_N6 = 0
1311 ,
const size_t arg_N7 = 0
1313 : View( Impl::ViewCtorProp< std::string >( arg_label )
1314 ,
typename traits::array_layout
1315 ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1316 , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1322 View(
const ViewAllocateWithoutInitializing & arg_prop
1323 ,
const typename traits::array_layout & arg_layout
1325 : View( Impl::ViewCtorProp< std::string , Kokkos::Impl::WithoutInitializing_t >( arg_prop.label , Kokkos::WithoutInitializing )
1331 View(
const ViewAllocateWithoutInitializing & arg_prop
1332 ,
const size_t arg_N0 = 0
1333 ,
const size_t arg_N1 = 0
1334 ,
const size_t arg_N2 = 0
1335 ,
const size_t arg_N3 = 0
1336 ,
const size_t arg_N4 = 0
1337 ,
const size_t arg_N5 = 0
1338 ,
const size_t arg_N6 = 0
1339 ,
const size_t arg_N7 = 0
1341 : View( Impl::ViewCtorProp< std::string , Kokkos::Impl::WithoutInitializing_t >( arg_prop.label , Kokkos::WithoutInitializing )
1342 ,
typename traits::array_layout
1343 ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1344 , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1350 static constexpr
size_t required_allocation_size(
1351 const size_t arg_N0 = 0
1352 ,
const size_t arg_N1 = 0
1353 ,
const size_t arg_N2 = 0
1354 ,
const size_t arg_N3 = 0
1355 ,
const size_t arg_N4 = 0
1356 ,
const size_t arg_N5 = 0
1357 ,
const size_t arg_N6 = 0
1358 ,
const size_t arg_N7 = 0
1361 return map_type::memory_span(
1362 typename traits::array_layout
1363 ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1364 , arg_N4 , arg_N5 , arg_N6 , arg_N7 ) );
1367 explicit KOKKOS_INLINE_FUNCTION
1368 View( pointer_type arg_ptr
1369 ,
const size_t arg_N0 = 0
1370 ,
const size_t arg_N1 = 0
1371 ,
const size_t arg_N2 = 0
1372 ,
const size_t arg_N3 = 0
1373 ,
const size_t arg_N4 = 0
1374 ,
const size_t arg_N5 = 0
1375 ,
const size_t arg_N6 = 0
1376 ,
const size_t arg_N7 = 0
1378 : View( Impl::ViewCtorProp<pointer_type>(arg_ptr)
1379 ,
typename traits::array_layout
1380 ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1381 , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1385 explicit KOKKOS_INLINE_FUNCTION
1386 View( pointer_type arg_ptr
1387 ,
const typename traits::array_layout & arg_layout
1389 : View( Impl::ViewCtorProp<pointer_type>(arg_ptr) , arg_layout )
1396 size_t shmem_size(
const size_t arg_N0 = ~
size_t(0) ,
1397 const size_t arg_N1 = ~
size_t(0) ,
1398 const size_t arg_N2 = ~
size_t(0) ,
1399 const size_t arg_N3 = ~
size_t(0) ,
1400 const size_t arg_N4 = ~
size_t(0) ,
1401 const size_t arg_N5 = ~
size_t(0) ,
1402 const size_t arg_N6 = ~
size_t(0) ,
1403 const size_t arg_N7 = ~
size_t(0) )
1405 const size_t num_passed_args =
1406 ( arg_N0 != ~size_t(0) ) + ( arg_N1 != ~
size_t(0) ) + ( arg_N2 != ~
size_t(0) ) +
1407 ( arg_N3 != ~
size_t(0) ) + ( arg_N4 != ~
size_t(0) ) + ( arg_N5 != ~
size_t(0) ) +
1408 ( arg_N6 != ~
size_t(0) ) + ( arg_N7 != ~
size_t(0) );
1410 if ( std::is_same<typename traits::specialize,void>::value && num_passed_args != traits::rank_dynamic ) {
1411 Kokkos::abort(
"Kokkos::View::shmem_size() rank_dynamic != number of arguments.\n" );
1414 return map_type::memory_span(
1415 typename traits::array_layout
1416 ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1417 , arg_N4 , arg_N5 , arg_N6 , arg_N7 ) );
1420 explicit KOKKOS_INLINE_FUNCTION
1421 View(
const typename traits::execution_space::scratch_memory_space & arg_space
1422 ,
const typename traits::array_layout & arg_layout )
1423 : View( Impl::ViewCtorProp<pointer_type>(
1424 reinterpret_cast<pointer_type>(
1425 arg_space.get_shmem( map_type::memory_span( arg_layout ) ) ) )
1429 explicit KOKKOS_INLINE_FUNCTION
1430 View(
const typename traits::execution_space::scratch_memory_space & arg_space
1431 ,
const size_t arg_N0 = 0
1432 ,
const size_t arg_N1 = 0
1433 ,
const size_t arg_N2 = 0
1434 ,
const size_t arg_N3 = 0
1435 ,
const size_t arg_N4 = 0
1436 ,
const size_t arg_N5 = 0
1437 ,
const size_t arg_N6 = 0
1438 ,
const size_t arg_N7 = 0 )
1439 : View( Impl::ViewCtorProp<pointer_type>(
1440 reinterpret_cast<pointer_type>(
1441 arg_space.get_shmem(
1442 map_type::memory_span(
1443 typename traits::array_layout
1444 ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1445 , arg_N4 , arg_N5 , arg_N6 , arg_N7 ) ) ) ) )
1446 ,
typename traits::array_layout
1447 ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1448 , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1458 template <
typename D ,
class ... P >
1459 KOKKOS_INLINE_FUNCTION
1465 template<
class V ,
class ... Args >
1467 typename Kokkos::Impl::ViewMapping
1469 ,
typename V::traits
1473 template<
class D,
class ... P ,
class ... Args >
1474 KOKKOS_INLINE_FUNCTION
1475 typename Kokkos::Impl::ViewMapping
1483 "subview requires one argument for each source View rank" );
1486 Kokkos::Impl::ViewMapping
1489 , Args ... >::type( src , args ... );
1492 template<
class MemoryTraits ,
class D,
class ... P ,
class ... Args >
1493 KOKKOS_INLINE_FUNCTION
1494 typename Kokkos::Impl::ViewMapping
1498 >::template apply< MemoryTraits >::type
1502 "subview requires one argument for each source View rank" );
1505 Kokkos::Impl::ViewMapping
1509 ::template apply< MemoryTraits >
1510 ::type( src , args ... );
1520 template<
class LT ,
class ... LP ,
class RT ,
class ... RP >
1521 KOKKOS_INLINE_FUNCTION
1530 std::is_same<
typename lhs_traits::const_value_type ,
1531 typename rhs_traits::const_value_type >::value &&
1532 std::is_same<
typename lhs_traits::array_layout ,
1533 typename rhs_traits::array_layout >::value &&
1534 std::is_same<
typename lhs_traits::memory_space ,
1535 typename rhs_traits::memory_space >::value &&
1536 unsigned(lhs_traits::rank) == unsigned(rhs_traits::rank) &&
1537 lhs.data() == rhs.data() &&
1538 lhs.span() == rhs.span() &&
1539 lhs.dimension_0() == rhs.dimension_0() &&
1540 lhs.dimension_1() == rhs.dimension_1() &&
1541 lhs.dimension_2() == rhs.dimension_2() &&
1542 lhs.dimension_3() == rhs.dimension_3() &&
1543 lhs.dimension_4() == rhs.dimension_4() &&
1544 lhs.dimension_5() == rhs.dimension_5() &&
1545 lhs.dimension_6() == rhs.dimension_6() &&
1546 lhs.dimension_7() == rhs.dimension_7();
1549 template<
class LT ,
class ... LP ,
class RT ,
class ... RP >
1550 KOKKOS_INLINE_FUNCTION
1566 void shared_allocation_tracking_claim_and_disable()
1567 { Kokkos::Impl::SharedAllocationRecord<void,void>::tracking_claim_and_disable(); }
1570 void shared_allocation_tracking_release_and_enable()
1571 { Kokkos::Impl::SharedAllocationRecord<void,void>::tracking_release_and_enable(); }
1582 template<
class OutputView ,
typename Enable =
void >
1585 typedef typename OutputView::const_value_type const_value_type ;
1587 const OutputView output ;
1588 const_value_type input ;
1590 KOKKOS_INLINE_FUNCTION
1591 void operator()(
const size_t i0 )
const 1593 const size_t n1 = output.dimension_1();
1594 const size_t n2 = output.dimension_2();
1595 const size_t n3 = output.dimension_3();
1596 const size_t n4 = output.dimension_4();
1597 const size_t n5 = output.dimension_5();
1598 const size_t n6 = output.dimension_6();
1599 const size_t n7 = output.dimension_7();
1601 for (
size_t i1 = 0 ; i1 < n1 ; ++i1 ) {
1602 for (
size_t i2 = 0 ; i2 < n2 ; ++i2 ) {
1603 for (
size_t i3 = 0 ; i3 < n3 ; ++i3 ) {
1604 for (
size_t i4 = 0 ; i4 < n4 ; ++i4 ) {
1605 for (
size_t i5 = 0 ; i5 < n5 ; ++i5 ) {
1606 for (
size_t i6 = 0 ; i6 < n6 ; ++i6 ) {
1607 for (
size_t i7 = 0 ; i7 < n7 ; ++i7 ) {
1608 output(i0,i1,i2,i3,i4,i5,i6,i7) = input ;
1612 ViewFill(
const OutputView & arg_out , const_value_type & arg_in )
1613 : output( arg_out ), input( arg_in )
1615 typedef typename OutputView::execution_space execution_space ;
1622 execution_space::fence();
1626 template<
class OutputView >
1627 struct ViewFill< OutputView , typename std::enable_if< OutputView::Rank == 0 >::type > {
1628 ViewFill(
const OutputView & dst ,
const typename OutputView::const_value_type & src )
1630 Kokkos::Impl::DeepCopy< typename OutputView::memory_space , Kokkos::HostSpace >
1631 ( dst.data() , & src ,
sizeof(
typename OutputView::const_value_type) );
1635 template<
class OutputView ,
class InputView ,
class ExecSpace =
typename OutputView::execution_space >
1638 const OutputView output ;
1639 const InputView input ;
1649 ViewRemap(
const OutputView & arg_out ,
const InputView & arg_in )
1650 : output( arg_out ), input( arg_in )
1651 , n0( std::min( (
size_t)arg_out.dimension_0() , (size_t)arg_in.dimension_0() ) )
1652 , n1( std::min( (
size_t)arg_out.dimension_1() , (size_t)arg_in.dimension_1() ) )
1653 , n2( std::min( (
size_t)arg_out.dimension_2() , (size_t)arg_in.dimension_2() ) )
1654 , n3( std::min( (
size_t)arg_out.dimension_3() , (size_t)arg_in.dimension_3() ) )
1655 , n4( std::min( (
size_t)arg_out.dimension_4() , (size_t)arg_in.dimension_4() ) )
1656 , n5( std::min( (
size_t)arg_out.dimension_5() , (size_t)arg_in.dimension_5() ) )
1657 , n6( std::min( (
size_t)arg_out.dimension_6() , (size_t)arg_in.dimension_6() ) )
1658 , n7( std::min( (
size_t)arg_out.dimension_7() , (size_t)arg_in.dimension_7() ) )
1665 KOKKOS_INLINE_FUNCTION
1666 void operator()(
const size_t i0 )
const 1668 for (
size_t i1 = 0 ; i1 < n1 ; ++i1 ) {
1669 for (
size_t i2 = 0 ; i2 < n2 ; ++i2 ) {
1670 for (
size_t i3 = 0 ; i3 < n3 ; ++i3 ) {
1671 for (
size_t i4 = 0 ; i4 < n4 ; ++i4 ) {
1672 for (
size_t i5 = 0 ; i5 < n5 ; ++i5 ) {
1673 for (
size_t i6 = 0 ; i6 < n6 ; ++i6 ) {
1674 for (
size_t i7 = 0 ; i7 < n7 ; ++i7 ) {
1675 output(i0,i1,i2,i3,i4,i5,i6,i7) = input(i0,i1,i2,i3,i4,i5,i6,i7);
1689 template<
class DT ,
class ... DP >
1693 ,
typename ViewTraits<DT,DP...>::const_value_type & value
1694 ,
typename std::enable_if<
1695 std::is_same<
typename ViewTraits<DT,DP...>::specialize ,
void >::value
1699 std::is_same<
typename ViewTraits<DT,DP...>::non_const_value_type ,
1700 typename ViewTraits<DT,DP...>::value_type >::value
1701 ,
"deep_copy requires non-const type" );
1703 Kokkos::Impl::ViewFill<
View<DT,DP...> >( dst , value );
1707 template<
class ST ,
class ... SP >
1710 (
typename ViewTraits<ST,SP...>::non_const_value_type & dst
1712 ,
typename std::enable_if<
1713 std::is_same<
typename ViewTraits<ST,SP...>::specialize ,
void >::value
1717 ,
"ERROR: Non-rank-zero view in deep_copy( value , View )" );
1720 typedef typename src_traits::memory_space src_memory_space ;
1721 Kokkos::Impl::DeepCopy< HostSpace , src_memory_space >( & dst , src.data() ,
sizeof(ST) );
1726 template<
class DT ,
class ... DP ,
class ST ,
class ... SP >
1731 ,
typename std::enable_if<(
1732 std::is_same<
typename ViewTraits<DT,DP...>::specialize ,
void >::value &&
1733 std::is_same<
typename ViewTraits<ST,SP...>::specialize ,
void >::value &&
1739 std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
1740 typename ViewTraits<ST,SP...>::non_const_value_type >::value
1741 ,
"deep_copy requires matching non-const destination type" );
1743 typedef View<DT,DP...> dst_type ;
1744 typedef View<ST,SP...> src_type ;
1746 typedef typename dst_type::value_type value_type ;
1747 typedef typename dst_type::memory_space dst_memory_space ;
1748 typedef typename src_type::memory_space src_memory_space ;
1750 if ( dst.data() != src.data() ) {
1751 Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() ,
sizeof(value_type) );
1759 template<
class DT ,
class ... DP ,
class ST ,
class ... SP >
1764 ,
typename std::enable_if<(
1765 std::is_same<
typename ViewTraits<DT,DP...>::specialize ,
void >::value &&
1766 std::is_same<
typename ViewTraits<ST,SP...>::specialize ,
void >::value &&
1772 std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
1773 typename ViewTraits<DT,DP...>::non_const_value_type >::value
1774 ,
"deep_copy requires non-const destination type" );
1779 ,
"deep_copy requires Views of equal rank" );
1781 typedef View<DT,DP...> dst_type ;
1782 typedef View<ST,SP...> src_type ;
1784 typedef typename dst_type::execution_space dst_execution_space ;
1785 typedef typename src_type::execution_space src_execution_space ;
1786 typedef typename dst_type::memory_space dst_memory_space ;
1787 typedef typename src_type::memory_space src_memory_space ;
1789 enum { DstExecCanAccessSrc =
1792 enum { SrcExecCanAccessDst =
1796 if ( (
void *) dst.data() != (
void*) src.data() ) {
1803 if ( std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
1804 typename ViewTraits<ST,SP...>::non_const_value_type >::value &&
1806 ( std::is_same<
typename ViewTraits<DT,DP...>::array_layout ,
1807 typename ViewTraits<ST,SP...>::array_layout >::value
1809 ( std::is_same<
typename ViewTraits<DT,DP...>::array_layout ,
1812 std::is_same<
typename ViewTraits<DT,DP...>::array_layout ,
1820 dst.span_is_contiguous() &&
1821 src.span_is_contiguous() &&
1822 dst.span() == src.span() &&
1823 dst.dimension_0() == src.dimension_0() &&
1824 dst.dimension_1() == src.dimension_1() &&
1825 dst.dimension_2() == src.dimension_2() &&
1826 dst.dimension_3() == src.dimension_3() &&
1827 dst.dimension_4() == src.dimension_4() &&
1828 dst.dimension_5() == src.dimension_5() &&
1829 dst.dimension_6() == src.dimension_6() &&
1830 dst.dimension_7() == src.dimension_7() ) {
1832 const size_t nbytes =
sizeof(
typename dst_type::value_type) * dst.span();
1834 Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1836 else if ( std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
1837 typename ViewTraits<ST,SP...>::non_const_value_type >::value &&
1839 ( std::is_same<
typename ViewTraits<DT,DP...>::array_layout ,
1840 typename ViewTraits<ST,SP...>::array_layout >::value
1842 std::is_same<
typename ViewTraits<DT,DP...>::array_layout ,
1849 dst.span_is_contiguous() &&
1850 src.span_is_contiguous() &&
1851 dst.span() == src.span() &&
1852 dst.dimension_0() == src.dimension_0() &&
1853 dst.dimension_1() == src.dimension_1() &&
1854 dst.dimension_2() == src.dimension_2() &&
1855 dst.dimension_3() == src.dimension_3() &&
1856 dst.dimension_4() == src.dimension_4() &&
1857 dst.dimension_5() == src.dimension_5() &&
1858 dst.dimension_6() == src.dimension_6() &&
1859 dst.dimension_7() == src.dimension_7() &&
1860 dst.stride_0() == src.stride_0() &&
1861 dst.stride_1() == src.stride_1() &&
1862 dst.stride_2() == src.stride_2() &&
1863 dst.stride_3() == src.stride_3() &&
1864 dst.stride_4() == src.stride_4() &&
1865 dst.stride_5() == src.stride_5() &&
1866 dst.stride_6() == src.stride_6() &&
1867 dst.stride_7() == src.stride_7()
1870 const size_t nbytes =
sizeof(
typename dst_type::value_type) * dst.span();
1872 Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1874 else if ( DstExecCanAccessSrc ) {
1876 Kokkos::Impl::ViewRemap< dst_type , src_type >( dst , src );
1878 else if ( SrcExecCanAccessDst ) {
1880 Kokkos::Impl::ViewRemap< dst_type , src_type , src_execution_space >( dst , src );
1883 Kokkos::Impl::throw_runtime_exception(
"deep_copy given views that would require a temporary allocation");
1896 template<
class ExecSpace ,
class DT ,
class ... DP >
1901 ,
typename ViewTraits<DT,DP...>::const_value_type & value
1902 ,
typename std::enable_if<
1903 Kokkos::Impl::is_execution_space< ExecSpace >::value &&
1904 std::is_same<
typename ViewTraits<DT,DP...>::specialize ,
void >::value
1908 std::is_same<
typename ViewTraits<DT,DP...>::non_const_value_type ,
1909 typename ViewTraits<DT,DP...>::value_type >::value
1910 ,
"deep_copy requires non-const type" );
1912 Kokkos::Impl::ViewFill<
View<DT,DP...> >( dst , value );
1916 template<
class ExecSpace ,
class ST ,
class ... SP >
1919 (
const ExecSpace & exec_space
1920 ,
typename ViewTraits<ST,SP...>::non_const_value_type & dst
1922 ,
typename std::enable_if<
1923 Kokkos::Impl::is_execution_space< ExecSpace >::value &&
1924 std::is_same<
typename ViewTraits<ST,SP...>::specialize ,
void >::value
1928 ,
"ERROR: Non-rank-zero view in deep_copy( value , View )" );
1931 typedef typename src_traits::memory_space src_memory_space ;
1932 Kokkos::Impl::DeepCopy< HostSpace , src_memory_space , ExecSpace >
1933 ( exec_space , & dst , src.data() ,
sizeof(ST) );
1938 template<
class ExecSpace ,
class DT ,
class ... DP ,
class ST ,
class ... SP >
1941 (
const ExecSpace & exec_space
1944 ,
typename std::enable_if<(
1945 Kokkos::Impl::is_execution_space< ExecSpace >::value &&
1946 std::is_same<
typename ViewTraits<DT,DP...>::specialize ,
void >::value &&
1947 std::is_same<
typename ViewTraits<ST,SP...>::specialize ,
void >::value &&
1953 std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
1954 typename ViewTraits<ST,SP...>::non_const_value_type >::value
1955 ,
"deep_copy requires matching non-const destination type" );
1957 typedef View<DT,DP...> dst_type ;
1958 typedef View<ST,SP...> src_type ;
1960 typedef typename dst_type::value_type value_type ;
1961 typedef typename dst_type::memory_space dst_memory_space ;
1962 typedef typename src_type::memory_space src_memory_space ;
1964 if ( dst.data() != src.data() ) {
1965 Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space , ExecSpace >
1966 ( exec_space , dst.data() , src.data() ,
sizeof(value_type) );
1974 template<
class ExecSpace ,
class DT,
class ... DP,
class ST,
class ... SP >
1977 (
const ExecSpace & exec_space
1980 ,
typename std::enable_if<(
1981 Kokkos::Impl::is_execution_space< ExecSpace >::value &&
1982 std::is_same<
typename ViewTraits<DT,DP...>::specialize ,
void >::value &&
1983 std::is_same<
typename ViewTraits<ST,SP...>::specialize ,
void >::value &&
1989 std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
1990 typename ViewTraits<DT,DP...>::non_const_value_type >::value
1991 ,
"deep_copy requires non-const destination type" );
1996 ,
"deep_copy requires Views of equal rank" );
1998 typedef View<DT,DP...> dst_type ;
1999 typedef View<ST,SP...> src_type ;
2001 typedef typename dst_type::execution_space dst_execution_space ;
2002 typedef typename src_type::execution_space src_execution_space ;
2003 typedef typename dst_type::memory_space dst_memory_space ;
2004 typedef typename src_type::memory_space src_memory_space ;
2006 enum { DstExecCanAccessSrc =
2009 enum { SrcExecCanAccessDst =
2012 if ( (
void *) dst.data() != (
void*) src.data() ) {
2019 if ( std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
2020 typename ViewTraits<ST,SP...>::non_const_value_type >::value &&
2022 std::is_same<
typename ViewTraits<DT,DP...>::array_layout ,
2023 typename ViewTraits<ST,SP...>::array_layout >::value
2028 dst.span_is_contiguous() &&
2029 src.span_is_contiguous() &&
2030 dst.span() == src.span() &&
2031 dst.dimension_0() == src.dimension_0() &&
2032 dst.dimension_1() == src.dimension_1() &&
2033 dst.dimension_2() == src.dimension_2() &&
2034 dst.dimension_3() == src.dimension_3() &&
2035 dst.dimension_4() == src.dimension_4() &&
2036 dst.dimension_5() == src.dimension_5() &&
2037 dst.dimension_6() == src.dimension_6() &&
2038 dst.dimension_7() == src.dimension_7() ) {
2040 const size_t nbytes =
sizeof(
typename dst_type::value_type) * dst.span();
2042 Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space , ExecSpace >
2043 ( exec_space , dst.data() , src.data() , nbytes );
2045 else if ( DstExecCanAccessSrc ) {
2047 Kokkos::Impl::ViewRemap< dst_type , src_type >( dst , src );
2049 else if ( SrcExecCanAccessDst ) {
2051 Kokkos::Impl::ViewRemap< dst_type , src_type , src_execution_space >( dst , src );
2054 Kokkos::Impl::throw_runtime_exception(
"deep_copy given views that would require a temporary allocation");
2068 template<
class Space,
class T,
class ... P>
2069 struct MirrorViewType {
2073 typedef typename Space::memory_space memory_space;
2075 enum { is_same_memspace = std::is_same<memory_space,typename src_view_type::memory_space>::value };
2077 typedef typename src_view_type::array_layout array_layout;
2079 typedef typename src_view_type::non_const_data_type data_type;
2084 typedef typename std::conditional<is_same_memspace,src_view_type,dest_view_type>::type view_type;
2087 template<
class Space,
class T,
class ... P>
2092 typedef typename Space::memory_space memory_space;
2094 enum { is_same_memspace = std::is_same<memory_space,typename src_view_type::memory_space>::value };
2096 typedef typename src_view_type::array_layout array_layout;
2098 typedef typename src_view_type::non_const_data_type data_type;
2105 template<
class T ,
class ... P >
2109 ,
typename std::enable_if<
2110 ! std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout
2115 typedef View<T,P...> src_type ;
2116 typedef typename src_type::HostMirror dst_type ;
2118 return dst_type( std::string( src.label() ).append(
"_mirror")
2126 , src.dimension_7() );
2129 template<
class T ,
class ... P >
2133 ,
typename std::enable_if<
2134 std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout
2139 typedef View<T,P...> src_type ;
2140 typedef typename src_type::HostMirror dst_type ;
2144 layout.dimension[0] = src.dimension_0();
2145 layout.dimension[1] = src.dimension_1();
2146 layout.dimension[2] = src.dimension_2();
2147 layout.dimension[3] = src.dimension_3();
2148 layout.dimension[4] = src.dimension_4();
2149 layout.dimension[5] = src.dimension_5();
2150 layout.dimension[6] = src.dimension_6();
2151 layout.dimension[7] = src.dimension_7();
2153 layout.stride[0] = src.stride_0();
2154 layout.stride[1] = src.stride_1();
2155 layout.stride[2] = src.stride_2();
2156 layout.stride[3] = src.stride_3();
2157 layout.stride[4] = src.stride_4();
2158 layout.stride[5] = src.stride_5();
2159 layout.stride[6] = src.stride_6();
2160 layout.stride[7] = src.stride_7();
2162 return dst_type( std::string( src.label() ).append(
"_mirror") , layout );
2167 template<
class Space,
class T,
class ... P>
2168 typename Impl::MirrorType<Space,T,P ...>::view_type create_mirror(
const Space& ,
const Kokkos::View<T,P...> & src) {
2172 template<
class T ,
class ... P >
2176 ,
typename std::enable_if<(
2177 std::is_same<
typename Kokkos::View<T,P...>::memory_space
2178 ,
typename Kokkos::View<T,P...>::HostMirror::memory_space
2181 std::is_same<
typename Kokkos::View<T,P...>::data_type
2182 ,
typename Kokkos::View<T,P...>::HostMirror::data_type
2190 template<
class T ,
class ... P >
2194 ,
typename std::enable_if< ! (
2195 std::is_same<
typename Kokkos::View<T,P...>::memory_space
2196 ,
typename Kokkos::View<T,P...>::HostMirror::memory_space
2199 std::is_same<
typename Kokkos::View<T,P...>::data_type
2200 ,
typename Kokkos::View<T,P...>::HostMirror::data_type
2205 return Kokkos::create_mirror( src );
2209 template<
class Space,
class T,
class ... P>
2210 typename Impl::MirrorViewType<Space,T,P ...>::view_type
2212 ,
typename std::enable_if<Impl::MirrorViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2217 template<
class Space,
class T,
class ... P>
2218 typename Impl::MirrorViewType<Space,T,P ...>::view_type
2220 ,
typename std::enable_if<!Impl::MirrorViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2221 return typename Impl::MirrorViewType<Space,T,P ...>::view_type(src.label(),src.layout());
2232 template<
class T ,
class ... P >
2234 typename std::enable_if<
2239 const size_t n0 = 0 ,
2240 const size_t n1 = 0 ,
2241 const size_t n2 = 0 ,
2242 const size_t n3 = 0 ,
2243 const size_t n4 = 0 ,
2244 const size_t n5 = 0 ,
2245 const size_t n6 = 0 ,
2246 const size_t n7 = 0 )
2252 view_type v_resized( v.label(), n0, n1, n2, n3, n4, n5, n6, n7 );
2254 Kokkos::Impl::ViewRemap< view_type , view_type >( v_resized , v );
2260 template<
class T ,
class ... P >
2263 const typename Kokkos::View<T,P...>::array_layout & layout)
2269 view_type v_resized( v.label(), layout );
2271 Kokkos::Impl::ViewRemap< view_type , view_type >( v_resized , v );
2277 template<
class T ,
class ... P >
2279 typename std::enable_if<
2284 const size_t n0 = 0 ,
2285 const size_t n1 = 0 ,
2286 const size_t n2 = 0 ,
2287 const size_t n3 = 0 ,
2288 const size_t n4 = 0 ,
2289 const size_t n5 = 0 ,
2290 const size_t n6 = 0 ,
2291 const size_t n7 = 0 )
2297 const std::string label = v.label();
2300 v = view_type( label, n0, n1, n2, n3, n4, n5, n6, n7 );
2304 template<
class T ,
class ... P >
2307 const typename Kokkos::View<T,P...>::array_layout & layout)
2313 const std::string label = v.label();
2316 v = view_type( label, layout );
2329 using Kokkos::Subview ;
2330 using Kokkos::is_view ;
2331 using Kokkos::subview ;
2333 using Kokkos::WithoutInitializing ;
2334 using Kokkos::AllowPadding ;
2336 using Kokkos::view_wrap ;
2338 using Kokkos::create_mirror ;
2339 using Kokkos::create_mirror_view ;
2345 using Kokkos::Impl::ViewFill ;
2346 using Kokkos::Impl::ViewRemap ;
2347 using Kokkos::Impl::ViewCtorProp ;
2348 using Kokkos::Impl::is_view_label ;
2349 using Kokkos::Impl::WithoutInitializing_t ;
2350 using Kokkos::Impl::AllowPadding_t ;
2351 using Kokkos::Impl::SharedAllocationRecord ;
2352 using Kokkos::Impl::SharedAllocationTracker ;
2361 using Kokkos::is_view ;
2363 template<
class SrcViewType
2373 struct ViewSubview ;
2378 #include <impl/Kokkos_Atomic_View.hpp>
std::enable_if< std::is_same< typename Kokkos::View< T, P... >::array_layout, Kokkos::LayoutLeft >::value||std::is_same< typename Kokkos::View< T, P... >::array_layout, Kokkos::LayoutRight >::value >::type resize(Kokkos::View< T, P... > &v, const size_t n0=0, const size_t n1=0, const size_t n2=0, const size_t n3=0, const size_t n4=0, const size_t n5=0, const size_t n6=0, const size_t n7=0)
Resize a view with copying old data to new data at the corresponding indices.
Memory layout tag indicating left-to-right (Fortran scheme) striding of multi-indices.
std::enable_if< std::is_same< typename Kokkos::View< T, P... >::array_layout, Kokkos::LayoutLeft >::value||std::is_same< typename Kokkos::View< T, P... >::array_layout, Kokkos::LayoutRight >::value >::type realloc(Kokkos::View< T, P... > &v, const size_t n0=0, const size_t n1=0, const size_t n2=0, const size_t n3=0, const size_t n4=0, const size_t n5=0, const size_t n6=0, const size_t n7=0)
Resize a view with discarding old data.
KOKKOS_INLINE_FUNCTION bool operator!=(const complex< RealType > &x, const complex< RealType > &y)
Inequality operator for two complex numbers.
View< typename traits::scalar_array_type, typename traits::array_layout, typename traits::device_type, typename traits::memory_traits > array_type
Compatible view of array of scalar types.
Memory layout tag indicated arbitrarily strided multi-index mapping into contiguous memory...
View to an array of data.
Can AccessSpace access MemorySpace ?
Memory space for main process and CPU execution spaces.
Memory layout tag indicating right-to-left (C or lexigraphical scheme) striding of multi-indices...
Implementation of the ParallelFor operator that has a partial specialization for the device...
View< typename traits::non_const_data_type, typename traits::array_layout, typename traits::device_type, typename traits::memory_traits > non_const_type
Compatible view of non-const data type.
Impl::ViewCtorProp< typename Impl::ViewCtorProp< void, Args >::type ... > view_alloc(Args const &... args)
Create View allocation parameter bundle from argument list.
KOKKOS_INLINE_FUNCTION bool operator==(const complex< RealType > &x, const complex< RealType > &y)
Equality operator for two complex numbers.
void deep_copy(const View< DT, DP... > &dst, typename ViewTraits< DT, DP... >::const_value_type &value, typename std::enable_if< std::is_same< typename ViewTraits< DT, DP... >::specialize, void >::value >::type *=0)
Deep copy a value from Host memory into a view.
Execution policy for work over a range of an integral type.
View< typename traits::non_const_data_type, typename traits::array_layout, typename traits::host_mirror_space > HostMirror
Compatible HostMirror view.
Traits class for accessing attributes of a View.
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< std::is_integral< iType >::value, size_t >::type extent(const iType &r) const
rank() to be implemented
KOKKOS_INLINE_FUNCTION constexpr unsigned rank(const View< D, P... > &V)
Temporary free function rank() until rank() is implemented in the View.
View< typename traits::const_data_type, typename traits::array_layout, typename traits::device_type, typename traits::memory_traits > const_type
Compatible view of const data type.