17 #ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
18 #include <Kokkos_Macros.hpp>
20 "Including non-public Kokkos header files is not allowed.");
22 #ifndef KOKKOS_VIEW_HPP
23 #define KOKKOS_VIEW_HPP
25 #include <type_traits>
28 #include <initializer_list>
30 #include <Kokkos_Core_fwd.hpp>
31 #include <Kokkos_HostSpace.hpp>
32 #include <Kokkos_MemoryTraits.hpp>
33 #include <Kokkos_ExecPolicy.hpp>
34 #include <View/Hooks/Kokkos_ViewHooks.hpp>
36 #include <impl/Kokkos_Tools.hpp>
37 #include <impl/Kokkos_Utilities.hpp>
39 #ifdef KOKKOS_ENABLE_IMPL_MDSPAN
40 #include <View/MDSpan/Kokkos_MDSpan_Extents.hpp>
41 #include <View/MDSpan/Kokkos_MDSpan_Layout.hpp>
42 #include <View/MDSpan/Kokkos_MDSpan_Accessor.hpp>
44 #include <Kokkos_MinMax.hpp>
52 template <
class DataType>
53 struct ViewArrayAnalysis;
55 template <
class DataType,
class ArrayLayout,
57 typename ViewArrayAnalysis<DataType>::non_const_value_type>
58 struct ViewDataAnalysis;
60 template <
class,
class...>
63 enum :
bool { is_assignable_data_type =
false };
64 enum :
bool { is_assignable =
false };
67 template <
typename IntType>
68 constexpr KOKKOS_INLINE_FUNCTION std::size_t count_valid_integers(
69 const IntType i0,
const IntType i1,
const IntType i2,
const IntType i3,
70 const IntType i4,
const IntType i5,
const IntType i6,
const IntType i7) {
71 static_assert(std::is_integral<IntType>::value,
72 "count_valid_integers() must have integer arguments.");
74 return (i0 != KOKKOS_INVALID_INDEX) + (i1 != KOKKOS_INVALID_INDEX) +
75 (i2 != KOKKOS_INVALID_INDEX) + (i3 != KOKKOS_INVALID_INDEX) +
76 (i4 != KOKKOS_INVALID_INDEX) + (i5 != KOKKOS_INVALID_INDEX) +
77 (i6 != KOKKOS_INVALID_INDEX) + (i7 != KOKKOS_INVALID_INDEX);
82 template <
typename View>
83 KOKKOS_INLINE_FUNCTION
void runtime_check_rank(
84 const View&,
const bool is_void_spec,
const size_t i0,
const size_t i1,
85 const size_t i2,
const size_t i3,
const size_t i4,
const size_t i5,
86 const size_t i6,
const size_t i7,
const char* label) {
90 const size_t num_passed_args =
91 count_valid_integers(i0, i1, i2, i3, i4, i5, i6, i7);
96 constexpr
int rank = View::rank();
97 constexpr
int dyn_rank = View::rank_dynamic();
98 const bool n_args_is_dyn_rank = num_passed_args == dyn_rank;
99 const bool n_args_is_rank = num_passed_args == rank;
101 if constexpr (rank != dyn_rank) {
102 if (n_args_is_rank) {
103 size_t new_extents[8] = {i0, i1, i2, i3, i4, i5, i6, i7};
104 for (
int i = dyn_rank; i < rank; ++i)
105 if (new_extents[i] != View::static_extent(i)) {
107 const std::string message =
108 "The specified run-time extent for Kokkos::View '" +
110 "' does not match the compile-time extent in dimension " +
111 std::to_string(i) +
". The given extent is " +
112 std::to_string(new_extents[i]) +
" but should be " +
113 std::to_string(View::static_extent(i)) +
".\n";
114 Kokkos::abort(message.c_str());)
117 "The specified run-time extents for a Kokkos::View "
118 "do not match the compile-time extents.");)
123 if (!n_args_is_dyn_rank && !n_args_is_rank) {
125 const std::string message =
126 "Constructor for Kokkos::View '" + std::string(label) +
127 "' has mismatched number of arguments. The number "
129 std::to_string(num_passed_args) +
130 " neither matches the dynamic rank = " +
131 std::to_string(dyn_rank) +
132 " nor the total rank = " + std::to_string(rank) +
"\n";
133 Kokkos::abort(message.c_str());)
134 KOKKOS_IF_ON_DEVICE(Kokkos::abort(
"Constructor for Kokkos View has "
135 "mismatched number of arguments.");)
146 template <
class ViewType,
int Traits = 0>
147 struct ViewUniformType;
173 template <
class DataType,
class... Properties>
178 using execution_space = void;
179 using memory_space = void;
180 using HostMirrorSpace = void;
181 using array_layout = void;
182 using memory_traits = void;
183 using specialize = void;
184 using hooks_policy = void;
187 template <
class... Prop>
190 using execution_space =
typename ViewTraits<void, Prop...>::execution_space;
191 using memory_space =
typename ViewTraits<void, Prop...>::memory_space;
192 using HostMirrorSpace =
typename ViewTraits<void, Prop...>::HostMirrorSpace;
193 using array_layout =
typename ViewTraits<void, Prop...>::array_layout;
194 using memory_traits =
typename ViewTraits<void, Prop...>::memory_traits;
195 using specialize =
typename ViewTraits<void, Prop...>::specialize;
196 using hooks_policy =
typename ViewTraits<void, Prop...>::hooks_policy;
199 template <
class HooksPolicy,
class... Prop>
201 std::enable_if_t<Kokkos::Experimental::is_hooks_policy<HooksPolicy>::value>,
202 HooksPolicy, Prop...> {
203 using execution_space =
typename ViewTraits<void, Prop...>::execution_space;
204 using memory_space =
typename ViewTraits<void, Prop...>::memory_space;
205 using HostMirrorSpace =
typename ViewTraits<void, Prop...>::HostMirrorSpace;
206 using array_layout =
typename ViewTraits<void, Prop...>::array_layout;
207 using memory_traits =
typename ViewTraits<void, Prop...>::memory_traits;
208 using specialize =
typename ViewTraits<void, Prop...>::specialize;
209 using hooks_policy = HooksPolicy;
212 template <
class ArrayLayout,
class... Prop>
213 struct ViewTraits<std::enable_if_t<Kokkos::is_array_layout<ArrayLayout>::value>,
214 ArrayLayout, Prop...> {
217 using execution_space =
typename ViewTraits<void, Prop...>::execution_space;
218 using memory_space =
typename ViewTraits<void, Prop...>::memory_space;
219 using HostMirrorSpace =
typename ViewTraits<void, Prop...>::HostMirrorSpace;
220 using array_layout = ArrayLayout;
221 using memory_traits =
typename ViewTraits<void, Prop...>::memory_traits;
222 using specialize =
typename ViewTraits<void, Prop...>::specialize;
223 using hooks_policy =
typename ViewTraits<void, Prop...>::hooks_policy;
226 template <
class Space,
class... Prop>
227 struct ViewTraits<std::enable_if_t<Kokkos::is_space<Space>::value>, Space,
232 std::is_same<
typename ViewTraits<void, Prop...>::execution_space,
234 std::is_same<
typename ViewTraits<void, Prop...>::memory_space,
236 std::is_same<
typename ViewTraits<void, Prop...>::HostMirrorSpace,
238 std::is_same<
typename ViewTraits<void, Prop...>::array_layout,
240 "Only one View Execution or Memory Space template argument");
242 using execution_space =
typename Space::execution_space;
243 using memory_space =
typename Space::memory_space;
244 using HostMirrorSpace =
245 typename Kokkos::Impl::HostMirror<Space>::Space::memory_space;
246 using array_layout =
typename execution_space::array_layout;
247 using memory_traits =
typename ViewTraits<void, Prop...>::memory_traits;
248 using specialize =
typename ViewTraits<void, Prop...>::specialize;
249 using hooks_policy =
typename ViewTraits<void, Prop...>::hooks_policy;
252 template <
class MemoryTraits,
class... Prop>
254 std::enable_if_t<Kokkos::is_memory_traits<MemoryTraits>::value>,
255 MemoryTraits, Prop...> {
259 std::is_same<
typename ViewTraits<void, Prop...>::execution_space,
261 std::is_same<
typename ViewTraits<void, Prop...>::memory_space,
263 std::is_same<
typename ViewTraits<void, Prop...>::array_layout,
265 std::is_same<
typename ViewTraits<void, Prop...>::memory_traits,
267 std::is_same<
typename ViewTraits<void, Prop...>::hooks_policy,
269 "MemoryTrait is the final optional template argument for a View");
271 using execution_space = void;
272 using memory_space = void;
273 using HostMirrorSpace = void;
274 using array_layout = void;
275 using memory_traits = MemoryTraits;
276 using specialize = void;
277 using hooks_policy = void;
280 template <
class DataType,
class... Properties>
284 using prop = ViewTraits<void, Properties...>;
286 using ExecutionSpace =
287 std::conditional_t<!std::is_void<typename prop::execution_space>::value,
288 typename prop::execution_space,
289 Kokkos::DefaultExecutionSpace>;
292 std::conditional_t<!std::is_void<typename prop::memory_space>::value,
293 typename prop::memory_space,
294 typename ExecutionSpace::memory_space>;
297 std::conditional_t<!std::is_void<typename prop::array_layout>::value,
298 typename prop::array_layout,
299 typename ExecutionSpace::array_layout>;
301 using HostMirrorSpace = std::conditional_t<
302 !std::is_void<typename prop::HostMirrorSpace>::value,
303 typename prop::HostMirrorSpace,
304 typename Kokkos::Impl::HostMirror<ExecutionSpace>::Space>;
307 std::conditional_t<!std::is_void<typename prop::memory_traits>::value,
308 typename prop::memory_traits,
309 typename Kokkos::MemoryManaged>;
312 std::conditional_t<!std::is_void<typename prop::hooks_policy>::value,
313 typename prop::hooks_policy,
314 Kokkos::Experimental::DefaultViewHooks>;
318 using data_analysis = Kokkos::Impl::ViewDataAnalysis<DataType, ArrayLayout>;
324 using data_type =
typename data_analysis::type;
325 using const_data_type =
typename data_analysis::const_type;
326 using non_const_data_type =
typename data_analysis::non_const_type;
331 using scalar_array_type =
typename data_analysis::scalar_array_type;
332 using const_scalar_array_type =
333 typename data_analysis::const_scalar_array_type;
334 using non_const_scalar_array_type =
335 typename data_analysis::non_const_scalar_array_type;
340 using value_type =
typename data_analysis::value_type;
341 using const_value_type =
typename data_analysis::const_value_type;
342 using non_const_value_type =
typename data_analysis::non_const_value_type;
347 using array_layout = ArrayLayout;
348 using dimension =
typename data_analysis::dimension;
350 using specialize = std::conditional_t<
351 std::is_void<typename data_analysis::specialize>::value,
352 typename prop::specialize,
353 typename data_analysis::specialize>;
355 static constexpr
unsigned rank = dimension::rank;
356 static constexpr
unsigned rank_dynamic = dimension::rank_dynamic;
361 using execution_space = ExecutionSpace;
362 using memory_space = MemorySpace;
363 using device_type = Kokkos::Device<ExecutionSpace, MemorySpace>;
364 using memory_traits = MemoryTraits;
365 using host_mirror_space = HostMirrorSpace;
366 using hooks_policy = HooksPolicy;
368 using size_type =
typename MemorySpace::size_type;
370 enum { is_hostspace = std::is_same<MemorySpace, HostSpace>::value };
371 enum { is_managed = MemoryTraits::is_unmanaged == 0 };
372 enum { is_random_access = MemoryTraits::is_random_access == 1 };
377 #ifdef KOKKOS_ENABLE_IMPL_MDSPAN
379 struct UnsupportedKokkosArrayLayout;
381 template <
class Traits,
class Enabled =
void>
382 struct MDSpanViewTraits {
383 using mdspan_type = UnsupportedKokkosArrayLayout;
387 template <
class Traits>
388 struct MDSpanViewTraits<Traits,
389 std::void_t<typename Impl::LayoutFromArrayLayout<
390 typename Traits::array_layout>::type>> {
391 using index_type = std::size_t;
393 typename Impl::ExtentsFromDataType<index_type,
394 typename Traits::data_type>::type;
395 using mdspan_layout_type =
396 typename Impl::LayoutFromArrayLayout<typename Traits::array_layout>::type;
397 using accessor_type = Impl::SpaceAwareAccessor<
398 typename Traits::memory_space,
399 Kokkos::default_accessor<typename Traits::value_type>>;
400 using mdspan_type = mdspan<
typename Traits::value_type, extents_type,
401 mdspan_layout_type, accessor_type>;
404 #endif // KOKKOS_ENABLE_IMPL_MDSPAN
494 template <
class T1,
class T2>
495 struct is_always_assignable_impl;
497 template <
class... ViewTDst,
class... ViewTSrc>
498 struct is_always_assignable_impl<Kokkos::
View<ViewTDst...>,
500 using mapping_type = Kokkos::Impl::ViewMapping<
503 typename Kokkos::View<ViewTDst...>::traits::specialize>;
505 constexpr
static bool value =
506 mapping_type::is_assignable &&
507 static_cast<int>(
Kokkos::View<ViewTDst...>::rank_dynamic) >=
511 template <
class View1,
class View2>
512 using is_always_assignable = is_always_assignable_impl<
513 std::remove_reference_t<View1>,
514 std::remove_const_t<std::remove_reference_t<View2>>>;
516 template <
class T1,
class T2>
517 inline constexpr
bool is_always_assignable_v =
518 is_always_assignable<T1, T2>::value;
520 template <
class... ViewTDst,
class... ViewTSrc>
523 using DstTraits =
typename Kokkos::View<ViewTDst...>::traits;
524 using SrcTraits =
typename Kokkos::View<ViewTSrc...>::traits;
526 Kokkos::Impl::ViewMapping<DstTraits, SrcTraits,
527 typename DstTraits::specialize>;
529 return is_always_assignable_v<
Kokkos::View<ViewTDst...>,
531 (mapping_type::is_assignable &&
532 ((DstTraits::dimension::rank_dynamic >= 1) ||
533 (dst.static_extent(0) == src.extent(0))) &&
534 ((DstTraits::dimension::rank_dynamic >= 2) ||
535 (dst.static_extent(1) == src.extent(1))) &&
536 ((DstTraits::dimension::rank_dynamic >= 3) ||
537 (dst.static_extent(2) == src.extent(2))) &&
538 ((DstTraits::dimension::rank_dynamic >= 4) ||
539 (dst.static_extent(3) == src.extent(3))) &&
540 ((DstTraits::dimension::rank_dynamic >= 5) ||
541 (dst.static_extent(4) == src.extent(4))) &&
542 ((DstTraits::dimension::rank_dynamic >= 6) ||
543 (dst.static_extent(5) == src.extent(5))) &&
544 ((DstTraits::dimension::rank_dynamic >= 7) ||
545 (dst.static_extent(6) == src.extent(6))) &&
546 ((DstTraits::dimension::rank_dynamic >= 8) ||
547 (dst.static_extent(7) == src.extent(7))));
555 #include <impl/Kokkos_ViewMapping.hpp>
564 #if defined(KOKKOS_ENABLE_OPENMPTARGET) && defined(KOKKOS_COMPILER_INTEL_LLVM)
565 #pragma omp declare target
568 inline constexpr Kokkos::ALL_t ALL{};
570 #if defined(KOKKOS_ENABLE_OPENMPTARGET) && defined(KOKKOS_COMPILER_INTEL_LLVM)
571 #pragma omp end declare target
574 inline constexpr Kokkos::Impl::SequentialHostInit_t SequentialHostInit{};
576 inline constexpr Kokkos::Impl::WithoutInitializing_t WithoutInitializing{};
578 inline constexpr Kokkos::Impl::AllowPadding_t AllowPadding{};
590 template <
class... Args>
591 inline Impl::ViewCtorProp<typename Impl::ViewCtorProp<void, Args>::type...>
592 view_alloc(Args
const&... args) {
594 Impl::ViewCtorProp<typename Impl::ViewCtorProp<void, Args>::type...>;
596 static_assert(!return_type::has_pointer,
597 "Cannot give pointer-to-memory for view allocation");
599 return return_type(args...);
602 template <
class... Args>
603 KOKKOS_INLINE_FUNCTION
604 Impl::ViewCtorProp<typename Impl::ViewCtorProp<void, Args>::type...>
605 view_wrap(Args
const&... args) {
607 Impl::ViewCtorProp<typename Impl::ViewCtorProp<void, Args>::type...>;
609 static_assert(!return_type::has_memory_space &&
610 !return_type::has_execution_space &&
611 !return_type::has_label && return_type::has_pointer,
612 "Must only give pointer-to-memory for view wrapping");
614 return return_type(args...);
624 template <
class DataType,
class... Properties>
628 struct is_view :
public std::false_type {};
630 template <
class D,
class... P>
631 struct is_view<
View<D, P...>> :
public std::true_type {};
633 template <
class D,
class... P>
634 struct is_view<const
View<D, P...>> :
public std::true_type {};
637 inline constexpr
bool is_view_v = is_view<T>::value;
639 template <
class DataType,
class... Properties>
640 class View :
public ViewTraits<DataType, Properties...> {
642 template <
class,
class...>
644 template <
class,
class...>
645 friend class Kokkos::Impl::ViewMapping;
647 using view_tracker_type = Kokkos::Impl::ViewTracker<View>;
650 using traits = ViewTraits<DataType, Properties...>;
654 Kokkos::Impl::ViewMapping<traits, typename traits::specialize>;
655 template <
typename V>
656 friend struct Kokkos::Impl::ViewTracker;
657 using hooks_policy =
typename traits::hooks_policy;
659 view_tracker_type m_track;
666 View<
typename traits::scalar_array_type,
typename traits::array_layout,
667 typename traits::device_type,
typename traits::hooks_policy,
668 typename traits::memory_traits>;
672 View<
typename traits::const_data_type,
typename traits::array_layout,
673 typename traits::device_type,
typename traits::hooks_policy,
674 typename traits::memory_traits>;
678 View<
typename traits::non_const_data_type,
typename traits::array_layout,
679 typename traits::device_type,
typename traits::hooks_policy,
680 typename traits::memory_traits>;
684 View<
typename traits::non_const_data_type,
typename traits::array_layout,
685 Device<DefaultHostExecutionSpace,
686 typename traits::host_mirror_space::memory_space>,
687 typename traits::hooks_policy>;
691 View<
typename traits::non_const_data_type,
typename traits::array_layout,
692 typename traits::host_mirror_space,
typename traits::hooks_policy>;
696 using uniform_const_type =
697 typename Impl::ViewUniformType<View, 0>::const_type;
698 using uniform_runtime_type =
699 typename Impl::ViewUniformType<View, 0>::runtime_type;
700 using uniform_runtime_const_type =
701 typename Impl::ViewUniformType<View, 0>::runtime_const_type;
702 using uniform_nomemspace_type =
703 typename Impl::ViewUniformType<View, 0>::nomemspace_type;
704 using uniform_const_nomemspace_type =
705 typename Impl::ViewUniformType<View, 0>::const_nomemspace_type;
706 using uniform_runtime_nomemspace_type =
707 typename Impl::ViewUniformType<View, 0>::runtime_nomemspace_type;
708 using uniform_runtime_const_nomemspace_type =
709 typename Impl::ViewUniformType<View, 0>::runtime_const_nomemspace_type;
714 static constexpr Impl::integral_constant<size_t, traits::dimension::rank>
716 static constexpr Impl::integral_constant<size_t,
717 traits::dimension::rank_dynamic>
719 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
720 enum {Rank KOKKOS_DEPRECATED_WITH_COMMENT(
"Use rank instead.") =
724 template <
typename iType>
725 KOKKOS_INLINE_FUNCTION constexpr std::enable_if_t<
726 std::is_integral<iType>::value,
size_t>
727 extent(
const iType& r)
const noexcept {
728 return m_map.extent(r);
731 static KOKKOS_INLINE_FUNCTION constexpr
size_t static_extent(
732 const unsigned r) noexcept {
733 return map_type::static_extent(r);
736 template <
typename iType>
737 KOKKOS_INLINE_FUNCTION constexpr std::enable_if_t<
738 std::is_integral<iType>::value,
int>
739 extent_int(
const iType& r)
const noexcept {
740 return static_cast<int>(m_map.extent(r));
743 KOKKOS_INLINE_FUNCTION constexpr
typename traits::array_layout layout()
745 return m_map.layout();
753 KOKKOS_INLINE_FUNCTION constexpr
size_t size()
const {
754 return m_map.dimension_0() * m_map.dimension_1() * m_map.dimension_2() *
755 m_map.dimension_3() * m_map.dimension_4() * m_map.dimension_5() *
756 m_map.dimension_6() * m_map.dimension_7();
759 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_0()
const {
760 return m_map.stride_0();
762 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_1()
const {
763 return m_map.stride_1();
765 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_2()
const {
766 return m_map.stride_2();
768 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_3()
const {
769 return m_map.stride_3();
771 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_4()
const {
772 return m_map.stride_4();
774 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_5()
const {
775 return m_map.stride_5();
777 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_6()
const {
778 return m_map.stride_6();
780 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_7()
const {
781 return m_map.stride_7();
784 template <
typename iType>
785 KOKKOS_INLINE_FUNCTION constexpr std::enable_if_t<
786 std::is_integral<iType>::value,
size_t>
787 stride(iType r)
const {
803 : m_map.stride_7())))))));
806 template <
typename iType>
807 KOKKOS_INLINE_FUNCTION
void stride(iType*
const s)
const {
814 using reference_type =
typename map_type::reference_type;
815 using pointer_type =
typename map_type::pointer_type;
818 reference_type_is_lvalue_reference =
819 std::is_lvalue_reference<reference_type>::value
822 KOKKOS_INLINE_FUNCTION constexpr
size_t span()
const {
return m_map.span(); }
823 KOKKOS_INLINE_FUNCTION
bool span_is_contiguous()
const {
824 return m_map.span_is_contiguous();
826 KOKKOS_INLINE_FUNCTION constexpr
bool is_allocated()
const {
827 return m_map.data() !=
nullptr;
829 KOKKOS_INLINE_FUNCTION constexpr pointer_type data()
const {
836 KOKKOS_INLINE_FUNCTION
837 const Kokkos::Impl::ViewMapping<traits, typename traits::specialize>&
841 KOKKOS_INLINE_FUNCTION
842 const Kokkos::Impl::SharedAllocationTracker& impl_track()
const {
843 return m_track.m_tracker;
848 static constexpr
bool is_layout_left =
849 std::is_same<typename traits::array_layout, Kokkos::LayoutLeft>::value;
851 static constexpr
bool is_layout_right =
852 std::is_same<typename traits::array_layout, Kokkos::LayoutRight>::value;
854 static constexpr
bool is_layout_stride =
855 std::is_same<typename traits::array_layout, Kokkos::LayoutStride>::value;
857 static constexpr
bool is_default_map =
858 std::is_void<typename traits::specialize>::value &&
859 (is_layout_left || is_layout_right || is_layout_stride);
861 #if defined(KOKKOS_ENABLE_DEBUG_BOUNDS_CHECK)
863 #define KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(...) \
864 Kokkos::Impl::runtime_check_memory_access_violation< \
865 typename traits::memory_space>( \
866 "Kokkos::View ERROR: attempt to access inaccessible memory space", \
868 Kokkos::Impl::view_verify_operator_bounds<typename traits::memory_space>( \
873 #define KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(...) \
874 Kokkos::Impl::runtime_check_memory_access_violation< \
875 typename traits::memory_space>( \
876 "Kokkos::View ERROR: attempt to access inaccessible memory space", \
881 template <
typename... Is>
882 static KOKKOS_FUNCTION
void check_access_member_function_valid_args(Is...) {
883 static_assert(rank <=
sizeof...(Is));
884 static_assert(
sizeof...(Is) <= 8);
885 static_assert(Kokkos::Impl::are_integral<Is...>::value);
888 template <
typename... Is>
889 static KOKKOS_FUNCTION
void check_operator_parens_valid_args(Is...) {
890 static_assert(rank ==
sizeof...(Is));
891 static_assert(Kokkos::Impl::are_integral<Is...>::value);
898 template <
typename I0>
899 KOKKOS_FORCEINLINE_FUNCTION
900 std::enable_if_t<(Kokkos::Impl::always_true<I0>::value &&
901 (1 == rank) && is_default_map && !is_layout_stride),
903 operator()(I0 i0)
const {
904 check_operator_parens_valid_args(i0);
905 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, i0)
906 return m_map.m_impl_handle[i0];
909 template <typename I0>
910 KOKKOS_FORCEINLINE_FUNCTION
911 std::enable_if_t<(Kokkos::Impl::always_true<I0>::value &&
912 (1 == rank) && is_default_map && is_layout_stride),
914 operator()(I0 i0)
const {
915 check_operator_parens_valid_args(i0);
916 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, i0)
917 return m_map.m_impl_handle[m_map.m_impl_offset.m_stride.S0 * i0];
923 template <typename I0>
924 KOKKOS_FORCEINLINE_FUNCTION std::enable_if_t<
925 ((1 == rank) && Kokkos::Impl::are_integral<I0>::value && !is_default_map),
927 operator[](I0 i0)
const {
928 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, i0)
929 return m_map.reference(i0);
932 template <typename I0>
933 KOKKOS_FORCEINLINE_FUNCTION
934 std::enable_if_t<((1 == rank) && Kokkos::Impl::are_integral<I0>::value &&
935 is_default_map && !is_layout_stride),
937 operator[](I0 i0)
const {
938 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, i0)
939 return m_map.m_impl_handle[i0];
942 template <typename I0>
943 KOKKOS_FORCEINLINE_FUNCTION
944 std::enable_if_t<((1 == rank) && Kokkos::Impl::are_integral<I0>::value &&
945 is_default_map && is_layout_stride),
947 operator[](I0 i0)
const {
948 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, i0)
949 return m_map.m_impl_handle[m_map.m_impl_offset.m_stride.S0 * i0];
955 template <typename I0, typename I1>
956 KOKKOS_FORCEINLINE_FUNCTION std::enable_if_t<
957 (Kokkos::Impl::always_true<I0, I1>::value &&
958 (2 == rank) && is_default_map &&
959 (is_layout_left || is_layout_right || is_layout_stride)),
961 operator()(I0 i0, I1 i1)
const {
962 check_operator_parens_valid_args(i0, i1);
963 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, i0, i1)
964 if constexpr (is_layout_left) {
965 if constexpr (rank_dynamic == 0)
966 return m_map.m_impl_handle[i0 + m_map.m_impl_offset.m_dim.N0 * i1];
968 return m_map.m_impl_handle[i0 + m_map.m_impl_offset.m_stride * i1];
969 } else if constexpr (is_layout_right) {
970 if constexpr (rank_dynamic == 0)
971 return m_map.m_impl_handle[i1 + m_map.m_impl_offset.m_dim.N1 * i0];
973 return m_map.m_impl_handle[i1 + m_map.m_impl_offset.m_stride * i0];
975 static_assert(is_layout_stride);
976 return m_map.m_impl_handle[i0 * m_map.m_impl_offset.m_stride.S0 +
977 i1 * m_map.m_impl_offset.m_stride.S1];
979 #if defined KOKKOS_COMPILER_INTEL
980 __builtin_unreachable();
987 template <
typename... Is>
988 KOKKOS_FORCEINLINE_FUNCTION std::enable_if_t<
989 (Kokkos::Impl::always_true<Is...>::value &&
990 (2 != rank) && (1 != rank) && (0 != rank) && is_default_map),
992 operator()(Is... indices)
const {
993 check_operator_parens_valid_args(indices...);
994 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, indices...)
995 return m_map.m_impl_handle[m_map.m_impl_offset(indices...)];
998 template <typename... Is>
999 KOKKOS_FORCEINLINE_FUNCTION
1000 std::enable_if_t<(Kokkos::Impl::always_true<Is...>::value &&
1001 ((0 == rank) || !is_default_map)),
1003 operator()(Is... indices)
const {
1004 check_operator_parens_valid_args(indices...);
1005 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, indices...)
1006 return m_map.reference(indices...);
1012 template <typename... Is>
1013 KOKKOS_FORCEINLINE_FUNCTION std::enable_if_t<
1014 (Kokkos::Impl::always_true<Is...>::value && (0 == rank)), reference_type>
1015 access(Is... extra)
const {
1016 check_access_member_function_valid_args(extra...);
1017 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, extra...)
1018 return m_map.reference();
1024 template <typename I0, typename... Is>
1025 KOKKOS_FORCEINLINE_FUNCTION
1026 std::enable_if_t<(Kokkos::Impl::always_true<I0, Is...>::value &&
1027 (1 == rank) && !is_default_map),
1029 access(I0 i0, Is... extra)
const {
1030 check_access_member_function_valid_args(i0, extra...);
1031 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, i0, extra...)
1032 return m_map.reference(i0);
1035 template <typename I0, typename... Is>
1036 KOKKOS_FORCEINLINE_FUNCTION
1037 std::enable_if_t<(Kokkos::Impl::always_true<I0, Is...>::value &&
1038 (1 == rank) && is_default_map && !is_layout_stride),
1040 access(I0 i0, Is... extra)
const {
1041 check_access_member_function_valid_args(i0, extra...);
1042 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, i0, extra...)
1043 return m_map.m_impl_handle[i0];
1046 template <typename I0, typename... Is>
1047 KOKKOS_FORCEINLINE_FUNCTION
1048 std::enable_if_t<(Kokkos::Impl::always_true<I0, Is...>::value &&
1049 (1 == rank) && is_default_map && is_layout_stride),
1051 access(I0 i0, Is... extra)
const {
1052 check_access_member_function_valid_args(i0, extra...);
1053 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, i0, extra...)
1054 return m_map.m_impl_handle[m_map.m_impl_offset.m_stride.S0 * i0];
1060 template <typename I0, typename I1, typename... Is>
1061 KOKKOS_FORCEINLINE_FUNCTION
1062 std::enable_if_t<(Kokkos::Impl::always_true<I0, I1, Is...>::value &&
1063 (2 == rank) && !is_default_map),
1065 access(I0 i0, I1 i1, Is... extra)
const {
1066 check_access_member_function_valid_args(i0, i1, extra...);
1067 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, i0, i1, extra...)
1068 return m_map.reference(i0, i1);
1071 template <typename I0, typename I1, typename... Is>
1072 KOKKOS_FORCEINLINE_FUNCTION std::enable_if_t<
1073 (Kokkos::Impl::always_true<I0, I1, Is...>::value && (2 == rank) &&
1075 (is_layout_left || is_layout_right || is_layout_stride)),
1077 access(I0 i0, I1 i1, Is... extra)
const {
1078 check_access_member_function_valid_args(i0, i1, extra...);
1079 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, i0, i1, extra...)
1080 if constexpr (is_layout_left) {
1081 if constexpr (rank_dynamic == 0)
1082 return m_map.m_impl_handle[i0 + m_map.m_impl_offset.m_dim.N0 * i1];
1084 return m_map.m_impl_handle[i0 + m_map.m_impl_offset.m_stride * i1];
1085 } else if constexpr (is_layout_right) {
1086 if constexpr (rank_dynamic == 0)
1087 return m_map.m_impl_handle[i1 + m_map.m_impl_offset.m_dim.N1 * i0];
1089 return m_map.m_impl_handle[i1 + m_map.m_impl_offset.m_stride * i0];
1091 static_assert(is_layout_stride);
1092 return m_map.m_impl_handle[i0 * m_map.m_impl_offset.m_stride.S0 +
1093 i1 * m_map.m_impl_offset.m_stride.S1];
1095 #if defined KOKKOS_COMPILER_INTEL
1096 __builtin_unreachable();
1103 template <
typename I0,
typename I1,
typename I2,
typename... Is>
1104 KOKKOS_FORCEINLINE_FUNCTION
1105 std::enable_if_t<(Kokkos::Impl::always_true<I0, I1, I2, Is...>::value &&
1106 (3 == rank) && is_default_map),
1108 access(I0 i0, I1 i1, I2 i2, Is... extra)
const {
1109 check_access_member_function_valid_args(i0, i1, i2, extra...);
1110 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, i0, i1, i2, extra...)
1111 return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2)];
1114 template <typename I0, typename I1, typename I2, typename... Is>
1115 KOKKOS_FORCEINLINE_FUNCTION
1116 std::enable_if_t<(Kokkos::Impl::always_true<I0, I1, I2, Is...>::value &&
1117 (3 == rank) && !is_default_map),
1119 access(I0 i0, I1 i1, I2 i2, Is... extra)
const {
1120 check_access_member_function_valid_args(i0, i1, i2, extra...);
1121 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, i0, i1, i2, extra...)
1122 return m_map.reference(i0, i1, i2);
1128 template <typename I0, typename I1, typename I2, typename I3, typename... Is>
1129 KOKKOS_FORCEINLINE_FUNCTION std::enable_if_t<
1130 (Kokkos::Impl::always_true<I0, I1, I2, I3, Is...>::value && (4 == rank) &&
1133 access(I0 i0, I1 i1, I2 i2, I3 i3, Is... extra)
const {
1134 check_access_member_function_valid_args(i0, i1, i2, i3, extra...);
1135 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, i0, i1, i2, i3, extra...)
1136 return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3)];
1139 template <typename I0, typename I1, typename I2, typename I3, typename... Is>
1140 KOKKOS_FORCEINLINE_FUNCTION std::enable_if_t<
1141 (Kokkos::Impl::always_true<I0, I1, I2, I3, Is...>::value && (4 == rank) &&
1144 access(I0 i0, I1 i1, I2 i2, I3 i3, Is... extra)
const {
1145 check_access_member_function_valid_args(i0, i1, i2, i3, extra...);
1146 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, i0, i1, i2, i3, extra...)
1147 return m_map.reference(i0, i1, i2, i3);
1153 template <typename I0, typename I1, typename I2, typename I3, typename I4,
1155 KOKKOS_FORCEINLINE_FUNCTION std::enable_if_t<
1156 (Kokkos::Impl::always_true<I0, I1, I2, I3, I4, Is...>::value &&
1157 (5 == rank) && is_default_map),
1159 access(I0 i0, I1 i1, I2 i2, I3 i3, I4 i4, Is... extra)
const {
1160 check_access_member_function_valid_args(i0, i1, i2, i3, i4, extra...);
1161 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, i0, i1, i2, i3, i4,
1163 return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3, i4)];
1166 template <typename I0, typename I1, typename I2, typename I3, typename I4,
1168 KOKKOS_FORCEINLINE_FUNCTION std::enable_if_t<
1169 (Kokkos::Impl::always_true<I0, I1, I2, I3, I4, Is...>::value &&
1170 (5 == rank) && !is_default_map),
1172 access(I0 i0, I1 i1, I2 i2, I3 i3, I4 i4, Is... extra)
const {
1173 check_access_member_function_valid_args(i0, i1, i2, i3, i4, extra...);
1174 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, i0, i1, i2, i3, i4,
1176 return m_map.reference(i0, i1, i2, i3, i4);
1182 template <typename I0, typename I1, typename I2, typename I3, typename I4,
1183 typename I5, typename... Is>
1184 KOKKOS_FORCEINLINE_FUNCTION std::enable_if_t<
1185 (Kokkos::Impl::always_true<I0, I1, I2, I3, I4, I5, Is...>::value &&
1186 (6 == rank) && is_default_map),
1188 access(I0 i0, I1 i1, I2 i2, I3 i3, I4 i4, I5 i5, Is... extra)
const {
1189 check_access_member_function_valid_args(i0, i1, i2, i3, i4, i5, extra...);
1190 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, i0, i1, i2, i3, i4, i5,
1192 return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3, i4, i5)];
1195 template <typename I0, typename I1, typename I2, typename I3, typename I4,
1196 typename I5, typename... Is>
1197 KOKKOS_FORCEINLINE_FUNCTION std::enable_if_t<
1198 (Kokkos::Impl::always_true<I0, I1, I2, I3, I4, I5, Is...>::value &&
1199 (6 == rank) && !is_default_map),
1201 access(I0 i0, I1 i1, I2 i2, I3 i3, I4 i4, I5 i5, Is... extra)
const {
1202 check_access_member_function_valid_args(i0, i1, i2, i3, i4, i5, extra...);
1203 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, i0, i1, i2, i3, i4, i5,
1205 return m_map.reference(i0, i1, i2, i3, i4, i5);
1211 template <typename I0, typename I1, typename I2, typename I3, typename I4,
1212 typename I5, typename I6, typename... Is>
1213 KOKKOS_FORCEINLINE_FUNCTION std::enable_if_t<
1214 (Kokkos::Impl::always_true<I0, I1, I2, I3, I4, I5, I6, Is...>::value &&
1215 (7 == rank) && is_default_map),
1217 access(I0 i0, I1 i1, I2 i2, I3 i3, I4 i4, I5 i5, I6 i6, Is... extra)
const {
1218 check_access_member_function_valid_args(i0, i1, i2, i3, i4, i5, i6,
1220 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, i0, i1, i2, i3, i4, i5, i6,
1222 return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3, i4, i5, i6)];
1225 template <typename I0, typename I1, typename I2, typename I3, typename I4,
1226 typename I5, typename I6, typename... Is>
1227 KOKKOS_FORCEINLINE_FUNCTION std::enable_if_t<
1228 (Kokkos::Impl::always_true<I0, I1, I2, I3, I4, I5, I6, Is...>::value &&
1229 (7 == rank) && !is_default_map),
1231 access(I0 i0, I1 i1, I2 i2, I3 i3, I4 i4, I5 i5, I6 i6, Is... extra)
const {
1232 check_access_member_function_valid_args(i0, i1, i2, i3, i4, i5, i6,
1234 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, i0, i1, i2, i3, i4, i5, i6,
1236 return m_map.reference(i0, i1, i2, i3, i4, i5, i6);
1242 template <typename I0, typename I1, typename I2, typename I3, typename I4,
1243 typename I5, typename I6, typename I7, typename... Is>
1244 KOKKOS_FORCEINLINE_FUNCTION
1245 std::enable_if_t<(Kokkos::Impl::always_true<I0, I1, I2, I3, I4, I5, I6,
1246 I7, Is...>::value &&
1247 (8 == rank) && is_default_map),
1249 access(I0 i0, I1 i1, I2 i2, I3 i3, I4 i4, I5 i5, I6 i6, I7 i7,
1250 Is... extra)
const {
1251 check_access_member_function_valid_args(i0, i1, i2, i3, i4, i5, i6, i7,
1253 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, i0, i1, i2, i3, i4, i5, i6,
1256 .m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3, i4, i5, i6, i7)];
1259 template <typename I0, typename I1, typename I2, typename I3, typename I4,
1260 typename I5, typename I6, typename I7, typename... Is>
1261 KOKKOS_FORCEINLINE_FUNCTION
1262 std::enable_if_t<(Kokkos::Impl::always_true<I0, I1, I2, I3, I4, I5, I6,
1263 I7, Is...>::value &&
1264 (8 == rank) && !is_default_map),
1266 access(I0 i0, I1 i1, I2 i2, I3 i3, I4 i4, I5 i5, I6 i6, I7 i7,
1267 Is... extra)
const {
1268 check_access_member_function_valid_args(i0, i1, i2, i3, i4, i5, i6, i7,
1270 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(m_track, m_map, i0, i1, i2, i3, i4, i5, i6,
1272 return m_map.reference(i0, i1, i2, i3, i4, i5, i6, i7);
1275 #undef KOKKOS_IMPL_VIEW_OPERATOR_VERIFY
1280 KOKKOS_DEFAULTED_FUNCTION
1283 KOKKOS_DEFAULTED_FUNCTION
1287 View(
const View& other) : m_track(other.m_track), m_map(other.m_map) {
1288 KOKKOS_IF_ON_HOST((hooks_policy::copy_construct(*
this, other);))
1293 : m_track{std::move(other.m_track)}, m_map{std::move(other.m_map)} {
1294 KOKKOS_IF_ON_HOST((hooks_policy::move_construct(*
this, other);))
1298 View& operator=(
const View& other) {
1299 m_map = other.m_map;
1300 m_track = other.m_track;
1302 KOKKOS_IF_ON_HOST((hooks_policy::copy_assign(*
this, other);))
1308 View& operator=(View&& other) {
1309 m_map = std::move(other.m_map);
1310 m_track = std::move(other.m_track);
1312 KOKKOS_IF_ON_HOST((hooks_policy::move_assign(*
this, other);))
1321 template <class RT, class... RP>
1322 KOKKOS_INLINE_FUNCTION View(
1323 const View<RT, RP...>& rhs,
1324 std::enable_if_t<Kokkos::Impl::ViewMapping<
1325 traits, typename View<RT, RP...>::traits,
1326 typename traits::specialize>::is_assignable_data_type>* =
nullptr)
1327 : m_track(rhs), m_map() {
1328 using SrcTraits =
typename View<RT, RP...>::traits;
1329 using Mapping = Kokkos::Impl::ViewMapping<traits, SrcTraits,
1330 typename traits::specialize>;
1331 static_assert(Mapping::is_assignable,
1332 "Incompatible View copy construction");
1333 Mapping::assign(m_map, rhs.m_map, rhs.m_track.m_tracker);
1336 template <
class RT,
class... RP>
1337 KOKKOS_INLINE_FUNCTION std::enable_if_t<
1338 Kokkos::Impl::ViewMapping<
1339 traits,
typename View<RT, RP...>::traits,
1340 typename traits::specialize>::is_assignable_data_type,
1342 operator=(
const View<RT, RP...>& rhs) {
1343 using SrcTraits =
typename View<RT, RP...>::traits;
1344 using Mapping = Kokkos::Impl::ViewMapping<traits, SrcTraits,
1345 typename traits::specialize>;
1346 static_assert(Mapping::is_assignable,
"Incompatible View copy assignment");
1347 Mapping::assign(m_map, rhs.m_map, rhs.m_track.m_tracker);
1348 m_track.assign(rhs);
1356 template <
class RT,
class... RP,
class Arg0,
class... Args>
1357 KOKKOS_INLINE_FUNCTION View(
const View<RT, RP...>& src_view,
const Arg0 arg0,
1359 : m_track(src_view), m_map() {
1360 using SrcType = View<RT, RP...>;
1362 using Mapping = Kokkos::Impl::ViewMapping<void,
typename SrcType::traits,
1365 using DstType =
typename Mapping::type;
1368 Kokkos::Impl::ViewMapping<traits,
typename DstType::traits,
1369 typename traits::specialize>::is_assignable,
1370 "Subview construction requires compatible view and subview arguments");
1372 Mapping::assign(m_map, src_view.m_map, arg0, args...);
1378 KOKKOS_INLINE_FUNCTION
1379 int use_count()
const {
return m_track.m_tracker.use_count(); }
1381 inline const std::string label()
const {
1382 return m_track.m_tracker
1383 .template get_label<typename traits::memory_space>();
1390 template <
class... P>
1391 explicit inline View(
1392 const Impl::ViewCtorProp<P...>& arg_prop,
1393 std::enable_if_t<!Impl::ViewCtorProp<P...>::has_pointer,
1394 typename traits::array_layout>
const& arg_layout)
1395 : m_track(), m_map() {
1398 auto prop_copy_tmp =
1399 Impl::with_properties_if_unset(arg_prop, std::string{});
1400 auto prop_copy = Impl::with_properties_if_unset(
1401 prop_copy_tmp,
typename traits::device_type::memory_space{},
1402 typename traits::device_type::execution_space{});
1403 using alloc_prop = decltype(prop_copy);
1405 static_assert(traits::is_managed,
1406 "View allocation constructor requires managed memory");
1408 if (alloc_prop::initialize &&
1409 !alloc_prop::execution_space::impl_is_initialized()) {
1412 Kokkos::Impl::throw_runtime_exception(
1413 "Constructing View and initializing data with uninitialized "
1417 #ifdef KOKKOS_ENABLE_DEBUG_BOUNDS_CHECK
1418 if constexpr (std::is_same_v<
typename traits::array_layout,
1420 std::is_same_v<
typename traits::array_layout,
1422 std::is_same_v<
typename traits::array_layout,
1424 size_t i0 = arg_layout.dimension[0];
1425 size_t i1 = arg_layout.dimension[1];
1426 size_t i2 = arg_layout.dimension[2];
1427 size_t i3 = arg_layout.dimension[3];
1428 size_t i4 = arg_layout.dimension[4];
1429 size_t i5 = arg_layout.dimension[5];
1430 size_t i6 = arg_layout.dimension[6];
1431 size_t i7 = arg_layout.dimension[7];
1433 const std::string& alloc_name =
1434 Impl::get_property<Impl::LabelTag>(prop_copy);
1435 Impl::runtime_check_rank(
1436 *
this, std::is_same<typename traits::specialize, void>::value, i0, i1,
1437 i2, i3, i4, i5, i6, i7, alloc_name.c_str());
1441 Kokkos::Impl::SharedAllocationRecord<>* record = m_map.allocate_shared(
1442 prop_copy, arg_layout, Impl::ViewCtorProp<P...>::has_execution_space);
1445 m_track.m_tracker.assign_allocated_record_to_uninitialized(record);
1448 KOKKOS_INLINE_FUNCTION
1449 void assign_data(pointer_type arg_data) {
1450 m_track.m_tracker.clear();
1451 m_map.assign_data(arg_data);
1455 template <
class... P>
1456 explicit KOKKOS_INLINE_FUNCTION View(
1457 const Impl::ViewCtorProp<P...>& arg_prop,
1458 std::enable_if_t<Impl::ViewCtorProp<P...>::has_pointer,
1459 typename traits::array_layout>
const& arg_layout)
1462 m_map(arg_prop, arg_layout) {
1464 std::is_same<pointer_type,
1465 typename Impl::ViewCtorProp<P...>::pointer_type>::value,
1466 "Constructing View to wrap user memory must supply matching pointer "
1469 #ifdef KOKKOS_ENABLE_DEBUG_BOUNDS_CHECK
1470 if constexpr (std::is_same_v<
typename traits::array_layout,
1472 std::is_same_v<
typename traits::array_layout,
1474 std::is_same_v<
typename traits::array_layout,
1476 size_t i0 = arg_layout.dimension[0];
1477 size_t i1 = arg_layout.dimension[1];
1478 size_t i2 = arg_layout.dimension[2];
1479 size_t i3 = arg_layout.dimension[3];
1480 size_t i4 = arg_layout.dimension[4];
1481 size_t i5 = arg_layout.dimension[5];
1482 size_t i6 = arg_layout.dimension[6];
1483 size_t i7 = arg_layout.dimension[7];
1485 Impl::runtime_check_rank(
1486 *
this, std::is_same<typename traits::specialize, void>::value, i0, i1,
1487 i2, i3, i4, i5, i6, i7,
"UNMANAGED");
1493 template <
class... P>
1494 explicit inline View(
1495 const Impl::ViewCtorProp<P...>& arg_prop,
1496 std::enable_if_t<!Impl::ViewCtorProp<P...>::has_pointer,
size_t>
const
1497 arg_N0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1498 const size_t arg_N1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1499 const size_t arg_N2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1500 const size_t arg_N3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1501 const size_t arg_N4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1502 const size_t arg_N5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1503 const size_t arg_N6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1504 const size_t arg_N7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG)
1506 typename traits::array_layout(arg_N0, arg_N1, arg_N2, arg_N3,
1507 arg_N4, arg_N5, arg_N6, arg_N7)) {
1508 static_assert(traits::array_layout::is_extent_constructible,
1509 "Layout is not constructible from extent arguments. Use "
1510 "overload taking a layout object instead.");
1513 template <
class... P>
1514 explicit KOKKOS_INLINE_FUNCTION View(
1515 const Impl::ViewCtorProp<P...>& arg_prop,
1516 std::enable_if_t<Impl::ViewCtorProp<P...>::has_pointer,
size_t>
const
1517 arg_N0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1518 const size_t arg_N1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1519 const size_t arg_N2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1520 const size_t arg_N3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1521 const size_t arg_N4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1522 const size_t arg_N5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1523 const size_t arg_N6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1524 const size_t arg_N7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG)
1526 typename traits::array_layout(arg_N0, arg_N1, arg_N2, arg_N3,
1527 arg_N4, arg_N5, arg_N6, arg_N7)) {
1528 static_assert(traits::array_layout::is_extent_constructible,
1529 "Layout is not constructible from extent arguments. Use "
1530 "overload taking a layout object instead.");
1534 template <
typename Label>
1535 explicit inline View(
1536 const Label& arg_label,
1537 std::enable_if_t<Kokkos::Impl::is_view_label<Label>::value,
1538 typename traits::array_layout>
const& arg_layout)
1539 : View(Impl::ViewCtorProp<std::string>(arg_label), arg_layout) {}
1542 template <
typename Label>
1543 explicit inline View(
1544 const Label& arg_label,
1545 std::enable_if_t<Kokkos::Impl::is_view_label<Label>::value,
const size_t>
1546 arg_N0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1547 const size_t arg_N1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1548 const size_t arg_N2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1549 const size_t arg_N3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1550 const size_t arg_N4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1551 const size_t arg_N5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1552 const size_t arg_N6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1553 const size_t arg_N7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG)
1554 : View(Impl::ViewCtorProp<std::string>(arg_label),
1555 typename traits::array_layout(arg_N0, arg_N1, arg_N2, arg_N3,
1556 arg_N4, arg_N5, arg_N6, arg_N7)) {
1557 static_assert(traits::array_layout::is_extent_constructible,
1558 "Layout is not constructible from extent arguments. Use "
1559 "overload taking a layout object instead.");
1565 template <
class Traits>
1566 KOKKOS_INLINE_FUNCTION View(
1567 const view_tracker_type& track,
1568 const Kokkos::Impl::ViewMapping<Traits, typename Traits::specialize>& map)
1569 : m_track(track), m_map() {
1571 Kokkos::Impl::ViewMapping<traits, Traits, typename traits::specialize>;
1572 static_assert(Mapping::is_assignable,
1573 "Incompatible View copy construction");
1574 Mapping::assign(m_map, map, track.m_tracker);
1580 template <
class Traits>
1581 KOKKOS_INLINE_FUNCTION View(
1582 const typename view_tracker_type::track_type& track,
1583 const Kokkos::Impl::ViewMapping<Traits, typename Traits::specialize>& map)
1584 : m_track(track), m_map() {
1586 Kokkos::Impl::ViewMapping<traits, Traits, typename traits::specialize>;
1587 static_assert(Mapping::is_assignable,
1588 "Incompatible View copy construction");
1589 Mapping::assign(m_map, map, track);
1594 static constexpr
size_t required_allocation_size(
1595 typename traits::array_layout
const& layout) {
1596 return map_type::memory_span(layout);
1599 static constexpr
size_t required_allocation_size(
1600 const size_t arg_N0 = 0,
const size_t arg_N1 = 0,
const size_t arg_N2 = 0,
1601 const size_t arg_N3 = 0,
const size_t arg_N4 = 0,
const size_t arg_N5 = 0,
1602 const size_t arg_N6 = 0,
const size_t arg_N7 = 0) {
1603 static_assert(traits::array_layout::is_extent_constructible,
1604 "Layout is not constructible from extent arguments. Use "
1605 "overload taking a layout object instead.");
1606 return map_type::memory_span(
typename traits::array_layout(
1607 arg_N0, arg_N1, arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7));
1610 explicit KOKKOS_INLINE_FUNCTION View(
1611 pointer_type arg_ptr,
const size_t arg_N0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1612 const size_t arg_N1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1613 const size_t arg_N2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1614 const size_t arg_N3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1615 const size_t arg_N4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1616 const size_t arg_N5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1617 const size_t arg_N6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1618 const size_t arg_N7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG)
1619 : View(Impl::ViewCtorProp<pointer_type>(arg_ptr),
1620 typename traits::array_layout(arg_N0, arg_N1, arg_N2, arg_N3,
1621 arg_N4, arg_N5, arg_N6, arg_N7)) {
1622 static_assert(traits::array_layout::is_extent_constructible,
1623 "Layout is not constructible from extent arguments. Use "
1624 "overload taking a layout object instead.");
1627 explicit KOKKOS_INLINE_FUNCTION View(
1628 pointer_type arg_ptr,
const typename traits::array_layout& arg_layout)
1629 : View(Impl::ViewCtorProp<pointer_type>(arg_ptr), arg_layout) {}
1634 static KOKKOS_INLINE_FUNCTION
size_t
1635 shmem_size(
const size_t arg_N0 = KOKKOS_INVALID_INDEX,
1636 const size_t arg_N1 = KOKKOS_INVALID_INDEX,
1637 const size_t arg_N2 = KOKKOS_INVALID_INDEX,
1638 const size_t arg_N3 = KOKKOS_INVALID_INDEX,
1639 const size_t arg_N4 = KOKKOS_INVALID_INDEX,
1640 const size_t arg_N5 = KOKKOS_INVALID_INDEX,
1641 const size_t arg_N6 = KOKKOS_INVALID_INDEX,
1642 const size_t arg_N7 = KOKKOS_INVALID_INDEX) {
1643 static_assert(traits::array_layout::is_extent_constructible,
1644 "Layout is not constructible from extent arguments. Use "
1645 "overload taking a layout object instead.");
1646 const size_t num_passed_args = Impl::count_valid_integers(
1647 arg_N0, arg_N1, arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7);
1649 if (std::is_void<typename traits::specialize>::value &&
1650 num_passed_args != rank_dynamic) {
1652 "Kokkos::View::shmem_size() rank_dynamic != number of arguments.\n");
1655 return View::shmem_size(
typename traits::array_layout(
1656 arg_N0, arg_N1, arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7));
1662 static constexpr
size_t scratch_value_alignment =
1663 max({
sizeof(
typename traits::value_type),
1664 alignof(
typename traits::value_type),
1665 static_cast<size_t>(
1666 traits::execution_space::scratch_memory_space::ALIGN)});
1669 static KOKKOS_INLINE_FUNCTION
size_t
1670 shmem_size(
typename traits::array_layout
const& arg_layout) {
1671 return map_type::memory_span(arg_layout) + scratch_value_alignment;
1674 explicit KOKKOS_INLINE_FUNCTION View(
1675 const typename traits::execution_space::scratch_memory_space& arg_space,
1676 const typename traits::array_layout& arg_layout)
1677 : View(Impl::ViewCtorProp<pointer_type>(reinterpret_cast<pointer_type>(
1678 arg_space.get_shmem_aligned(map_type::memory_span(arg_layout),
1679 scratch_value_alignment))),
1682 explicit KOKKOS_INLINE_FUNCTION View(
1683 const typename traits::execution_space::scratch_memory_space& arg_space,
1684 const size_t arg_N0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1685 const size_t arg_N1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1686 const size_t arg_N2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1687 const size_t arg_N3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1688 const size_t arg_N4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1689 const size_t arg_N5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1690 const size_t arg_N6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1691 const size_t arg_N7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG)
1692 : View(Impl::ViewCtorProp<pointer_type>(
1693 reinterpret_cast<pointer_type>(arg_space.get_shmem_aligned(
1694 map_type::memory_span(typename traits::array_layout(
1695 arg_N0, arg_N1, arg_N2, arg_N3, arg_N4, arg_N5, arg_N6,
1697 scratch_value_alignment))),
1698 typename traits::array_layout(arg_N0, arg_N1, arg_N2, arg_N3,
1699 arg_N4, arg_N5, arg_N6, arg_N7)) {
1700 static_assert(traits::array_layout::is_extent_constructible,
1701 "Layout is not constructible from extent arguments. Use "
1702 "overload taking a layout object instead.");
1707 #ifdef KOKKOS_ENABLE_IMPL_MDSPAN
1708 template <typename U = typename Impl::MDSpanViewTraits<traits>::mdspan_type>
1709 KOKKOS_INLINE_FUNCTION
1710 #ifndef KOKKOS_ENABLE_CXX17
1711 explicit(traits::is_managed)
1713 View(
const typename Impl::MDSpanViewTraits<traits>::mdspan_type& mds,
1715 !std::is_same_v<Impl::UnsupportedKokkosArrayLayout, U>>* =
1717 : View(mds.data_handle(),
1718 Impl::array_layout_from_mapping<
1719 typename traits::array_layout,
1720 typename Impl::MDSpanViewTraits<traits>::mdspan_type>(
1724 template <
class ElementType,
class ExtentsType,
class LayoutType,
1726 KOKKOS_INLINE_FUNCTION
1727 #ifndef KOKKOS_ENABLE_CXX17
1728 explicit(!std::is_convertible_v<
1729 Kokkos::mdspan<ElementType, ExtentsType, LayoutType,
1731 typename Impl::MDSpanViewTraits<traits>::mdspan_type>)
1733 View(
const Kokkos::mdspan<ElementType, ExtentsType, LayoutType,
1735 : View(typename Impl::MDSpanViewTraits<traits>::mdspan_type(mds)) {
1740 template <
class OtherElementType,
class OtherExtents,
class OtherLayoutPolicy,
1741 class OtherAccessor,
1742 class ImplNaturalMDSpanType =
1743 typename Impl::MDSpanViewTraits<traits>::mdspan_type,
1744 typename = std::enable_if_t<std::conditional_t<
1745 std::is_same_v<Impl::UnsupportedKokkosArrayLayout,
1746 ImplNaturalMDSpanType>,
1748 std::is_assignable<mdspan<OtherElementType, OtherExtents,
1749 OtherLayoutPolicy, OtherAccessor>,
1750 ImplNaturalMDSpanType>>::value>>
1751 KOKKOS_INLINE_FUNCTION constexpr
operator mdspan<
1752 OtherElementType, OtherExtents, OtherLayoutPolicy, OtherAccessor>() {
1753 using mdspan_type =
typename Impl::MDSpanViewTraits<traits>::mdspan_type;
1754 return mdspan_type{data(),
1755 Impl::mapping_from_view_mapping<mdspan_type>(m_map)};
1758 template <
class OtherAccessorType = Impl::SpaceAwareAccessor<
1759 typename traits::memory_space,
1760 Kokkos::default_accessor<typename traits::value_type>>,
1761 typename = std::enable_if_t<std::is_assignable_v<
1762 typename traits::value_type*&,
1763 typename OtherAccessorType::data_handle_type>>>
1764 KOKKOS_INLINE_FUNCTION constexpr
auto to_mdspan(
1765 const OtherAccessorType& other_accessor =
1766 typename Impl::MDSpanViewTraits<traits>::accessor_type()) {
1767 using mdspan_type =
typename Impl::MDSpanViewTraits<traits>::mdspan_type;
1768 using ret_mdspan_type =
1769 mdspan<
typename mdspan_type::element_type,
1770 typename mdspan_type::extents_type,
1771 typename mdspan_type::layout_type, OtherAccessorType>;
1772 return ret_mdspan_type{data(),
1773 Impl::mapping_from_view_mapping<mdspan_type>(m_map),
1776 #endif // KOKKOS_ENABLE_IMPL_MDSPAN
1779 template <
typename D,
class... P>
1780 KOKKOS_INLINE_FUNCTION constexpr
unsigned rank(
const View<D, P...>&) {
1781 return View<D, P...>::rank();
1786 template <
typename ValueType,
unsigned int Rank>
1787 struct RankDataType {
1788 using type =
typename RankDataType<ValueType, Rank - 1>::type*;
1791 template <
typename ValueType>
1792 struct RankDataType<ValueType, 0> {
1793 using type = ValueType;
1796 template <
unsigned N,
typename... Args>
1797 KOKKOS_FUNCTION std::enable_if_t<
1798 N == View<Args...>::rank() &&
1799 std::is_same<
typename ViewTraits<Args...>::specialize,
void>::value,
1801 as_view_of_rank_n(View<Args...> v) {
1807 template <
unsigned N,
typename T,
typename... Args>
1808 KOKKOS_FUNCTION std::enable_if_t<
1809 N != View<T, Args...>::rank() &&
1810 std::is_same<
typename ViewTraits<T, Args...>::specialize,
void>::value,
1811 View<
typename RankDataType<
typename View<T, Args...>::value_type, N>::type,
1813 as_view_of_rank_n(View<T, Args...>) {
1814 Kokkos::abort(
"Trying to get at a View of the wrong rank");
1818 template <
typename Function,
typename... Args>
1819 void apply_to_view_of_static_rank(Function&& f, View<Args...> a) {
1828 template <
class ValueType,
class TypeList>
1829 struct TypeListToViewTraits;
1831 template <
class ValueType,
class... Properties>
1832 struct TypeListToViewTraits<ValueType, Kokkos::Impl::type_list<Properties...>> {
1833 using type = ViewTraits<ValueType, Properties...>;
1838 template <
class D,
class... P>
1839 struct RemoveAlignedMemoryTrait {
1841 using type_list_in = Kokkos::Impl::type_list<P...>;
1842 using memory_traits =
typename ViewTraits<D, P...>::memory_traits;
1843 using type_list_in_wo_memory_traits =
1844 typename Kokkos::Impl::type_list_remove_first<memory_traits,
1845 type_list_in>::type;
1846 using new_memory_traits =
1847 Kokkos::MemoryTraits<memory_traits::impl_value & ~Kokkos::Aligned>;
1848 using new_type_list =
typename Kokkos::Impl::concat_type_list<
1849 type_list_in_wo_memory_traits,
1850 Kokkos::Impl::type_list<new_memory_traits>>::type;
1853 using type =
typename TypeListToViewTraits<D, new_type_list>::type;
1857 template <
class D,
class... P,
class... Args>
1858 KOKKOS_INLINE_FUNCTION
auto subview(
const View<D, P...>& src, Args... args) {
1859 static_assert(View<D, P...>::rank ==
sizeof...(Args),
1860 "subview requires one argument for each source View rank");
1862 return typename Kokkos::Impl::ViewMapping<
1865 typename Impl::RemoveAlignedMemoryTrait<D, P...>::type,
1866 Args...>::type(src, args...);
1869 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
1870 template <
class MemoryTraits,
class D,
class... P,
class... Args>
1871 KOKKOS_DEPRECATED KOKKOS_INLINE_FUNCTION
auto subview(
const View<D, P...>& src,
1873 static_assert(View<D, P...>::rank ==
sizeof...(Args),
1874 "subview requires one argument for each source View rank");
1875 static_assert(Kokkos::is_memory_traits<MemoryTraits>::value);
1877 return typename Kokkos::Impl::ViewMapping<
1880 typename Impl::RemoveAlignedMemoryTrait<D, P..., MemoryTraits>::type,
1881 Args...>::type(src, args...);
1885 template <
class V,
class... Args>
1886 using Subview = decltype(subview(std::declval<V>(), std::declval<Args>()...));
1895 template <
class LT,
class... LP,
class RT,
class... RP>
1896 KOKKOS_INLINE_FUNCTION
bool operator==(
const View<LT, LP...>& lhs,
1897 const View<RT, RP...>& rhs) {
1899 using lhs_traits = ViewTraits<LT, LP...>;
1900 using rhs_traits = ViewTraits<RT, RP...>;
1902 return std::is_same<
typename lhs_traits::const_value_type,
1903 typename rhs_traits::const_value_type>::value &&
1904 std::is_same<
typename lhs_traits::array_layout,
1905 typename rhs_traits::array_layout>::value &&
1906 std::is_same<
typename lhs_traits::memory_space,
1907 typename rhs_traits::memory_space>::value &&
1908 View<LT, LP...>::rank() == View<RT, RP...>::rank() &&
1909 lhs.data() == rhs.data() && lhs.span() == rhs.span() &&
1910 lhs.extent(0) == rhs.extent(0) && lhs.extent(1) == rhs.extent(1) &&
1911 lhs.extent(2) == rhs.extent(2) && lhs.extent(3) == rhs.extent(3) &&
1912 lhs.extent(4) == rhs.extent(4) && lhs.extent(5) == rhs.extent(5) &&
1913 lhs.extent(6) == rhs.extent(6) && lhs.extent(7) == rhs.extent(7);
1916 template <
class LT,
class... LP,
class RT,
class... RP>
1917 KOKKOS_INLINE_FUNCTION
bool operator!=(
const View<LT, LP...>& lhs,
1918 const View<RT, RP...>& rhs) {
1919 return !(operator==(lhs, rhs));
1930 template <
class Specialize,
typename A,
typename B>
1931 struct CommonViewValueType;
1933 template <
typename A,
typename B>
1934 struct CommonViewValueType<void, A, B> {
1935 using value_type = std::common_type_t<A, B>;
1938 template <
class Specialize,
class ValueType>
1939 struct CommonViewAllocProp;
1941 template <
class ValueType>
1942 struct CommonViewAllocProp<void, ValueType> {
1943 using value_type = ValueType;
1944 using scalar_array_type = ValueType;
1946 template <
class... Views>
1947 KOKKOS_INLINE_FUNCTION CommonViewAllocProp(
const Views&...) {}
1950 template <
class... Views>
1951 struct DeduceCommonViewAllocProp;
1955 template <
class FirstView>
1956 struct DeduceCommonViewAllocProp<FirstView> {
1957 using specialize =
typename FirstView::traits::specialize;
1959 using value_type =
typename FirstView::traits::value_type;
1961 enum :
bool { is_view = is_view<FirstView>::value };
1963 using prop_type = CommonViewAllocProp<specialize, value_type>;
1966 template <
class FirstView,
class... NextViews>
1967 struct DeduceCommonViewAllocProp<FirstView, NextViews...> {
1968 using NextTraits = DeduceCommonViewAllocProp<NextViews...>;
1970 using first_specialize =
typename FirstView::traits::specialize;
1971 using first_value_type =
typename FirstView::traits::value_type;
1973 enum :
bool { first_is_view = is_view<FirstView>::value };
1975 using next_specialize =
typename NextTraits::specialize;
1976 using next_value_type =
typename NextTraits::value_type;
1978 enum :
bool { next_is_view = NextTraits::is_view };
1985 static_assert(!(!std::is_same<first_specialize, next_specialize>::value &&
1986 !std::is_void<first_specialize>::value &&
1987 !std::is_void<next_specialize>::value),
1988 "Kokkos DeduceCommonViewAllocProp ERROR: Only one non-void "
1989 "specialize trait allowed");
1992 using specialize = std::conditional_t<
1993 std::is_same<first_specialize, next_specialize>::value, first_specialize,
1994 std::conditional_t<(std::is_void<first_specialize>::value &&
1995 !std::is_void<next_specialize>::value),
1996 next_specialize, first_specialize>>;
1998 using value_type =
typename CommonViewValueType<specialize, first_value_type,
1999 next_value_type>::value_type;
2001 enum :
bool { is_view = (first_is_view && next_is_view) };
2003 using prop_type = CommonViewAllocProp<specialize, value_type>;
2008 template <
class... Views>
2009 using DeducedCommonPropsType =
2010 typename Impl::DeduceCommonViewAllocProp<Views...>::prop_type;
2023 template <
class... Views>
2024 KOKKOS_INLINE_FUNCTION DeducedCommonPropsType<Views...> common_view_alloc_prop(
2025 Views
const&... views) {
2026 return DeducedCommonPropsType<Views...>(views...);
2031 #include <impl/Kokkos_ViewUniformType.hpp>
2032 #include <impl/Kokkos_Atomic_View.hpp>
Memory layout tag indicating left-to-right (Fortran scheme) striding of multi-indices.
typename Impl::ViewUniformType< View, 0 >::type uniform_type
Unified types.
Memory layout tag indicated arbitrarily strided multi-index mapping into contiguous memory...
View to an array of data.
Memory layout tag indicating right-to-left (C or lexigraphical scheme) striding of multi-indices...
Traits class for accessing attributes of a View.