Kokkos Core Kernels Package Version of the Day
Kokkos_View.hpp
1/*
2//@HEADER
3// ************************************************************************
4//
5// Kokkos v. 3.0
6// Copyright (2020) National Technology & Engineering
7// Solutions of Sandia, LLC (NTESS).
8//
9// Under the terms of Contract DE-NA0003525 with NTESS,
10// the U.S. Government retains certain rights in this software.
11//
12// Redistribution and use in source and binary forms, with or without
13// modification, are permitted provided that the following conditions are
14// met:
15//
16// 1. Redistributions of source code must retain the above copyright
17// notice, this list of conditions and the following disclaimer.
18//
19// 2. Redistributions in binary form must reproduce the above copyright
20// notice, this list of conditions and the following disclaimer in the
21// documentation and/or other materials provided with the distribution.
22//
23// 3. Neither the name of the Corporation nor the names of the
24// contributors may be used to endorse or promote products derived from
25// this software without specific prior written permission.
26//
27// THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY
28// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NTESS OR THE
31// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38//
39// Questions? Contact Christian R. Trott (crtrott@sandia.gov)
40//
41// ************************************************************************
42//@HEADER
43*/
44
45#ifndef KOKKOS_VIEW_HPP
46#define KOKKOS_VIEW_HPP
47
48#include <type_traits>
49#include <string>
50#include <algorithm>
51#include <initializer_list>
52
53#include <Kokkos_Core_fwd.hpp>
54#include <Kokkos_HostSpace.hpp>
55#include <Kokkos_MemoryTraits.hpp>
56#include <Kokkos_ExecPolicy.hpp>
57
58#include <impl/Kokkos_Tools.hpp>
59
60//----------------------------------------------------------------------------
61//----------------------------------------------------------------------------
62
63namespace Kokkos {
64namespace Impl {
65
66template <class DataType>
67struct ViewArrayAnalysis;
68
69template <class DataType, class ArrayLayout,
70 typename ValueType =
71 typename ViewArrayAnalysis<DataType>::non_const_value_type>
72struct ViewDataAnalysis;
73
74template <class, class...>
75class ViewMapping {
76 public:
77 enum : bool { is_assignable_data_type = false };
78 enum : bool { is_assignable = false };
79};
80
81template <typename IntType>
82KOKKOS_INLINE_FUNCTION std::size_t count_valid_integers(
83 const IntType i0, const IntType i1, const IntType i2, const IntType i3,
84 const IntType i4, const IntType i5, const IntType i6, const IntType i7) {
85 static_assert(std::is_integral<IntType>::value,
86 "count_valid_integers() must have integer arguments.");
87
88 return (i0 != KOKKOS_INVALID_INDEX) + (i1 != KOKKOS_INVALID_INDEX) +
89 (i2 != KOKKOS_INVALID_INDEX) + (i3 != KOKKOS_INVALID_INDEX) +
90 (i4 != KOKKOS_INVALID_INDEX) + (i5 != KOKKOS_INVALID_INDEX) +
91 (i6 != KOKKOS_INVALID_INDEX) + (i7 != KOKKOS_INVALID_INDEX);
92}
93
94KOKKOS_INLINE_FUNCTION
95void runtime_check_rank_device(const size_t dyn_rank, const bool is_void_spec,
96 const size_t i0, const size_t i1,
97 const size_t i2, const size_t i3,
98 const size_t i4, const size_t i5,
99 const size_t i6, const size_t i7) {
100 if (is_void_spec) {
101 const size_t num_passed_args =
102 count_valid_integers(i0, i1, i2, i3, i4, i5, i6, i7);
103
104 if (num_passed_args != dyn_rank && is_void_spec) {
105 Kokkos::abort(
106 "Number of arguments passed to Kokkos::View() constructor must match "
107 "the dynamic rank of the view.");
108 }
109 }
110}
111
112#ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
113KOKKOS_INLINE_FUNCTION
114void runtime_check_rank_host(const size_t dyn_rank, const bool is_void_spec,
115 const size_t i0, const size_t i1, const size_t i2,
116 const size_t i3, const size_t i4, const size_t i5,
117 const size_t i6, const size_t i7,
118 const std::string& label) {
119 if (is_void_spec) {
120 const size_t num_passed_args =
121 count_valid_integers(i0, i1, i2, i3, i4, i5, i6, i7);
122
123 if (num_passed_args != dyn_rank) {
124 const std::string message =
125 "Constructor for Kokkos View '" + label +
126 "' has mismatched number of arguments. Number of arguments = " +
127 std::to_string(num_passed_args) +
128 " but dynamic rank = " + std::to_string(dyn_rank) + " \n";
129 Kokkos::abort(message.c_str());
130 }
131 }
132}
133#endif
134
135} /* namespace Impl */
136} /* namespace Kokkos */
137
138// Class to provide a uniform type
139namespace Kokkos {
140namespace Impl {
141template <class ViewType, int Traits = 0>
142struct ViewUniformType;
143}
144} // namespace Kokkos
145
146//----------------------------------------------------------------------------
147//----------------------------------------------------------------------------
148
149namespace Kokkos {
150
168template <class DataType, class... Properties>
169struct ViewTraits;
170
171template <>
172struct ViewTraits<void> {
173 using execution_space = void;
174 using memory_space = void;
175 using HostMirrorSpace = void;
176 using array_layout = void;
177 using memory_traits = void;
178 using specialize = void;
179};
180
181template <class... Prop>
182struct ViewTraits<void, void, Prop...> {
183 // Ignore an extraneous 'void'
184 using execution_space = typename ViewTraits<void, Prop...>::execution_space;
185 using memory_space = typename ViewTraits<void, Prop...>::memory_space;
186 using HostMirrorSpace = typename ViewTraits<void, Prop...>::HostMirrorSpace;
187 using array_layout = typename ViewTraits<void, Prop...>::array_layout;
188 using memory_traits = typename ViewTraits<void, Prop...>::memory_traits;
189 using specialize = typename ViewTraits<void, Prop...>::specialize;
190};
191
192template <class ArrayLayout, class... Prop>
193struct ViewTraits<typename std::enable_if<
194 Kokkos::Impl::is_array_layout<ArrayLayout>::value>::type,
195 ArrayLayout, Prop...> {
196 // Specify layout, keep subsequent space and memory traits arguments
197
198 using execution_space = typename ViewTraits<void, Prop...>::execution_space;
199 using memory_space = typename ViewTraits<void, Prop...>::memory_space;
200 using HostMirrorSpace = typename ViewTraits<void, Prop...>::HostMirrorSpace;
201 using array_layout = ArrayLayout;
202 using memory_traits = typename ViewTraits<void, Prop...>::memory_traits;
203 using specialize = typename ViewTraits<void, Prop...>::specialize;
204};
205
206template <class Space, class... Prop>
207struct ViewTraits<
208 typename std::enable_if<Kokkos::Impl::is_space<Space>::value>::type, Space,
209 Prop...> {
210 // Specify Space, memory traits should be the only subsequent argument.
211
212 static_assert(
213 std::is_same<typename ViewTraits<void, Prop...>::execution_space,
214 void>::value &&
215 std::is_same<typename ViewTraits<void, Prop...>::memory_space,
216 void>::value &&
217 std::is_same<typename ViewTraits<void, Prop...>::HostMirrorSpace,
218 void>::value &&
219 std::is_same<typename ViewTraits<void, Prop...>::array_layout,
220 void>::value,
221 "Only one View Execution or Memory Space template argument");
222
223 using execution_space = typename Space::execution_space;
224 using memory_space = typename Space::memory_space;
225 using HostMirrorSpace =
226 typename Kokkos::Impl::HostMirror<Space>::Space::memory_space;
227 using array_layout = typename execution_space::array_layout;
228 using memory_traits = typename ViewTraits<void, Prop...>::memory_traits;
229 using specialize = typename ViewTraits<void, Prop...>::specialize;
230};
231
232template <class MemoryTraits, class... Prop>
233struct ViewTraits<typename std::enable_if<Kokkos::Impl::is_memory_traits<
234 MemoryTraits>::value>::type,
235 MemoryTraits, Prop...> {
236 // Specify memory trait, should not be any subsequent arguments
237
238 static_assert(
239 std::is_same<typename ViewTraits<void, Prop...>::execution_space,
240 void>::value &&
241 std::is_same<typename ViewTraits<void, Prop...>::memory_space,
242 void>::value &&
243 std::is_same<typename ViewTraits<void, Prop...>::array_layout,
244 void>::value &&
245 std::is_same<typename ViewTraits<void, Prop...>::memory_traits,
246 void>::value,
247 "MemoryTrait is the final optional template argument for a View");
248
249 using execution_space = void;
250 using memory_space = void;
251 using HostMirrorSpace = void;
252 using array_layout = void;
253 using memory_traits = MemoryTraits;
254 using specialize = void;
255};
256
257template <class DataType, class... Properties>
259 private:
260 // Unpack the properties arguments
261 using prop = ViewTraits<void, Properties...>;
262
263 using ExecutionSpace = typename std::conditional<
264 !std::is_same<typename prop::execution_space, void>::value,
265 typename prop::execution_space, Kokkos::DefaultExecutionSpace>::type;
266
267 using MemorySpace = typename std::conditional<
268 !std::is_same<typename prop::memory_space, void>::value,
269 typename prop::memory_space, typename ExecutionSpace::memory_space>::type;
270
271 using ArrayLayout = typename std::conditional<
272 !std::is_same<typename prop::array_layout, void>::value,
273 typename prop::array_layout, typename ExecutionSpace::array_layout>::type;
274
275 using HostMirrorSpace = typename std::conditional<
276 !std::is_same<typename prop::HostMirrorSpace, void>::value,
277 typename prop::HostMirrorSpace,
278 typename Kokkos::Impl::HostMirror<ExecutionSpace>::Space>::type;
279
280 using MemoryTraits = typename std::conditional<
281 !std::is_same<typename prop::memory_traits, void>::value,
282 typename prop::memory_traits, typename Kokkos::MemoryManaged>::type;
283
284 // Analyze data type's properties,
285 // May be specialized based upon the layout and value type
286 using data_analysis = Kokkos::Impl::ViewDataAnalysis<DataType, ArrayLayout>;
287
288 public:
289 //------------------------------------
290 // Data type traits:
291
292 using data_type = typename data_analysis::type;
293 using const_data_type = typename data_analysis::const_type;
294 using non_const_data_type = typename data_analysis::non_const_type;
295
296 //------------------------------------
297 // Compatible array of trivial type traits:
298
299 using scalar_array_type = typename data_analysis::scalar_array_type;
300 using const_scalar_array_type =
301 typename data_analysis::const_scalar_array_type;
302 using non_const_scalar_array_type =
303 typename data_analysis::non_const_scalar_array_type;
304
305 //------------------------------------
306 // Value type traits:
307
308 using value_type = typename data_analysis::value_type;
309 using const_value_type = typename data_analysis::const_value_type;
310 using non_const_value_type = typename data_analysis::non_const_value_type;
311
312 //------------------------------------
313 // Mapping traits:
314
315 using array_layout = ArrayLayout;
316 using dimension = typename data_analysis::dimension;
317
318 using specialize = typename std::conditional<
319 std::is_same<typename data_analysis::specialize, void>::value,
320 typename prop::specialize, typename data_analysis::specialize>::
321 type; /* mapping specialization tag */
322
323 enum { rank = dimension::rank };
324 enum { rank_dynamic = dimension::rank_dynamic };
325
326 //------------------------------------
327 // Execution space, memory space, memory access traits, and host mirror space.
328
329 using execution_space = ExecutionSpace;
330 using memory_space = MemorySpace;
331 using device_type = Kokkos::Device<ExecutionSpace, MemorySpace>;
332 using memory_traits = MemoryTraits;
333 using host_mirror_space = HostMirrorSpace;
334
335 using size_type = typename MemorySpace::size_type;
336
337 enum { is_hostspace = std::is_same<MemorySpace, HostSpace>::value };
338 enum { is_managed = MemoryTraits::is_unmanaged == 0 };
339 enum { is_random_access = MemoryTraits::is_random_access == 1 };
340
341 //------------------------------------
342};
343
428} // namespace Kokkos
429
430namespace Kokkos {
431
432template <class T1, class T2>
433struct is_always_assignable_impl;
434
435template <class... ViewTDst, class... ViewTSrc>
436struct is_always_assignable_impl<Kokkos::View<ViewTDst...>,
437 Kokkos::View<ViewTSrc...>> {
438 using mapping_type = Kokkos::Impl::ViewMapping<
439 typename Kokkos::View<ViewTDst...>::traits,
440 typename Kokkos::View<ViewTSrc...>::traits,
441 typename Kokkos::View<ViewTDst...>::traits::specialize>;
442
443 constexpr static bool value =
444 mapping_type::is_assignable &&
445 static_cast<int>(Kokkos::View<ViewTDst...>::rank_dynamic) >=
447};
448
449template <class View1, class View2>
450using is_always_assignable = is_always_assignable_impl<
451 typename std::remove_reference<View1>::type,
452 typename std::remove_const<
453 typename std::remove_reference<View2>::type>::type>;
454
455#ifdef KOKKOS_ENABLE_CXX17
456template <class T1, class T2>
457inline constexpr bool is_always_assignable_v =
458 is_always_assignable<T1, T2>::value;
459#endif
460
461template <class... ViewTDst, class... ViewTSrc>
462constexpr bool is_assignable(const Kokkos::View<ViewTDst...>& dst,
463 const Kokkos::View<ViewTSrc...>& src) {
464 using DstTraits = typename Kokkos::View<ViewTDst...>::traits;
465 using SrcTraits = typename Kokkos::View<ViewTSrc...>::traits;
466 using mapping_type =
467 Kokkos::Impl::ViewMapping<DstTraits, SrcTraits,
468 typename DstTraits::specialize>;
469
470#ifdef KOKKOS_ENABLE_CXX17
471 return is_always_assignable_v<Kokkos::View<ViewTDst...>,
472 Kokkos::View<ViewTSrc...>> ||
473#else
474 return is_always_assignable<Kokkos::View<ViewTDst...>,
475 Kokkos::View<ViewTSrc...>>::value ||
476#endif
477 (mapping_type::is_assignable &&
478 ((DstTraits::dimension::rank_dynamic >= 1) ||
479 (dst.static_extent(0) == src.extent(0))) &&
480 ((DstTraits::dimension::rank_dynamic >= 2) ||
481 (dst.static_extent(1) == src.extent(1))) &&
482 ((DstTraits::dimension::rank_dynamic >= 3) ||
483 (dst.static_extent(2) == src.extent(2))) &&
484 ((DstTraits::dimension::rank_dynamic >= 4) ||
485 (dst.static_extent(3) == src.extent(3))) &&
486 ((DstTraits::dimension::rank_dynamic >= 5) ||
487 (dst.static_extent(4) == src.extent(4))) &&
488 ((DstTraits::dimension::rank_dynamic >= 6) ||
489 (dst.static_extent(5) == src.extent(5))) &&
490 ((DstTraits::dimension::rank_dynamic >= 7) ||
491 (dst.static_extent(6) == src.extent(6))) &&
492 ((DstTraits::dimension::rank_dynamic >= 8) ||
493 (dst.static_extent(7) == src.extent(7))));
494}
495
496} /* namespace Kokkos */
497
498//----------------------------------------------------------------------------
499//----------------------------------------------------------------------------
500
501#include <impl/Kokkos_ViewMapping.hpp>
502#include <impl/Kokkos_ViewArray.hpp>
503
504//----------------------------------------------------------------------------
505//----------------------------------------------------------------------------
506
507namespace Kokkos {
508
509namespace {
510
511constexpr Kokkos::Impl::ALL_t ALL = Kokkos::Impl::ALL_t();
512
513constexpr Kokkos::Impl::WithoutInitializing_t WithoutInitializing =
514 Kokkos::Impl::WithoutInitializing_t();
515
516constexpr Kokkos::Impl::AllowPadding_t AllowPadding =
517 Kokkos::Impl::AllowPadding_t();
518
519} // namespace
520
531template <class... Args>
532inline Impl::ViewCtorProp<typename Impl::ViewCtorProp<void, Args>::type...>
533view_alloc(Args const&... args) {
534 using return_type =
535 Impl::ViewCtorProp<typename Impl::ViewCtorProp<void, Args>::type...>;
536
537 static_assert(!return_type::has_pointer,
538 "Cannot give pointer-to-memory for view allocation");
539
540 return return_type(args...);
541}
542
543template <class... Args>
544KOKKOS_INLINE_FUNCTION
545 Impl::ViewCtorProp<typename Impl::ViewCtorProp<void, Args>::type...>
546 view_wrap(Args const&... args) {
547 using return_type =
548 Impl::ViewCtorProp<typename Impl::ViewCtorProp<void, Args>::type...>;
549
550 static_assert(!return_type::has_memory_space &&
551 !return_type::has_execution_space &&
552 !return_type::has_label && return_type::has_pointer,
553 "Must only give pointer-to-memory for view wrapping");
554
555 return return_type(args...);
556}
557
558} /* namespace Kokkos */
559
560//----------------------------------------------------------------------------
561//----------------------------------------------------------------------------
562
563namespace Kokkos {
564
565template <class DataType, class... Properties>
566class View;
567
568template <class>
569struct is_view : public std::false_type {};
570
571template <class D, class... P>
572struct is_view<View<D, P...>> : public std::true_type {};
573
574template <class D, class... P>
575struct is_view<const View<D, P...>> : public std::true_type {};
576
577template <class DataType, class... Properties>
578class View : public ViewTraits<DataType, Properties...> {
579 private:
580 template <class, class...>
581 friend class View;
582 template <class, class...>
583 friend class Kokkos::Impl::ViewMapping;
584
585 using view_tracker_type = Kokkos::Impl::ViewTracker<View>;
586
587 public:
588 using traits = ViewTraits<DataType, Properties...>;
589
590 private:
591 using map_type =
592 Kokkos::Impl::ViewMapping<traits, typename traits::specialize>;
593 template <typename V>
594 friend struct Kokkos::Impl::ViewTracker;
595
596 view_tracker_type m_track;
597 map_type m_map;
598
599 public:
600 //----------------------------------------
603 View<typename traits::scalar_array_type, typename traits::array_layout,
604 typename traits::device_type, typename traits::memory_traits>;
605
608 View<typename traits::const_data_type, typename traits::array_layout,
609 typename traits::device_type, typename traits::memory_traits>;
610
613 View<typename traits::non_const_data_type, typename traits::array_layout,
614 typename traits::device_type, typename traits::memory_traits>;
615
618 View<typename traits::non_const_data_type, typename traits::array_layout,
619 Device<DefaultHostExecutionSpace,
620 typename traits::host_mirror_space::memory_space>>;
621
624 View<typename traits::non_const_data_type, typename traits::array_layout,
625 typename traits::host_mirror_space>;
626
628 using uniform_type = typename Impl::ViewUniformType<View, 0>::type;
629 using uniform_const_type =
630 typename Impl::ViewUniformType<View, 0>::const_type;
631 using uniform_runtime_type =
632 typename Impl::ViewUniformType<View, 0>::runtime_type;
633 using uniform_runtime_const_type =
634 typename Impl::ViewUniformType<View, 0>::runtime_const_type;
635 using uniform_nomemspace_type =
636 typename Impl::ViewUniformType<View, 0>::nomemspace_type;
637 using uniform_const_nomemspace_type =
638 typename Impl::ViewUniformType<View, 0>::const_nomemspace_type;
639 using uniform_runtime_nomemspace_type =
640 typename Impl::ViewUniformType<View, 0>::runtime_nomemspace_type;
641 using uniform_runtime_const_nomemspace_type =
642 typename Impl::ViewUniformType<View, 0>::runtime_const_nomemspace_type;
643
644 //----------------------------------------
645 // Domain rank and extents
646
647 enum { Rank = map_type::Rank };
648
651 // KOKKOS_INLINE_FUNCTION
652 // static
653 // constexpr unsigned rank() { return map_type::Rank; }
654
655 template <typename iType>
656 KOKKOS_INLINE_FUNCTION constexpr
657 typename std::enable_if<std::is_integral<iType>::value, size_t>::type
658 extent(const iType& r) const noexcept {
659 return m_map.extent(r);
660 }
661
662 static KOKKOS_INLINE_FUNCTION constexpr size_t static_extent(
663 const unsigned r) noexcept {
664 return map_type::static_extent(r);
665 }
666
667 template <typename iType>
668 KOKKOS_INLINE_FUNCTION constexpr
669 typename std::enable_if<std::is_integral<iType>::value, int>::type
670 extent_int(const iType& r) const noexcept {
671 return static_cast<int>(m_map.extent(r));
672 }
673
674 KOKKOS_INLINE_FUNCTION constexpr typename traits::array_layout layout()
675 const {
676 return m_map.layout();
677 }
678
679 //----------------------------------------
680 /* Deprecate all 'dimension' functions in favor of
681 * ISO/C++ vocabulary 'extent'.
682 */
683
684 KOKKOS_INLINE_FUNCTION constexpr size_t size() const {
685 return m_map.dimension_0() * m_map.dimension_1() * m_map.dimension_2() *
686 m_map.dimension_3() * m_map.dimension_4() * m_map.dimension_5() *
687 m_map.dimension_6() * m_map.dimension_7();
688 }
689
690 KOKKOS_INLINE_FUNCTION constexpr size_t stride_0() const {
691 return m_map.stride_0();
692 }
693 KOKKOS_INLINE_FUNCTION constexpr size_t stride_1() const {
694 return m_map.stride_1();
695 }
696 KOKKOS_INLINE_FUNCTION constexpr size_t stride_2() const {
697 return m_map.stride_2();
698 }
699 KOKKOS_INLINE_FUNCTION constexpr size_t stride_3() const {
700 return m_map.stride_3();
701 }
702 KOKKOS_INLINE_FUNCTION constexpr size_t stride_4() const {
703 return m_map.stride_4();
704 }
705 KOKKOS_INLINE_FUNCTION constexpr size_t stride_5() const {
706 return m_map.stride_5();
707 }
708 KOKKOS_INLINE_FUNCTION constexpr size_t stride_6() const {
709 return m_map.stride_6();
710 }
711 KOKKOS_INLINE_FUNCTION constexpr size_t stride_7() const {
712 return m_map.stride_7();
713 }
714
715 template <typename iType>
716 KOKKOS_INLINE_FUNCTION constexpr
717 typename std::enable_if<std::is_integral<iType>::value, size_t>::type
718 stride(iType r) const {
719 return (
720 r == 0
721 ? m_map.stride_0()
722 : (r == 1
723 ? m_map.stride_1()
724 : (r == 2
725 ? m_map.stride_2()
726 : (r == 3
727 ? m_map.stride_3()
728 : (r == 4
729 ? m_map.stride_4()
730 : (r == 5
731 ? m_map.stride_5()
732 : (r == 6
733 ? m_map.stride_6()
734 : m_map.stride_7())))))));
735 }
736
737 template <typename iType>
738 KOKKOS_INLINE_FUNCTION void stride(iType* const s) const {
739 m_map.stride(s);
740 }
741
742 //----------------------------------------
743 // Range span is the span which contains all members.
744
745 using reference_type = typename map_type::reference_type;
746 using pointer_type = typename map_type::pointer_type;
747
748 enum {
749 reference_type_is_lvalue_reference =
750 std::is_lvalue_reference<reference_type>::value
751 };
752
753 KOKKOS_INLINE_FUNCTION constexpr size_t span() const { return m_map.span(); }
754 KOKKOS_INLINE_FUNCTION bool span_is_contiguous() const {
755 return m_map.span_is_contiguous();
756 }
757 KOKKOS_INLINE_FUNCTION constexpr bool is_allocated() const {
758 return m_map.data() != nullptr;
759 }
760 KOKKOS_INLINE_FUNCTION constexpr pointer_type data() const {
761 return m_map.data();
762 }
763
764 //----------------------------------------
765 // Allow specializations to query their specialized map
766
767 KOKKOS_INLINE_FUNCTION
768 const Kokkos::Impl::ViewMapping<traits, typename traits::specialize>&
769 impl_map() const {
770 return m_map;
771 }
772 KOKKOS_INLINE_FUNCTION
773 const Kokkos::Impl::SharedAllocationTracker& impl_track() const {
774 return m_track.m_tracker;
775 }
776 //----------------------------------------
777
778 private:
779 static constexpr bool is_layout_left =
780 std::is_same<typename traits::array_layout, Kokkos::LayoutLeft>::value;
781
782 static constexpr bool is_layout_right =
783 std::is_same<typename traits::array_layout, Kokkos::LayoutRight>::value;
784
785 static constexpr bool is_layout_stride =
786 std::is_same<typename traits::array_layout, Kokkos::LayoutStride>::value;
787
788 static constexpr bool is_default_map =
789 std::is_same<typename traits::specialize, void>::value &&
790 (is_layout_left || is_layout_right || is_layout_stride);
791
792#if defined(KOKKOS_ENABLE_DEBUG_BOUNDS_CHECK)
793
794#define KOKKOS_IMPL_SINK(ARG) ARG
795
796#define KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(ARG) \
797 Kokkos::Impl::verify_space<Kokkos::Impl::ActiveExecutionMemorySpace, \
798 typename traits::memory_space>::check(); \
799 Kokkos::Impl::view_verify_operator_bounds<typename traits::memory_space> ARG;
800
801#else
802
803#define KOKKOS_IMPL_SINK(ARG)
804
805#define KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(ARG) \
806 Kokkos::Impl::verify_space<Kokkos::Impl::ActiveExecutionMemorySpace, \
807 typename traits::memory_space>::check();
808
809#endif
810
811 public:
812 //------------------------------
813 // Rank 0 operator()
814
815 KOKKOS_FORCEINLINE_FUNCTION
816 reference_type operator()() const { return m_map.reference(); }
817 //------------------------------
818 // Rank 1 operator()
819
820 template <typename I0>
821 KOKKOS_FORCEINLINE_FUNCTION
822 typename std::enable_if<(Kokkos::Impl::are_integral<I0>::value &&
823 (1 == Rank) && !is_default_map),
824 reference_type>::type
825 operator()(const I0& i0) const {
826 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0))
827 return m_map.reference(i0);
828 }
829
830 template <typename I0>
831 KOKKOS_FORCEINLINE_FUNCTION
832 typename std::enable_if<(Kokkos::Impl::are_integral<I0>::value &&
833 (1 == Rank) && is_default_map &&
834 !is_layout_stride),
835 reference_type>::type
836 operator()(const I0& i0) const {
837 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0))
838 return m_map.m_impl_handle[i0];
839 }
840
841 template <typename I0>
842 KOKKOS_FORCEINLINE_FUNCTION
843 typename std::enable_if<(Kokkos::Impl::are_integral<I0>::value &&
844 (1 == Rank) && is_default_map &&
845 is_layout_stride),
846 reference_type>::type
847 operator()(const I0& i0) const {
848 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0))
849 return m_map.m_impl_handle[m_map.m_impl_offset.m_stride.S0 * i0];
850 }
851 //------------------------------
852 // Rank 1 operator[]
853
854 template <typename I0>
855 KOKKOS_FORCEINLINE_FUNCTION
856 typename std::enable_if<(Kokkos::Impl::are_integral<I0>::value &&
857 (1 == Rank) && !is_default_map),
858 reference_type>::type
859 operator[](const I0& i0) const {
860 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0))
861 return m_map.reference(i0);
862 }
863
864 template <typename I0>
865 KOKKOS_FORCEINLINE_FUNCTION
866 typename std::enable_if<(Kokkos::Impl::are_integral<I0>::value &&
867 (1 == Rank) && is_default_map &&
868 !is_layout_stride),
869 reference_type>::type
870 operator[](const I0& i0) const {
871 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0))
872 return m_map.m_impl_handle[i0];
873 }
874
875 template <typename I0>
876 KOKKOS_FORCEINLINE_FUNCTION
877 typename std::enable_if<(Kokkos::Impl::are_integral<I0>::value &&
878 (1 == Rank) && is_default_map &&
879 is_layout_stride),
880 reference_type>::type
881 operator[](const I0& i0) const {
882 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0))
883 return m_map.m_impl_handle[m_map.m_impl_offset.m_stride.S0 * i0];
884 }
885
886 //------------------------------
887 // Rank 2
888
889 template <typename I0, typename I1>
890 KOKKOS_FORCEINLINE_FUNCTION
891 typename std::enable_if<(Kokkos::Impl::are_integral<I0, I1>::value &&
892 (2 == Rank) && !is_default_map),
893 reference_type>::type
894 operator()(const I0& i0, const I1& i1) const {
895 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1))
896 return m_map.reference(i0, i1);
897 }
898
899 template <typename I0, typename I1>
900 KOKKOS_FORCEINLINE_FUNCTION
901 typename std::enable_if<(Kokkos::Impl::are_integral<I0, I1>::value &&
902 (2 == Rank) && is_default_map &&
903 is_layout_left && (traits::rank_dynamic == 0)),
904 reference_type>::type
905 operator()(const I0& i0, const I1& i1) const {
906 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1))
907 return m_map.m_impl_handle[i0 + m_map.m_impl_offset.m_dim.N0 * i1];
908 }
909
910 template <typename I0, typename I1>
911 KOKKOS_FORCEINLINE_FUNCTION
912 typename std::enable_if<(Kokkos::Impl::are_integral<I0, I1>::value &&
913 (2 == Rank) && is_default_map &&
914 is_layout_left && (traits::rank_dynamic != 0)),
915 reference_type>::type
916 operator()(const I0& i0, const I1& i1) const {
917 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1))
918 return m_map.m_impl_handle[i0 + m_map.m_impl_offset.m_stride * i1];
919 }
920
921 template <typename I0, typename I1>
922 KOKKOS_FORCEINLINE_FUNCTION
923 typename std::enable_if<(Kokkos::Impl::are_integral<I0, I1>::value &&
924 (2 == Rank) && is_default_map &&
925 is_layout_right && (traits::rank_dynamic == 0)),
926 reference_type>::type
927 operator()(const I0& i0, const I1& i1) const {
928 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1))
929 return m_map.m_impl_handle[i1 + m_map.m_impl_offset.m_dim.N1 * i0];
930 }
931
932 template <typename I0, typename I1>
933 KOKKOS_FORCEINLINE_FUNCTION
934 typename std::enable_if<(Kokkos::Impl::are_integral<I0, I1>::value &&
935 (2 == Rank) && is_default_map &&
936 is_layout_right && (traits::rank_dynamic != 0)),
937 reference_type>::type
938 operator()(const I0& i0, const I1& i1) const {
939 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1))
940 return m_map.m_impl_handle[i1 + m_map.m_impl_offset.m_stride * i0];
941 }
942
943 template <typename I0, typename I1>
944 KOKKOS_FORCEINLINE_FUNCTION
945 typename std::enable_if<(Kokkos::Impl::are_integral<I0, I1>::value &&
946 (2 == Rank) && is_default_map &&
947 is_layout_stride),
948 reference_type>::type
949 operator()(const I0& i0, const I1& i1) const {
950 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1))
951 return m_map.m_impl_handle[i0 * m_map.m_impl_offset.m_stride.S0 +
952 i1 * m_map.m_impl_offset.m_stride.S1];
953 }
954
955 //------------------------------
956 // Rank 3
957
958 template <typename I0, typename I1, typename I2>
959 KOKKOS_FORCEINLINE_FUNCTION
960 typename std::enable_if<(Kokkos::Impl::are_integral<I0, I1, I2>::value &&
961 (3 == Rank) && is_default_map),
962 reference_type>::type
963 operator()(const I0& i0, const I1& i1, const I2& i2) const {
964 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, i2))
965 return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2)];
966 }
967
968 template <typename I0, typename I1, typename I2>
969 KOKKOS_FORCEINLINE_FUNCTION
970 typename std::enable_if<(Kokkos::Impl::are_integral<I0, I1, I2>::value &&
971 (3 == Rank) && !is_default_map),
972 reference_type>::type
973 operator()(const I0& i0, const I1& i1, const I2& i2) const {
974 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, i2))
975 return m_map.reference(i0, i1, i2);
976 }
977
978 //------------------------------
979 // Rank 4
980
981 template <typename I0, typename I1, typename I2, typename I3>
982 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
983 (Kokkos::Impl::are_integral<I0, I1, I2, I3>::value && (4 == Rank) &&
984 is_default_map),
985 reference_type>::type
986 operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3) const {
987 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, i2, i3))
988 return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3)];
989 }
990
991 template <typename I0, typename I1, typename I2, typename I3>
992 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
993 (Kokkos::Impl::are_integral<I0, I1, I2, I3>::value && (4 == Rank) &&
994 !is_default_map),
995 reference_type>::type
996 operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3) const {
997 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, i2, i3))
998 return m_map.reference(i0, i1, i2, i3);
999 }
1000
1001 //------------------------------
1002 // Rank 5
1003
1004 template <typename I0, typename I1, typename I2, typename I3, typename I4>
1005 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1006 (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4>::value && (5 == Rank) &&
1007 is_default_map),
1008 reference_type>::type
1009 operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1010 const I4& i4) const {
1011 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, i2, i3, i4))
1012 return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3, i4)];
1013 }
1014
1015 template <typename I0, typename I1, typename I2, typename I3, typename I4>
1016 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1017 (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4>::value && (5 == Rank) &&
1018 !is_default_map),
1019 reference_type>::type
1020 operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1021 const I4& i4) const {
1022 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, i2, i3, i4))
1023 return m_map.reference(i0, i1, i2, i3, i4);
1024 }
1025
1026 //------------------------------
1027 // Rank 6
1028
1029 template <typename I0, typename I1, typename I2, typename I3, typename I4,
1030 typename I5>
1031 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1032 (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5>::value &&
1033 (6 == Rank) && is_default_map),
1034 reference_type>::type
1035 operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1036 const I4& i4, const I5& i5) const {
1037 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, i2, i3, i4, i5))
1038 return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3, i4, i5)];
1039 }
1040
1041 template <typename I0, typename I1, typename I2, typename I3, typename I4,
1042 typename I5>
1043 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1044 (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5>::value &&
1045 (6 == Rank) && !is_default_map),
1046 reference_type>::type
1047 operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1048 const I4& i4, const I5& i5) const {
1049 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, i2, i3, i4, i5))
1050 return m_map.reference(i0, i1, i2, i3, i4, i5);
1051 }
1052
1053 //------------------------------
1054 // Rank 7
1055
1056 template <typename I0, typename I1, typename I2, typename I3, typename I4,
1057 typename I5, typename I6>
1058 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1059 (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, I6>::value &&
1060 (7 == Rank) && is_default_map),
1061 reference_type>::type
1062 operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1063 const I4& i4, const I5& i5, const I6& i6) const {
1064 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1065 (m_track, m_map, i0, i1, i2, i3, i4, i5, i6))
1066 return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3, i4, i5, i6)];
1067 }
1068
1069 template <typename I0, typename I1, typename I2, typename I3, typename I4,
1070 typename I5, typename I6>
1071 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1072 (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, I6>::value &&
1073 (7 == Rank) && !is_default_map),
1074 reference_type>::type
1075 operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1076 const I4& i4, const I5& i5, const I6& i6) const {
1077 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1078 (m_track, m_map, i0, i1, i2, i3, i4, i5, i6))
1079 return m_map.reference(i0, i1, i2, i3, i4, i5, i6);
1080 }
1081
1082 //------------------------------
1083 // Rank 8
1084
1085 template <typename I0, typename I1, typename I2, typename I3, typename I4,
1086 typename I5, typename I6, typename I7>
1087 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1088 (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, I6, I7>::value &&
1089 (8 == Rank) && is_default_map),
1090 reference_type>::type
1091 operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1092 const I4& i4, const I5& i5, const I6& i6, const I7& i7) const {
1093 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1094 (m_track, m_map, i0, i1, i2, i3, i4, i5, i6, i7))
1095 return m_map
1096 .m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3, i4, i5, i6, i7)];
1097 }
1098
1099 template <typename I0, typename I1, typename I2, typename I3, typename I4,
1100 typename I5, typename I6, typename I7>
1101 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1102 (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, I6, I7>::value &&
1103 (8 == Rank) && !is_default_map),
1104 reference_type>::type
1105 operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1106 const I4& i4, const I5& i5, const I6& i6, const I7& i7) const {
1107 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1108 (m_track, m_map, i0, i1, i2, i3, i4, i5, i6, i7))
1109 return m_map.reference(i0, i1, i2, i3, i4, i5, i6, i7);
1110 }
1111
1112 template <class... Args>
1113 KOKKOS_FORCEINLINE_FUNCTION
1114 typename std::enable_if<(Kokkos::Impl::are_integral<Args...>::value &&
1115 (0 == Rank)),
1116 reference_type>::type
1117 access(Args... KOKKOS_IMPL_SINK(args)) const {
1118 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1119 KOKKOS_IMPL_SINK((m_track, m_map, args...)))
1120 return m_map.reference();
1121 }
1122
1123 template <typename I0, class... Args>
1124 KOKKOS_FORCEINLINE_FUNCTION
1125 typename std::enable_if<(Kokkos::Impl::are_integral<I0, Args...>::value &&
1126 (1 == Rank) && !is_default_map),
1127 reference_type>::type
1128 access(const I0& i0, Args... KOKKOS_IMPL_SINK(args)) const {
1129 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1130 KOKKOS_IMPL_SINK((m_track, m_map, i0, args...)))
1131 return m_map.reference(i0);
1132 }
1133
1134 template <typename I0, class... Args>
1135 KOKKOS_FORCEINLINE_FUNCTION
1136 typename std::enable_if<(Kokkos::Impl::are_integral<I0, Args...>::value &&
1137 (1 == Rank) && is_default_map &&
1138 !is_layout_stride),
1139 reference_type>::type
1140 access(const I0& i0, Args... KOKKOS_IMPL_SINK(args)) const {
1141 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1142 KOKKOS_IMPL_SINK((m_track, m_map, i0, args...)))
1143 return m_map.m_impl_handle[i0];
1144 }
1145
1146 template <typename I0, class... Args>
1147 KOKKOS_FORCEINLINE_FUNCTION
1148 typename std::enable_if<(Kokkos::Impl::are_integral<I0, Args...>::value &&
1149 (1 == Rank) && is_default_map &&
1150 is_layout_stride),
1151 reference_type>::type
1152 access(const I0& i0, Args... KOKKOS_IMPL_SINK(args)) const {
1153 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1154 KOKKOS_IMPL_SINK((m_track, m_map, i0, args...)))
1155 return m_map.m_impl_handle[m_map.m_impl_offset.m_stride.S0 * i0];
1156 }
1157
1158 template <typename I0, typename I1, class... Args>
1159 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1160 (Kokkos::Impl::are_integral<I0, I1, Args...>::value && (2 == Rank) &&
1161 !is_default_map),
1162 reference_type>::type
1163 access(const I0& i0, const I1& i1, Args... KOKKOS_IMPL_SINK(args)) const {
1164 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1165 KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, args...)))
1166 return m_map.reference(i0, i1);
1167 }
1168
1169 template <typename I0, typename I1, class... Args>
1170 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1171 (Kokkos::Impl::are_integral<I0, I1, Args...>::value && (2 == Rank) &&
1172 is_default_map && is_layout_left && (traits::rank_dynamic == 0)),
1173 reference_type>::type
1174 access(const I0& i0, const I1& i1, Args... KOKKOS_IMPL_SINK(args)) const {
1175 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1176 KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, args...)))
1177 return m_map.m_impl_handle[i0 + m_map.m_impl_offset.m_dim.N0 * i1];
1178 }
1179
1180 template <typename I0, typename I1, class... Args>
1181 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1182 (Kokkos::Impl::are_integral<I0, I1, Args...>::value && (2 == Rank) &&
1183 is_default_map && is_layout_left && (traits::rank_dynamic != 0)),
1184 reference_type>::type
1185 access(const I0& i0, const I1& i1, Args... KOKKOS_IMPL_SINK(args)) const {
1186 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1187 KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, args...)))
1188 return m_map.m_impl_handle[i0 + m_map.m_impl_offset.m_stride * i1];
1189 }
1190
1191 template <typename I0, typename I1, class... Args>
1192 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1193 (Kokkos::Impl::are_integral<I0, I1, Args...>::value && (2 == Rank) &&
1194 is_default_map && is_layout_right && (traits::rank_dynamic == 0)),
1195 reference_type>::type
1196 access(const I0& i0, const I1& i1, Args... KOKKOS_IMPL_SINK(args)) const {
1197 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1198 KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, args...)))
1199 return m_map.m_impl_handle[i1 + m_map.m_impl_offset.m_dim.N1 * i0];
1200 }
1201
1202 template <typename I0, typename I1, class... Args>
1203 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1204 (Kokkos::Impl::are_integral<I0, I1, Args...>::value && (2 == Rank) &&
1205 is_default_map && is_layout_right && (traits::rank_dynamic != 0)),
1206 reference_type>::type
1207 access(const I0& i0, const I1& i1, Args... KOKKOS_IMPL_SINK(args)) const {
1208 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1209 KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, args...)))
1210 return m_map.m_impl_handle[i1 + m_map.m_impl_offset.m_stride * i0];
1211 }
1212
1213 template <typename I0, typename I1, class... Args>
1214 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1215 (Kokkos::Impl::are_integral<I0, I1, Args...>::value && (2 == Rank) &&
1216 is_default_map && is_layout_stride),
1217 reference_type>::type
1218 access(const I0& i0, const I1& i1, Args... KOKKOS_IMPL_SINK(args)) const {
1219 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1220 KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, args...)))
1221 return m_map.m_impl_handle[i0 * m_map.m_impl_offset.m_stride.S0 +
1222 i1 * m_map.m_impl_offset.m_stride.S1];
1223 }
1224
1225 //------------------------------
1226 // Rank 3
1227
1228 template <typename I0, typename I1, typename I2, class... Args>
1229 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1230 (Kokkos::Impl::are_integral<I0, I1, I2, Args...>::value && (3 == Rank) &&
1231 is_default_map),
1232 reference_type>::type
1233 access(const I0& i0, const I1& i1, const I2& i2,
1234 Args... KOKKOS_IMPL_SINK(args)) const {
1235 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1236 KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, i2, args...)))
1237 return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2)];
1238 }
1239
1240 template <typename I0, typename I1, typename I2, class... Args>
1241 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1242 (Kokkos::Impl::are_integral<I0, I1, I2, Args...>::value && (3 == Rank) &&
1243 !is_default_map),
1244 reference_type>::type
1245 access(const I0& i0, const I1& i1, const I2& i2,
1246 Args... KOKKOS_IMPL_SINK(args)) const {
1247 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1248 KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, i2, args...)))
1249 return m_map.reference(i0, i1, i2);
1250 }
1251
1252 //------------------------------
1253 // Rank 4
1254
1255 template <typename I0, typename I1, typename I2, typename I3, class... Args>
1256 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1257 (Kokkos::Impl::are_integral<I0, I1, I2, I3, Args...>::value &&
1258 (4 == Rank) && is_default_map),
1259 reference_type>::type
1260 access(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1261 Args... KOKKOS_IMPL_SINK(args)) const {
1262 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1263 KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, i2, i3, args...)))
1264 return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3)];
1265 }
1266
1267 template <typename I0, typename I1, typename I2, typename I3, class... Args>
1268 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1269 (Kokkos::Impl::are_integral<I0, I1, I2, I3, Args...>::value &&
1270 (4 == Rank) && !is_default_map),
1271 reference_type>::type
1272 access(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1273 Args... KOKKOS_IMPL_SINK(args)) const {
1274 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1275 KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, i2, i3, args...)))
1276 return m_map.reference(i0, i1, i2, i3);
1277 }
1278
1279 //------------------------------
1280 // Rank 5
1281
1282 template <typename I0, typename I1, typename I2, typename I3, typename I4,
1283 class... Args>
1284 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1285 (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, Args...>::value &&
1286 (5 == Rank) && is_default_map),
1287 reference_type>::type
1288 access(const I0& i0, const I1& i1, const I2& i2, const I3& i3, const I4& i4,
1289 Args... KOKKOS_IMPL_SINK(args)) const {
1290 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1291 KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, i2, i3, i4, args...)))
1292 return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3, i4)];
1293 }
1294
1295 template <typename I0, typename I1, typename I2, typename I3, typename I4,
1296 class... Args>
1297 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1298 (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, Args...>::value &&
1299 (5 == Rank) && !is_default_map),
1300 reference_type>::type
1301 access(const I0& i0, const I1& i1, const I2& i2, const I3& i3, const I4& i4,
1302 Args... KOKKOS_IMPL_SINK(args)) const {
1303 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1304 KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, i2, i3, i4, args...)))
1305 return m_map.reference(i0, i1, i2, i3, i4);
1306 }
1307
1308 //------------------------------
1309 // Rank 6
1310
1311 template <typename I0, typename I1, typename I2, typename I3, typename I4,
1312 typename I5, class... Args>
1313 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1314 (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, Args...>::value &&
1315 (6 == Rank) && is_default_map),
1316 reference_type>::type
1317 access(const I0& i0, const I1& i1, const I2& i2, const I3& i3, const I4& i4,
1318 const I5& i5, Args... KOKKOS_IMPL_SINK(args)) const {
1319 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1320 KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, i2, i3, i4, i5, args...)))
1321 return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3, i4, i5)];
1322 }
1323
1324 template <typename I0, typename I1, typename I2, typename I3, typename I4,
1325 typename I5, class... Args>
1326 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1327 (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, Args...>::value &&
1328 (6 == Rank) && !is_default_map),
1329 reference_type>::type
1330 access(const I0& i0, const I1& i1, const I2& i2, const I3& i3, const I4& i4,
1331 const I5& i5, Args... KOKKOS_IMPL_SINK(args)) const {
1332 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1333 KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, i2, i3, i4, i5, args...)))
1334 return m_map.reference(i0, i1, i2, i3, i4, i5);
1335 }
1336
1337 //------------------------------
1338 // Rank 7
1339
1340 template <typename I0, typename I1, typename I2, typename I3, typename I4,
1341 typename I5, typename I6, class... Args>
1342 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1343 (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, I6, Args...>::value &&
1344 (7 == Rank) && is_default_map),
1345 reference_type>::type
1346 access(const I0& i0, const I1& i1, const I2& i2, const I3& i3, const I4& i4,
1347 const I5& i5, const I6& i6, Args... KOKKOS_IMPL_SINK(args)) const {
1348 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1349 KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, i2, i3, i4, i5, i6, args...)))
1350 return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3, i4, i5, i6)];
1351 }
1352
1353 template <typename I0, typename I1, typename I2, typename I3, typename I4,
1354 typename I5, typename I6, class... Args>
1355 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1356 (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, I6, Args...>::value &&
1357 (7 == Rank) && !is_default_map),
1358 reference_type>::type
1359 access(const I0& i0, const I1& i1, const I2& i2, const I3& i3, const I4& i4,
1360 const I5& i5, const I6& i6, Args... KOKKOS_IMPL_SINK(args)) const {
1361 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1362 KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, i2, i3, i4, i5, i6, args...)))
1363 return m_map.reference(i0, i1, i2, i3, i4, i5, i6);
1364 }
1365
1366 //------------------------------
1367 // Rank 8
1368
1369 template <typename I0, typename I1, typename I2, typename I3, typename I4,
1370 typename I5, typename I6, typename I7, class... Args>
1371 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1372 (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, I6, I7,
1373 Args...>::value &&
1374 (8 == Rank) && is_default_map),
1375 reference_type>::type
1376 access(const I0& i0, const I1& i1, const I2& i2, const I3& i3, const I4& i4,
1377 const I5& i5, const I6& i6, const I7& i7,
1378 Args... KOKKOS_IMPL_SINK(args)) const {
1379 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(KOKKOS_IMPL_SINK(
1380 (m_track, m_map, i0, i1, i2, i3, i4, i5, i6, i7, args...)))
1381 return m_map
1382 .m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3, i4, i5, i6, i7)];
1383 }
1384
1385 template <typename I0, typename I1, typename I2, typename I3, typename I4,
1386 typename I5, typename I6, typename I7, class... Args>
1387 KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1388 (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, I6, I7,
1389 Args...>::value &&
1390 (8 == Rank) && !is_default_map),
1391 reference_type>::type
1392 access(const I0& i0, const I1& i1, const I2& i2, const I3& i3, const I4& i4,
1393 const I5& i5, const I6& i6, const I7& i7,
1394 Args... KOKKOS_IMPL_SINK(args)) const {
1395 KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(KOKKOS_IMPL_SINK(
1396 (m_track, m_map, i0, i1, i2, i3, i4, i5, i6, i7, args...)))
1397 return m_map.reference(i0, i1, i2, i3, i4, i5, i6, i7);
1398 }
1399
1400#undef KOKKOS_IMPL_VIEW_OPERATOR_VERIFY
1401
1402 //----------------------------------------
1403 // Standard destructor, constructors, and assignment operators
1404
1405 KOKKOS_DEFAULTED_FUNCTION
1406 ~View() = default;
1407
1408 KOKKOS_DEFAULTED_FUNCTION
1409 View() = default;
1410
1411 KOKKOS_DEFAULTED_FUNCTION
1412 View(const View&) = default;
1413
1414 KOKKOS_DEFAULTED_FUNCTION
1415 View(View&&) = default;
1416
1417 KOKKOS_DEFAULTED_FUNCTION
1418 View& operator=(const View&) = default;
1419
1420 KOKKOS_DEFAULTED_FUNCTION
1421 View& operator=(View&&) = default;
1422
1423 //----------------------------------------
1424 // Compatible view copy constructor and assignment
1425 // may assign unmanaged from managed.
1426
1427 template <class RT, class... RP>
1428 KOKKOS_INLINE_FUNCTION View(
1429 const View<RT, RP...>& rhs,
1430 typename std::enable_if<Kokkos::Impl::ViewMapping<
1431 traits, typename View<RT, RP...>::traits,
1432 typename traits::specialize>::is_assignable_data_type>::type* =
1433 nullptr)
1434 : m_track(rhs), m_map() {
1435 using SrcTraits = typename View<RT, RP...>::traits;
1436 using Mapping = Kokkos::Impl::ViewMapping<traits, SrcTraits,
1437 typename traits::specialize>;
1438 static_assert(Mapping::is_assignable,
1439 "Incompatible View copy construction");
1440 Mapping::assign(m_map, rhs.m_map, rhs.m_track.m_tracker);
1441 }
1442
1443 template <class RT, class... RP>
1444 KOKKOS_INLINE_FUNCTION typename std::enable_if<
1445 Kokkos::Impl::ViewMapping<
1446 traits, typename View<RT, RP...>::traits,
1447 typename traits::specialize>::is_assignable_data_type,
1448 View>::type&
1449 operator=(const View<RT, RP...>& rhs) {
1450 using SrcTraits = typename View<RT, RP...>::traits;
1451 using Mapping = Kokkos::Impl::ViewMapping<traits, SrcTraits,
1452 typename traits::specialize>;
1453 static_assert(Mapping::is_assignable, "Incompatible View copy assignment");
1454 Mapping::assign(m_map, rhs.m_map, rhs.m_track.m_tracker);
1455 m_track.assign(rhs);
1456 return *this;
1457 }
1458
1459 //----------------------------------------
1460 // Compatible subview constructor
1461 // may assign unmanaged from managed.
1462
1463 template <class RT, class... RP, class Arg0, class... Args>
1464 KOKKOS_INLINE_FUNCTION View(const View<RT, RP...>& src_view, const Arg0 arg0,
1465 Args... args)
1466 : m_track(src_view), m_map() {
1467 using SrcType = View<RT, RP...>;
1468
1469 using Mapping = Kokkos::Impl::ViewMapping<void, typename SrcType::traits,
1470 Arg0, Args...>;
1471
1472 using DstType = typename Mapping::type;
1473
1474 static_assert(
1475 Kokkos::Impl::ViewMapping<traits, typename DstType::traits,
1476 typename traits::specialize>::is_assignable,
1477 "Subview construction requires compatible view and subview arguments");
1478
1479 Mapping::assign(m_map, src_view.m_map, arg0, args...);
1480 }
1481
1482 //----------------------------------------
1483 // Allocation tracking properties
1484
1485 KOKKOS_INLINE_FUNCTION
1486 int use_count() const { return m_track.m_tracker.use_count(); }
1487
1488 inline const std::string label() const {
1489 return m_track.m_tracker
1490 .template get_label<typename traits::memory_space>();
1491 }
1492
1493 //----------------------------------------
1494 // Allocation according to allocation properties and array layout
1495
1496 template <class... P>
1497 explicit inline View(
1498 const Impl::ViewCtorProp<P...>& arg_prop,
1499 typename std::enable_if<!Impl::ViewCtorProp<P...>::has_pointer,
1500 typename traits::array_layout>::type const&
1501 arg_layout)
1502 : m_track(), m_map() {
1503 // Append layout and spaces if not input
1504 using alloc_prop_input = Impl::ViewCtorProp<P...>;
1505
1506 // use 'std::integral_constant<unsigned,I>' for non-types
1507 // to avoid duplicate class error.
1508 using alloc_prop = Impl::ViewCtorProp<
1509 P...,
1510 typename std::conditional<alloc_prop_input::has_label,
1511 std::integral_constant<unsigned int, 0>,
1512 typename std::string>::type,
1513 typename std::conditional<
1514 alloc_prop_input::has_memory_space,
1515 std::integral_constant<unsigned int, 1>,
1516 typename traits::device_type::memory_space>::type,
1517 typename std::conditional<
1518 alloc_prop_input::has_execution_space,
1519 std::integral_constant<unsigned int, 2>,
1520 typename traits::device_type::execution_space>::type>;
1521
1522 static_assert(traits::is_managed,
1523 "View allocation constructor requires managed memory");
1524
1525 if (alloc_prop::initialize &&
1526 !alloc_prop::execution_space::impl_is_initialized()) {
1527 // If initializing view data then
1528 // the execution space must be initialized.
1529 Kokkos::Impl::throw_runtime_exception(
1530 "Constructing View and initializing data with uninitialized "
1531 "execution space");
1532 }
1533
1534 // Copy the input allocation properties with possibly defaulted properties
1535 alloc_prop prop_copy(arg_prop);
1536
1537//------------------------------------------------------------
1538#if defined(KOKKOS_ENABLE_CUDA)
1539 // If allocating in CudaUVMSpace must fence before and after
1540 // the allocation to protect against possible concurrent access
1541 // on the CPU and the GPU.
1542 // Fence using the trait's execution space (which will be Kokkos::Cuda)
1543 // to avoid incomplete type errors from using Kokkos::Cuda directly.
1544 if (std::is_same<Kokkos::CudaUVMSpace,
1545 typename traits::device_type::memory_space>::value) {
1546 typename traits::device_type::memory_space::execution_space().fence();
1547 }
1548#endif
1549 //------------------------------------------------------------
1550
1551 Kokkos::Impl::SharedAllocationRecord<>* record =
1552 m_map.allocate_shared(prop_copy, arg_layout);
1553
1554//------------------------------------------------------------
1555#if defined(KOKKOS_ENABLE_CUDA)
1556 if (std::is_same<Kokkos::CudaUVMSpace,
1557 typename traits::device_type::memory_space>::value) {
1558 typename traits::device_type::memory_space::execution_space().fence();
1559 }
1560#endif
1561 //------------------------------------------------------------
1562
1563 // Setup and initialization complete, start tracking
1564 m_track.m_tracker.assign_allocated_record_to_uninitialized(record);
1565 }
1566
1567 KOKKOS_INLINE_FUNCTION
1568 void assign_data(pointer_type arg_data) {
1569 m_track.m_tracker.clear();
1570 m_map.assign_data(arg_data);
1571 }
1572
1573 // Wrap memory according to properties and array layout
1574 template <class... P>
1575 explicit KOKKOS_INLINE_FUNCTION View(
1576 const Impl::ViewCtorProp<P...>& arg_prop,
1577 typename std::enable_if<Impl::ViewCtorProp<P...>::has_pointer,
1578 typename traits::array_layout>::type const&
1579 arg_layout)
1580 : m_track() // No memory tracking
1581 ,
1582 m_map(arg_prop, arg_layout) {
1583 static_assert(
1584 std::is_same<pointer_type,
1585 typename Impl::ViewCtorProp<P...>::pointer_type>::value,
1586 "Constructing View to wrap user memory must supply matching pointer "
1587 "type");
1588 }
1589
1590 // Simple dimension-only layout
1591 template <class... P>
1592 explicit inline View(
1593 const Impl::ViewCtorProp<P...>& arg_prop,
1594 typename std::enable_if<!Impl::ViewCtorProp<P...>::has_pointer,
1595 size_t>::type const arg_N0 =
1596 KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1597 const size_t arg_N1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1598 const size_t arg_N2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1599 const size_t arg_N3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1600 const size_t arg_N4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1601 const size_t arg_N5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1602 const size_t arg_N6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1603 const size_t arg_N7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG)
1604 : View(arg_prop,
1605 typename traits::array_layout(arg_N0, arg_N1, arg_N2, arg_N3,
1606 arg_N4, arg_N5, arg_N6, arg_N7)) {
1607#ifdef KOKKOS_ENABLE_OPENMPTARGET
1608 KOKKOS_IMPL_IF_ON_HOST
1609 Impl::runtime_check_rank_host(
1610 traits::rank_dynamic,
1611 std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
1612 arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7, label());
1613 else Impl::runtime_check_rank_device(
1614 traits::rank_dynamic,
1615 std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
1616 arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7);
1617#elif defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST)
1618 Impl::runtime_check_rank_host(
1619 traits::rank_dynamic,
1620 std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
1621 arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7, label());
1622#else
1623 Impl::runtime_check_rank_device(
1624 traits::rank_dynamic,
1625 std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
1626 arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7);
1627
1628#endif
1629 }
1630
1631 template <class... P>
1632 explicit KOKKOS_INLINE_FUNCTION View(
1633 const Impl::ViewCtorProp<P...>& arg_prop,
1634 typename std::enable_if<Impl::ViewCtorProp<P...>::has_pointer,
1635 size_t>::type const arg_N0 =
1636 KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1637 const size_t arg_N1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1638 const size_t arg_N2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1639 const size_t arg_N3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1640 const size_t arg_N4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1641 const size_t arg_N5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1642 const size_t arg_N6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1643 const size_t arg_N7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG)
1644 : View(arg_prop,
1645 typename traits::array_layout(arg_N0, arg_N1, arg_N2, arg_N3,
1646 arg_N4, arg_N5, arg_N6, arg_N7)) {
1647#ifdef KOKKOS_ENABLE_OPENMPTARGET
1648 KOKKOS_IMPL_IF_ON_HOST
1649 Impl::runtime_check_rank_host(
1650 traits::rank_dynamic,
1651 std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
1652 arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7, label());
1653 else Impl::runtime_check_rank_device(
1654 traits::rank_dynamic,
1655 std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
1656 arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7);
1657#elif defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST)
1658 Impl::runtime_check_rank_host(
1659 traits::rank_dynamic,
1660 std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
1661 arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7, label());
1662#else
1663 Impl::runtime_check_rank_device(
1664 traits::rank_dynamic,
1665 std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
1666 arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7);
1667
1668#endif
1669 }
1670
1671 // Allocate with label and layout
1672 template <typename Label>
1673 explicit inline View(
1674 const Label& arg_label,
1675 typename std::enable_if<Kokkos::Impl::is_view_label<Label>::value,
1676 typename traits::array_layout>::type const&
1677 arg_layout)
1678 : View(Impl::ViewCtorProp<std::string>(arg_label), arg_layout) {}
1679
1680 // Allocate label and layout, must disambiguate from subview constructor.
1681 template <typename Label>
1682 explicit inline View(
1683 const Label& arg_label,
1684 typename std::enable_if<Kokkos::Impl::is_view_label<Label>::value,
1685 const size_t>::type arg_N0 =
1686 KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1687 const size_t arg_N1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1688 const size_t arg_N2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1689 const size_t arg_N3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1690 const size_t arg_N4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1691 const size_t arg_N5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1692 const size_t arg_N6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1693 const size_t arg_N7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG)
1694 : View(Impl::ViewCtorProp<std::string>(arg_label),
1695 typename traits::array_layout(arg_N0, arg_N1, arg_N2, arg_N3,
1696 arg_N4, arg_N5, arg_N6, arg_N7)) {
1697 static_assert(traits::array_layout::is_extent_constructible,
1698 "Layout is not extent constructible. A layout object should "
1699 "be passed too.\n");
1700
1701#ifdef KOKKOS_ENABLE_OPENMPTARGET
1702 KOKKOS_IMPL_IF_ON_HOST
1703 Impl::runtime_check_rank_host(
1704 traits::rank_dynamic,
1705 std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
1706 arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7, label());
1707 else Impl::runtime_check_rank_device(
1708 traits::rank_dynamic,
1709 std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
1710 arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7);
1711#elif defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST)
1712 Impl::runtime_check_rank_host(
1713 traits::rank_dynamic,
1714 std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
1715 arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7, label());
1716#else
1717 Impl::runtime_check_rank_device(
1718 traits::rank_dynamic,
1719 std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
1720 arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7);
1721
1722#endif
1723 }
1724
1725 // Construct view from ViewTracker and map
1726 // This should be the preferred method because future extensions may need to
1727 // use the ViewTracker class.
1728 template <class Traits>
1729 KOKKOS_INLINE_FUNCTION View(
1730 const view_tracker_type& track,
1731 const Kokkos::Impl::ViewMapping<Traits, typename Traits::specialize>& map)
1732 : m_track(track), m_map() {
1733 using Mapping =
1734 Kokkos::Impl::ViewMapping<traits, Traits, typename traits::specialize>;
1735 static_assert(Mapping::is_assignable,
1736 "Incompatible View copy construction");
1737 Mapping::assign(m_map, map, track.m_tracker);
1738 }
1739
1740 // Construct View from internal shared allocation tracker object and map
1741 // This is here for backwards compatibility for classes that derive from
1742 // Kokkos::View
1743 template <class Traits>
1744 KOKKOS_INLINE_FUNCTION View(
1745 const typename view_tracker_type::track_type& track,
1746 const Kokkos::Impl::ViewMapping<Traits, typename Traits::specialize>& map)
1747 : m_track(track), m_map() {
1748 using Mapping =
1749 Kokkos::Impl::ViewMapping<traits, Traits, typename traits::specialize>;
1750 static_assert(Mapping::is_assignable,
1751 "Incompatible View copy construction");
1752 Mapping::assign(m_map, map, track);
1753 }
1754
1755 //----------------------------------------
1756 // Memory span required to wrap these dimensions.
1757 static constexpr size_t required_allocation_size(
1758 const size_t arg_N0 = 0, const size_t arg_N1 = 0, const size_t arg_N2 = 0,
1759 const size_t arg_N3 = 0, const size_t arg_N4 = 0, const size_t arg_N5 = 0,
1760 const size_t arg_N6 = 0, const size_t arg_N7 = 0) {
1761 return map_type::memory_span(typename traits::array_layout(
1762 arg_N0, arg_N1, arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7));
1763 }
1764
1765 explicit KOKKOS_INLINE_FUNCTION View(
1766 pointer_type arg_ptr, const size_t arg_N0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1767 const size_t arg_N1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1768 const size_t arg_N2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1769 const size_t arg_N3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1770 const size_t arg_N4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1771 const size_t arg_N5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1772 const size_t arg_N6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1773 const size_t arg_N7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG)
1774 : View(Impl::ViewCtorProp<pointer_type>(arg_ptr),
1775 typename traits::array_layout(arg_N0, arg_N1, arg_N2, arg_N3,
1776 arg_N4, arg_N5, arg_N6, arg_N7)) {
1777#ifdef KOKKOS_ENABLE_OPENMPTARGET
1778 KOKKOS_IMPL_IF_ON_HOST
1779 Impl::runtime_check_rank_host(
1780 traits::rank_dynamic,
1781 std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
1782 arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7, label());
1783 else Impl::runtime_check_rank_device(
1784 traits::rank_dynamic,
1785 std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
1786 arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7);
1787#elif defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST)
1788 Impl::runtime_check_rank_host(
1789 traits::rank_dynamic,
1790 std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
1791 arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7, label());
1792#else
1793 Impl::runtime_check_rank_device(
1794 traits::rank_dynamic,
1795 std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
1796 arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7);
1797
1798#endif
1799 }
1800
1801 explicit KOKKOS_INLINE_FUNCTION View(
1802 pointer_type arg_ptr, const typename traits::array_layout& arg_layout)
1803 : View(Impl::ViewCtorProp<pointer_type>(arg_ptr), arg_layout) {}
1804
1805 //----------------------------------------
1806 // Shared scratch memory constructor
1807
1808 static inline size_t shmem_size(const size_t arg_N0 = KOKKOS_INVALID_INDEX,
1809 const size_t arg_N1 = KOKKOS_INVALID_INDEX,
1810 const size_t arg_N2 = KOKKOS_INVALID_INDEX,
1811 const size_t arg_N3 = KOKKOS_INVALID_INDEX,
1812 const size_t arg_N4 = KOKKOS_INVALID_INDEX,
1813 const size_t arg_N5 = KOKKOS_INVALID_INDEX,
1814 const size_t arg_N6 = KOKKOS_INVALID_INDEX,
1815 const size_t arg_N7 = KOKKOS_INVALID_INDEX) {
1816 if (is_layout_stride) {
1817 Kokkos::abort(
1818 "Kokkos::View::shmem_size(extents...) doesn't work with "
1819 "LayoutStride. Pass a LayoutStride object instead");
1820 }
1821 const size_t num_passed_args = Impl::count_valid_integers(
1822 arg_N0, arg_N1, arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7);
1823
1824 if (std::is_same<typename traits::specialize, void>::value &&
1825 num_passed_args != traits::rank_dynamic) {
1826 Kokkos::abort(
1827 "Kokkos::View::shmem_size() rank_dynamic != number of arguments.\n");
1828 }
1829
1830 return View::shmem_size(typename traits::array_layout(
1831 arg_N0, arg_N1, arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7));
1832 }
1833
1834 static inline size_t shmem_size(
1835 typename traits::array_layout const& arg_layout) {
1836 return map_type::memory_span(arg_layout) +
1837 sizeof(typename traits::value_type);
1838 }
1839
1840 explicit KOKKOS_INLINE_FUNCTION View(
1841 const typename traits::execution_space::scratch_memory_space& arg_space,
1842 const typename traits::array_layout& arg_layout)
1843 : View(Impl::ViewCtorProp<pointer_type>(
1844 reinterpret_cast<pointer_type>(arg_space.get_shmem_aligned(
1845 map_type::memory_span(arg_layout),
1846 sizeof(typename traits::value_type)))),
1847 arg_layout) {}
1848
1849 explicit KOKKOS_INLINE_FUNCTION View(
1850 const typename traits::execution_space::scratch_memory_space& arg_space,
1851 const size_t arg_N0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1852 const size_t arg_N1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1853 const size_t arg_N2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1854 const size_t arg_N3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1855 const size_t arg_N4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1856 const size_t arg_N5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1857 const size_t arg_N6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
1858 const size_t arg_N7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG)
1859 : View(Impl::ViewCtorProp<pointer_type>(
1860 reinterpret_cast<pointer_type>(arg_space.get_shmem_aligned(
1861 map_type::memory_span(typename traits::array_layout(
1862 arg_N0, arg_N1, arg_N2, arg_N3, arg_N4, arg_N5, arg_N6,
1863 arg_N7)),
1864 sizeof(typename traits::value_type)))),
1865 typename traits::array_layout(arg_N0, arg_N1, arg_N2, arg_N3,
1866 arg_N4, arg_N5, arg_N6, arg_N7)) {
1867#ifdef KOKKOS_ENABLE_OPENMPTARGET
1868 KOKKOS_IMPL_IF_ON_HOST
1869 Impl::runtime_check_rank_host(
1870 traits::rank_dynamic,
1871 std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
1872 arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7, label());
1873 else Impl::runtime_check_rank_device(
1874 traits::rank_dynamic,
1875 std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
1876 arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7);
1877#elif defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST)
1878 Impl::runtime_check_rank_host(
1879 traits::rank_dynamic,
1880 std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
1881 arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7, label());
1882#else
1883 Impl::runtime_check_rank_device(
1884 traits::rank_dynamic,
1885 std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
1886 arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7);
1887
1888#endif
1889 }
1890};
1891
1896template <typename D, class... P>
1897KOKKOS_INLINE_FUNCTION constexpr unsigned rank(const View<D, P...>& V) {
1898 return V.Rank;
1899} // Temporary until added to view
1900
1901//----------------------------------------------------------------------------
1902//----------------------------------------------------------------------------
1903
1904template <class V, class... Args>
1905using Subview =
1906 typename Kokkos::Impl::ViewMapping<void /* deduce subview type from source
1907 view traits */
1908 ,
1909 typename V::traits, Args...>::type;
1910
1911template <class D, class... P, class... Args>
1912KOKKOS_INLINE_FUNCTION
1913 typename Kokkos::Impl::ViewMapping<void /* deduce subview type from source
1914 view traits */
1915 ,
1916 ViewTraits<D, P...>, Args...>::type
1917 subview(const View<D, P...>& src, Args... args) {
1918 static_assert(View<D, P...>::Rank == sizeof...(Args),
1919 "subview requires one argument for each source View rank");
1920
1921 return typename Kokkos::Impl::ViewMapping<
1922 void /* deduce subview type from source view traits */
1923 ,
1924 ViewTraits<D, P...>, Args...>::type(src, args...);
1925}
1926
1927template <class MemoryTraits, class D, class... P, class... Args>
1928KOKKOS_INLINE_FUNCTION typename Kokkos::Impl::ViewMapping<
1929 void /* deduce subview type from source view traits */
1930 ,
1931 ViewTraits<D, P...>, Args...>::template apply<MemoryTraits>::type
1932subview(const View<D, P...>& src, Args... args) {
1933 static_assert(View<D, P...>::Rank == sizeof...(Args),
1934 "subview requires one argument for each source View rank");
1935
1936 return typename Kokkos::Impl::ViewMapping<
1937 void /* deduce subview type from source view traits */
1938 ,
1939 ViewTraits<D, P...>,
1940 Args...>::template apply<MemoryTraits>::type(src, args...);
1941}
1942
1943} /* namespace Kokkos */
1944
1945//----------------------------------------------------------------------------
1946//----------------------------------------------------------------------------
1947
1948namespace Kokkos {
1949
1950template <class LT, class... LP, class RT, class... RP>
1951KOKKOS_INLINE_FUNCTION bool operator==(const View<LT, LP...>& lhs,
1952 const View<RT, RP...>& rhs) {
1953 // Same data, layout, dimensions
1954 using lhs_traits = ViewTraits<LT, LP...>;
1955 using rhs_traits = ViewTraits<RT, RP...>;
1956
1957 return std::is_same<typename lhs_traits::const_value_type,
1958 typename rhs_traits::const_value_type>::value &&
1959 std::is_same<typename lhs_traits::array_layout,
1960 typename rhs_traits::array_layout>::value &&
1961 std::is_same<typename lhs_traits::memory_space,
1962 typename rhs_traits::memory_space>::value &&
1963 unsigned(lhs_traits::rank) == unsigned(rhs_traits::rank) &&
1964 lhs.data() == rhs.data() && lhs.span() == rhs.span() &&
1965 lhs.extent(0) == rhs.extent(0) && lhs.extent(1) == rhs.extent(1) &&
1966 lhs.extent(2) == rhs.extent(2) && lhs.extent(3) == rhs.extent(3) &&
1967 lhs.extent(4) == rhs.extent(4) && lhs.extent(5) == rhs.extent(5) &&
1968 lhs.extent(6) == rhs.extent(6) && lhs.extent(7) == rhs.extent(7);
1969}
1970
1971template <class LT, class... LP, class RT, class... RP>
1972KOKKOS_INLINE_FUNCTION bool operator!=(const View<LT, LP...>& lhs,
1973 const View<RT, RP...>& rhs) {
1974 return !(operator==(lhs, rhs));
1975}
1976
1977} /* namespace Kokkos */
1978
1979//----------------------------------------------------------------------------
1980//----------------------------------------------------------------------------
1981
1982namespace Kokkos {
1983namespace Impl {
1984
1985inline void shared_allocation_tracking_disable() {
1986 Kokkos::Impl::SharedAllocationRecord<void, void>::tracking_disable();
1987}
1988
1989inline void shared_allocation_tracking_enable() {
1990 Kokkos::Impl::SharedAllocationRecord<void, void>::tracking_enable();
1991}
1992
1993} /* namespace Impl */
1994} /* namespace Kokkos */
1995
1996//----------------------------------------------------------------------------
1997//----------------------------------------------------------------------------
1998
1999namespace Kokkos {
2000namespace Impl {
2001
2002template <class Specialize, typename A, typename B>
2003struct CommonViewValueType;
2004
2005template <typename A, typename B>
2006struct CommonViewValueType<void, A, B> {
2007 using value_type = typename std::common_type<A, B>::type;
2008};
2009
2010template <class Specialize, class ValueType>
2011struct CommonViewAllocProp;
2012
2013template <class ValueType>
2014struct CommonViewAllocProp<void, ValueType> {
2015 using value_type = ValueType;
2016 using scalar_array_type = ValueType;
2017
2018 template <class... Views>
2019 KOKKOS_INLINE_FUNCTION CommonViewAllocProp(const Views&...) {}
2020};
2021
2022template <class... Views>
2023struct DeduceCommonViewAllocProp;
2024
2025// Base case must provide types for:
2026// 1. specialize 2. value_type 3. is_view 4. prop_type
2027template <class FirstView>
2028struct DeduceCommonViewAllocProp<FirstView> {
2029 using specialize = typename FirstView::traits::specialize;
2030
2031 using value_type = typename FirstView::traits::value_type;
2032
2033 enum : bool { is_view = is_view<FirstView>::value };
2034
2035 using prop_type = CommonViewAllocProp<specialize, value_type>;
2036};
2037
2038template <class FirstView, class... NextViews>
2039struct DeduceCommonViewAllocProp<FirstView, NextViews...> {
2040 using NextTraits = DeduceCommonViewAllocProp<NextViews...>;
2041
2042 using first_specialize = typename FirstView::traits::specialize;
2043 using first_value_type = typename FirstView::traits::value_type;
2044
2045 enum : bool { first_is_view = is_view<FirstView>::value };
2046
2047 using next_specialize = typename NextTraits::specialize;
2048 using next_value_type = typename NextTraits::value_type;
2049
2050 enum : bool { next_is_view = NextTraits::is_view };
2051
2052 // common types
2053
2054 // determine specialize type
2055 // if first and next specialize differ, but are not the same specialize, error
2056 // out
2057 static_assert(!(!std::is_same<first_specialize, next_specialize>::value &&
2058 !std::is_same<first_specialize, void>::value &&
2059 !std::is_same<void, next_specialize>::value),
2060 "Kokkos DeduceCommonViewAllocProp ERROR: Only one non-void "
2061 "specialize trait allowed");
2062
2063 // otherwise choose non-void specialize if either/both are non-void
2064 using specialize = typename std::conditional<
2065 std::is_same<first_specialize, next_specialize>::value, first_specialize,
2066 typename std::conditional<(std::is_same<first_specialize, void>::value &&
2067 !std::is_same<next_specialize, void>::value),
2068 next_specialize, first_specialize>::type>::type;
2069
2070 using value_type = typename CommonViewValueType<specialize, first_value_type,
2071 next_value_type>::value_type;
2072
2073 enum : bool { is_view = (first_is_view && next_is_view) };
2074
2075 using prop_type = CommonViewAllocProp<specialize, value_type>;
2076};
2077
2078} // end namespace Impl
2079
2080template <class... Views>
2081using DeducedCommonPropsType =
2082 typename Impl::DeduceCommonViewAllocProp<Views...>::prop_type;
2083
2084// User function
2085template <class... Views>
2086KOKKOS_INLINE_FUNCTION DeducedCommonPropsType<Views...> common_view_alloc_prop(
2087 Views const&... views) {
2088 return DeducedCommonPropsType<Views...>(views...);
2089}
2090
2091} // namespace Kokkos
2092
2093namespace Kokkos {
2094namespace Impl {
2095
2096using Kokkos::is_view;
2097
2098} /* namespace Impl */
2099} /* namespace Kokkos */
2100
2101#include <impl/Kokkos_ViewUniformType.hpp>
2102#include <impl/Kokkos_Atomic_View.hpp>
2103
2104//----------------------------------------------------------------------------
2105//----------------------------------------------------------------------------
2106
2107#endif /* #ifndef KOKKOS_VIEW_HPP */
View
View to an array of data.
typename Impl::ViewUniformType< View, 0 >::type uniform_type
Unified types.
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< std::is_integral< iType >::value, size_t >::type extent(const iType &r) const noexcept
rank() to be implemented
Traits class for accessing attributes of a View.