Kokkos Core Kernels Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 #if defined(KOKKOS_ENABLE_PROFILING)
59 #include <impl/Kokkos_Profiling_Interface.hpp>
60 #endif
61 
62 //----------------------------------------------------------------------------
63 //----------------------------------------------------------------------------
64 
65 namespace Kokkos {
66 namespace Impl {
67 
68 template <class DataType>
69 struct ViewArrayAnalysis;
70 
71 template <class DataType, class ArrayLayout,
72  typename ValueType =
73  typename ViewArrayAnalysis<DataType>::non_const_value_type>
74 struct ViewDataAnalysis;
75 
76 template <class, class...>
77 class ViewMapping {
78  public:
79  enum { is_assignable_data_type = false };
80  enum { is_assignable = false };
81 };
82 
83 template <typename IntType>
84 KOKKOS_INLINE_FUNCTION std::size_t count_valid_integers(
85  const IntType i0, const IntType i1, const IntType i2, const IntType i3,
86  const IntType i4, const IntType i5, const IntType i6, const IntType i7) {
87  static_assert(std::is_integral<IntType>::value,
88  "count_valid_integers() must have integer arguments.");
89 
90  return (i0 != KOKKOS_INVALID_INDEX) + (i1 != KOKKOS_INVALID_INDEX) +
91  (i2 != KOKKOS_INVALID_INDEX) + (i3 != KOKKOS_INVALID_INDEX) +
92  (i4 != KOKKOS_INVALID_INDEX) + (i5 != KOKKOS_INVALID_INDEX) +
93  (i6 != KOKKOS_INVALID_INDEX) + (i7 != KOKKOS_INVALID_INDEX);
94 }
95 
96 #ifndef KOKKOS_ENABLE_DEPRECATED_CODE
97 KOKKOS_INLINE_FUNCTION
98 void runtime_check_rank_device(const size_t dyn_rank, const bool is_void_spec,
99  const size_t i0, const size_t i1,
100  const size_t i2, const size_t i3,
101  const size_t i4, const size_t i5,
102  const size_t i6, const size_t i7) {
103  if (is_void_spec) {
104  const size_t num_passed_args =
105  count_valid_integers(i0, i1, i2, i3, i4, i5, i6, i7);
106 
107  if (num_passed_args != dyn_rank && is_void_spec) {
108  Kokkos::abort(
109  "Number of arguments passed to Kokkos::View() constructor must match "
110  "the dynamic rank of the view.");
111  }
112  }
113 }
114 #else
115 KOKKOS_INLINE_FUNCTION
116 void runtime_check_rank_device(const size_t, const bool, const size_t,
117  const size_t, const size_t, const size_t,
118  const size_t, const size_t, const size_t,
119  const size_t) {}
120 #endif
121 
122 #ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
123 #ifndef KOKKOS_ENABLE_DEPRECATED_CODE
124 KOKKOS_INLINE_FUNCTION
125 void runtime_check_rank_host(const size_t dyn_rank, const bool is_void_spec,
126  const size_t i0, const size_t i1, const size_t i2,
127  const size_t i3, const size_t i4, const size_t i5,
128  const size_t i6, const size_t i7,
129  const std::string& label) {
130  if (is_void_spec) {
131  const size_t num_passed_args =
132  count_valid_integers(i0, i1, i2, i3, i4, i5, i6, i7);
133 
134  if (num_passed_args != dyn_rank) {
135  const std::string message =
136  "Constructor for Kokkos View '" + label +
137  "' has mismatched number of arguments. Number of arguments = " +
138  std::to_string(num_passed_args) +
139  " but dynamic rank = " + std::to_string(dyn_rank) + " \n";
140  Kokkos::abort(message.c_str());
141  }
142  }
143 }
144 #else
145 KOKKOS_INLINE_FUNCTION
146 void runtime_check_rank_host(const size_t, const bool, const size_t,
147  const size_t, const size_t, const size_t,
148  const size_t, const size_t, const size_t,
149  const size_t, const std::string&) {}
150 #endif
151 #endif
152 
153 } /* namespace Impl */
154 } /* namespace Kokkos */
155 
156 // Class to provide a uniform type
157 namespace Kokkos {
158 namespace Impl {
159 template <class ViewType, int Traits = 0>
160 struct ViewUniformType;
161 }
162 } // namespace Kokkos
163 
164 //----------------------------------------------------------------------------
165 //----------------------------------------------------------------------------
166 
167 namespace Kokkos {
168 
186 template <class DataType, class... Properties>
187 struct ViewTraits;
188 
189 template <>
190 struct ViewTraits<void> {
191  typedef void execution_space;
192  typedef void memory_space;
193  typedef void HostMirrorSpace;
194  typedef void array_layout;
195  typedef void memory_traits;
196  typedef void specialize;
197 };
198 
199 template <class... Prop>
200 struct ViewTraits<void, void, Prop...> {
201  // Ignore an extraneous 'void'
202  typedef typename ViewTraits<void, Prop...>::execution_space execution_space;
203  typedef typename ViewTraits<void, Prop...>::memory_space memory_space;
204  typedef typename ViewTraits<void, Prop...>::HostMirrorSpace HostMirrorSpace;
205  typedef typename ViewTraits<void, Prop...>::array_layout array_layout;
206  typedef typename ViewTraits<void, Prop...>::memory_traits memory_traits;
207  typedef typename ViewTraits<void, Prop...>::specialize specialize;
208 };
209 
210 template <class ArrayLayout, class... Prop>
211 struct ViewTraits<typename std::enable_if<
212  Kokkos::Impl::is_array_layout<ArrayLayout>::value>::type,
213  ArrayLayout, Prop...> {
214  // Specify layout, keep subsequent space and memory traits arguments
215 
216  typedef typename ViewTraits<void, Prop...>::execution_space execution_space;
217  typedef typename ViewTraits<void, Prop...>::memory_space memory_space;
218  typedef typename ViewTraits<void, Prop...>::HostMirrorSpace HostMirrorSpace;
219  typedef ArrayLayout array_layout;
220  typedef typename ViewTraits<void, Prop...>::memory_traits memory_traits;
221  typedef typename ViewTraits<void, Prop...>::specialize specialize;
222 };
223 
224 template <class Space, class... Prop>
225 struct ViewTraits<
226  typename std::enable_if<Kokkos::Impl::is_space<Space>::value>::type, Space,
227  Prop...> {
228  // Specify Space, memory traits should be the only subsequent argument.
229 
230  static_assert(
231  std::is_same<typename ViewTraits<void, Prop...>::execution_space,
232  void>::value &&
233  std::is_same<typename ViewTraits<void, Prop...>::memory_space,
234  void>::value &&
235  std::is_same<typename ViewTraits<void, Prop...>::HostMirrorSpace,
236  void>::value &&
237  std::is_same<typename ViewTraits<void, Prop...>::array_layout,
238  void>::value,
239  "Only one View Execution or Memory Space template argument");
240 
241  typedef typename Space::execution_space execution_space;
242  typedef typename Space::memory_space memory_space;
243  typedef typename Kokkos::Impl::HostMirror<Space>::Space::memory_space
244  HostMirrorSpace;
245  typedef typename execution_space::array_layout array_layout;
246  typedef typename ViewTraits<void, Prop...>::memory_traits memory_traits;
247  typedef typename ViewTraits<void, Prop...>::specialize specialize;
248 };
249 
250 template <class MemoryTraits, class... Prop>
251 struct ViewTraits<typename std::enable_if<Kokkos::Impl::is_memory_traits<
252  MemoryTraits>::value>::type,
253  MemoryTraits, Prop...> {
254  // Specify memory trait, should not be any subsequent arguments
255 
256  static_assert(
257  std::is_same<typename ViewTraits<void, Prop...>::execution_space,
258  void>::value &&
259  std::is_same<typename ViewTraits<void, Prop...>::memory_space,
260  void>::value &&
261  std::is_same<typename ViewTraits<void, Prop...>::array_layout,
262  void>::value &&
263  std::is_same<typename ViewTraits<void, Prop...>::memory_traits,
264  void>::value,
265  "MemoryTrait is the final optional template argument for a View");
266 
267  typedef void execution_space;
268  typedef void memory_space;
269  typedef void HostMirrorSpace;
270  typedef void array_layout;
271  typedef MemoryTraits memory_traits;
272  typedef void specialize;
273 };
274 
275 template <class DataType, class... Properties>
276 struct ViewTraits {
277  private:
278  // Unpack the properties arguments
279  typedef ViewTraits<void, Properties...> prop;
280 
281  typedef typename std::conditional<
282  !std::is_same<typename prop::execution_space, void>::value,
283  typename prop::execution_space, Kokkos::DefaultExecutionSpace>::type
284  ExecutionSpace;
285 
286  typedef typename std::conditional<
287  !std::is_same<typename prop::memory_space, void>::value,
288  typename prop::memory_space, typename ExecutionSpace::memory_space>::type
289  MemorySpace;
290 
291  typedef typename std::conditional<
292  !std::is_same<typename prop::array_layout, void>::value,
293  typename prop::array_layout, typename ExecutionSpace::array_layout>::type
294  ArrayLayout;
295 
296  typedef typename std::conditional<
297  !std::is_same<typename prop::HostMirrorSpace, void>::value,
298  typename prop::HostMirrorSpace,
299  typename Kokkos::Impl::HostMirror<ExecutionSpace>::Space>::type
300  HostMirrorSpace;
301 
302  typedef typename std::conditional<
303  !std::is_same<typename prop::memory_traits, void>::value,
304  typename prop::memory_traits, typename Kokkos::MemoryManaged>::type
305  MemoryTraits;
306 
307  // Analyze data type's properties,
308  // May be specialized based upon the layout and value type
309  typedef Kokkos::Impl::ViewDataAnalysis<DataType, ArrayLayout> data_analysis;
310 
311  public:
312  //------------------------------------
313  // Data type traits:
314 
315  typedef typename data_analysis::type data_type;
316  typedef typename data_analysis::const_type const_data_type;
317  typedef typename data_analysis::non_const_type non_const_data_type;
318 
319  //------------------------------------
320  // Compatible array of trivial type traits:
321 
322  typedef typename data_analysis::scalar_array_type scalar_array_type;
323  typedef
324  typename data_analysis::const_scalar_array_type const_scalar_array_type;
325  typedef typename data_analysis::non_const_scalar_array_type
326  non_const_scalar_array_type;
327 
328  //------------------------------------
329  // Value type traits:
330 
331  typedef typename data_analysis::value_type value_type;
332  typedef typename data_analysis::const_value_type const_value_type;
333  typedef typename data_analysis::non_const_value_type non_const_value_type;
334 
335  //------------------------------------
336  // Mapping traits:
337 
338  typedef ArrayLayout array_layout;
339  typedef typename data_analysis::dimension dimension;
340 
341  typedef typename std::conditional<
342  std::is_same<typename data_analysis::specialize, void>::value,
343  typename prop::specialize, typename data_analysis::specialize>::type
344  specialize; /* mapping specialization tag */
345 
346  enum { rank = dimension::rank };
347  enum { rank_dynamic = dimension::rank_dynamic };
348 
349  //------------------------------------
350  // Execution space, memory space, memory access traits, and host mirror space.
351 
352  typedef ExecutionSpace execution_space;
353  typedef MemorySpace memory_space;
354  typedef Kokkos::Device<ExecutionSpace, MemorySpace> device_type;
355  typedef MemoryTraits memory_traits;
356  typedef HostMirrorSpace host_mirror_space;
357 
358  typedef typename MemorySpace::size_type size_type;
359 
360  enum { is_hostspace = std::is_same<MemorySpace, HostSpace>::value };
361  enum { is_managed = MemoryTraits::is_unmanaged == 0 };
362  enum { is_random_access = MemoryTraits::is_random_access == 1 };
363 
364  //------------------------------------
365 };
366 
450 template <class DataType, class... Properties>
451 class View;
452 
453 template <class T1, class T2>
454 struct is_always_assignable_impl;
455 
456 template <class... ViewTDst, class... ViewTSrc>
457 struct is_always_assignable_impl<Kokkos::View<ViewTDst...>,
458  Kokkos::View<ViewTSrc...>> {
459  using mapping_type = Kokkos::Impl::ViewMapping<
460  typename Kokkos::View<ViewTDst...>::traits,
461  typename Kokkos::View<ViewTSrc...>::traits,
462  typename Kokkos::View<ViewTDst...>::traits::specialize>;
463 
464  constexpr static bool value =
465  mapping_type::is_assignable &&
466  static_cast<int>(Kokkos::View<ViewTDst...>::rank_dynamic) >=
467  static_cast<int>(Kokkos::View<ViewTSrc...>::rank_dynamic);
468 };
469 
470 template <class View1, class View2>
471 using is_always_assignable = is_always_assignable_impl<
472  typename std::remove_reference<View1>::type,
473  typename std::remove_const<
474  typename std::remove_reference<View2>::type>::type>;
475 
476 #ifdef KOKKOS_ENABLE_CXX17
477 template <class T1, class T2>
478 inline constexpr bool is_always_assignable_v =
479  is_always_assignable<T1, T2>::value;
480 #endif
481 
482 template <class... ViewTDst, class... ViewTSrc>
483 constexpr bool is_assignable(const Kokkos::View<ViewTDst...>& dst,
484  const Kokkos::View<ViewTSrc...>& src) {
485  using DstTraits = typename Kokkos::View<ViewTDst...>::traits;
486  using SrcTraits = typename Kokkos::View<ViewTSrc...>::traits;
487  using mapping_type =
488  Kokkos::Impl::ViewMapping<DstTraits, SrcTraits,
489  typename DstTraits::specialize>;
490 
491 #ifdef KOKKOS_ENABLE_CXX17
492  return is_always_assignable_v<Kokkos::View<ViewTDst...>,
493  Kokkos::View<ViewTSrc...>> ||
494 #else
495  return is_always_assignable<Kokkos::View<ViewTDst...>,
496  Kokkos::View<ViewTSrc...>>::value ||
497 #endif
498  (mapping_type::is_assignable &&
499  ((DstTraits::dimension::rank_dynamic >= 1) ||
500  (dst.static_extent(0) == src.extent(0))) &&
501  ((DstTraits::dimension::rank_dynamic >= 2) ||
502  (dst.static_extent(1) == src.extent(1))) &&
503  ((DstTraits::dimension::rank_dynamic >= 3) ||
504  (dst.static_extent(2) == src.extent(2))) &&
505  ((DstTraits::dimension::rank_dynamic >= 4) ||
506  (dst.static_extent(3) == src.extent(3))) &&
507  ((DstTraits::dimension::rank_dynamic >= 5) ||
508  (dst.static_extent(4) == src.extent(4))) &&
509  ((DstTraits::dimension::rank_dynamic >= 6) ||
510  (dst.static_extent(5) == src.extent(5))) &&
511  ((DstTraits::dimension::rank_dynamic >= 7) ||
512  (dst.static_extent(6) == src.extent(6))) &&
513  ((DstTraits::dimension::rank_dynamic >= 8) ||
514  (dst.static_extent(7) == src.extent(7))));
515 }
516 
517 } /* namespace Kokkos */
518 
519 //----------------------------------------------------------------------------
520 //----------------------------------------------------------------------------
521 
522 #include <impl/Kokkos_ViewMapping.hpp>
523 #include <impl/Kokkos_ViewArray.hpp>
524 
525 //----------------------------------------------------------------------------
526 //----------------------------------------------------------------------------
527 
528 namespace Kokkos {
529 
530 namespace {
531 
532 constexpr Kokkos::Impl::ALL_t ALL = Kokkos::Impl::ALL_t();
533 
534 constexpr Kokkos::Impl::WithoutInitializing_t WithoutInitializing =
535  Kokkos::Impl::WithoutInitializing_t();
536 
537 constexpr Kokkos::Impl::AllowPadding_t AllowPadding =
538  Kokkos::Impl::AllowPadding_t();
539 
540 } // namespace
541 
552 template <class... Args>
553 inline Impl::ViewCtorProp<typename Impl::ViewCtorProp<void, Args>::type...>
554 view_alloc(Args const&... args) {
555  typedef Impl::ViewCtorProp<typename Impl::ViewCtorProp<void, Args>::type...>
556  return_type;
557 
558  static_assert(!return_type::has_pointer,
559  "Cannot give pointer-to-memory for view allocation");
560 
561  return return_type(args...);
562 }
563 
564 template <class... Args>
565 KOKKOS_INLINE_FUNCTION
566  Impl::ViewCtorProp<typename Impl::ViewCtorProp<void, Args>::type...>
567  view_wrap(Args const&... args) {
568  typedef Impl::ViewCtorProp<typename Impl::ViewCtorProp<void, Args>::type...>
569  return_type;
570 
571  static_assert(!return_type::has_memory_space &&
572  !return_type::has_execution_space &&
573  !return_type::has_label && return_type::has_pointer,
574  "Must only give pointer-to-memory for view wrapping");
575 
576  return return_type(args...);
577 }
578 
579 } /* namespace Kokkos */
580 
581 //----------------------------------------------------------------------------
582 //----------------------------------------------------------------------------
583 
584 namespace Kokkos {
585 
586 template <class DataType, class... Properties>
587 class View;
588 
589 template <class>
590 struct is_view : public std::false_type {};
591 
592 template <class D, class... P>
593 struct is_view<View<D, P...>> : public std::true_type {};
594 
595 template <class D, class... P>
596 struct is_view<const View<D, P...>> : public std::true_type {};
597 
598 template <class DataType, class... Properties>
599 class View : public ViewTraits<DataType, Properties...> {
600  private:
601  template <class, class...>
602  friend class View;
603  template <class, class...>
604  friend class Kokkos::Impl::ViewMapping;
605 
606  public:
607  typedef ViewTraits<DataType, Properties...> traits;
608 
609  private:
610  typedef Kokkos::Impl::ViewMapping<traits, typename traits::specialize>
611  map_type;
612  typedef Kokkos::Impl::SharedAllocationTracker track_type;
613 
614  track_type m_track;
615  map_type m_map;
616 
617  public:
618  //----------------------------------------
620  typedef View<typename traits::scalar_array_type,
621  typename traits::array_layout, typename traits::device_type,
622  typename traits::memory_traits>
624 
626  typedef View<typename traits::const_data_type, typename traits::array_layout,
627  typename traits::device_type, typename traits::memory_traits>
629 
631  typedef View<typename traits::non_const_data_type,
632  typename traits::array_layout, typename traits::device_type,
633  typename traits::memory_traits>
635 
637  typedef View<typename traits::non_const_data_type,
638  typename traits::array_layout,
639  Device<DefaultHostExecutionSpace,
640  typename traits::host_mirror_space::memory_space>>
642 
644  typedef View<typename traits::non_const_data_type,
645  typename traits::array_layout,
646  typename traits::host_mirror_space>
648 
650  typedef typename Impl::ViewUniformType<View, 0>::type uniform_type;
651  typedef
652  typename Impl::ViewUniformType<View, 0>::const_type uniform_const_type;
653  typedef typename Impl::ViewUniformType<View, 0>::runtime_type
654  uniform_runtime_type;
655  typedef typename Impl::ViewUniformType<View, 0>::runtime_const_type
656  uniform_runtime_const_type;
657  typedef typename Impl::ViewUniformType<View, 0>::nomemspace_type
658  uniform_nomemspace_type;
659  typedef typename Impl::ViewUniformType<View, 0>::const_nomemspace_type
660  uniform_const_nomemspace_type;
661  typedef typename Impl::ViewUniformType<View, 0>::runtime_nomemspace_type
662  uniform_runtime_nomemspace_type;
663  typedef typename Impl::ViewUniformType<View, 0>::runtime_const_nomemspace_type
664  uniform_runtime_const_nomemspace_type;
665 
666  //----------------------------------------
667  // Domain rank and extents
668 
669  enum { Rank = map_type::Rank };
670 
673  // KOKKOS_INLINE_FUNCTION
674  // static
675  // constexpr unsigned rank() { return map_type::Rank; }
676 
677  template <typename iType>
678  KOKKOS_INLINE_FUNCTION constexpr
679  typename std::enable_if<std::is_integral<iType>::value, size_t>::type
680  extent(const iType& r) const noexcept {
681  return m_map.extent(r);
682  }
683 
684  static KOKKOS_INLINE_FUNCTION constexpr size_t static_extent(
685  const unsigned r) noexcept {
686  return map_type::static_extent(r);
687  }
688 
689  template <typename iType>
690  KOKKOS_INLINE_FUNCTION constexpr
691  typename std::enable_if<std::is_integral<iType>::value, int>::type
692  extent_int(const iType& r) const noexcept {
693  return static_cast<int>(m_map.extent(r));
694  }
695 
696  KOKKOS_INLINE_FUNCTION constexpr typename traits::array_layout layout()
697  const {
698  return m_map.layout();
699  }
700 
701  //----------------------------------------
702  /* Deprecate all 'dimension' functions in favor of
703  * ISO/C++ vocabulary 'extent'.
704  */
705 
706 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
707 
708  template <typename iType>
709  KOKKOS_INLINE_FUNCTION constexpr
710  typename std::enable_if<std::is_integral<iType>::value, size_t>::type
711  dimension(const iType& r) const {
712  return extent(r);
713  }
714 
715  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_0() const {
716  return m_map.dimension_0();
717  }
718  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_1() const {
719  return m_map.dimension_1();
720  }
721  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_2() const {
722  return m_map.dimension_2();
723  }
724  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_3() const {
725  return m_map.dimension_3();
726  }
727  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_4() const {
728  return m_map.dimension_4();
729  }
730  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_5() const {
731  return m_map.dimension_5();
732  }
733  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_6() const {
734  return m_map.dimension_6();
735  }
736  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_7() const {
737  return m_map.dimension_7();
738  }
739 
740 #endif
741 
742  //----------------------------------------
743 
744  KOKKOS_INLINE_FUNCTION constexpr size_t size() const {
745  return m_map.dimension_0() * m_map.dimension_1() * m_map.dimension_2() *
746  m_map.dimension_3() * m_map.dimension_4() * m_map.dimension_5() *
747  m_map.dimension_6() * m_map.dimension_7();
748  }
749 
750  KOKKOS_INLINE_FUNCTION constexpr size_t stride_0() const {
751  return m_map.stride_0();
752  }
753  KOKKOS_INLINE_FUNCTION constexpr size_t stride_1() const {
754  return m_map.stride_1();
755  }
756  KOKKOS_INLINE_FUNCTION constexpr size_t stride_2() const {
757  return m_map.stride_2();
758  }
759  KOKKOS_INLINE_FUNCTION constexpr size_t stride_3() const {
760  return m_map.stride_3();
761  }
762  KOKKOS_INLINE_FUNCTION constexpr size_t stride_4() const {
763  return m_map.stride_4();
764  }
765  KOKKOS_INLINE_FUNCTION constexpr size_t stride_5() const {
766  return m_map.stride_5();
767  }
768  KOKKOS_INLINE_FUNCTION constexpr size_t stride_6() const {
769  return m_map.stride_6();
770  }
771  KOKKOS_INLINE_FUNCTION constexpr size_t stride_7() const {
772  return m_map.stride_7();
773  }
774 
775  template <typename iType>
776  KOKKOS_INLINE_FUNCTION constexpr
777  typename std::enable_if<std::is_integral<iType>::value, size_t>::type
778  stride(iType r) const {
779  return (
780  r == 0
781  ? m_map.stride_0()
782  : (r == 1
783  ? m_map.stride_1()
784  : (r == 2
785  ? m_map.stride_2()
786  : (r == 3
787  ? m_map.stride_3()
788  : (r == 4
789  ? m_map.stride_4()
790  : (r == 5
791  ? m_map.stride_5()
792  : (r == 6
793  ? m_map.stride_6()
794  : m_map.stride_7())))))));
795  }
796 
797  template <typename iType>
798  KOKKOS_INLINE_FUNCTION void stride(iType* const s) const {
799  m_map.stride(s);
800  }
801 
802  //----------------------------------------
803  // Range span is the span which contains all members.
804 
805  typedef typename map_type::reference_type reference_type;
806  typedef typename map_type::pointer_type pointer_type;
807 
808  enum {
809  reference_type_is_lvalue_reference =
810  std::is_lvalue_reference<reference_type>::value
811  };
812 
813  KOKKOS_INLINE_FUNCTION constexpr size_t span() const { return m_map.span(); }
814 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
815  // Deprecated, use 'span()' instead
816  KOKKOS_INLINE_FUNCTION constexpr size_t capacity() const {
817  return m_map.span();
818  }
819 #endif
820  KOKKOS_INLINE_FUNCTION bool span_is_contiguous() const {
821  return m_map.span_is_contiguous();
822  }
823  KOKKOS_INLINE_FUNCTION constexpr pointer_type data() const {
824  return m_map.data();
825  }
826 
827 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
828  // Deprecated, use 'span_is_contigous()' instead
829  KOKKOS_INLINE_FUNCTION constexpr bool is_contiguous() const {
830  return m_map.span_is_contiguous();
831  }
832  // Deprecated, use 'data()' instead
833  KOKKOS_INLINE_FUNCTION constexpr pointer_type ptr_on_device() const {
834  return m_map.data();
835  }
836 #endif
837 
838  //----------------------------------------
839  // Allow specializations to query their specialized map
840 
841 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
842  KOKKOS_INLINE_FUNCTION
843  const Kokkos::Impl::ViewMapping<traits, typename traits::specialize>&
844  implementation_map() const {
845  return m_map;
846  }
847 #endif
848  KOKKOS_INLINE_FUNCTION
849  const Kokkos::Impl::ViewMapping<traits, typename traits::specialize>&
850  impl_map() const {
851  return m_map;
852  }
853  KOKKOS_INLINE_FUNCTION
854  const Kokkos::Impl::SharedAllocationTracker& impl_track() const {
855  return m_track;
856  }
857  //----------------------------------------
858 
859  private:
860  static constexpr bool is_layout_left =
861  std::is_same<typename traits::array_layout, Kokkos::LayoutLeft>::value;
862 
863  static constexpr bool is_layout_right =
864  std::is_same<typename traits::array_layout, Kokkos::LayoutRight>::value;
865 
866  static constexpr bool is_layout_stride =
867  std::is_same<typename traits::array_layout, Kokkos::LayoutStride>::value;
868 
869  static constexpr bool is_default_map =
870  std::is_same<typename traits::specialize, void>::value &&
871  (is_layout_left || is_layout_right || is_layout_stride);
872 
873  template <class Space, bool = Kokkos::Impl::MemorySpaceAccess<
874  Space, typename traits::memory_space>::accessible>
875  struct verify_space {
876  KOKKOS_FORCEINLINE_FUNCTION static void check() {}
877  };
878 
879  template <class Space>
880  struct verify_space<Space, false> {
881  KOKKOS_FORCEINLINE_FUNCTION static void check() {
882  Kokkos::abort(
883  "Kokkos::View ERROR: attempt to access inaccessible memory space");
884  };
885  };
886 
887 #if defined(KOKKOS_ENABLE_DEBUG_BOUNDS_CHECK)
888 
889 #define KOKKOS_IMPL_SINK(ARG) ARG
890 
891 #define KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(ARG) \
892  View::template verify_space< \
893  Kokkos::Impl::ActiveExecutionMemorySpace>::check(); \
894  Kokkos::Impl::view_verify_operator_bounds<typename traits::memory_space> ARG;
895 
896 #else
897 
898 #define KOKKOS_IMPL_SINK(ARG)
899 
900 #define KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(ARG) \
901  View::template verify_space< \
902  Kokkos::Impl::ActiveExecutionMemorySpace>::check();
903 
904 #endif
905 
906  public:
907 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
908  template <class... Args>
909  KOKKOS_FORCEINLINE_FUNCTION
910  typename std::enable_if<(Kokkos::Impl::are_integral<Args...>::value &&
911  (0 == Rank)),
912  reference_type>::type
913  operator()(Args... args) const {
914  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, args...))
915  return m_map.reference();
916  }
917 
918  template <typename I0, class... Args>
919  KOKKOS_FORCEINLINE_FUNCTION
920  typename std::enable_if<(Kokkos::Impl::are_integral<I0, Args...>::value &&
921  (1 == Rank) && !is_default_map),
922  reference_type>::type
923  operator()(const I0& i0, Args... args) const {
924  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, args...))
925  return m_map.reference(i0);
926  }
927 
928  template <typename I0, class... Args>
929  KOKKOS_FORCEINLINE_FUNCTION
930  typename std::enable_if<(Kokkos::Impl::are_integral<I0, Args...>::value &&
931  (1 == Rank) && is_default_map &&
932  !is_layout_stride),
933  reference_type>::type
934  operator()(const I0& i0, Args... args) const {
935  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, args...))
936  return m_map.m_impl_handle[i0];
937  }
938 
939  template <typename I0, class... Args>
940  KOKKOS_FORCEINLINE_FUNCTION
941  typename std::enable_if<(Kokkos::Impl::are_integral<I0, Args...>::value &&
942  (1 == Rank) && is_default_map &&
943  is_layout_stride),
944  reference_type>::type
945  operator()(const I0& i0, Args... args) const {
946  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, args...))
947  return m_map.m_impl_handle[m_map.m_impl_offset.m_stride.S0 * i0];
948  }
949 
950  //------------------------------
951  // Rank 1 operator[]
952 
953  template <typename I0>
954  KOKKOS_FORCEINLINE_FUNCTION
955  typename std::enable_if<(Kokkos::Impl::are_integral<I0>::value &&
956  (1 == Rank) && !is_default_map),
957  reference_type>::type
958  operator[](const I0& i0) const {
959  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0))
960  return m_map.reference(i0);
961  }
962 
963  template <typename I0>
964  KOKKOS_FORCEINLINE_FUNCTION
965  typename std::enable_if<(Kokkos::Impl::are_integral<I0>::value &&
966  (1 == Rank) && is_default_map &&
967  !is_layout_stride),
968  reference_type>::type
969  operator[](const I0& i0) const {
970  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0))
971  return m_map.m_impl_handle[i0];
972  }
973 
974  template <typename I0>
975  KOKKOS_FORCEINLINE_FUNCTION
976  typename std::enable_if<(Kokkos::Impl::are_integral<I0>::value &&
977  (1 == Rank) && is_default_map &&
978  is_layout_stride),
979  reference_type>::type
980  operator[](const I0& i0) const {
981  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0))
982  return m_map.m_impl_handle[m_map.m_impl_offset.m_stride.S0 * i0];
983  }
984 
985  template <typename I0, typename I1, class... Args>
986  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
987  (Kokkos::Impl::are_integral<I0, I1, Args...>::value && (2 == Rank) &&
988  !is_default_map),
989  reference_type>::type
990  operator()(const I0& i0, const I1& i1, Args... args) const {
991  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, args...))
992  return m_map.reference(i0, i1);
993  }
994 
995  template <typename I0, typename I1, class... Args>
996  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
997  (Kokkos::Impl::are_integral<I0, I1, Args...>::value && (2 == Rank) &&
998  is_default_map && is_layout_left && (traits::rank_dynamic == 0)),
999  reference_type>::type
1000  operator()(const I0& i0, const I1& i1, Args... args) const {
1001  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, args...))
1002  return m_map.m_impl_handle[i0 + m_map.m_impl_offset.m_dim.N0 * i1];
1003  }
1004 
1005  template <typename I0, typename I1, class... Args>
1006  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1007  (Kokkos::Impl::are_integral<I0, I1, Args...>::value && (2 == Rank) &&
1008  is_default_map && is_layout_left && (traits::rank_dynamic != 0)),
1009  reference_type>::type
1010  operator()(const I0& i0, const I1& i1, Args... args) const {
1011  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, args...))
1012  return m_map.m_impl_handle[i0 + m_map.m_impl_offset.m_stride * i1];
1013  }
1014 
1015  template <typename I0, typename I1, class... Args>
1016  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1017  (Kokkos::Impl::are_integral<I0, I1, Args...>::value && (2 == Rank) &&
1018  is_default_map && is_layout_right && (traits::rank_dynamic == 0)),
1019  reference_type>::type
1020  operator()(const I0& i0, const I1& i1, Args... args) const {
1021  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, args...))
1022  return m_map.m_impl_handle[i1 + m_map.m_impl_offset.m_dim.N1 * i0];
1023  }
1024 
1025  template <typename I0, typename I1, class... Args>
1026  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1027  (Kokkos::Impl::are_integral<I0, I1, Args...>::value && (2 == Rank) &&
1028  is_default_map && is_layout_right && (traits::rank_dynamic != 0)),
1029  reference_type>::type
1030  operator()(const I0& i0, const I1& i1, Args... args) const {
1031  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, args...))
1032  return m_map.m_impl_handle[i1 + m_map.m_impl_offset.m_stride * i0];
1033  }
1034 
1035  template <typename I0, typename I1, class... Args>
1036  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1037  (Kokkos::Impl::are_integral<I0, I1, Args...>::value && (2 == Rank) &&
1038  is_default_map && is_layout_stride),
1039  reference_type>::type
1040  operator()(const I0& i0, const I1& i1, Args... args) const {
1041  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, args...))
1042  return m_map.m_impl_handle[i0 * m_map.m_impl_offset.m_stride.S0 +
1043  i1 * m_map.m_impl_offset.m_stride.S1];
1044  }
1045 
1046  //------------------------------
1047  // Rank 3
1048 
1049  template <typename I0, typename I1, typename I2, class... Args>
1050  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1051  (Kokkos::Impl::are_integral<I0, I1, I2, Args...>::value && (3 == Rank) &&
1052  is_default_map),
1053  reference_type>::type
1054  operator()(const I0& i0, const I1& i1, const I2& i2, Args... args) const {
1055  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, i2, args...))
1056  return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2)];
1057  }
1058 
1059  template <typename I0, typename I1, typename I2, class... Args>
1060  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1061  (Kokkos::Impl::are_integral<I0, I1, I2, Args...>::value && (3 == Rank) &&
1062  !is_default_map),
1063  reference_type>::type
1064  operator()(const I0& i0, const I1& i1, const I2& i2, Args... args) const {
1065  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, i2, args...))
1066  return m_map.reference(i0, i1, i2);
1067  }
1068 
1069  //------------------------------
1070  // Rank 4
1071 
1072  template <typename I0, typename I1, typename I2, typename I3, class... Args>
1073  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1074  (Kokkos::Impl::are_integral<I0, I1, I2, I3, Args...>::value &&
1075  (4 == Rank) && is_default_map),
1076  reference_type>::type
1077  operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1078  Args... args) const {
1079  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, i2, i3, args...))
1080  return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3)];
1081  }
1082 
1083  template <typename I0, typename I1, typename I2, typename I3, class... Args>
1084  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1085  (Kokkos::Impl::are_integral<I0, I1, I2, I3, Args...>::value &&
1086  (4 == Rank) && !is_default_map),
1087  reference_type>::type
1088  operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1089  Args... args) const {
1090  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, i2, i3, args...))
1091  return m_map.reference(i0, i1, i2, i3);
1092  }
1093 
1094  //------------------------------
1095  // Rank 5
1096 
1097  template <typename I0, typename I1, typename I2, typename I3, typename I4,
1098  class... Args>
1099  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1100  (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, Args...>::value &&
1101  (5 == Rank) && is_default_map),
1102  reference_type>::type
1103  operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1104  const I4& i4, Args... args) const {
1105  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1106  (m_track, m_map, i0, i1, i2, i3, i4, args...))
1107  return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3, i4)];
1108  }
1109 
1110  template <typename I0, typename I1, typename I2, typename I3, typename I4,
1111  class... Args>
1112  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1113  (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, Args...>::value &&
1114  (5 == Rank) && !is_default_map),
1115  reference_type>::type
1116  operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1117  const I4& i4, Args... args) const {
1118  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1119  (m_track, m_map, i0, i1, i2, i3, i4, args...))
1120  return m_map.reference(i0, i1, i2, i3, i4);
1121  }
1122 
1123  //------------------------------
1124  // Rank 6
1125 
1126  template <typename I0, typename I1, typename I2, typename I3, typename I4,
1127  typename I5, class... Args>
1128  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1129  (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, Args...>::value &&
1130  (6 == Rank) && is_default_map),
1131  reference_type>::type
1132  operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1133  const I4& i4, const I5& i5, Args... args) const {
1134  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1135  (m_track, m_map, i0, i1, i2, i3, i4, i5, args...))
1136  return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3, i4, i5)];
1137  }
1138 
1139  template <typename I0, typename I1, typename I2, typename I3, typename I4,
1140  typename I5, class... Args>
1141  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1142  (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, Args...>::value &&
1143  (6 == Rank) && !is_default_map),
1144  reference_type>::type
1145  operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1146  const I4& i4, const I5& i5, Args... args) const {
1147  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1148  (m_track, m_map, i0, i1, i2, i3, i4, i5, args...))
1149  return m_map.reference(i0, i1, i2, i3, i4, i5);
1150  }
1151 
1152  //------------------------------
1153  // Rank 7
1154 
1155  template <typename I0, typename I1, typename I2, typename I3, typename I4,
1156  typename I5, typename I6, class... Args>
1157  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1158  (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, I6, Args...>::value &&
1159  (7 == Rank) && is_default_map),
1160  reference_type>::type
1161  operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1162  const I4& i4, const I5& i5, const I6& i6, Args... args) const {
1163  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1164  (m_track, m_map, i0, i1, i2, i3, i4, i5, i6, args...))
1165  return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3, i4, i5, i6)];
1166  }
1167 
1168  template <typename I0, typename I1, typename I2, typename I3, typename I4,
1169  typename I5, typename I6, class... Args>
1170  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1171  (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, I6, Args...>::value &&
1172  (7 == Rank) && !is_default_map),
1173  reference_type>::type
1174  operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1175  const I4& i4, const I5& i5, const I6& i6, Args... args) const {
1176  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1177  (m_track, m_map, i0, i1, i2, i3, i4, i5, i6, args...))
1178  return m_map.reference(i0, i1, i2, i3, i4, i5, i6);
1179  }
1180 
1181  //------------------------------
1182  // Rank 8
1183 
1184  template <typename I0, typename I1, typename I2, typename I3, typename I4,
1185  typename I5, typename I6, typename I7, class... Args>
1186  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1187  (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, I6, I7,
1188  Args...>::value &&
1189  (8 == Rank) && is_default_map),
1190  reference_type>::type
1191  operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1192  const I4& i4, const I5& i5, const I6& i6, const I7& i7,
1193  Args... args) const {
1194  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1195  (m_track, m_map, i0, i1, i2, i3, i4, i5, i6, i7, args...))
1196  return m_map
1197  .m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3, i4, i5, i6, i7)];
1198  }
1199 
1200  template <typename I0, typename I1, typename I2, typename I3, typename I4,
1201  typename I5, typename I6, typename I7, class... Args>
1202  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1203  (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, I6, I7,
1204  Args...>::value &&
1205  (8 == Rank) && !is_default_map),
1206  reference_type>::type
1207  operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1208  const I4& i4, const I5& i5, const I6& i6, const I7& i7,
1209  Args... args) const {
1210  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1211  (m_track, m_map, i0, i1, i2, i3, i4, i5, i6, i7, args...))
1212  return m_map.reference(i0, i1, i2, i3, i4, i5, i6, i7);
1213  }
1214 
1215 #else
1216  //------------------------------
1217  // Rank 0 operator()
1218 
1219  KOKKOS_FORCEINLINE_FUNCTION
1220  reference_type operator()() const { return m_map.reference(); }
1221  //------------------------------
1222  // Rank 1 operator()
1223 
1224  template <typename I0>
1225  KOKKOS_FORCEINLINE_FUNCTION
1226  typename std::enable_if<(Kokkos::Impl::are_integral<I0>::value &&
1227  (1 == Rank) && !is_default_map),
1228  reference_type>::type
1229  operator()(const I0& i0) const {
1230  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0))
1231  return m_map.reference(i0);
1232  }
1233 
1234  template <typename I0>
1235  KOKKOS_FORCEINLINE_FUNCTION
1236  typename std::enable_if<(Kokkos::Impl::are_integral<I0>::value &&
1237  (1 == Rank) && is_default_map &&
1238  !is_layout_stride),
1239  reference_type>::type
1240  operator()(const I0& i0) const {
1241  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0))
1242  return m_map.m_impl_handle[i0];
1243  }
1244 
1245  template <typename I0>
1246  KOKKOS_FORCEINLINE_FUNCTION
1247  typename std::enable_if<(Kokkos::Impl::are_integral<I0>::value &&
1248  (1 == Rank) && is_default_map &&
1249  is_layout_stride),
1250  reference_type>::type
1251  operator()(const I0& i0) const {
1252  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0))
1253  return m_map.m_impl_handle[m_map.m_impl_offset.m_stride.S0 * i0];
1254  }
1255  //------------------------------
1256  // Rank 1 operator[]
1257 
1258  template <typename I0>
1259  KOKKOS_FORCEINLINE_FUNCTION
1260  typename std::enable_if<(Kokkos::Impl::are_integral<I0>::value &&
1261  (1 == Rank) && !is_default_map),
1262  reference_type>::type
1263  operator[](const I0& i0) const {
1264  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0))
1265  return m_map.reference(i0);
1266  }
1267 
1268  template <typename I0>
1269  KOKKOS_FORCEINLINE_FUNCTION
1270  typename std::enable_if<(Kokkos::Impl::are_integral<I0>::value &&
1271  (1 == Rank) && is_default_map &&
1272  !is_layout_stride),
1273  reference_type>::type
1274  operator[](const I0& i0) const {
1275  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0))
1276  return m_map.m_impl_handle[i0];
1277  }
1278 
1279  template <typename I0>
1280  KOKKOS_FORCEINLINE_FUNCTION
1281  typename std::enable_if<(Kokkos::Impl::are_integral<I0>::value &&
1282  (1 == Rank) && is_default_map &&
1283  is_layout_stride),
1284  reference_type>::type
1285  operator[](const I0& i0) const {
1286  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0))
1287  return m_map.m_impl_handle[m_map.m_impl_offset.m_stride.S0 * i0];
1288  }
1289 
1290  //------------------------------
1291  // Rank 2
1292 
1293  template <typename I0, typename I1>
1294  KOKKOS_FORCEINLINE_FUNCTION
1295  typename std::enable_if<(Kokkos::Impl::are_integral<I0, I1>::value &&
1296  (2 == Rank) && !is_default_map),
1297  reference_type>::type
1298  operator()(const I0& i0, const I1& i1) const {
1299  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1))
1300  return m_map.reference(i0, i1);
1301  }
1302 
1303  template <typename I0, typename I1>
1304  KOKKOS_FORCEINLINE_FUNCTION
1305  typename std::enable_if<(Kokkos::Impl::are_integral<I0, I1>::value &&
1306  (2 == Rank) && is_default_map &&
1307  is_layout_left && (traits::rank_dynamic == 0)),
1308  reference_type>::type
1309  operator()(const I0& i0, const I1& i1) const {
1310  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1))
1311  return m_map.m_impl_handle[i0 + m_map.m_impl_offset.m_dim.N0 * i1];
1312  }
1313 
1314  template <typename I0, typename I1>
1315  KOKKOS_FORCEINLINE_FUNCTION
1316  typename std::enable_if<(Kokkos::Impl::are_integral<I0, I1>::value &&
1317  (2 == Rank) && is_default_map &&
1318  is_layout_left && (traits::rank_dynamic != 0)),
1319  reference_type>::type
1320  operator()(const I0& i0, const I1& i1) const {
1321  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1))
1322  return m_map.m_impl_handle[i0 + m_map.m_impl_offset.m_stride * i1];
1323  }
1324 
1325  template <typename I0, typename I1>
1326  KOKKOS_FORCEINLINE_FUNCTION
1327  typename std::enable_if<(Kokkos::Impl::are_integral<I0, I1>::value &&
1328  (2 == Rank) && is_default_map &&
1329  is_layout_right && (traits::rank_dynamic == 0)),
1330  reference_type>::type
1331  operator()(const I0& i0, const I1& i1) const {
1332  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1))
1333  return m_map.m_impl_handle[i1 + m_map.m_impl_offset.m_dim.N1 * i0];
1334  }
1335 
1336  template <typename I0, typename I1>
1337  KOKKOS_FORCEINLINE_FUNCTION
1338  typename std::enable_if<(Kokkos::Impl::are_integral<I0, I1>::value &&
1339  (2 == Rank) && is_default_map &&
1340  is_layout_right && (traits::rank_dynamic != 0)),
1341  reference_type>::type
1342  operator()(const I0& i0, const I1& i1) const {
1343  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1))
1344  return m_map.m_impl_handle[i1 + m_map.m_impl_offset.m_stride * i0];
1345  }
1346 
1347  template <typename I0, typename I1>
1348  KOKKOS_FORCEINLINE_FUNCTION
1349  typename std::enable_if<(Kokkos::Impl::are_integral<I0, I1>::value &&
1350  (2 == Rank) && is_default_map &&
1351  is_layout_stride),
1352  reference_type>::type
1353  operator()(const I0& i0, const I1& i1) const {
1354  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1))
1355  return m_map.m_impl_handle[i0 * m_map.m_impl_offset.m_stride.S0 +
1356  i1 * m_map.m_impl_offset.m_stride.S1];
1357  }
1358 
1359  //------------------------------
1360  // Rank 3
1361 
1362  template <typename I0, typename I1, typename I2>
1363  KOKKOS_FORCEINLINE_FUNCTION
1364  typename std::enable_if<(Kokkos::Impl::are_integral<I0, I1, I2>::value &&
1365  (3 == Rank) && is_default_map),
1366  reference_type>::type
1367  operator()(const I0& i0, const I1& i1, const I2& i2) const {
1368  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, i2))
1369  return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2)];
1370  }
1371 
1372  template <typename I0, typename I1, typename I2>
1373  KOKKOS_FORCEINLINE_FUNCTION
1374  typename std::enable_if<(Kokkos::Impl::are_integral<I0, I1, I2>::value &&
1375  (3 == Rank) && !is_default_map),
1376  reference_type>::type
1377  operator()(const I0& i0, const I1& i1, const I2& i2) const {
1378  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, i2))
1379  return m_map.reference(i0, i1, i2);
1380  }
1381 
1382  //------------------------------
1383  // Rank 4
1384 
1385  template <typename I0, typename I1, typename I2, typename I3>
1386  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1387  (Kokkos::Impl::are_integral<I0, I1, I2, I3>::value && (4 == Rank) &&
1388  is_default_map),
1389  reference_type>::type
1390  operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3) const {
1391  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, i2, i3))
1392  return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3)];
1393  }
1394 
1395  template <typename I0, typename I1, typename I2, typename I3>
1396  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1397  (Kokkos::Impl::are_integral<I0, I1, I2, I3>::value && (4 == Rank) &&
1398  !is_default_map),
1399  reference_type>::type
1400  operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3) const {
1401  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, i2, i3))
1402  return m_map.reference(i0, i1, i2, i3);
1403  }
1404 
1405  //------------------------------
1406  // Rank 5
1407 
1408  template <typename I0, typename I1, typename I2, typename I3, typename I4>
1409  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1410  (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4>::value && (5 == Rank) &&
1411  is_default_map),
1412  reference_type>::type
1413  operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1414  const I4& i4) const {
1415  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, i2, i3, i4))
1416  return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3, i4)];
1417  }
1418 
1419  template <typename I0, typename I1, typename I2, typename I3, typename I4>
1420  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1421  (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4>::value && (5 == Rank) &&
1422  !is_default_map),
1423  reference_type>::type
1424  operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1425  const I4& i4) const {
1426  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, i2, i3, i4))
1427  return m_map.reference(i0, i1, i2, i3, i4);
1428  }
1429 
1430  //------------------------------
1431  // Rank 6
1432 
1433  template <typename I0, typename I1, typename I2, typename I3, typename I4,
1434  typename I5>
1435  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1436  (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5>::value &&
1437  (6 == Rank) && is_default_map),
1438  reference_type>::type
1439  operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1440  const I4& i4, const I5& i5) const {
1441  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, i2, i3, i4, i5))
1442  return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3, i4, i5)];
1443  }
1444 
1445  template <typename I0, typename I1, typename I2, typename I3, typename I4,
1446  typename I5>
1447  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1448  (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5>::value &&
1449  (6 == Rank) && !is_default_map),
1450  reference_type>::type
1451  operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1452  const I4& i4, const I5& i5) const {
1453  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((m_track, m_map, i0, i1, i2, i3, i4, i5))
1454  return m_map.reference(i0, i1, i2, i3, i4, i5);
1455  }
1456 
1457  //------------------------------
1458  // Rank 7
1459 
1460  template <typename I0, typename I1, typename I2, typename I3, typename I4,
1461  typename I5, typename I6>
1462  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1463  (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, I6>::value &&
1464  (7 == Rank) && is_default_map),
1465  reference_type>::type
1466  operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1467  const I4& i4, const I5& i5, const I6& i6) const {
1468  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1469  (m_track, m_map, i0, i1, i2, i3, i4, i5, i6))
1470  return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3, i4, i5, i6)];
1471  }
1472 
1473  template <typename I0, typename I1, typename I2, typename I3, typename I4,
1474  typename I5, typename I6>
1475  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1476  (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, I6>::value &&
1477  (7 == Rank) && !is_default_map),
1478  reference_type>::type
1479  operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1480  const I4& i4, const I5& i5, const I6& i6) const {
1481  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1482  (m_track, m_map, i0, i1, i2, i3, i4, i5, i6))
1483  return m_map.reference(i0, i1, i2, i3, i4, i5, i6);
1484  }
1485 
1486  //------------------------------
1487  // Rank 8
1488 
1489  template <typename I0, typename I1, typename I2, typename I3, typename I4,
1490  typename I5, typename I6, typename I7>
1491  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1492  (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, I6, I7>::value &&
1493  (8 == Rank) && is_default_map),
1494  reference_type>::type
1495  operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1496  const I4& i4, const I5& i5, const I6& i6, const I7& i7) const {
1497  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1498  (m_track, m_map, i0, i1, i2, i3, i4, i5, i6, i7))
1499  return m_map
1500  .m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3, i4, i5, i6, i7)];
1501  }
1502 
1503  template <typename I0, typename I1, typename I2, typename I3, typename I4,
1504  typename I5, typename I6, typename I7>
1505  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1506  (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, I6, I7>::value &&
1507  (8 == Rank) && !is_default_map),
1508  reference_type>::type
1509  operator()(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1510  const I4& i4, const I5& i5, const I6& i6, const I7& i7) const {
1511  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1512  (m_track, m_map, i0, i1, i2, i3, i4, i5, i6, i7))
1513  return m_map.reference(i0, i1, i2, i3, i4, i5, i6, i7);
1514  }
1515 
1516 #endif
1517  template <class... Args>
1518  KOKKOS_FORCEINLINE_FUNCTION
1519  typename std::enable_if<(Kokkos::Impl::are_integral<Args...>::value &&
1520  (0 == Rank)),
1521  reference_type>::type
1522  access(Args... KOKKOS_IMPL_SINK(args)) const {
1523  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1524  KOKKOS_IMPL_SINK((m_track, m_map, args...)))
1525  return m_map.reference();
1526  }
1527 
1528  template <typename I0, class... Args>
1529  KOKKOS_FORCEINLINE_FUNCTION
1530  typename std::enable_if<(Kokkos::Impl::are_integral<I0, Args...>::value &&
1531  (1 == Rank) && !is_default_map),
1532  reference_type>::type
1533  access(const I0& i0, Args... KOKKOS_IMPL_SINK(args)) const {
1534  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1535  KOKKOS_IMPL_SINK((m_track, m_map, i0, args...)))
1536  return m_map.reference(i0);
1537  }
1538 
1539  template <typename I0, class... Args>
1540  KOKKOS_FORCEINLINE_FUNCTION
1541  typename std::enable_if<(Kokkos::Impl::are_integral<I0, Args...>::value &&
1542  (1 == Rank) && is_default_map &&
1543  !is_layout_stride),
1544  reference_type>::type
1545  access(const I0& i0, Args... KOKKOS_IMPL_SINK(args)) const {
1546  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1547  KOKKOS_IMPL_SINK((m_track, m_map, i0, args...)))
1548  return m_map.m_impl_handle[i0];
1549  }
1550 
1551  template <typename I0, class... Args>
1552  KOKKOS_FORCEINLINE_FUNCTION
1553  typename std::enable_if<(Kokkos::Impl::are_integral<I0, Args...>::value &&
1554  (1 == Rank) && is_default_map &&
1555  is_layout_stride),
1556  reference_type>::type
1557  access(const I0& i0, Args... KOKKOS_IMPL_SINK(args)) const {
1558  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1559  KOKKOS_IMPL_SINK((m_track, m_map, i0, args...)))
1560  return m_map.m_impl_handle[m_map.m_impl_offset.m_stride.S0 * i0];
1561  }
1562 
1563  template <typename I0, typename I1, class... Args>
1564  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1565  (Kokkos::Impl::are_integral<I0, I1, Args...>::value && (2 == Rank) &&
1566  !is_default_map),
1567  reference_type>::type
1568  access(const I0& i0, const I1& i1, Args... KOKKOS_IMPL_SINK(args)) const {
1569  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1570  KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, args...)))
1571  return m_map.reference(i0, i1);
1572  }
1573 
1574  template <typename I0, typename I1, class... Args>
1575  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1576  (Kokkos::Impl::are_integral<I0, I1, Args...>::value && (2 == Rank) &&
1577  is_default_map && is_layout_left && (traits::rank_dynamic == 0)),
1578  reference_type>::type
1579  access(const I0& i0, const I1& i1, Args... KOKKOS_IMPL_SINK(args)) const {
1580  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1581  KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, args...)))
1582  return m_map.m_impl_handle[i0 + m_map.m_impl_offset.m_dim.N0 * i1];
1583  }
1584 
1585  template <typename I0, typename I1, class... Args>
1586  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1587  (Kokkos::Impl::are_integral<I0, I1, Args...>::value && (2 == Rank) &&
1588  is_default_map && is_layout_left && (traits::rank_dynamic != 0)),
1589  reference_type>::type
1590  access(const I0& i0, const I1& i1, Args... KOKKOS_IMPL_SINK(args)) const {
1591  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1592  KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, args...)))
1593  return m_map.m_impl_handle[i0 + m_map.m_impl_offset.m_stride * i1];
1594  }
1595 
1596  template <typename I0, typename I1, class... Args>
1597  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1598  (Kokkos::Impl::are_integral<I0, I1, Args...>::value && (2 == Rank) &&
1599  is_default_map && is_layout_right && (traits::rank_dynamic == 0)),
1600  reference_type>::type
1601  access(const I0& i0, const I1& i1, Args... KOKKOS_IMPL_SINK(args)) const {
1602  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1603  KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, args...)))
1604  return m_map.m_impl_handle[i1 + m_map.m_impl_offset.m_dim.N1 * i0];
1605  }
1606 
1607  template <typename I0, typename I1, class... Args>
1608  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1609  (Kokkos::Impl::are_integral<I0, I1, Args...>::value && (2 == Rank) &&
1610  is_default_map && is_layout_right && (traits::rank_dynamic != 0)),
1611  reference_type>::type
1612  access(const I0& i0, const I1& i1, Args... KOKKOS_IMPL_SINK(args)) const {
1613  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1614  KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, args...)))
1615  return m_map.m_impl_handle[i1 + m_map.m_impl_offset.m_stride * i0];
1616  }
1617 
1618  template <typename I0, typename I1, class... Args>
1619  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1620  (Kokkos::Impl::are_integral<I0, I1, Args...>::value && (2 == Rank) &&
1621  is_default_map && is_layout_stride),
1622  reference_type>::type
1623  access(const I0& i0, const I1& i1, Args... KOKKOS_IMPL_SINK(args)) const {
1624  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1625  KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, args...)))
1626  return m_map.m_impl_handle[i0 * m_map.m_impl_offset.m_stride.S0 +
1627  i1 * m_map.m_impl_offset.m_stride.S1];
1628  }
1629 
1630  //------------------------------
1631  // Rank 3
1632 
1633  template <typename I0, typename I1, typename I2, class... Args>
1634  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1635  (Kokkos::Impl::are_integral<I0, I1, I2, Args...>::value && (3 == Rank) &&
1636  is_default_map),
1637  reference_type>::type
1638  access(const I0& i0, const I1& i1, const I2& i2,
1639  Args... KOKKOS_IMPL_SINK(args)) const {
1640  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1641  KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, i2, args...)))
1642  return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2)];
1643  }
1644 
1645  template <typename I0, typename I1, typename I2, class... Args>
1646  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1647  (Kokkos::Impl::are_integral<I0, I1, I2, Args...>::value && (3 == Rank) &&
1648  !is_default_map),
1649  reference_type>::type
1650  access(const I0& i0, const I1& i1, const I2& i2,
1651  Args... KOKKOS_IMPL_SINK(args)) const {
1652  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1653  KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, i2, args...)))
1654  return m_map.reference(i0, i1, i2);
1655  }
1656 
1657  //------------------------------
1658  // Rank 4
1659 
1660  template <typename I0, typename I1, typename I2, typename I3, class... Args>
1661  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1662  (Kokkos::Impl::are_integral<I0, I1, I2, I3, Args...>::value &&
1663  (4 == Rank) && is_default_map),
1664  reference_type>::type
1665  access(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1666  Args... KOKKOS_IMPL_SINK(args)) const {
1667  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1668  KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, i2, i3, args...)))
1669  return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3)];
1670  }
1671 
1672  template <typename I0, typename I1, typename I2, typename I3, class... Args>
1673  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1674  (Kokkos::Impl::are_integral<I0, I1, I2, I3, Args...>::value &&
1675  (4 == Rank) && !is_default_map),
1676  reference_type>::type
1677  access(const I0& i0, const I1& i1, const I2& i2, const I3& i3,
1678  Args... KOKKOS_IMPL_SINK(args)) const {
1679  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1680  KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, i2, i3, args...)))
1681  return m_map.reference(i0, i1, i2, i3);
1682  }
1683 
1684  //------------------------------
1685  // Rank 5
1686 
1687  template <typename I0, typename I1, typename I2, typename I3, typename I4,
1688  class... Args>
1689  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1690  (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, Args...>::value &&
1691  (5 == Rank) && is_default_map),
1692  reference_type>::type
1693  access(const I0& i0, const I1& i1, const I2& i2, const I3& i3, const I4& i4,
1694  Args... KOKKOS_IMPL_SINK(args)) const {
1695  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1696  KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, i2, i3, i4, args...)))
1697  return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3, i4)];
1698  }
1699 
1700  template <typename I0, typename I1, typename I2, typename I3, typename I4,
1701  class... Args>
1702  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1703  (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, Args...>::value &&
1704  (5 == Rank) && !is_default_map),
1705  reference_type>::type
1706  access(const I0& i0, const I1& i1, const I2& i2, const I3& i3, const I4& i4,
1707  Args... KOKKOS_IMPL_SINK(args)) const {
1708  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1709  KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, i2, i3, i4, args...)))
1710  return m_map.reference(i0, i1, i2, i3, i4);
1711  }
1712 
1713  //------------------------------
1714  // Rank 6
1715 
1716  template <typename I0, typename I1, typename I2, typename I3, typename I4,
1717  typename I5, class... Args>
1718  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1719  (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, Args...>::value &&
1720  (6 == Rank) && is_default_map),
1721  reference_type>::type
1722  access(const I0& i0, const I1& i1, const I2& i2, const I3& i3, const I4& i4,
1723  const I5& i5, Args... KOKKOS_IMPL_SINK(args)) const {
1724  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1725  KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, i2, i3, i4, i5, args...)))
1726  return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3, i4, i5)];
1727  }
1728 
1729  template <typename I0, typename I1, typename I2, typename I3, typename I4,
1730  typename I5, class... Args>
1731  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1732  (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, Args...>::value &&
1733  (6 == Rank) && !is_default_map),
1734  reference_type>::type
1735  access(const I0& i0, const I1& i1, const I2& i2, const I3& i3, const I4& i4,
1736  const I5& i5, Args... KOKKOS_IMPL_SINK(args)) const {
1737  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1738  KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, i2, i3, i4, i5, args...)))
1739  return m_map.reference(i0, i1, i2, i3, i4, i5);
1740  }
1741 
1742  //------------------------------
1743  // Rank 7
1744 
1745  template <typename I0, typename I1, typename I2, typename I3, typename I4,
1746  typename I5, typename I6, class... Args>
1747  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1748  (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, I6, Args...>::value &&
1749  (7 == Rank) && is_default_map),
1750  reference_type>::type
1751  access(const I0& i0, const I1& i1, const I2& i2, const I3& i3, const I4& i4,
1752  const I5& i5, const I6& i6, Args... KOKKOS_IMPL_SINK(args)) const {
1753  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1754  KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, i2, i3, i4, i5, i6, args...)))
1755  return m_map.m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3, i4, i5, i6)];
1756  }
1757 
1758  template <typename I0, typename I1, typename I2, typename I3, typename I4,
1759  typename I5, typename I6, class... Args>
1760  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1761  (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, I6, Args...>::value &&
1762  (7 == Rank) && !is_default_map),
1763  reference_type>::type
1764  access(const I0& i0, const I1& i1, const I2& i2, const I3& i3, const I4& i4,
1765  const I5& i5, const I6& i6, Args... KOKKOS_IMPL_SINK(args)) const {
1766  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
1767  KOKKOS_IMPL_SINK((m_track, m_map, i0, i1, i2, i3, i4, i5, i6, args...)))
1768  return m_map.reference(i0, i1, i2, i3, i4, i5, i6);
1769  }
1770 
1771  //------------------------------
1772  // Rank 8
1773 
1774  template <typename I0, typename I1, typename I2, typename I3, typename I4,
1775  typename I5, typename I6, typename I7, class... Args>
1776  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1777  (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, I6, I7,
1778  Args...>::value &&
1779  (8 == Rank) && is_default_map),
1780  reference_type>::type
1781  access(const I0& i0, const I1& i1, const I2& i2, const I3& i3, const I4& i4,
1782  const I5& i5, const I6& i6, const I7& i7,
1783  Args... KOKKOS_IMPL_SINK(args)) const {
1784  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(KOKKOS_IMPL_SINK(
1785  (m_track, m_map, i0, i1, i2, i3, i4, i5, i6, i7, args...)))
1786  return m_map
1787  .m_impl_handle[m_map.m_impl_offset(i0, i1, i2, i3, i4, i5, i6, i7)];
1788  }
1789 
1790  template <typename I0, typename I1, typename I2, typename I3, typename I4,
1791  typename I5, typename I6, typename I7, class... Args>
1792  KOKKOS_FORCEINLINE_FUNCTION typename std::enable_if<
1793  (Kokkos::Impl::are_integral<I0, I1, I2, I3, I4, I5, I6, I7,
1794  Args...>::value &&
1795  (8 == Rank) && !is_default_map),
1796  reference_type>::type
1797  access(const I0& i0, const I1& i1, const I2& i2, const I3& i3, const I4& i4,
1798  const I5& i5, const I6& i6, const I7& i7,
1799  Args... KOKKOS_IMPL_SINK(args)) const {
1800  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(KOKKOS_IMPL_SINK(
1801  (m_track, m_map, i0, i1, i2, i3, i4, i5, i6, i7, args...)))
1802  return m_map.reference(i0, i1, i2, i3, i4, i5, i6, i7);
1803  }
1804 
1805 #undef KOKKOS_IMPL_VIEW_OPERATOR_VERIFY
1806 
1807  //----------------------------------------
1808  // Standard destructor, constructors, and assignment operators
1809 
1810  KOKKOS_DEFAULTED_FUNCTION
1811  ~View() = default;
1812 
1813  KOKKOS_INLINE_FUNCTION
1814  View() : m_track(), m_map() {}
1815 
1816  KOKKOS_INLINE_FUNCTION
1817  View(const View& rhs)
1818  : m_track(rhs.m_track, traits::is_managed), m_map(rhs.m_map) {}
1819 
1820  KOKKOS_INLINE_FUNCTION
1821  View(View&& rhs)
1822  : m_track(std::move(rhs.m_track)), m_map(std::move(rhs.m_map)) {}
1823 
1824  KOKKOS_INLINE_FUNCTION
1825  View& operator=(const View& rhs) {
1826  m_track = rhs.m_track;
1827  m_map = rhs.m_map;
1828  return *this;
1829  }
1830 
1831  KOKKOS_INLINE_FUNCTION
1832  View& operator=(View&& rhs) {
1833  m_track = std::move(rhs.m_track);
1834  m_map = std::move(rhs.m_map);
1835  return *this;
1836  }
1837 
1838  //----------------------------------------
1839  // Compatible view copy constructor and assignment
1840  // may assign unmanaged from managed.
1841 
1842  template <class RT, class... RP>
1843  KOKKOS_INLINE_FUNCTION View(
1844  const View<RT, RP...>& rhs,
1845  typename std::enable_if<Kokkos::Impl::ViewMapping<
1846  traits, typename View<RT, RP...>::traits,
1847  typename traits::specialize>::is_assignable_data_type>::type* =
1848  nullptr)
1849  : m_track(rhs.m_track, traits::is_managed), m_map() {
1850  typedef typename View<RT, RP...>::traits SrcTraits;
1851  typedef Kokkos::Impl::ViewMapping<traits, SrcTraits,
1852  typename traits::specialize>
1853  Mapping;
1854  static_assert(Mapping::is_assignable,
1855  "Incompatible View copy construction");
1856  Mapping::assign(m_map, rhs.m_map, rhs.m_track);
1857  }
1858 
1859  template <class RT, class... RP>
1860  KOKKOS_INLINE_FUNCTION typename std::enable_if<
1861  Kokkos::Impl::ViewMapping<
1862  traits, typename View<RT, RP...>::traits,
1863  typename traits::specialize>::is_assignable_data_type,
1864  View>::type&
1865  operator=(const View<RT, RP...>& rhs) {
1866  typedef typename View<RT, RP...>::traits SrcTraits;
1867  typedef Kokkos::Impl::ViewMapping<traits, SrcTraits,
1868  typename traits::specialize>
1869  Mapping;
1870  static_assert(Mapping::is_assignable, "Incompatible View copy assignment");
1871  Mapping::assign(m_map, rhs.m_map, rhs.m_track);
1872  m_track.assign(rhs.m_track, traits::is_managed);
1873  return *this;
1874  }
1875 
1876  //----------------------------------------
1877  // Compatible subview constructor
1878  // may assign unmanaged from managed.
1879 
1880  template <class RT, class... RP, class Arg0, class... Args>
1881  KOKKOS_INLINE_FUNCTION View(const View<RT, RP...>& src_view, const Arg0 arg0,
1882  Args... args)
1883  : m_track(src_view.m_track, traits::is_managed), m_map() {
1884  typedef View<RT, RP...> SrcType;
1885 
1886  typedef Kokkos::Impl::ViewMapping<void /* deduce destination view type from
1887  source view traits */
1888  ,
1889  typename SrcType::traits, Arg0, Args...>
1890  Mapping;
1891 
1892  typedef typename Mapping::type DstType;
1893 
1894  static_assert(
1895  Kokkos::Impl::ViewMapping<traits, typename DstType::traits,
1896  typename traits::specialize>::is_assignable,
1897  "Subview construction requires compatible view and subview arguments");
1898 
1899  Mapping::assign(m_map, src_view.m_map, arg0, args...);
1900  }
1901 
1902  //----------------------------------------
1903  // Allocation tracking properties
1904 
1905  KOKKOS_INLINE_FUNCTION
1906  int use_count() const { return m_track.use_count(); }
1907 
1908  inline const std::string label() const {
1909  return m_track.template get_label<typename traits::memory_space>();
1910  }
1911 
1912  //----------------------------------------
1913  // Allocation according to allocation properties and array layout
1914 
1915  template <class... P>
1916  explicit inline View(
1917  const Impl::ViewCtorProp<P...>& arg_prop,
1918  typename std::enable_if<!Impl::ViewCtorProp<P...>::has_pointer,
1919  typename traits::array_layout>::type const&
1920  arg_layout)
1921  : m_track(), m_map() {
1922  // Append layout and spaces if not input
1923  typedef Impl::ViewCtorProp<P...> alloc_prop_input;
1924 
1925  // use 'std::integral_constant<unsigned,I>' for non-types
1926  // to avoid duplicate class error.
1927  typedef Impl::ViewCtorProp<
1928  P...,
1929  typename std::conditional<alloc_prop_input::has_label,
1930  std::integral_constant<unsigned, 0>,
1931  typename std::string>::type,
1932  typename std::conditional<
1933  alloc_prop_input::has_memory_space,
1934  std::integral_constant<unsigned, 1>,
1935  typename traits::device_type::memory_space>::type,
1936  typename std::conditional<
1937  alloc_prop_input::has_execution_space,
1938  std::integral_constant<unsigned, 2>,
1939  typename traits::device_type::execution_space>::type>
1940  alloc_prop;
1941 
1942  static_assert(traits::is_managed,
1943  "View allocation constructor requires managed memory");
1944 
1945  if (alloc_prop::initialize &&
1946 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
1947  !alloc_prop::execution_space::is_initialized()
1948 #else
1949  !alloc_prop::execution_space::impl_is_initialized()
1950 #endif
1951  ) {
1952  // If initializing view data then
1953  // the execution space must be initialized.
1954  Kokkos::Impl::throw_runtime_exception(
1955  "Constructing View and initializing data with uninitialized "
1956  "execution space");
1957  }
1958 
1959  // Copy the input allocation properties with possibly defaulted properties
1960  alloc_prop prop_copy(arg_prop);
1961 
1962 //------------------------------------------------------------
1963 #if defined(KOKKOS_ENABLE_CUDA)
1964  // If allocating in CudaUVMSpace must fence before and after
1965  // the allocation to protect against possible concurrent access
1966  // on the CPU and the GPU.
1967  // Fence using the trait's execution space (which will be Kokkos::Cuda)
1968  // to avoid incomplete type errors from using Kokkos::Cuda directly.
1969  if (std::is_same<Kokkos::CudaUVMSpace,
1970  typename traits::device_type::memory_space>::value) {
1971  typename traits::device_type::memory_space::execution_space().fence();
1972  }
1973 #endif
1974  //------------------------------------------------------------
1975 
1976  Kokkos::Impl::SharedAllocationRecord<>* record =
1977  m_map.allocate_shared(prop_copy, arg_layout);
1978 
1979 //------------------------------------------------------------
1980 #if defined(KOKKOS_ENABLE_CUDA)
1981  if (std::is_same<Kokkos::CudaUVMSpace,
1982  typename traits::device_type::memory_space>::value) {
1983  typename traits::device_type::memory_space::execution_space().fence();
1984  }
1985 #endif
1986  //------------------------------------------------------------
1987 
1988  // Setup and initialization complete, start tracking
1989  m_track.assign_allocated_record_to_uninitialized(record);
1990  }
1991 
1992  KOKKOS_INLINE_FUNCTION
1993  void assign_data(pointer_type arg_data) {
1994  m_track.clear();
1995  m_map.assign_data(arg_data);
1996  }
1997 
1998  // Wrap memory according to properties and array layout
1999  template <class... P>
2000  explicit KOKKOS_INLINE_FUNCTION View(
2001  const Impl::ViewCtorProp<P...>& arg_prop,
2002  typename std::enable_if<Impl::ViewCtorProp<P...>::has_pointer,
2003  typename traits::array_layout>::type const&
2004  arg_layout)
2005  : m_track() // No memory tracking
2006  ,
2007  m_map(arg_prop, arg_layout) {
2008  static_assert(
2009  std::is_same<pointer_type,
2010  typename Impl::ViewCtorProp<P...>::pointer_type>::value,
2011  "Constructing View to wrap user memory must supply matching pointer "
2012  "type");
2013  }
2014 
2015  // Simple dimension-only layout
2016  template <class... P>
2017  explicit inline View(
2018  const Impl::ViewCtorProp<P...>& arg_prop,
2019  typename std::enable_if<!Impl::ViewCtorProp<P...>::has_pointer,
2020  size_t>::type const arg_N0 =
2021  KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2022  const size_t arg_N1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2023  const size_t arg_N2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2024  const size_t arg_N3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2025  const size_t arg_N4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2026  const size_t arg_N5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2027  const size_t arg_N6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2028  const size_t arg_N7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG)
2029  : View(arg_prop,
2030  typename traits::array_layout(arg_N0, arg_N1, arg_N2, arg_N3,
2031  arg_N4, arg_N5, arg_N6, arg_N7)) {
2032 #ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
2033  Impl::runtime_check_rank_host(
2034  traits::rank_dynamic,
2035  std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
2036  arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7, label());
2037 #else
2038  Impl::runtime_check_rank_device(
2039  traits::rank_dynamic,
2040  std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
2041  arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7);
2042 
2043 #endif
2044  }
2045 
2046  template <class... P>
2047  explicit KOKKOS_INLINE_FUNCTION View(
2048  const Impl::ViewCtorProp<P...>& arg_prop,
2049  typename std::enable_if<Impl::ViewCtorProp<P...>::has_pointer,
2050  size_t>::type const arg_N0 =
2051  KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2052  const size_t arg_N1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2053  const size_t arg_N2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2054  const size_t arg_N3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2055  const size_t arg_N4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2056  const size_t arg_N5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2057  const size_t arg_N6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2058  const size_t arg_N7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG)
2059  : View(arg_prop,
2060  typename traits::array_layout(arg_N0, arg_N1, arg_N2, arg_N3,
2061  arg_N4, arg_N5, arg_N6, arg_N7)) {
2062 #ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
2063  Impl::runtime_check_rank_host(
2064  traits::rank_dynamic,
2065  std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
2066  arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7, label());
2067 #else
2068  Impl::runtime_check_rank_device(
2069  traits::rank_dynamic,
2070  std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
2071  arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7);
2072 
2073 #endif
2074  }
2075 
2076  // Allocate with label and layout
2077  template <typename Label>
2078  explicit inline View(
2079  const Label& arg_label,
2080  typename std::enable_if<Kokkos::Impl::is_view_label<Label>::value,
2081  typename traits::array_layout>::type const&
2082  arg_layout)
2083  : View(Impl::ViewCtorProp<std::string>(arg_label), arg_layout) {}
2084 
2085  // Allocate label and layout, must disambiguate from subview constructor.
2086  template <typename Label>
2087  explicit inline View(
2088  const Label& arg_label,
2089  typename std::enable_if<Kokkos::Impl::is_view_label<Label>::value,
2090  const size_t>::type arg_N0 =
2091  KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2092  const size_t arg_N1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2093  const size_t arg_N2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2094  const size_t arg_N3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2095  const size_t arg_N4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2096  const size_t arg_N5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2097  const size_t arg_N6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2098  const size_t arg_N7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG)
2099  : View(Impl::ViewCtorProp<std::string>(arg_label),
2100  typename traits::array_layout(arg_N0, arg_N1, arg_N2, arg_N3,
2101  arg_N4, arg_N5, arg_N6, arg_N7)) {
2102  static_assert(traits::array_layout::is_extent_constructible,
2103  "Layout is not extent constructible. A layout object should "
2104  "be passed too.\n");
2105 
2106 #ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
2107  Impl::runtime_check_rank_host(
2108  traits::rank_dynamic,
2109  std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
2110  arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7, label());
2111 #else
2112  Impl::runtime_check_rank_device(
2113  traits::rank_dynamic,
2114  std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
2115  arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7);
2116 
2117 #endif
2118  }
2119 
2120  // For backward compatibility
2121  explicit inline View(const ViewAllocateWithoutInitializing& arg_prop,
2122  const typename traits::array_layout& arg_layout)
2123  : View(Impl::ViewCtorProp<std::string,
2124  Kokkos::Impl::WithoutInitializing_t>(
2125  arg_prop.label, Kokkos::WithoutInitializing),
2126  arg_layout) {}
2127 
2128  explicit inline View(const ViewAllocateWithoutInitializing& arg_prop,
2129  const size_t arg_N0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2130  const size_t arg_N1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2131  const size_t arg_N2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2132  const size_t arg_N3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2133  const size_t arg_N4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2134  const size_t arg_N5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2135  const size_t arg_N6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2136  const size_t arg_N7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG)
2137  : View(Impl::ViewCtorProp<std::string,
2138  Kokkos::Impl::WithoutInitializing_t>(
2139  arg_prop.label, Kokkos::WithoutInitializing),
2140  typename traits::array_layout(arg_N0, arg_N1, arg_N2, arg_N3,
2141  arg_N4, arg_N5, arg_N6, arg_N7)) {
2142 #ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
2143  Impl::runtime_check_rank_host(
2144  traits::rank_dynamic,
2145  std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
2146  arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7, label());
2147 #else
2148  Impl::runtime_check_rank_device(
2149  traits::rank_dynamic,
2150  std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
2151  arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7);
2152 
2153 #endif
2154  }
2155  template <class Traits>
2156  KOKKOS_INLINE_FUNCTION View(
2157  const track_type& track,
2158  const Kokkos::Impl::ViewMapping<Traits, typename Traits::specialize>& map)
2159  : m_track(track), m_map() {
2160  typedef Kokkos::Impl::ViewMapping<traits, Traits,
2161  typename traits::specialize>
2162  Mapping;
2163  static_assert(Mapping::is_assignable,
2164  "Incompatible View copy construction");
2165  Mapping::assign(m_map, map, track);
2166  }
2167 
2168  //----------------------------------------
2169  // Memory span required to wrap these dimensions.
2170  static constexpr size_t required_allocation_size(
2171  const size_t arg_N0 = 0, const size_t arg_N1 = 0, const size_t arg_N2 = 0,
2172  const size_t arg_N3 = 0, const size_t arg_N4 = 0, const size_t arg_N5 = 0,
2173  const size_t arg_N6 = 0, const size_t arg_N7 = 0) {
2174  return map_type::memory_span(typename traits::array_layout(
2175  arg_N0, arg_N1, arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7));
2176  }
2177 
2178  explicit KOKKOS_INLINE_FUNCTION View(
2179  pointer_type arg_ptr, const size_t arg_N0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2180  const size_t arg_N1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2181  const size_t arg_N2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2182  const size_t arg_N3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2183  const size_t arg_N4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2184  const size_t arg_N5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2185  const size_t arg_N6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2186  const size_t arg_N7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG)
2187  : View(Impl::ViewCtorProp<pointer_type>(arg_ptr),
2188  typename traits::array_layout(arg_N0, arg_N1, arg_N2, arg_N3,
2189  arg_N4, arg_N5, arg_N6, arg_N7)) {
2190 #ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
2191  Impl::runtime_check_rank_host(
2192  traits::rank_dynamic,
2193  std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
2194  arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7, label());
2195 #else
2196  Impl::runtime_check_rank_device(
2197  traits::rank_dynamic,
2198  std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
2199  arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7);
2200 
2201 #endif
2202  }
2203 
2204  explicit KOKKOS_INLINE_FUNCTION View(
2205  pointer_type arg_ptr, const typename traits::array_layout& arg_layout)
2206  : View(Impl::ViewCtorProp<pointer_type>(arg_ptr), arg_layout) {}
2207 
2208  //----------------------------------------
2209  // Shared scratch memory constructor
2210 
2211  static inline size_t shmem_size(const size_t arg_N0 = KOKKOS_INVALID_INDEX,
2212  const size_t arg_N1 = KOKKOS_INVALID_INDEX,
2213  const size_t arg_N2 = KOKKOS_INVALID_INDEX,
2214  const size_t arg_N3 = KOKKOS_INVALID_INDEX,
2215  const size_t arg_N4 = KOKKOS_INVALID_INDEX,
2216  const size_t arg_N5 = KOKKOS_INVALID_INDEX,
2217  const size_t arg_N6 = KOKKOS_INVALID_INDEX,
2218  const size_t arg_N7 = KOKKOS_INVALID_INDEX) {
2219  if (is_layout_stride) {
2220  Kokkos::abort(
2221  "Kokkos::View::shmem_size(extents...) doesn't work with "
2222  "LayoutStride. Pass a LayoutStride object instead");
2223  }
2224  const size_t num_passed_args = Impl::count_valid_integers(
2225  arg_N0, arg_N1, arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7);
2226 
2227  if (std::is_same<typename traits::specialize, void>::value &&
2228  num_passed_args != traits::rank_dynamic) {
2229  Kokkos::abort(
2230  "Kokkos::View::shmem_size() rank_dynamic != number of arguments.\n");
2231  }
2232 
2233  return View::shmem_size(typename traits::array_layout(
2234  arg_N0, arg_N1, arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7));
2235  }
2236 
2237  static inline size_t shmem_size(
2238  typename traits::array_layout const& arg_layout) {
2239  return map_type::memory_span(arg_layout) +
2240  sizeof(typename traits::value_type);
2241  }
2242 
2243  explicit KOKKOS_INLINE_FUNCTION View(
2244  const typename traits::execution_space::scratch_memory_space& arg_space,
2245  const typename traits::array_layout& arg_layout)
2246  : View(Impl::ViewCtorProp<pointer_type>(
2247  reinterpret_cast<pointer_type>(arg_space.get_shmem_aligned(
2248  map_type::memory_span(arg_layout),
2249  sizeof(typename traits::value_type)))),
2250  arg_layout) {}
2251 
2252  explicit KOKKOS_INLINE_FUNCTION View(
2253  const typename traits::execution_space::scratch_memory_space& arg_space,
2254  const size_t arg_N0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2255  const size_t arg_N1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2256  const size_t arg_N2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2257  const size_t arg_N3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2258  const size_t arg_N4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2259  const size_t arg_N5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2260  const size_t arg_N6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2261  const size_t arg_N7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG)
2262  : View(Impl::ViewCtorProp<pointer_type>(
2263  reinterpret_cast<pointer_type>(arg_space.get_shmem_aligned(
2264  map_type::memory_span(typename traits::array_layout(
2265  arg_N0, arg_N1, arg_N2, arg_N3, arg_N4, arg_N5, arg_N6,
2266  arg_N7)),
2267  sizeof(typename traits::value_type)))),
2268  typename traits::array_layout(arg_N0, arg_N1, arg_N2, arg_N3,
2269  arg_N4, arg_N5, arg_N6, arg_N7)) {
2270 #ifdef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
2271  Impl::runtime_check_rank_host(
2272  traits::rank_dynamic,
2273  std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
2274  arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7, label());
2275 #else
2276  Impl::runtime_check_rank_device(
2277  traits::rank_dynamic,
2278  std::is_same<typename traits::specialize, void>::value, arg_N0, arg_N1,
2279  arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7);
2280 
2281 #endif
2282  }
2283 };
2284 
2289 template <typename D, class... P>
2290 KOKKOS_INLINE_FUNCTION constexpr unsigned rank(const View<D, P...>& V) {
2291  return V.Rank;
2292 } // Temporary until added to view
2293 
2294 //----------------------------------------------------------------------------
2295 //----------------------------------------------------------------------------
2296 
2297 template <class V, class... Args>
2298 using Subview =
2299  typename Kokkos::Impl::ViewMapping<void /* deduce subview type from source
2300  view traits */
2301  ,
2302  typename V::traits, Args...>::type;
2303 
2304 template <class D, class... P, class... Args>
2305 KOKKOS_INLINE_FUNCTION
2306  typename Kokkos::Impl::ViewMapping<void /* deduce subview type from source
2307  view traits */
2308  ,
2309  ViewTraits<D, P...>, Args...>::type
2310  subview(const View<D, P...>& src, Args... args) {
2311  static_assert(View<D, P...>::Rank == sizeof...(Args),
2312  "subview requires one argument for each source View rank");
2313 
2314  return typename Kokkos::Impl::ViewMapping<
2315  void /* deduce subview type from source view traits */
2316  ,
2317  ViewTraits<D, P...>, Args...>::type(src, args...);
2318 }
2319 
2320 template <class MemoryTraits, class D, class... P, class... Args>
2321 KOKKOS_INLINE_FUNCTION typename Kokkos::Impl::ViewMapping<
2322  void /* deduce subview type from source view traits */
2323  ,
2324  ViewTraits<D, P...>, Args...>::template apply<MemoryTraits>::type
2325 subview(const View<D, P...>& src, Args... args) {
2326  static_assert(View<D, P...>::Rank == sizeof...(Args),
2327  "subview requires one argument for each source View rank");
2328 
2329  return typename Kokkos::Impl::ViewMapping<
2330  void /* deduce subview type from source view traits */
2331  ,
2332  ViewTraits<D, P...>,
2333  Args...>::template apply<MemoryTraits>::type(src, args...);
2334 }
2335 
2336 } /* namespace Kokkos */
2337 
2338 //----------------------------------------------------------------------------
2339 //----------------------------------------------------------------------------
2340 
2341 namespace Kokkos {
2342 
2343 template <class LT, class... LP, class RT, class... RP>
2344 KOKKOS_INLINE_FUNCTION bool operator==(const View<LT, LP...>& lhs,
2345  const View<RT, RP...>& rhs) {
2346  // Same data, layout, dimensions
2347  typedef ViewTraits<LT, LP...> lhs_traits;
2348  typedef ViewTraits<RT, RP...> rhs_traits;
2349 
2350  return std::is_same<typename lhs_traits::const_value_type,
2351  typename rhs_traits::const_value_type>::value &&
2352  std::is_same<typename lhs_traits::array_layout,
2353  typename rhs_traits::array_layout>::value &&
2354  std::is_same<typename lhs_traits::memory_space,
2355  typename rhs_traits::memory_space>::value &&
2356  unsigned(lhs_traits::rank) == unsigned(rhs_traits::rank) &&
2357  lhs.data() == rhs.data() && lhs.span() == rhs.span() &&
2358  lhs.extent(0) == rhs.extent(0) && lhs.extent(1) == rhs.extent(1) &&
2359  lhs.extent(2) == rhs.extent(2) && lhs.extent(3) == rhs.extent(3) &&
2360  lhs.extent(4) == rhs.extent(4) && lhs.extent(5) == rhs.extent(5) &&
2361  lhs.extent(6) == rhs.extent(6) && lhs.extent(7) == rhs.extent(7);
2362 }
2363 
2364 template <class LT, class... LP, class RT, class... RP>
2365 KOKKOS_INLINE_FUNCTION bool operator!=(const View<LT, LP...>& lhs,
2366  const View<RT, RP...>& rhs) {
2367  return !(operator==(lhs, rhs));
2368 }
2369 
2370 } /* namespace Kokkos */
2371 
2372 //----------------------------------------------------------------------------
2373 //----------------------------------------------------------------------------
2374 
2375 namespace Kokkos {
2376 namespace Impl {
2377 
2378 inline void shared_allocation_tracking_disable() {
2379  Kokkos::Impl::SharedAllocationRecord<void, void>::tracking_disable();
2380 }
2381 
2382 inline void shared_allocation_tracking_enable() {
2383  Kokkos::Impl::SharedAllocationRecord<void, void>::tracking_enable();
2384 }
2385 
2386 } /* namespace Impl */
2387 } /* namespace Kokkos */
2388 
2389 //----------------------------------------------------------------------------
2390 //----------------------------------------------------------------------------
2391 
2392 namespace Kokkos {
2393 namespace Impl {
2394 
2395 template <class Specialize, typename A, typename B>
2396 struct CommonViewValueType;
2397 
2398 template <typename A, typename B>
2399 struct CommonViewValueType<void, A, B> {
2400  using value_type = typename std::common_type<A, B>::type;
2401 };
2402 
2403 template <class Specialize, class ValueType>
2404 struct CommonViewAllocProp;
2405 
2406 template <class ValueType>
2407 struct CommonViewAllocProp<void, ValueType> {
2408  using value_type = ValueType;
2409  using scalar_array_type = ValueType;
2410 
2411  template <class... Views>
2412  KOKKOS_INLINE_FUNCTION CommonViewAllocProp(const Views&...) {}
2413 };
2414 
2415 template <class... Views>
2416 struct DeduceCommonViewAllocProp;
2417 
2418 // Base case must provide types for:
2419 // 1. specialize 2. value_type 3. is_view 4. prop_type
2420 template <class FirstView>
2421 struct DeduceCommonViewAllocProp<FirstView> {
2422  using specialize = typename FirstView::traits::specialize;
2423 
2424  using value_type = typename FirstView::traits::value_type;
2425 
2426  enum : bool { is_view = is_view<FirstView>::value };
2427 
2428  using prop_type = CommonViewAllocProp<specialize, value_type>;
2429 };
2430 
2431 template <class FirstView, class... NextViews>
2432 struct DeduceCommonViewAllocProp<FirstView, NextViews...> {
2433  using NextTraits = DeduceCommonViewAllocProp<NextViews...>;
2434 
2435  using first_specialize = typename FirstView::traits::specialize;
2436  using first_value_type = typename FirstView::traits::value_type;
2437 
2438  enum : bool { first_is_view = is_view<FirstView>::value };
2439 
2440  using next_specialize = typename NextTraits::specialize;
2441  using next_value_type = typename NextTraits::value_type;
2442 
2443  enum : bool { next_is_view = NextTraits::is_view };
2444 
2445  // common types
2446 
2447  // determine specialize type
2448  // if first and next specialize differ, but are not the same specialize, error
2449  // out
2450  static_assert(!(!std::is_same<first_specialize, next_specialize>::value &&
2451  !std::is_same<first_specialize, void>::value &&
2452  !std::is_same<void, next_specialize>::value),
2453  "Kokkos DeduceCommonViewAllocProp ERROR: Only one non-void "
2454  "specialize trait allowed");
2455 
2456  // otherwise choose non-void specialize if either/both are non-void
2457  using specialize = typename std::conditional<
2458  std::is_same<first_specialize, next_specialize>::value, first_specialize,
2459  typename std::conditional<(std::is_same<first_specialize, void>::value &&
2460  !std::is_same<next_specialize, void>::value),
2461  next_specialize, first_specialize>::type>::type;
2462 
2463  using value_type = typename CommonViewValueType<specialize, first_value_type,
2464  next_value_type>::value_type;
2465 
2466  enum : bool { is_view = (first_is_view && next_is_view) };
2467 
2468  using prop_type = CommonViewAllocProp<specialize, value_type>;
2469 };
2470 
2471 } // end namespace Impl
2472 
2473 template <class... Views>
2474 using DeducedCommonPropsType =
2475  typename Impl::DeduceCommonViewAllocProp<Views...>::prop_type;
2476 
2477 // User function
2478 template <class... Views>
2479 KOKKOS_INLINE_FUNCTION DeducedCommonPropsType<Views...> common_view_alloc_prop(
2480  Views const&... views) {
2481  return DeducedCommonPropsType<Views...>(views...);
2482 }
2483 
2484 } // namespace Kokkos
2485 
2486 namespace Kokkos {
2487 namespace Impl {
2488 
2489 using Kokkos::is_view;
2490 
2491 } /* namespace Impl */
2492 } /* namespace Kokkos */
2493 
2494 #include <impl/Kokkos_ViewUniformType.hpp>
2495 #include <impl/Kokkos_Atomic_View.hpp>
2496 
2497 //----------------------------------------------------------------------------
2498 //----------------------------------------------------------------------------
2499 
2500 #endif /* #ifndef KOKKOS_VIEW_HPP */
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
KOKKOS_INLINE_FUNCTION bool operator==(complex< RealType1 > const &x, complex< RealType2 > const &y) noexcept
Binary == operator for complex complex.
View< typename traits::non_const_data_type, typename traits::array_layout, Device< DefaultHostExecutionSpace, typename traits::host_mirror_space::memory_space > > HostMirror
Compatible HostMirror view.
View< typename traits::const_data_type, typename traits::array_layout, typename traits::device_type, typename traits::memory_traits > const_type
Compatible view of const data type.
View to an array of data.
Impl::ViewCtorProp< typename Impl::ViewCtorProp< void, Args >::type...> view_alloc(Args const &...args)
Create View allocation parameter bundle from argument list.
Impl::ViewUniformType< View, 0 >::type uniform_type
Unified types.
View< typename traits::non_const_data_type, typename traits::array_layout, typename traits::host_mirror_space > host_mirror_type
Compatible HostMirror view.
View< typename traits::scalar_array_type, typename traits::array_layout, typename traits::device_type, typename traits::memory_traits > array_type
Compatible view of array of scalar types.
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.
View< typename traits::non_const_data_type, typename traits::array_layout, typename traits::device_type, typename traits::memory_traits > non_const_type
Compatible view of non-const data type.
Traits class for accessing attributes of a View.
Access relationship between DstMemorySpace and SrcMemorySpace.