51 #ifndef KOKKOS_DYNRANKVIEW_HPP
52 #define KOKKOS_DYNRANKVIEW_HPP
54 #include <Kokkos_Core.hpp>
55 #include <impl/Kokkos_Error.hpp>
56 #include <type_traits>
60 template <
typename DataType,
class... Properties>
65 template <
typename Specialize>
66 struct DynRankDimTraits {
67 enum :
size_t { unspecified = KOKKOS_INVALID_INDEX };
70 KOKKOS_INLINE_FUNCTION
71 static size_t computeRank(
const size_t N0,
const size_t N1,
const size_t N2,
72 const size_t N3,
const size_t N4,
const size_t N5,
73 const size_t N6,
const size_t ) {
75 (N6 == unspecified && N5 == unspecified && N4 == unspecified &&
76 N3 == unspecified && N2 == unspecified && N1 == unspecified &&
79 : ((N6 == unspecified && N5 == unspecified && N4 == unspecified &&
80 N3 == unspecified && N2 == unspecified && N1 == unspecified)
82 : ((N6 == unspecified && N5 == unspecified &&
83 N4 == unspecified && N3 == unspecified &&
86 : ((N6 == unspecified && N5 == unspecified &&
87 N4 == unspecified && N3 == unspecified)
89 : ((N6 == unspecified && N5 == unspecified &&
92 : ((N6 == unspecified &&
95 : ((N6 == unspecified)
101 template <
typename Layout>
102 KOKKOS_INLINE_FUNCTION
static size_t computeRank(
const Layout& layout) {
103 return computeRank(layout.dimension[0], layout.dimension[1],
104 layout.dimension[2], layout.dimension[3],
105 layout.dimension[4], layout.dimension[5],
106 layout.dimension[6], layout.dimension[7]);
110 template <
typename Layout,
typename... P>
111 KOKKOS_INLINE_FUNCTION
static size_t computeRank(
112 const Kokkos::Impl::ViewCtorProp<P...>& ,
113 const Layout& layout) {
114 return computeRank(layout);
119 template <
typename Layout>
120 KOKKOS_INLINE_FUNCTION
static typename std::enable_if<
121 (std::is_same<Layout, Kokkos::LayoutRight>::value ||
122 std::is_same<Layout, Kokkos::LayoutLeft>::value),
124 createLayout(
const Layout& layout) {
125 return Layout(layout.dimension[0] != unspecified ? layout.dimension[0] : 1,
126 layout.dimension[1] != unspecified ? layout.dimension[1] : 1,
127 layout.dimension[2] != unspecified ? layout.dimension[2] : 1,
128 layout.dimension[3] != unspecified ? layout.dimension[3] : 1,
129 layout.dimension[4] != unspecified ? layout.dimension[4] : 1,
130 layout.dimension[5] != unspecified ? layout.dimension[5] : 1,
131 layout.dimension[6] != unspecified ? layout.dimension[6] : 1,
132 layout.dimension[7] != unspecified ? layout.dimension[7] : 1);
136 template <
typename Layout>
137 KOKKOS_INLINE_FUNCTION
static typename std::enable_if<
138 (std::is_same<Layout, Kokkos::LayoutStride>::value), Layout>::type
139 createLayout(
const Layout& layout) {
140 return Layout(layout.dimension[0] != unspecified ? layout.dimension[0] : 1,
142 layout.dimension[1] != unspecified ? layout.dimension[1] : 1,
144 layout.dimension[2] != unspecified ? layout.dimension[2] : 1,
146 layout.dimension[3] != unspecified ? layout.dimension[3] : 1,
148 layout.dimension[4] != unspecified ? layout.dimension[4] : 1,
150 layout.dimension[5] != unspecified ? layout.dimension[5] : 1,
152 layout.dimension[6] != unspecified ? layout.dimension[6] : 1,
154 layout.dimension[7] != unspecified ? layout.dimension[7] : 1,
159 template <
typename Traits,
typename... P>
160 KOKKOS_INLINE_FUNCTION
static typename std::enable_if<
161 (std::is_same<
typename Traits::array_layout,
163 std::is_same<typename Traits::array_layout, Kokkos::LayoutLeft>::value ||
164 std::is_same<
typename Traits::array_layout,
166 typename Traits::array_layout>::type
167 createLayout(
const Kokkos::Impl::ViewCtorProp<P...>& ,
168 const typename Traits::array_layout& layout) {
169 return createLayout(layout);
176 template <
typename ViewType,
typename ViewArg>
177 static ViewType createView(
const ViewArg& arg,
const size_t N0,
178 const size_t N1,
const size_t N2,
const size_t N3,
179 const size_t N4,
const size_t N5,
const size_t N6,
181 return ViewType(arg, N0 != unspecified ? N0 : 1, N1 != unspecified ? N1 : 1,
182 N2 != unspecified ? N2 : 1, N3 != unspecified ? N3 : 1,
183 N4 != unspecified ? N4 : 1, N5 != unspecified ? N5 : 1,
184 N6 != unspecified ? N6 : 1, N7 != unspecified ? N7 : 1);
189 template <
typename Layout,
typename iType>
190 KOKKOS_INLINE_FUNCTION
static
191 typename std::enable_if<(std::is_same<Layout, Kokkos::LayoutRight>::value ||
192 std::is_same<Layout, Kokkos::LayoutLeft>::value) &&
193 std::is_integral<iType>::value,
195 reconstructLayout(
const Layout& layout, iType dynrank) {
196 return Layout(dynrank > 0 ? layout.dimension[0] : KOKKOS_INVALID_INDEX,
197 dynrank > 1 ? layout.dimension[1] : KOKKOS_INVALID_INDEX,
198 dynrank > 2 ? layout.dimension[2] : KOKKOS_INVALID_INDEX,
199 dynrank > 3 ? layout.dimension[3] : KOKKOS_INVALID_INDEX,
200 dynrank > 4 ? layout.dimension[4] : KOKKOS_INVALID_INDEX,
201 dynrank > 5 ? layout.dimension[5] : KOKKOS_INVALID_INDEX,
202 dynrank > 6 ? layout.dimension[6] : KOKKOS_INVALID_INDEX,
203 dynrank > 7 ? layout.dimension[7] : KOKKOS_INVALID_INDEX);
207 template <
typename Layout,
typename iType>
208 KOKKOS_INLINE_FUNCTION
static typename std::enable_if<
209 (std::is_same<Layout, Kokkos::LayoutStride>::value) &&
210 std::is_integral<iType>::value,
212 reconstructLayout(
const Layout& layout, iType dynrank) {
213 return Layout(dynrank > 0 ? layout.dimension[0] : KOKKOS_INVALID_INDEX,
214 dynrank > 0 ? layout.stride[0] : (0),
215 dynrank > 1 ? layout.dimension[1] : KOKKOS_INVALID_INDEX,
216 dynrank > 1 ? layout.stride[1] : (0),
217 dynrank > 2 ? layout.dimension[2] : KOKKOS_INVALID_INDEX,
218 dynrank > 2 ? layout.stride[2] : (0),
219 dynrank > 3 ? layout.dimension[3] : KOKKOS_INVALID_INDEX,
220 dynrank > 3 ? layout.stride[3] : (0),
221 dynrank > 4 ? layout.dimension[4] : KOKKOS_INVALID_INDEX,
222 dynrank > 4 ? layout.stride[4] : (0),
223 dynrank > 5 ? layout.dimension[5] : KOKKOS_INVALID_INDEX,
224 dynrank > 5 ? layout.stride[5] : (0),
225 dynrank > 6 ? layout.dimension[6] : KOKKOS_INVALID_INDEX,
226 dynrank > 6 ? layout.stride[6] : (0),
227 dynrank > 7 ? layout.dimension[7] : KOKKOS_INVALID_INDEX,
228 dynrank > 7 ? layout.stride[7] : (0));
234 template <
unsigned,
typename iType0,
class MapType>
235 KOKKOS_INLINE_FUNCTION
bool dyn_rank_view_verify_operator_bounds(
236 const iType0&,
const MapType&) {
240 template <
unsigned R,
typename iType0,
class MapType,
typename iType1,
242 KOKKOS_INLINE_FUNCTION
bool dyn_rank_view_verify_operator_bounds(
243 const iType0&
rank,
const MapType& map,
const iType1& i, Args... args) {
244 if (static_cast<iType0>(R) < rank) {
245 return (
size_t(i) < map.extent(R)) &&
246 dyn_rank_view_verify_operator_bounds<R + 1>(rank, map, args...);
249 "DynRankView Debug Bounds Checking Error: at rank %u\n Extra "
250 "arguments beyond the rank must be zero \n",
253 dyn_rank_view_verify_operator_bounds<R + 1>(
rank, map, args...);
256 dyn_rank_view_verify_operator_bounds<R + 1>(
rank, map, args...);
260 template <
unsigned,
class MapType>
261 inline void dyn_rank_view_error_operator_bounds(
char*,
int,
const MapType&) {}
263 template <
unsigned R,
class MapType,
class iType,
class... Args>
264 inline void dyn_rank_view_error_operator_bounds(
char* buf,
int len,
266 const iType& i, Args... args) {
267 const int n = snprintf(
268 buf, len,
" %ld < %ld %c", static_cast<unsigned long>(i),
269 static_cast<unsigned long>(map.extent(R)), (
sizeof...(Args) ?
',' :
')'));
270 dyn_rank_view_error_operator_bounds<R + 1>(buf + n, len - n, map, args...);
274 template <
typename MemorySpace,
typename iType0,
typename iType1,
class MapType,
276 KOKKOS_INLINE_FUNCTION
void dyn_rank_view_verify_operator_bounds(
277 const iType0& op_rank,
const iType1& rank,
278 const Kokkos::Impl::SharedAllocationTracker& tracker,
const MapType& map,
280 if (static_cast<iType0>(rank) > op_rank) {
282 "DynRankView Bounds Checking Error: Need at least rank arguments to "
286 if (!dyn_rank_view_verify_operator_bounds<0>(rank, map, args...)) {
287 #if defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST)
290 const std::string label = tracker.template get_label<MemorySpace>();
291 int n = snprintf(buffer, LEN,
"DynRankView bounds error of view %s (",
293 dyn_rank_view_error_operator_bounds<0>(buffer + n, LEN - n, map, args...);
294 Kokkos::Impl::throw_runtime_exception(std::string(buffer));
297 Kokkos::abort(
"DynRankView bounds error");
309 template <
class DstTraits,
class SrcTraits>
311 DstTraits, SrcTraits,
312 typename std::enable_if<
313 (std::is_same<typename DstTraits::memory_space,
314 typename SrcTraits::memory_space>::value &&
315 std::is_same<typename DstTraits::specialize, void>::value &&
316 std::is_same<typename SrcTraits::specialize, void>::value &&
317 (std::is_same<typename DstTraits::array_layout,
318 typename SrcTraits::array_layout>::value ||
319 ((std::is_same<typename DstTraits::array_layout,
320 Kokkos::LayoutLeft>::value ||
321 std::is_same<typename DstTraits::array_layout,
322 Kokkos::LayoutRight>::value ||
323 std::is_same<typename DstTraits::array_layout,
324 Kokkos::LayoutStride>::value) &&
325 (std::is_same<typename SrcTraits::array_layout,
326 Kokkos::LayoutLeft>::value ||
327 std::is_same<typename SrcTraits::array_layout,
328 Kokkos::LayoutRight>::value ||
329 std::is_same<typename SrcTraits::array_layout,
330 Kokkos::LayoutStride>::value)))),
331 Kokkos::Impl::ViewToDynRankViewTag>::type> {
334 is_assignable_value_type =
335 std::is_same<
typename DstTraits::value_type,
336 typename SrcTraits::value_type>::value ||
337 std::is_same<
typename DstTraits::value_type,
338 typename SrcTraits::const_value_type>::value
342 is_assignable_layout =
343 std::is_same<
typename DstTraits::array_layout,
344 typename SrcTraits::array_layout>::value ||
345 std::is_same<
typename DstTraits::array_layout,
350 enum { is_assignable = is_assignable_value_type && is_assignable_layout };
352 typedef ViewMapping<DstTraits, typename DstTraits::specialize> DstType;
353 typedef ViewMapping<SrcTraits, typename SrcTraits::specialize> SrcType;
355 template <
typename DT,
typename... DP,
typename ST,
typename... SP>
356 KOKKOS_INLINE_FUNCTION
static void assign(
359 is_assignable_value_type,
360 "View assignment must have same value type or const = non-const");
363 is_assignable_layout,
364 "View assignment must have compatible layout or have rank <= 1");
368 typedef typename DstType::offset_type dst_offset_type;
369 dst.m_map.m_impl_offset = dst_offset_type(
370 std::integral_constant<unsigned, 0>(),
372 dst.m_map.m_impl_handle = Kokkos::Impl::ViewDataHandle<DstTraits>::assign(
373 src.m_map.m_impl_handle, src.m_track);
374 dst.m_track.assign(src.m_track, DstTraits::is_managed);
375 dst.m_rank = src.Rank;
398 struct is_dyn_rank_view :
public std::false_type {};
400 template <
class D,
class... P>
401 struct is_dyn_rank_view<Kokkos::DynRankView<D, P...> > :
public std::true_type {
404 template <
typename DataType,
class... Properties>
405 class DynRankView :
public ViewTraits<DataType, Properties...> {
406 static_assert(!std::is_array<DataType>::value &&
407 !std::is_pointer<DataType>::value,
408 "Cannot template DynRankView with array or pointer datatype - "
412 template <
class,
class...>
413 friend class DynRankView;
414 template <
class,
class...>
415 friend class Kokkos::Impl::ViewMapping;
418 typedef ViewTraits<DataType, Properties...> drvtraits;
420 typedef View<DataType*******, Properties...> view_type;
422 typedef ViewTraits<DataType*******, Properties...> traits;
425 typedef Kokkos::Impl::ViewMapping<traits, typename traits::specialize>
427 typedef Kokkos::Impl::SharedAllocationTracker track_type;
434 KOKKOS_INLINE_FUNCTION
435 view_type& DownCast()
const {
return (view_type&)(*this); }
436 KOKKOS_INLINE_FUNCTION
437 const view_type& ConstDownCast()
const {
return (
const view_type&)(*this); }
444 typename drvtraits::scalar_array_type,
typename drvtraits::array_layout,
445 typename drvtraits::device_type,
typename drvtraits::memory_traits>
450 typename drvtraits::const_data_type,
typename drvtraits::array_layout,
451 typename drvtraits::device_type,
typename drvtraits::memory_traits>
456 typename drvtraits::non_const_data_type,
typename drvtraits::array_layout,
457 typename drvtraits::device_type,
typename drvtraits::memory_traits>
461 typedef DynRankView<
typename drvtraits::non_const_data_type,
462 typename drvtraits::array_layout,
463 typename drvtraits::host_mirror_space>
472 template <
typename iType>
473 KOKKOS_INLINE_FUNCTION constexpr
474 typename std::enable_if<std::is_integral<iType>::value,
size_t>::type
475 extent(
const iType& r)
const {
476 return m_map.extent(r);
479 template <
typename iType>
480 KOKKOS_INLINE_FUNCTION constexpr
481 typename std::enable_if<std::is_integral<iType>::value,
int>::type
482 extent_int(
const iType& r)
const {
483 return static_cast<int>(m_map.extent(r));
486 KOKKOS_INLINE_FUNCTION constexpr
typename traits::array_layout layout()
488 return m_map.layout();
496 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
497 template <
typename iType>
498 KOKKOS_INLINE_FUNCTION constexpr
499 typename std::enable_if<std::is_integral<iType>::value,
size_t>::type
500 dimension(
const iType& r)
const {
504 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_0()
const {
505 return m_map.dimension_0();
507 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_1()
const {
508 return m_map.dimension_1();
510 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_2()
const {
511 return m_map.dimension_2();
513 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_3()
const {
514 return m_map.dimension_3();
516 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_4()
const {
517 return m_map.dimension_4();
519 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_5()
const {
520 return m_map.dimension_5();
522 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_6()
const {
523 return m_map.dimension_6();
525 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_7()
const {
526 return m_map.dimension_7();
532 KOKKOS_INLINE_FUNCTION constexpr
size_t size()
const {
533 return m_map.extent(0) * m_map.extent(1) * m_map.extent(2) *
534 m_map.extent(3) * m_map.extent(4) * m_map.extent(5) *
535 m_map.extent(6) * m_map.extent(7);
538 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_0()
const {
539 return m_map.stride_0();
541 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_1()
const {
542 return m_map.stride_1();
544 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_2()
const {
545 return m_map.stride_2();
547 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_3()
const {
548 return m_map.stride_3();
550 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_4()
const {
551 return m_map.stride_4();
553 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_5()
const {
554 return m_map.stride_5();
556 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_6()
const {
557 return m_map.stride_6();
559 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_7()
const {
560 return m_map.stride_7();
563 template <
typename iType>
564 KOKKOS_INLINE_FUNCTION
void stride(iType*
const s)
const {
571 typedef typename map_type::reference_type reference_type;
572 typedef typename map_type::pointer_type pointer_type;
575 reference_type_is_lvalue_reference =
576 std::is_lvalue_reference<reference_type>::value
579 KOKKOS_INLINE_FUNCTION constexpr
size_t span()
const {
return m_map.span(); }
580 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
582 KOKKOS_INLINE_FUNCTION constexpr
size_t capacity()
const {
586 KOKKOS_INLINE_FUNCTION constexpr
bool span_is_contiguous()
const {
587 return m_map.span_is_contiguous();
589 KOKKOS_INLINE_FUNCTION constexpr pointer_type data()
const {
593 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
595 KOKKOS_INLINE_FUNCTION constexpr
bool is_contiguous()
const {
596 return m_map.span_is_contiguous();
599 KOKKOS_INLINE_FUNCTION constexpr pointer_type ptr_on_device()
const {
606 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
607 KOKKOS_INLINE_FUNCTION
608 const Kokkos::Impl::ViewMapping<traits, typename traits::specialize>&
609 implementation_map()
const {
613 KOKKOS_INLINE_FUNCTION
614 const Kokkos::Impl::ViewMapping<traits, typename traits::specialize>&
624 std::is_same<typename traits::array_layout, Kokkos::LayoutLeft>::value,
627 std::is_same<typename traits::array_layout, Kokkos::LayoutRight>::value,
629 is_layout_stride = std::is_same<
typename traits::array_layout,
632 is_default_map = std::is_same<typename traits::specialize, void>::value &&
633 (is_layout_left || is_layout_right || is_layout_stride)
637 Space,
typename traits::memory_space>::accessible>
638 struct verify_space {
639 KOKKOS_FORCEINLINE_FUNCTION
static void check() {}
642 template <
class Space>
643 struct verify_space<Space, false> {
644 KOKKOS_FORCEINLINE_FUNCTION
static void check() {
646 "Kokkos::DynRankView ERROR: attempt to access inaccessible memory "
652 #if defined(KOKKOS_ENABLE_DEBUG_BOUNDS_CHECK)
655 #define KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(ARG) \
656 DynRankView::template verify_space< \
657 Kokkos::Impl::ActiveExecutionMemorySpace>::check(); \
658 Kokkos::Impl::dyn_rank_view_verify_operator_bounds< \
659 typename traits::memory_space> \
664 #define KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(ARG) \
665 DynRankView::template verify_space< \
666 Kokkos::Impl::ActiveExecutionMemorySpace>::check();
671 KOKKOS_INLINE_FUNCTION
672 constexpr
unsigned rank()
const {
return m_rank; }
676 KOKKOS_INLINE_FUNCTION
677 reference_type operator()()
const {
678 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((0, this->
rank(), m_track, m_map))
679 return impl_map().reference();
686 template <typename iType>
687 KOKKOS_INLINE_FUNCTION typename std::enable_if<
688 std::is_same<typename drvtraits::value_type,
689 typename drvtraits::scalar_array_type>::value &&
690 std::is_integral<iType>::value,
691 reference_type>::type
692 operator[](const iType& i0)
const {
701 template <
typename iType>
702 KOKKOS_INLINE_FUNCTION
typename std::enable_if<
703 !std::is_same<
typename drvtraits::value_type,
704 typename drvtraits::scalar_array_type>::value &&
705 std::is_integral<iType>::value,
706 reference_type>::type
707 operator[](
const iType& i0)
const {
709 const size_t dim_scalar = m_map.dimension_scalar();
710 const size_t bytes = this->span() / dim_scalar;
713 DataType*,
typename traits::array_layout,
typename traits::device_type,
714 Kokkos::MemoryTraits<traits::memory_traits::is_unmanaged |
715 traits::memory_traits::is_random_access |
716 traits::memory_traits::is_atomic> >
718 tmp_view_type rankone_view(this->data(), bytes, dim_scalar);
719 return rankone_view(i0);
723 template <
typename iType>
724 KOKKOS_INLINE_FUNCTION
typename std::enable_if<
725 (std::is_same<typename traits::specialize, void>::value &&
726 std::is_integral<iType>::value),
727 reference_type>::type
728 operator()(
const iType& i0)
const {
729 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((1, this->
rank(), m_track, m_map, i0))
730 return m_map.reference(i0);
733 template <typename iType>
734 KOKKOS_INLINE_FUNCTION typename std::enable_if<
735 !(std::is_same<typename traits::specialize,
void>::value &&
736 std::is_integral<iType>::value),
737 reference_type>::type
738 operator()(const iType& i0)
const {
739 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((1, this->
rank(), m_track, m_map, i0))
740 return m_map.reference(i0, 0, 0, 0, 0, 0, 0);
744 template <typename iType0, typename iType1>
745 KOKKOS_INLINE_FUNCTION typename std::enable_if<
746 (std::is_same<typename traits::specialize,
void>::value &&
747 std::is_integral<iType0>::value && std::is_integral<iType1>::value),
748 reference_type>::type
749 operator()(const iType0& i0, const iType1& i1)
const {
750 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((2, this->
rank(), m_track, m_map, i0, i1))
751 return m_map.reference(i0, i1);
754 template <typename iType0, typename iType1>
755 KOKKOS_INLINE_FUNCTION typename std::enable_if<
756 !(std::is_same<typename drvtraits::specialize,
void>::value &&
757 std::is_integral<iType0>::value),
758 reference_type>::type
759 operator()(const iType0& i0, const iType1& i1)
const {
760 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((2, this->
rank(), m_track, m_map, i0, i1))
761 return m_map.reference(i0, i1, 0, 0, 0, 0, 0);
765 template <typename iType0, typename iType1, typename iType2>
766 KOKKOS_INLINE_FUNCTION typename std::enable_if<
767 (std::is_same<typename traits::specialize,
void>::value &&
768 std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
769 std::is_integral<iType2>::value),
770 reference_type>::type
771 operator()(const iType0& i0, const iType1& i1, const iType2& i2)
const {
772 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
773 (3, this->
rank(), m_track, m_map, i0, i1, i2))
774 return m_map.reference(i0, i1, i2);
777 template <typename iType0, typename iType1, typename iType2>
778 KOKKOS_INLINE_FUNCTION typename std::enable_if<
779 !(std::is_same<typename drvtraits::specialize,
void>::value &&
780 std::is_integral<iType0>::value),
781 reference_type>::type
782 operator()(const iType0& i0, const iType1& i1, const iType2& i2)
const {
783 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
784 (3, this->
rank(), m_track, m_map, i0, i1, i2))
785 return m_map.reference(i0, i1, i2, 0, 0, 0, 0);
789 template <typename iType0, typename iType1, typename iType2, typename iType3>
790 KOKKOS_INLINE_FUNCTION typename std::enable_if<
791 (std::is_same<typename traits::specialize,
void>::value &&
792 std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
793 std::is_integral<iType2>::value && std::is_integral<iType3>::value),
794 reference_type>::type
795 operator()(const iType0& i0, const iType1& i1, const iType2& i2,
796 const iType3& i3)
const {
797 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
798 (4, this->
rank(), m_track, m_map, i0, i1, i2, i3))
799 return m_map.reference(i0, i1, i2, i3);
802 template <typename iType0, typename iType1, typename iType2, typename iType3>
803 KOKKOS_INLINE_FUNCTION typename std::enable_if<
804 !(std::is_same<typename drvtraits::specialize,
void>::value &&
805 std::is_integral<iType0>::value),
806 reference_type>::type
807 operator()(const iType0& i0, const iType1& i1, const iType2& i2,
808 const iType3& i3)
const {
809 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
810 (4, this->
rank(), m_track, m_map, i0, i1, i2, i3))
811 return m_map.reference(i0, i1, i2, i3, 0, 0, 0);
815 template <typename iType0, typename iType1, typename iType2, typename iType3,
817 KOKKOS_INLINE_FUNCTION typename std::enable_if<
818 (std::is_same<typename traits::specialize,
void>::value &&
819 std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
820 std::is_integral<iType2>::value && std::is_integral<iType3>::value &&
821 std::is_integral<iType4>::value),
822 reference_type>::type
823 operator()(const iType0& i0, const iType1& i1, const iType2& i2,
824 const iType3& i3, const iType4& i4)
const {
825 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
826 (5, this->
rank(), m_track, m_map, i0, i1, i2, i3, i4))
827 return m_map.reference(i0, i1, i2, i3, i4);
830 template <typename iType0, typename iType1, typename iType2, typename iType3,
832 KOKKOS_INLINE_FUNCTION typename std::enable_if<
833 !(std::is_same<typename drvtraits::specialize,
void>::value &&
834 std::is_integral<iType0>::value),
835 reference_type>::type
836 operator()(const iType0& i0, const iType1& i1, const iType2& i2,
837 const iType3& i3, const iType4& i4)
const {
838 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
839 (5, this->
rank(), m_track, m_map, i0, i1, i2, i3, i4))
840 return m_map.reference(i0, i1, i2, i3, i4, 0, 0);
844 template <typename iType0, typename iType1, typename iType2, typename iType3,
845 typename iType4, typename iType5>
846 KOKKOS_INLINE_FUNCTION typename std::enable_if<
847 (std::is_same<typename traits::specialize,
void>::value &&
848 std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
849 std::is_integral<iType2>::value && std::is_integral<iType3>::value &&
850 std::is_integral<iType4>::value && std::is_integral<iType5>::value),
851 reference_type>::type
852 operator()(const iType0& i0, const iType1& i1, const iType2& i2,
853 const iType3& i3, const iType4& i4, const iType5& i5)
const {
854 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
855 (6, this->
rank(), m_track, m_map, i0, i1, i2, i3, i4, i5))
856 return m_map.reference(i0, i1, i2, i3, i4, i5);
859 template <typename iType0, typename iType1, typename iType2, typename iType3,
860 typename iType4, typename iType5>
861 KOKKOS_INLINE_FUNCTION typename std::enable_if<
862 !(std::is_same<typename drvtraits::specialize,
void>::value &&
863 std::is_integral<iType0>::value),
864 reference_type>::type
865 operator()(const iType0& i0, const iType1& i1, const iType2& i2,
866 const iType3& i3, const iType4& i4, const iType5& i5)
const {
867 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
868 (6, this->
rank(), m_track, m_map, i0, i1, i2, i3, i4, i5))
869 return m_map.reference(i0, i1, i2, i3, i4, i5, 0);
873 template <typename iType0, typename iType1, typename iType2, typename iType3,
874 typename iType4, typename iType5, typename iType6>
875 KOKKOS_INLINE_FUNCTION typename std::enable_if<
876 (std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
877 std::is_integral<iType2>::value && std::is_integral<iType3>::value &&
878 std::is_integral<iType4>::value && std::is_integral<iType5>::value &&
879 std::is_integral<iType6>::value),
880 reference_type>::type
881 operator()(const iType0& i0, const iType1& i1, const iType2& i2,
882 const iType3& i3, const iType4& i4, const iType5& i5,
883 const iType6& i6)
const {
884 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
885 (7, this->
rank(), m_track, m_map, i0, i1, i2, i3, i4, i5, i6))
886 return m_map.reference(i0, i1, i2, i3, i4, i5, i6);
890 KOKKOS_INLINE_FUNCTION
891 reference_type access()
const {
892 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((0, this->
rank(), m_track, m_map))
893 return impl_map().reference();
899 template <typename iType>
900 KOKKOS_INLINE_FUNCTION typename std::enable_if<
901 (std::is_same<typename traits::specialize,
void>::value &&
902 std::is_integral<iType>::value),
903 reference_type>::type
904 access(const iType& i0)
const {
905 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((1, this->
rank(), m_track, m_map, i0))
906 return m_map.reference(i0);
909 template <typename iType>
910 KOKKOS_INLINE_FUNCTION typename std::enable_if<
911 !(std::is_same<typename traits::specialize,
void>::value &&
912 std::is_integral<iType>::value),
913 reference_type>::type
914 access(const iType& i0)
const {
915 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((1, this->
rank(), m_track, m_map, i0))
916 return m_map.reference(i0, 0, 0, 0, 0, 0, 0);
920 template <typename iType0, typename iType1>
921 KOKKOS_INLINE_FUNCTION typename std::enable_if<
922 (std::is_same<typename traits::specialize,
void>::value &&
923 std::is_integral<iType0>::value && std::is_integral<iType1>::value),
924 reference_type>::type
925 access(const iType0& i0, const iType1& i1)
const {
926 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((2, this->
rank(), m_track, m_map, i0, i1))
927 return m_map.reference(i0, i1);
930 template <typename iType0, typename iType1>
931 KOKKOS_INLINE_FUNCTION typename std::enable_if<
932 !(std::is_same<typename drvtraits::specialize,
void>::value &&
933 std::is_integral<iType0>::value),
934 reference_type>::type
935 access(const iType0& i0, const iType1& i1)
const {
936 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((2, this->
rank(), m_track, m_map, i0, i1))
937 return m_map.reference(i0, i1, 0, 0, 0, 0, 0);
941 template <typename iType0, typename iType1, typename iType2>
942 KOKKOS_INLINE_FUNCTION typename std::enable_if<
943 (std::is_same<typename traits::specialize,
void>::value &&
944 std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
945 std::is_integral<iType2>::value),
946 reference_type>::type
947 access(const iType0& i0, const iType1& i1, const iType2& i2)
const {
948 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
949 (3, this->
rank(), m_track, m_map, i0, i1, i2))
950 return m_map.reference(i0, i1, i2);
953 template <typename iType0, typename iType1, typename iType2>
954 KOKKOS_INLINE_FUNCTION typename std::enable_if<
955 !(std::is_same<typename drvtraits::specialize,
void>::value &&
956 std::is_integral<iType0>::value),
957 reference_type>::type
958 access(const iType0& i0, const iType1& i1, const iType2& i2)
const {
959 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
960 (3, this->
rank(), m_track, m_map, i0, i1, i2))
961 return m_map.reference(i0, i1, i2, 0, 0, 0, 0);
965 template <typename iType0, typename iType1, typename iType2, typename iType3>
966 KOKKOS_INLINE_FUNCTION typename std::enable_if<
967 (std::is_same<typename traits::specialize,
void>::value &&
968 std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
969 std::is_integral<iType2>::value && std::is_integral<iType3>::value),
970 reference_type>::type
971 access(const iType0& i0, const iType1& i1, const iType2& i2,
972 const iType3& i3)
const {
973 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
974 (4, this->
rank(), m_track, m_map, i0, i1, i2, i3))
975 return m_map.reference(i0, i1, i2, i3);
978 template <typename iType0, typename iType1, typename iType2, typename iType3>
979 KOKKOS_INLINE_FUNCTION typename std::enable_if<
980 !(std::is_same<typename drvtraits::specialize,
void>::value &&
981 std::is_integral<iType0>::value),
982 reference_type>::type
983 access(const iType0& i0, const iType1& i1, const iType2& i2,
984 const iType3& i3)
const {
985 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
986 (4, this->
rank(), m_track, m_map, i0, i1, i2, i3))
987 return m_map.reference(i0, i1, i2, i3, 0, 0, 0);
991 template <typename iType0, typename iType1, typename iType2, typename iType3,
993 KOKKOS_INLINE_FUNCTION typename std::enable_if<
994 (std::is_same<typename traits::specialize,
void>::value &&
995 std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
996 std::is_integral<iType2>::value && std::is_integral<iType3>::value &&
997 std::is_integral<iType4>::value),
998 reference_type>::type
999 access(const iType0& i0, const iType1& i1, const iType2& i2, const iType3& i3,
1000 const iType4& i4)
const {
1001 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1002 (5, this->
rank(), m_track, m_map, i0, i1, i2, i3, i4))
1003 return m_map.reference(i0, i1, i2, i3, i4);
1006 template <typename iType0, typename iType1, typename iType2, typename iType3,
1008 KOKKOS_INLINE_FUNCTION typename std::enable_if<
1009 !(std::is_same<typename drvtraits::specialize,
void>::value &&
1010 std::is_integral<iType0>::value),
1011 reference_type>::type
1012 access(const iType0& i0, const iType1& i1, const iType2& i2, const iType3& i3,
1013 const iType4& i4)
const {
1014 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1015 (5, this->
rank(), m_track, m_map, i0, i1, i2, i3, i4))
1016 return m_map.reference(i0, i1, i2, i3, i4, 0, 0);
1020 template <typename iType0, typename iType1, typename iType2, typename iType3,
1021 typename iType4, typename iType5>
1022 KOKKOS_INLINE_FUNCTION typename std::enable_if<
1023 (std::is_same<typename traits::specialize,
void>::value &&
1024 std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
1025 std::is_integral<iType2>::value && std::is_integral<iType3>::value &&
1026 std::is_integral<iType4>::value && std::is_integral<iType5>::value),
1027 reference_type>::type
1028 access(const iType0& i0, const iType1& i1, const iType2& i2, const iType3& i3,
1029 const iType4& i4, const iType5& i5)
const {
1030 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1031 (6, this->
rank(), m_track, m_map, i0, i1, i2, i3, i4, i5))
1032 return m_map.reference(i0, i1, i2, i3, i4, i5);
1035 template <typename iType0, typename iType1, typename iType2, typename iType3,
1036 typename iType4, typename iType5>
1037 KOKKOS_INLINE_FUNCTION typename std::enable_if<
1038 !(std::is_same<typename drvtraits::specialize,
void>::value &&
1039 std::is_integral<iType0>::value),
1040 reference_type>::type
1041 access(const iType0& i0, const iType1& i1, const iType2& i2, const iType3& i3,
1042 const iType4& i4, const iType5& i5)
const {
1043 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1044 (6, this->
rank(), m_track, m_map, i0, i1, i2, i3, i4, i5))
1045 return m_map.reference(i0, i1, i2, i3, i4, i5, 0);
1049 template <typename iType0, typename iType1, typename iType2, typename iType3,
1050 typename iType4, typename iType5, typename iType6>
1051 KOKKOS_INLINE_FUNCTION typename std::enable_if<
1052 (std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
1053 std::is_integral<iType2>::value && std::is_integral<iType3>::value &&
1054 std::is_integral<iType4>::value && std::is_integral<iType5>::value &&
1055 std::is_integral<iType6>::value),
1056 reference_type>::type
1057 access(const iType0& i0, const iType1& i1, const iType2& i2, const iType3& i3,
1058 const iType4& i4, const iType5& i5, const iType6& i6)
const {
1059 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1060 (7, this->
rank(), m_track, m_map, i0, i1, i2, i3, i4, i5, i6))
1061 return m_map.reference(i0, i1, i2, i3, i4, i5, i6);
1064 #undef KOKKOS_IMPL_VIEW_OPERATOR_VERIFY
1069 KOKKOS_DEFAULTED_FUNCTION
1070 ~DynRankView() =
default;
1072 KOKKOS_INLINE_FUNCTION
1073 DynRankView() : m_track(), m_map(), m_rank() {}
1075 KOKKOS_INLINE_FUNCTION
1076 DynRankView(
const DynRankView& rhs)
1077 : m_track(rhs.m_track), m_map(rhs.m_map), m_rank(rhs.m_rank) {}
1079 KOKKOS_INLINE_FUNCTION
1080 DynRankView(DynRankView&& rhs)
1081 : m_track(rhs.m_track), m_map(rhs.m_map), m_rank(rhs.m_rank) {}
1083 KOKKOS_INLINE_FUNCTION
1084 DynRankView& operator=(
const DynRankView& rhs) {
1085 m_track = rhs.m_track;
1087 m_rank = rhs.m_rank;
1091 KOKKOS_INLINE_FUNCTION
1092 DynRankView& operator=(DynRankView&& rhs) {
1093 m_track = rhs.m_track;
1095 m_rank = rhs.m_rank;
1102 template <
class RT,
class... RP>
1103 KOKKOS_INLINE_FUNCTION DynRankView(
const DynRankView<RT, RP...>& rhs)
1104 : m_track(rhs.m_track, traits::is_managed), m_map(), m_rank(rhs.m_rank) {
1105 typedef typename DynRankView<RT, RP...>::traits SrcTraits;
1106 typedef Kokkos::Impl::ViewMapping<traits, SrcTraits,
1107 typename traits::specialize>
1109 static_assert(Mapping::is_assignable,
1110 "Incompatible DynRankView copy construction");
1111 Mapping::assign(m_map, rhs.m_map, rhs.m_track);
1114 template <
class RT,
class... RP>
1115 KOKKOS_INLINE_FUNCTION DynRankView& operator=(
1116 const DynRankView<RT, RP...>& rhs) {
1117 typedef typename DynRankView<RT, RP...>::traits SrcTraits;
1118 typedef Kokkos::Impl::ViewMapping<traits, SrcTraits,
1119 typename traits::specialize>
1121 static_assert(Mapping::is_assignable,
1122 "Incompatible DynRankView copy construction");
1123 Mapping::assign(m_map, rhs.m_map, rhs.m_track);
1124 m_track.assign(rhs.m_track, traits::is_managed);
1125 m_rank = rhs.rank();
1130 template <
class RT,
class... RP>
1131 KOKKOS_INLINE_FUNCTION DynRankView(
const View<RT, RP...>& rhs)
1132 : m_track(), m_map(), m_rank(rhs.Rank) {
1133 typedef typename View<RT, RP...>::traits SrcTraits;
1134 typedef Kokkos::Impl::ViewMapping<traits, SrcTraits,
1137 static_assert(Mapping::is_assignable,
1138 "Incompatible View to DynRankView copy construction");
1139 Mapping::assign(*
this, rhs);
1142 template <
class RT,
class... RP>
1143 KOKKOS_INLINE_FUNCTION DynRankView& operator=(
const View<RT, RP...>& rhs) {
1144 typedef typename View<RT, RP...>::traits SrcTraits;
1145 typedef Kokkos::Impl::ViewMapping<traits, SrcTraits,
1148 static_assert(Mapping::is_assignable,
1149 "Incompatible View to DynRankView copy assignment");
1150 Mapping::assign(*
this, rhs);
1157 KOKKOS_INLINE_FUNCTION
1158 int use_count()
const {
return m_track.use_count(); }
1160 inline const std::string label()
const {
1161 return m_track.template get_label<typename traits::memory_space>();
1168 template <
class... P>
1169 explicit inline DynRankView(
1170 const Kokkos::Impl::ViewCtorProp<P...>& arg_prop,
1171 typename std::enable_if<!Kokkos::Impl::ViewCtorProp<P...>::has_pointer,
1172 typename traits::array_layout>::type
const&
1176 m_rank(Impl::DynRankDimTraits<typename traits::specialize>::
1177 template computeRank<typename traits::array_layout, P...>(
1178 arg_prop, arg_layout)) {
1180 typedef Kokkos::Impl::ViewCtorProp<P...> alloc_prop_input;
1184 typedef Kokkos::Impl::ViewCtorProp<
1186 typename std::conditional<alloc_prop_input::has_label,
1187 std::integral_constant<unsigned, 0>,
1188 typename std::string>::type,
1189 typename std::conditional<
1190 alloc_prop_input::has_memory_space,
1191 std::integral_constant<unsigned, 1>,
1192 typename traits::device_type::memory_space>::type,
1193 typename std::conditional<
1194 alloc_prop_input::has_execution_space,
1195 std::integral_constant<unsigned, 2>,
1196 typename traits::device_type::execution_space>::type>
1199 static_assert(traits::is_managed,
1200 "View allocation constructor requires managed memory");
1202 if (alloc_prop::initialize &&
1203 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
1204 !alloc_prop::execution_space::is_initialized()
1206 !alloc_prop::execution_space::impl_is_initialized()
1211 Kokkos::Impl::throw_runtime_exception(
1212 "Constructing DynRankView and initializing data with uninitialized "
1217 alloc_prop prop_copy(arg_prop);
1220 #if defined(KOKKOS_ENABLE_CUDA)
1226 if (std::is_same<Kokkos::CudaUVMSpace,
1227 typename traits::device_type::memory_space>::value) {
1228 typename traits::device_type::memory_space::execution_space().fence();
1233 Kokkos::Impl::SharedAllocationRecord<>* record = m_map.allocate_shared(
1235 Impl::DynRankDimTraits<typename traits::specialize>::
1236 template createLayout<traits, P...>(arg_prop, arg_layout));
1239 #if defined(KOKKOS_ENABLE_CUDA)
1240 if (std::is_same<Kokkos::CudaUVMSpace,
1241 typename traits::device_type::memory_space>::value) {
1242 typename traits::device_type::memory_space::execution_space().fence();
1248 m_track.assign_allocated_record_to_uninitialized(record);
1252 template <
class... P>
1253 explicit KOKKOS_INLINE_FUNCTION DynRankView(
1254 const Kokkos::Impl::ViewCtorProp<P...>& arg_prop,
1255 typename std::enable_if<Kokkos::Impl::ViewCtorProp<P...>::has_pointer,
1256 typename traits::array_layout>::type
const&
1261 Impl::DynRankDimTraits<typename traits::specialize>::
1262 template createLayout<traits, P...>(arg_prop, arg_layout)),
1263 m_rank(Impl::DynRankDimTraits<typename traits::specialize>::
1264 template computeRank<typename traits::array_layout, P...>(
1265 arg_prop, arg_layout)) {
1267 std::is_same<pointer_type,
1268 typename Impl::ViewCtorProp<P...>::pointer_type>::value,
1269 "Constructing DynRankView to wrap user memory must supply matching "
1277 template <
class... P>
1278 explicit inline DynRankView(
1279 const Kokkos::Impl::ViewCtorProp<P...>& arg_prop,
1280 typename std::enable_if<!Kokkos::Impl::ViewCtorProp<P...>::has_pointer,
1281 size_t>::type
const arg_N0 = KOKKOS_INVALID_INDEX,
1282 const size_t arg_N1 = KOKKOS_INVALID_INDEX,
1283 const size_t arg_N2 = KOKKOS_INVALID_INDEX,
1284 const size_t arg_N3 = KOKKOS_INVALID_INDEX,
1285 const size_t arg_N4 = KOKKOS_INVALID_INDEX,
1286 const size_t arg_N5 = KOKKOS_INVALID_INDEX,
1287 const size_t arg_N6 = KOKKOS_INVALID_INDEX,
1288 const size_t arg_N7 = KOKKOS_INVALID_INDEX)
1289 : DynRankView(arg_prop, typename traits::array_layout(
1290 arg_N0, arg_N1, arg_N2, arg_N3, arg_N4,
1291 arg_N5, arg_N6, arg_N7)) {}
1293 template <
class... P>
1294 explicit KOKKOS_INLINE_FUNCTION DynRankView(
1295 const Kokkos::Impl::ViewCtorProp<P...>& arg_prop,
1296 typename std::enable_if<Kokkos::Impl::ViewCtorProp<P...>::has_pointer,
1297 size_t>::type
const arg_N0 = KOKKOS_INVALID_INDEX,
1298 const size_t arg_N1 = KOKKOS_INVALID_INDEX,
1299 const size_t arg_N2 = KOKKOS_INVALID_INDEX,
1300 const size_t arg_N3 = KOKKOS_INVALID_INDEX,
1301 const size_t arg_N4 = KOKKOS_INVALID_INDEX,
1302 const size_t arg_N5 = KOKKOS_INVALID_INDEX,
1303 const size_t arg_N6 = KOKKOS_INVALID_INDEX,
1304 const size_t arg_N7 = KOKKOS_INVALID_INDEX)
1305 : DynRankView(arg_prop, typename traits::array_layout(
1306 arg_N0, arg_N1, arg_N2, arg_N3, arg_N4,
1307 arg_N5, arg_N6, arg_N7)) {}
1310 template <
typename Label>
1311 explicit inline DynRankView(
1312 const Label& arg_label,
1313 typename std::enable_if<Kokkos::Impl::is_view_label<Label>::value,
1314 typename traits::array_layout>::type
const&
1316 : DynRankView(Kokkos::Impl::ViewCtorProp<std::string>(arg_label),
1320 template <
typename Label>
1321 explicit inline DynRankView(
1322 const Label& arg_label,
1323 typename std::enable_if<Kokkos::Impl::is_view_label<Label>::value,
1324 const size_t>::type arg_N0 = KOKKOS_INVALID_INDEX,
1325 const size_t arg_N1 = KOKKOS_INVALID_INDEX,
1326 const size_t arg_N2 = KOKKOS_INVALID_INDEX,
1327 const size_t arg_N3 = KOKKOS_INVALID_INDEX,
1328 const size_t arg_N4 = KOKKOS_INVALID_INDEX,
1329 const size_t arg_N5 = KOKKOS_INVALID_INDEX,
1330 const size_t arg_N6 = KOKKOS_INVALID_INDEX,
1331 const size_t arg_N7 = KOKKOS_INVALID_INDEX)
1333 Kokkos::Impl::ViewCtorProp<std::string>(arg_label),
1334 typename traits::array_layout(arg_N0, arg_N1, arg_N2, arg_N3,
1335 arg_N4, arg_N5, arg_N6, arg_N7)) {}
1340 explicit inline DynRankView(
const ViewAllocateWithoutInitializing& arg_prop,
1341 const typename traits::array_layout& arg_layout)
1343 Kokkos::Impl::ViewCtorProp<std::string,
1344 Kokkos::Impl::WithoutInitializing_t>(
1345 arg_prop.label, Kokkos::WithoutInitializing),
1348 explicit inline DynRankView(
const ViewAllocateWithoutInitializing& arg_prop,
1349 const size_t arg_N0 = KOKKOS_INVALID_INDEX,
1350 const size_t arg_N1 = KOKKOS_INVALID_INDEX,
1351 const size_t arg_N2 = KOKKOS_INVALID_INDEX,
1352 const size_t arg_N3 = KOKKOS_INVALID_INDEX,
1353 const size_t arg_N4 = KOKKOS_INVALID_INDEX,
1354 const size_t arg_N5 = KOKKOS_INVALID_INDEX,
1355 const size_t arg_N6 = KOKKOS_INVALID_INDEX,
1356 const size_t arg_N7 = KOKKOS_INVALID_INDEX)
1358 Kokkos::Impl::ViewCtorProp<std::string,
1359 Kokkos::Impl::WithoutInitializing_t>(
1360 arg_prop.label, Kokkos::WithoutInitializing),
1361 typename traits::array_layout(arg_N0, arg_N1, arg_N2, arg_N3,
1362 arg_N4, arg_N5, arg_N6, arg_N7)) {}
1366 static constexpr
size_t required_allocation_size(
1367 const size_t arg_N0 = 0,
const size_t arg_N1 = 0,
const size_t arg_N2 = 0,
1368 const size_t arg_N3 = 0,
const size_t arg_N4 = 0,
const size_t arg_N5 = 0,
1369 const size_t arg_N6 = 0,
const size_t arg_N7 = 0) {
1370 return map_type::memory_span(
typename traits::array_layout(
1371 arg_N0, arg_N1, arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7));
1374 explicit KOKKOS_INLINE_FUNCTION DynRankView(
1375 pointer_type arg_ptr,
const size_t arg_N0 = KOKKOS_INVALID_INDEX,
1376 const size_t arg_N1 = KOKKOS_INVALID_INDEX,
1377 const size_t arg_N2 = KOKKOS_INVALID_INDEX,
1378 const size_t arg_N3 = KOKKOS_INVALID_INDEX,
1379 const size_t arg_N4 = KOKKOS_INVALID_INDEX,
1380 const size_t arg_N5 = KOKKOS_INVALID_INDEX,
1381 const size_t arg_N6 = KOKKOS_INVALID_INDEX,
1382 const size_t arg_N7 = KOKKOS_INVALID_INDEX)
1383 : DynRankView(Kokkos::Impl::ViewCtorProp<pointer_type>(arg_ptr), arg_N0,
1384 arg_N1, arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7) {}
1386 explicit KOKKOS_INLINE_FUNCTION DynRankView(
1387 pointer_type arg_ptr,
typename traits::array_layout& arg_layout)
1388 : DynRankView(Kokkos::Impl::ViewCtorProp<pointer_type>(arg_ptr),
1394 static inline size_t shmem_size(
const size_t arg_N0 = KOKKOS_INVALID_INDEX,
1395 const size_t arg_N1 = KOKKOS_INVALID_INDEX,
1396 const size_t arg_N2 = KOKKOS_INVALID_INDEX,
1397 const size_t arg_N3 = KOKKOS_INVALID_INDEX,
1398 const size_t arg_N4 = KOKKOS_INVALID_INDEX,
1399 const size_t arg_N5 = KOKKOS_INVALID_INDEX,
1400 const size_t arg_N6 = KOKKOS_INVALID_INDEX,
1401 const size_t arg_N7 = KOKKOS_INVALID_INDEX) {
1402 const size_t num_passed_args =
1403 (arg_N0 != KOKKOS_INVALID_INDEX) + (arg_N1 != KOKKOS_INVALID_INDEX) +
1404 (arg_N2 != KOKKOS_INVALID_INDEX) + (arg_N3 != KOKKOS_INVALID_INDEX) +
1405 (arg_N4 != KOKKOS_INVALID_INDEX) + (arg_N5 != KOKKOS_INVALID_INDEX) +
1406 (arg_N6 != KOKKOS_INVALID_INDEX) + (arg_N7 != KOKKOS_INVALID_INDEX);
1408 if (std::is_same<typename traits::specialize, void>::value &&
1409 num_passed_args != traits::rank_dynamic) {
1411 "Kokkos::View::shmem_size() rank_dynamic != number of arguments.\n");
1415 return map_type::memory_span(
typename traits::array_layout(
1416 arg_N0, arg_N1, arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7));
1419 explicit KOKKOS_INLINE_FUNCTION DynRankView(
1420 const typename traits::execution_space::scratch_memory_space& arg_space,
1421 const typename traits::array_layout& arg_layout)
1423 Kokkos::Impl::ViewCtorProp<pointer_type>(
1424 reinterpret_cast<pointer_type>(
1425 arg_space.get_shmem(map_type::memory_span(
1426 Impl::DynRankDimTraits<typename traits::specialize>::
1427 createLayout(arg_layout)
1431 explicit KOKKOS_INLINE_FUNCTION DynRankView(
1432 const typename traits::execution_space::scratch_memory_space& arg_space,
1433 const size_t arg_N0 = KOKKOS_INVALID_INDEX,
1434 const size_t arg_N1 = KOKKOS_INVALID_INDEX,
1435 const size_t arg_N2 = KOKKOS_INVALID_INDEX,
1436 const size_t arg_N3 = KOKKOS_INVALID_INDEX,
1437 const size_t arg_N4 = KOKKOS_INVALID_INDEX,
1438 const size_t arg_N5 = KOKKOS_INVALID_INDEX,
1439 const size_t arg_N6 = KOKKOS_INVALID_INDEX,
1440 const size_t arg_N7 = KOKKOS_INVALID_INDEX)
1443 Kokkos::Impl::ViewCtorProp<pointer_type>(
1444 reinterpret_cast<pointer_type>(
1445 arg_space.get_shmem(map_type::memory_span(
1446 Impl::DynRankDimTraits<typename traits::specialize>::
1447 createLayout(typename traits::array_layout(
1448 arg_N0, arg_N1, arg_N2, arg_N3, arg_N4, arg_N5,
1449 arg_N6, arg_N7)))))),
1450 typename traits::array_layout(arg_N0, arg_N1, arg_N2, arg_N3,
1451 arg_N4, arg_N5, arg_N6, arg_N7)) {}
1454 template <
typename D,
class... P>
1455 KOKKOS_INLINE_FUNCTION constexpr
unsigned rank(
1456 const DynRankView<D, P...>& DRV) {
1467 struct DynRankSubviewTag {};
1473 template <
class SrcTraits,
class... Args>
1475 typename std::enable_if<
1476 (std::is_same<typename SrcTraits::specialize, void>::value &&
1477 (std::is_same<typename SrcTraits::array_layout,
1478 Kokkos::LayoutLeft>::value ||
1479 std::is_same<typename SrcTraits::array_layout,
1480 Kokkos::LayoutRight>::value ||
1481 std::is_same<typename SrcTraits::array_layout,
1482 Kokkos::LayoutStride>::value)),
1483 Kokkos::Impl::DynRankSubviewTag>::type,
1484 SrcTraits, Args...> {
1488 R0 = bool(is_integral_extent<0, Args...>::value),
1489 R1 = bool(is_integral_extent<1, Args...>::value),
1490 R2 = bool(is_integral_extent<2, Args...>::value),
1491 R3 = bool(is_integral_extent<3, Args...>::value),
1492 R4 = bool(is_integral_extent<4, Args...>::value),
1493 R5 = bool(is_integral_extent<5, Args...>::value),
1494 R6 = bool(is_integral_extent<6, Args...>::value)
1498 rank = unsigned(R0) + unsigned(R1) + unsigned(R2) + unsigned(R3) +
1499 unsigned(R4) + unsigned(R5) + unsigned(R6)
1504 typedef typename SrcTraits::value_type value_type;
1506 typedef value_type******* data_type;
1510 typename SrcTraits::device_type,
1511 typename SrcTraits::memory_traits>
1514 typedef Kokkos::View<data_type, array_layout,
typename SrcTraits::device_type,
1515 typename SrcTraits::memory_traits>
1518 template <
class MemoryTraits>
1520 static_assert(Kokkos::Impl::is_memory_traits<MemoryTraits>::value,
"");
1523 typename SrcTraits::device_type, MemoryTraits>
1527 typename SrcTraits::device_type, MemoryTraits>
1531 typedef typename SrcTraits::dimension dimension;
1533 template <
class Arg0 = int,
class Arg1 = int,
class Arg2 = int,
1534 class Arg3 = int,
class Arg4 = int,
class Arg5 = int,
1536 struct ExtentGenerator {
1537 KOKKOS_INLINE_FUNCTION
1538 static SubviewExtents<7, rank> generator(
1539 const dimension& dim, Arg0 arg0 = Arg0(), Arg1 arg1 = Arg1(),
1540 Arg2 arg2 = Arg2(), Arg3 arg3 = Arg3(), Arg4 arg4 = Arg4(),
1541 Arg5 arg5 = Arg5(), Arg6 arg6 = Arg6()) {
1542 return SubviewExtents<7, rank>(dim, arg0, arg1, arg2, arg3, arg4, arg5,
1547 typedef Kokkos::DynRankView<value_type, array_layout,
1548 typename SrcTraits::device_type,
1549 typename SrcTraits::memory_traits>
1552 template <
typename T,
class... P>
1553 KOKKOS_INLINE_FUNCTION
static ret_type subview(
1554 const unsigned src_rank, Kokkos::DynRankView<T, P...>
const& src,
1556 typedef ViewMapping<traits_type, typename traits_type::specialize> DstType;
1558 typedef typename std::conditional<
1559 (rank == 0), ViewDimension<>,
1560 typename std::conditional<
1561 (rank == 1), ViewDimension<0>,
1562 typename std::conditional<
1563 (rank == 2), ViewDimension<0, 0>,
1564 typename std::conditional<
1565 (rank == 3), ViewDimension<0, 0, 0>,
1566 typename std::conditional<
1567 (rank == 4), ViewDimension<0, 0, 0, 0>,
1568 typename std::conditional<
1569 (rank == 5), ViewDimension<0, 0, 0, 0, 0>,
1570 typename std::conditional<
1571 (rank == 6), ViewDimension<0, 0, 0, 0, 0, 0>,
1572 ViewDimension<0, 0, 0, 0, 0, 0, 0> >::type>::
1573 type>::type>::type>::type>::type>::type DstDimType;
1575 typedef ViewOffset<DstDimType, Kokkos::LayoutStride> dst_offset_type;
1576 typedef typename DstType::handle_type dst_handle_type;
1580 const SubviewExtents<7, rank> extents = ExtentGenerator<Args...>::generator(
1581 src.m_map.m_impl_offset.m_dim, args...);
1583 dst_offset_type tempdst(src.m_map.m_impl_offset, extents);
1585 dst.m_track = src.m_track;
1587 dst.m_map.m_impl_offset.m_dim.N0 = tempdst.m_dim.N0;
1588 dst.m_map.m_impl_offset.m_dim.N1 = tempdst.m_dim.N1;
1589 dst.m_map.m_impl_offset.m_dim.N2 = tempdst.m_dim.N2;
1590 dst.m_map.m_impl_offset.m_dim.N3 = tempdst.m_dim.N3;
1591 dst.m_map.m_impl_offset.m_dim.N4 = tempdst.m_dim.N4;
1592 dst.m_map.m_impl_offset.m_dim.N5 = tempdst.m_dim.N5;
1593 dst.m_map.m_impl_offset.m_dim.N6 = tempdst.m_dim.N6;
1595 dst.m_map.m_impl_offset.m_stride.S0 = tempdst.m_stride.S0;
1596 dst.m_map.m_impl_offset.m_stride.S1 = tempdst.m_stride.S1;
1597 dst.m_map.m_impl_offset.m_stride.S2 = tempdst.m_stride.S2;
1598 dst.m_map.m_impl_offset.m_stride.S3 = tempdst.m_stride.S3;
1599 dst.m_map.m_impl_offset.m_stride.S4 = tempdst.m_stride.S4;
1600 dst.m_map.m_impl_offset.m_stride.S5 = tempdst.m_stride.S5;
1601 dst.m_map.m_impl_offset.m_stride.S6 = tempdst.m_stride.S6;
1603 dst.m_map.m_impl_handle =
1604 dst_handle_type(src.m_map.m_impl_handle +
1605 src.m_map.m_impl_offset(
1606 extents.domain_offset(0), extents.domain_offset(1),
1607 extents.domain_offset(2), extents.domain_offset(3),
1608 extents.domain_offset(4), extents.domain_offset(5),
1609 extents.domain_offset(6)));
1612 (src_rank > 0 ? unsigned(R0) : 0) + (src_rank > 1 ? unsigned(R1) : 0) +
1613 (src_rank > 2 ? unsigned(R2) : 0) + (src_rank > 3 ? unsigned(R3) : 0) +
1614 (src_rank > 4 ? unsigned(R4) : 0) + (src_rank > 5 ? unsigned(R5) : 0) +
1615 (src_rank > 6 ? unsigned(R6) : 0);
1623 template <
class V,
class... Args>
1624 using Subdynrankview =
1625 typename Kokkos::Impl::ViewMapping<Kokkos::Impl::DynRankSubviewTag, V,
1628 template <
class D,
class... P,
class... Args>
1629 KOKKOS_INLINE_FUNCTION Subdynrankview<ViewTraits<D*******, P...>, Args...>
1630 subdynrankview(
const Kokkos::DynRankView<D, P...>& src, Args... args) {
1631 if (src.rank() >
sizeof...(Args))
1635 "subdynrankview: num of args must be >= rank of the source "
1639 typedef Kokkos::Impl::ViewMapping<Kokkos::Impl::DynRankSubviewTag,
1643 return metafcn::subview(src.rank(), src, args...);
1647 template <
class D,
class... P,
class... Args>
1648 KOKKOS_INLINE_FUNCTION Subdynrankview<ViewTraits<D*******, P...>, Args...>
1649 subview(
const Kokkos::DynRankView<D, P...>& src, Args... args) {
1650 return subdynrankview(src, args...);
1658 template <
class LT,
class... LP,
class RT,
class... RP>
1659 KOKKOS_INLINE_FUNCTION
bool operator==(
const DynRankView<LT, LP...>& lhs,
1660 const DynRankView<RT, RP...>& rhs) {
1662 typedef ViewTraits<LT, LP...> lhs_traits;
1663 typedef ViewTraits<RT, RP...> rhs_traits;
1665 return std::is_same<
typename lhs_traits::const_value_type,
1666 typename rhs_traits::const_value_type>::value &&
1667 std::is_same<
typename lhs_traits::array_layout,
1668 typename rhs_traits::array_layout>::value &&
1669 std::is_same<
typename lhs_traits::memory_space,
1670 typename rhs_traits::memory_space>::value &&
1671 lhs.rank() == rhs.rank() && lhs.data() == rhs.data() &&
1672 lhs.span() == rhs.span() && lhs.extent(0) == rhs.extent(0) &&
1673 lhs.extent(1) == rhs.extent(1) && lhs.extent(2) == rhs.extent(2) &&
1674 lhs.extent(3) == rhs.extent(3) && lhs.extent(4) == rhs.extent(4) &&
1675 lhs.extent(5) == rhs.extent(5) && lhs.extent(6) == rhs.extent(6) &&
1676 lhs.extent(7) == rhs.extent(7);
1679 template <
class LT,
class... LP,
class RT,
class... RP>
1680 KOKKOS_INLINE_FUNCTION
bool operator!=(
const DynRankView<LT, LP...>& lhs,
1681 const DynRankView<RT, RP...>& rhs) {
1692 template <
class OutputView,
typename Enable =
void>
1693 struct DynRankViewFill {
1694 typedef typename OutputView::traits::const_value_type const_value_type;
1696 const OutputView output;
1697 const_value_type input;
1699 KOKKOS_INLINE_FUNCTION
1700 void operator()(
const size_t i0)
const {
1701 const size_t n1 = output.extent(1);
1702 const size_t n2 = output.extent(2);
1703 const size_t n3 = output.extent(3);
1704 const size_t n4 = output.extent(4);
1705 const size_t n5 = output.extent(5);
1706 const size_t n6 = output.extent(6);
1708 for (
size_t i1 = 0; i1 < n1; ++i1) {
1709 for (
size_t i2 = 0; i2 < n2; ++i2) {
1710 for (
size_t i3 = 0; i3 < n3; ++i3) {
1711 for (
size_t i4 = 0; i4 < n4; ++i4) {
1712 for (
size_t i5 = 0; i5 < n5; ++i5) {
1713 for (
size_t i6 = 0; i6 < n6; ++i6) {
1714 output.access(i0, i1, i2, i3, i4, i5, i6) = input;
1723 DynRankViewFill(
const OutputView& arg_out, const_value_type& arg_in)
1724 : output(arg_out), input(arg_in) {
1725 typedef typename OutputView::execution_space execution_space;
1729 *
this, Policy(0, output.extent(0)));
1733 execution_space().fence();
1737 template <
class OutputView>
1738 struct DynRankViewFill<OutputView,
1739 typename std::enable_if<OutputView::Rank == 0>::type> {
1740 DynRankViewFill(
const OutputView& dst,
1741 const typename OutputView::const_value_type& src) {
1742 Kokkos::Impl::DeepCopy<
typename OutputView::memory_space,
1744 dst.data(), &src,
sizeof(
typename OutputView::const_value_type));
1748 template <
class OutputView,
class InputView,
1749 class ExecSpace =
typename OutputView::execution_space>
1750 struct DynRankViewRemap {
1751 const OutputView output;
1752 const InputView input;
1762 DynRankViewRemap(
const OutputView& arg_out,
const InputView& arg_in)
1765 n0(std::min((size_t)arg_out.extent(0), (size_t)arg_in.extent(0))),
1766 n1(std::min((size_t)arg_out.extent(1), (size_t)arg_in.extent(1))),
1767 n2(std::min((size_t)arg_out.extent(2), (size_t)arg_in.extent(2))),
1768 n3(std::min((size_t)arg_out.extent(3), (size_t)arg_in.extent(3))),
1769 n4(std::min((size_t)arg_out.extent(4), (size_t)arg_in.extent(4))),
1770 n5(std::min((size_t)arg_out.extent(5), (size_t)arg_in.extent(5))),
1771 n6(std::min((size_t)arg_out.extent(6), (size_t)arg_in.extent(6))),
1772 n7(std::min((size_t)arg_out.extent(7), (size_t)arg_in.extent(7))) {
1775 *
this, Policy(0, n0));
1780 KOKKOS_INLINE_FUNCTION
1781 void operator()(
const size_t i0)
const {
1782 for (
size_t i1 = 0; i1 < n1; ++i1) {
1783 for (
size_t i2 = 0; i2 < n2; ++i2) {
1784 for (
size_t i3 = 0; i3 < n3; ++i3) {
1785 for (
size_t i4 = 0; i4 < n4; ++i4) {
1786 for (
size_t i5 = 0; i5 < n5; ++i5) {
1787 for (
size_t i6 = 0; i6 < n6; ++i6) {
1788 output.access(i0, i1, i2, i3, i4, i5, i6) =
1789 input.access(i0, i1, i2, i3, i4, i5, i6);
1805 template <
class DT,
class... DP>
1807 const DynRankView<DT, DP...>& dst,
1808 typename ViewTraits<DT, DP...>::const_value_type& value,
1809 typename std::enable_if<std::is_same<
1810 typename ViewTraits<DT, DP...>::specialize,
void>::value>::type* =
1813 std::is_same<
typename ViewTraits<DT, DP...>::non_const_value_type,
1814 typename ViewTraits<DT, DP...>::value_type>::value,
1815 "deep_copy requires non-const type");
1817 Kokkos::Impl::DynRankViewFill<DynRankView<DT, DP...> >(dst, value);
1821 template <
class ST,
class... SP>
1823 typename ViewTraits<ST, SP...>::non_const_value_type& dst,
1824 const DynRankView<ST, SP...>& src,
1825 typename std::enable_if<std::is_same<
1826 typename ViewTraits<ST, SP...>::specialize,
void>::value>::type* = 0) {
1827 if (src.rank() != 0) {
1832 typedef typename src_traits::memory_space src_memory_space;
1833 Kokkos::Impl::DeepCopy<HostSpace, src_memory_space>(&dst, src.data(),
1841 template <
class DstType,
class SrcType>
1843 const DstType& dst,
const SrcType& src,
1844 typename std::enable_if<
1845 (std::is_same<typename DstType::traits::specialize, void>::value &&
1846 std::is_same<typename SrcType::traits::specialize, void>::value &&
1847 (Kokkos::is_dyn_rank_view<DstType>::value ||
1848 Kokkos::is_dyn_rank_view<SrcType>::value))>::type* =
nullptr) {
1850 std::is_same<
typename DstType::traits::value_type,
1851 typename DstType::traits::non_const_value_type>::value,
1852 "deep_copy requires non-const destination type");
1854 typedef DstType dst_type;
1855 typedef SrcType src_type;
1857 typedef typename dst_type::execution_space dst_execution_space;
1858 typedef typename src_type::execution_space src_execution_space;
1859 typedef typename dst_type::memory_space dst_memory_space;
1860 typedef typename src_type::memory_space src_memory_space;
1863 DstExecCanAccessSrc =
1865 src_memory_space>::accessible
1869 SrcExecCanAccessDst =
1871 dst_memory_space>::accessible
1874 if ((
void*)dst.data() != (
void*)src.data()) {
1880 if (
rank(src) == 0 &&
rank(dst) == 0) {
1881 typedef typename dst_type::value_type value_type;
1882 Kokkos::Impl::DeepCopy<dst_memory_space, src_memory_space>(
1883 dst.data(), src.data(),
sizeof(value_type));
1884 }
else if (std::is_same<
1885 typename DstType::traits::value_type,
1886 typename SrcType::traits::non_const_value_type>::value &&
1887 ((std::is_same<
typename DstType::traits::array_layout,
1888 typename SrcType::traits::array_layout>::value &&
1889 (std::is_same<
typename DstType::traits::array_layout,
1891 std::is_same<
typename DstType::traits::array_layout,
1893 (
rank(dst) == 1 &&
rank(src) == 1)) &&
1894 dst.span_is_contiguous() && src.span_is_contiguous() &&
1895 dst.span() == src.span() && dst.extent(0) == src.extent(0) &&
1897 dst.extent(1) == src.extent(1) &&
1898 dst.extent(2) == src.extent(2) &&
1899 dst.extent(3) == src.extent(3) &&
1900 dst.extent(4) == src.extent(4) &&
1901 dst.extent(5) == src.extent(5) &&
1902 dst.extent(6) == src.extent(6) &&
1903 dst.extent(7) == src.extent(7)) {
1904 const size_t nbytes =
sizeof(
typename dst_type::value_type) * dst.span();
1906 Kokkos::Impl::DeepCopy<dst_memory_space, src_memory_space>(
1907 dst.data(), src.data(), nbytes);
1908 }
else if (std::is_same<
1909 typename DstType::traits::value_type,
1910 typename SrcType::traits::non_const_value_type>::value &&
1911 ((std::is_same<
typename DstType::traits::array_layout,
1912 typename SrcType::traits::array_layout>::value &&
1913 std::is_same<
typename DstType::traits::array_layout,
1915 (
rank(dst) == 1 &&
rank(src) == 1)) &&
1916 dst.span_is_contiguous() && src.span_is_contiguous() &&
1917 dst.span() == src.span() && dst.extent(0) == src.extent(0) &&
1918 dst.extent(1) == src.extent(1) &&
1919 dst.extent(2) == src.extent(2) &&
1920 dst.extent(3) == src.extent(3) &&
1921 dst.extent(4) == src.extent(4) &&
1922 dst.extent(5) == src.extent(5) &&
1923 dst.extent(6) == src.extent(6) &&
1924 dst.extent(7) == src.extent(7) &&
1925 dst.stride_0() == src.stride_0() &&
1926 dst.stride_1() == src.stride_1() &&
1927 dst.stride_2() == src.stride_2() &&
1928 dst.stride_3() == src.stride_3() &&
1929 dst.stride_4() == src.stride_4() &&
1930 dst.stride_5() == src.stride_5() &&
1931 dst.stride_6() == src.stride_6() &&
1932 dst.stride_7() == src.stride_7()) {
1933 const size_t nbytes =
sizeof(
typename dst_type::value_type) * dst.span();
1935 Kokkos::Impl::DeepCopy<dst_memory_space, src_memory_space>(
1936 dst.data(), src.data(), nbytes);
1937 }
else if (DstExecCanAccessSrc) {
1940 Kokkos::Impl::DynRankViewRemap<dst_type, src_type>(dst, src);
1941 }
else if (SrcExecCanAccessDst) {
1944 Kokkos::Impl::DynRankViewRemap<dst_type, src_type, src_execution_space>(
1947 Kokkos::Impl::throw_runtime_exception(
1948 "deep_copy given views that would require a temporary allocation");
1962 template <
class Space,
class T,
class... P>
1963 struct MirrorDRViewType {
1965 typedef typename Kokkos::DynRankView<T, P...> src_view_type;
1967 typedef typename Space::memory_space memory_space;
1971 std::is_same<memory_space, typename src_view_type::memory_space>::value
1974 typedef typename src_view_type::array_layout array_layout;
1977 typedef typename src_view_type::non_const_data_type data_type;
1979 typedef Kokkos::DynRankView<data_type, array_layout, Space> dest_view_type;
1982 typedef typename std::conditional<is_same_memspace, src_view_type,
1983 dest_view_type>::type view_type;
1986 template <
class Space,
class T,
class... P>
1987 struct MirrorDRVType {
1989 typedef typename Kokkos::DynRankView<T, P...> src_view_type;
1991 typedef typename Space::memory_space memory_space;
1995 std::is_same<memory_space, typename src_view_type::memory_space>::value
1998 typedef typename src_view_type::array_layout array_layout;
2001 typedef typename src_view_type::non_const_data_type data_type;
2003 typedef Kokkos::DynRankView<data_type, array_layout, Space> view_type;
2008 template <
class T,
class... P>
2009 inline typename DynRankView<T, P...>::HostMirror create_mirror(
2010 const DynRankView<T, P...>& src,
2011 typename std::enable_if<
2012 std::is_same<
typename ViewTraits<T, P...>::specialize,
void>::value &&
2013 !std::is_same<
typename Kokkos::ViewTraits<T, P...>::array_layout,
2015 typedef DynRankView<T, P...> src_type;
2016 typedef typename src_type::HostMirror dst_type;
2018 return dst_type(std::string(src.label()).append(
"_mirror"),
2019 Impl::reconstructLayout(src.layout(), src.rank()));
2022 template <
class T,
class... P>
2023 inline typename DynRankView<T, P...>::HostMirror create_mirror(
2024 const DynRankView<T, P...>& src,
2025 typename std::enable_if<
2026 std::is_same<
typename ViewTraits<T, P...>::specialize,
void>::value &&
2027 std::is_same<
typename Kokkos::ViewTraits<T, P...>::array_layout,
2029 typedef DynRankView<T, P...> src_type;
2030 typedef typename src_type::HostMirror dst_type;
2032 return dst_type(std::string(src.label()).append(
"_mirror"),
2033 Impl::reconstructLayout(src.layout(), src.rank()));
2037 template <
class Space,
class T,
class... P>
2038 typename Impl::MirrorDRVType<Space, T, P...>::view_type create_mirror(
2039 const Space&,
const Kokkos::DynRankView<T, P...>& src,
2040 typename std::enable_if<std::is_same<
2041 typename ViewTraits<T, P...>::specialize,
void>::value>::type* =
2043 return typename Impl::MirrorDRVType<Space, T, P...>::view_type(
2044 src.label(), Impl::reconstructLayout(src.layout(), src.rank()));
2047 template <
class T,
class... P>
2048 inline typename DynRankView<T, P...>::HostMirror create_mirror_view(
2049 const DynRankView<T, P...>& src,
2050 typename std::enable_if<
2052 typename DynRankView<T, P...>::memory_space,
2053 typename DynRankView<T, P...>::HostMirror::memory_space>::value &&
2054 std::is_same<
typename DynRankView<T, P...>::data_type,
2055 typename DynRankView<T, P...>::HostMirror::data_type>::
2056 value)>::type* =
nullptr) {
2060 template <
class T,
class... P>
2061 inline typename DynRankView<T, P...>::HostMirror create_mirror_view(
2062 const DynRankView<T, P...>& src,
2063 typename std::enable_if<
2065 typename DynRankView<T, P...>::memory_space,
2066 typename DynRankView<T, P...>::HostMirror::memory_space>::value &&
2067 std::is_same<
typename DynRankView<T, P...>::data_type,
2068 typename DynRankView<T, P...>::HostMirror::data_type>::
2069 value)>::type* = 0) {
2070 return Kokkos::create_mirror(src);
2074 template <
class Space,
class T,
class... P>
2075 typename Impl::MirrorDRViewType<Space, T, P...>::view_type create_mirror_view(
2076 const Space&,
const Kokkos::DynRankView<T, P...>& src,
2077 typename std::enable_if<
2078 Impl::MirrorDRViewType<Space, T, P...>::is_same_memspace>::type* =
2084 template <
class Space,
class T,
class... P>
2085 typename Impl::MirrorDRViewType<Space, T, P...>::view_type create_mirror_view(
2086 const Space&,
const Kokkos::DynRankView<T, P...>& src,
2087 typename std::enable_if<
2088 !Impl::MirrorDRViewType<Space, T, P...>::is_same_memspace>::type* = 0) {
2089 return typename Impl::MirrorDRViewType<Space, T, P...>::view_type(
2090 src.label(), Impl::reconstructLayout(src.layout(), src.rank()));
2095 template <
class Space,
class T,
class... P>
2096 typename Impl::MirrorDRViewType<Space, T, P...>::view_type
2097 create_mirror_view_and_copy(
2098 const Space&,
const Kokkos::DynRankView<T, P...>& src,
2099 std::string
const& name =
"",
2100 typename std::enable_if<
2101 Impl::MirrorDRViewType<Space, T, P...>::is_same_memspace>::type* =
2109 template <
class Space,
class T,
class... P>
2110 typename Impl::MirrorDRViewType<Space, T, P...>::view_type
2111 create_mirror_view_and_copy(
2112 const Space&,
const Kokkos::DynRankView<T, P...>& src,
2113 std::string
const& name =
"",
2114 typename std::enable_if<
2115 !Impl::MirrorDRViewType<Space, T, P...>::is_same_memspace>::type* = 0) {
2116 using Mirror =
typename Impl::MirrorDRViewType<Space, T, P...>::view_type;
2117 std::string label = name.empty() ? src.label() : name;
2118 auto mirror = Mirror(Kokkos::ViewAllocateWithoutInitializing(label),
2119 Impl::reconstructLayout(src.layout(), src.rank()));
2132 template <
class T,
class... P>
2134 const size_t n0 = KOKKOS_INVALID_INDEX,
2135 const size_t n1 = KOKKOS_INVALID_INDEX,
2136 const size_t n2 = KOKKOS_INVALID_INDEX,
2137 const size_t n3 = KOKKOS_INVALID_INDEX,
2138 const size_t n4 = KOKKOS_INVALID_INDEX,
2139 const size_t n5 = KOKKOS_INVALID_INDEX,
2140 const size_t n6 = KOKKOS_INVALID_INDEX,
2141 const size_t n7 = KOKKOS_INVALID_INDEX) {
2142 typedef DynRankView<T, P...> drview_type;
2145 "Can only resize managed views");
2147 drview_type v_resized(v.label(), n0, n1, n2, n3, n4, n5, n6, n7);
2149 Kokkos::Impl::DynRankViewRemap<drview_type, drview_type>(v_resized, v);
2156 template <
class T,
class... P>
2158 const size_t n0 = KOKKOS_INVALID_INDEX,
2159 const size_t n1 = KOKKOS_INVALID_INDEX,
2160 const size_t n2 = KOKKOS_INVALID_INDEX,
2161 const size_t n3 = KOKKOS_INVALID_INDEX,
2162 const size_t n4 = KOKKOS_INVALID_INDEX,
2163 const size_t n5 = KOKKOS_INVALID_INDEX,
2164 const size_t n6 = KOKKOS_INVALID_INDEX,
2165 const size_t n7 = KOKKOS_INVALID_INDEX) {
2166 typedef DynRankView<T, P...> drview_type;
2169 "Can only realloc managed views");
2171 const std::string label = v.label();
2174 v = drview_type(label, n0, n1, n2, n3, n4, n5, n6, n7);
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 *=nullptr)
Deep copy a value from Host memory into a view.
Memory layout tag indicating left-to-right (Fortran scheme) striding of multi-indices.
KOKKOS_INLINE_FUNCTION bool operator==(complex< RealType1 > const &x, complex< RealType2 > const &y) noexcept
Binary == operator for complex complex.
Can AccessSpace access MemorySpace ?
Memory layout tag indicated arbitrarily strided multi-index mapping into contiguous memory...
View to an array of data.
Memory management for host memory.
Memory layout tag indicating right-to-left (C or lexigraphical scheme) striding of multi-indices...
Assign compatible default mappings.
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=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n1=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n2=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n3=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n4=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n5=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n6=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n7=KOKKOS_IMPL_CTOR_DEFAULT_ARG)
Resize a view with copying old data to new data at the corresponding indices.
Implementation of the ParallelFor operator that has a partial specialization for the device...
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=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n1=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n2=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n3=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n4=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n5=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n6=KOKKOS_IMPL_CTOR_DEFAULT_ARG, const size_t n7=KOKKOS_IMPL_CTOR_DEFAULT_ARG)
Resize a view with discarding old data.
Execution policy for work over a range of an integral type.
KOKKOS_INLINE_FUNCTION constexpr unsigned rank(const View< D, P...> &V)
Temporary free function rank() until rank() is implemented in the View.
KOKKOS_INLINE_FUNCTION bool operator!=(complex< RealType1 > const &x, complex< RealType2 > const &y) noexcept
Binary != operator for complex complex.
Traits class for accessing attributes of a View.
Access relationship between DstMemorySpace and SrcMemorySpace.