Kokkos Core Kernels Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Kokkos_DynRankView.hpp
Go to the documentation of this file.
1 //@HEADER
2 // ************************************************************************
3 //
4 // Kokkos v. 4.0
5 // Copyright (2022) National Technology & Engineering
6 // Solutions of Sandia, LLC (NTESS).
7 //
8 // Under the terms of Contract DE-NA0003525 with NTESS,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
12 // See https://kokkos.org/LICENSE for license information.
13 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14 //
15 //@HEADER
16 
22 
23 #ifndef KOKKOS_DYNRANKVIEW_HPP
24 #define KOKKOS_DYNRANKVIEW_HPP
25 #ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
26 #define KOKKOS_IMPL_PUBLIC_INCLUDE
27 #define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_DYNRANKVIEW
28 #endif
29 
30 #include <Kokkos_Core.hpp>
31 #include <impl/Kokkos_Error.hpp>
32 #include <type_traits>
33 
34 namespace Kokkos {
35 
36 template <typename DataType, class... Properties>
37 class DynRankView; // forward declare
38 
39 namespace Impl {
40 
41 template <typename Specialize>
42 struct DynRankDimTraits {
43  enum : size_t { unspecified = KOKKOS_INVALID_INDEX };
44 
45  // Compute the rank of the view from the nonzero dimension arguments.
46  KOKKOS_INLINE_FUNCTION
47  static size_t computeRank(const size_t N0, const size_t N1, const size_t N2,
48  const size_t N3, const size_t N4, const size_t N5,
49  const size_t N6, const size_t /* N7 */) {
50  return (
51  (N6 == unspecified && N5 == unspecified && N4 == unspecified &&
52  N3 == unspecified && N2 == unspecified && N1 == unspecified &&
53  N0 == unspecified)
54  ? 0
55  : ((N6 == unspecified && N5 == unspecified && N4 == unspecified &&
56  N3 == unspecified && N2 == unspecified && N1 == unspecified)
57  ? 1
58  : ((N6 == unspecified && N5 == unspecified &&
59  N4 == unspecified && N3 == unspecified &&
60  N2 == unspecified)
61  ? 2
62  : ((N6 == unspecified && N5 == unspecified &&
63  N4 == unspecified && N3 == unspecified)
64  ? 3
65  : ((N6 == unspecified && N5 == unspecified &&
66  N4 == unspecified)
67  ? 4
68  : ((N6 == unspecified &&
69  N5 == unspecified)
70  ? 5
71  : ((N6 == unspecified)
72  ? 6
73  : 7)))))));
74  }
75 
76  // Compute the rank of the view from the nonzero layout arguments.
77  template <typename Layout>
78  KOKKOS_INLINE_FUNCTION static size_t computeRank(const Layout& layout) {
79  return computeRank(layout.dimension[0], layout.dimension[1],
80  layout.dimension[2], layout.dimension[3],
81  layout.dimension[4], layout.dimension[5],
82  layout.dimension[6], layout.dimension[7]);
83  }
84 
85  // Extra overload to match that for specialize types v2
86  template <typename Layout, typename... P>
87  KOKKOS_INLINE_FUNCTION static size_t computeRank(
88  const Kokkos::Impl::ViewCtorProp<P...>& /* prop */,
89  const Layout& layout) {
90  return computeRank(layout);
91  }
92 
93  // Create the layout for the rank-7 view.
94  // Non-strided Layout
95  template <typename Layout>
96  KOKKOS_INLINE_FUNCTION static std::enable_if_t<
97  (std::is_same<Layout, Kokkos::LayoutRight>::value ||
98  std::is_same<Layout, Kokkos::LayoutLeft>::value),
99  Layout>
100  createLayout(const Layout& layout) {
101  return Layout(layout.dimension[0] != unspecified ? layout.dimension[0] : 1,
102  layout.dimension[1] != unspecified ? layout.dimension[1] : 1,
103  layout.dimension[2] != unspecified ? layout.dimension[2] : 1,
104  layout.dimension[3] != unspecified ? layout.dimension[3] : 1,
105  layout.dimension[4] != unspecified ? layout.dimension[4] : 1,
106  layout.dimension[5] != unspecified ? layout.dimension[5] : 1,
107  layout.dimension[6] != unspecified ? layout.dimension[6] : 1,
108  layout.dimension[7] != unspecified ? layout.dimension[7] : 1);
109  }
110 
111  // LayoutStride
112  template <typename Layout>
113  KOKKOS_INLINE_FUNCTION static std::enable_if_t<
114  (std::is_same<Layout, Kokkos::LayoutStride>::value), Layout>
115  createLayout(const Layout& layout) {
116  return Layout(layout.dimension[0] != unspecified ? layout.dimension[0] : 1,
117  layout.stride[0],
118  layout.dimension[1] != unspecified ? layout.dimension[1] : 1,
119  layout.stride[1],
120  layout.dimension[2] != unspecified ? layout.dimension[2] : 1,
121  layout.stride[2],
122  layout.dimension[3] != unspecified ? layout.dimension[3] : 1,
123  layout.stride[3],
124  layout.dimension[4] != unspecified ? layout.dimension[4] : 1,
125  layout.stride[4],
126  layout.dimension[5] != unspecified ? layout.dimension[5] : 1,
127  layout.stride[5],
128  layout.dimension[6] != unspecified ? layout.dimension[6] : 1,
129  layout.stride[6],
130  layout.dimension[7] != unspecified ? layout.dimension[7] : 1,
131  layout.stride[7]);
132  }
133 
134  // Extra overload to match that for specialize types
135  template <typename Traits, typename... P>
136  KOKKOS_INLINE_FUNCTION static std::enable_if_t<
137  (std::is_same<typename Traits::array_layout,
138  Kokkos::LayoutRight>::value ||
139  std::is_same<typename Traits::array_layout, Kokkos::LayoutLeft>::value ||
140  std::is_same<typename Traits::array_layout,
141  Kokkos::LayoutStride>::value),
142  typename Traits::array_layout>
143  createLayout(const Kokkos::Impl::ViewCtorProp<P...>& /* prop */,
144  const typename Traits::array_layout& layout) {
145  return createLayout(layout);
146  }
147 
148  // Create a view from the given dimension arguments.
149  // This is only necessary because the shmem constructor doesn't take a layout.
150  // NDE shmem View's are not compatible with the added view_alloc value_type
151  // / fad_dim deduction functionality
152  template <typename ViewType, typename ViewArg>
153  static ViewType createView(const ViewArg& arg, const size_t N0,
154  const size_t N1, const size_t N2, const size_t N3,
155  const size_t N4, const size_t N5, const size_t N6,
156  const size_t N7) {
157  return ViewType(arg, N0 != unspecified ? N0 : 1, N1 != unspecified ? N1 : 1,
158  N2 != unspecified ? N2 : 1, N3 != unspecified ? N3 : 1,
159  N4 != unspecified ? N4 : 1, N5 != unspecified ? N5 : 1,
160  N6 != unspecified ? N6 : 1, N7 != unspecified ? N7 : 1);
161  }
162 };
163 
164 // Non-strided Layout
165 template <typename Layout, typename iType>
166 KOKKOS_INLINE_FUNCTION static std::enable_if_t<
167  (std::is_same<Layout, Kokkos::LayoutRight>::value ||
168  std::is_same<Layout, Kokkos::LayoutLeft>::value) &&
169  std::is_integral<iType>::value,
170  Layout>
171 reconstructLayout(const Layout& layout, iType dynrank) {
172  return Layout(dynrank > 0 ? layout.dimension[0] : KOKKOS_INVALID_INDEX,
173  dynrank > 1 ? layout.dimension[1] : KOKKOS_INVALID_INDEX,
174  dynrank > 2 ? layout.dimension[2] : KOKKOS_INVALID_INDEX,
175  dynrank > 3 ? layout.dimension[3] : KOKKOS_INVALID_INDEX,
176  dynrank > 4 ? layout.dimension[4] : KOKKOS_INVALID_INDEX,
177  dynrank > 5 ? layout.dimension[5] : KOKKOS_INVALID_INDEX,
178  dynrank > 6 ? layout.dimension[6] : KOKKOS_INVALID_INDEX,
179  dynrank > 7 ? layout.dimension[7] : KOKKOS_INVALID_INDEX);
180 }
181 
182 // LayoutStride
183 template <typename Layout, typename iType>
184 KOKKOS_INLINE_FUNCTION static std::enable_if_t<
185  (std::is_same<Layout, Kokkos::LayoutStride>::value) &&
186  std::is_integral<iType>::value,
187  Layout>
188 reconstructLayout(const Layout& layout, iType dynrank) {
189  return Layout(dynrank > 0 ? layout.dimension[0] : KOKKOS_INVALID_INDEX,
190  dynrank > 0 ? layout.stride[0] : (0),
191  dynrank > 1 ? layout.dimension[1] : KOKKOS_INVALID_INDEX,
192  dynrank > 1 ? layout.stride[1] : (0),
193  dynrank > 2 ? layout.dimension[2] : KOKKOS_INVALID_INDEX,
194  dynrank > 2 ? layout.stride[2] : (0),
195  dynrank > 3 ? layout.dimension[3] : KOKKOS_INVALID_INDEX,
196  dynrank > 3 ? layout.stride[3] : (0),
197  dynrank > 4 ? layout.dimension[4] : KOKKOS_INVALID_INDEX,
198  dynrank > 4 ? layout.stride[4] : (0),
199  dynrank > 5 ? layout.dimension[5] : KOKKOS_INVALID_INDEX,
200  dynrank > 5 ? layout.stride[5] : (0),
201  dynrank > 6 ? layout.dimension[6] : KOKKOS_INVALID_INDEX,
202  dynrank > 6 ? layout.stride[6] : (0),
203  dynrank > 7 ? layout.dimension[7] : KOKKOS_INVALID_INDEX,
204  dynrank > 7 ? layout.stride[7] : (0));
205 }
206 
208 // Enhanced debug checking - most infrastructure matches that of functions in
209 // Kokkos_ViewMapping; additional checks for extra arguments beyond rank are 0
210 template <unsigned, typename iType0, class MapType>
211 KOKKOS_INLINE_FUNCTION bool dyn_rank_view_verify_operator_bounds(
212  const iType0&, const MapType&) {
213  return true;
214 }
215 
216 template <unsigned R, typename iType0, class MapType, typename iType1,
217  class... Args>
218 KOKKOS_INLINE_FUNCTION bool dyn_rank_view_verify_operator_bounds(
219  const iType0& rank, const MapType& map, const iType1& i, Args... args) {
220  if (static_cast<iType0>(R) < rank) {
221  return (size_t(i) < map.extent(R)) &&
222  dyn_rank_view_verify_operator_bounds<R + 1>(rank, map, args...);
223  } else if (i != 0) {
224  Kokkos::printf(
225  "DynRankView Debug Bounds Checking Error: at rank %u\n Extra "
226  "arguments beyond the rank must be zero \n",
227  R);
228  return (false) &&
229  dyn_rank_view_verify_operator_bounds<R + 1>(rank, map, args...);
230  } else {
231  return (true) &&
232  dyn_rank_view_verify_operator_bounds<R + 1>(rank, map, args...);
233  }
234 }
235 
236 template <unsigned, class MapType>
237 inline void dyn_rank_view_error_operator_bounds(char*, int, const MapType&) {}
238 
239 template <unsigned R, class MapType, class iType, class... Args>
240 inline void dyn_rank_view_error_operator_bounds(char* buf, int len,
241  const MapType& map,
242  const iType& i, Args... args) {
243  const int n = snprintf(
244  buf, len, " %ld < %ld %c", static_cast<unsigned long>(i),
245  static_cast<unsigned long>(map.extent(R)), (sizeof...(Args) ? ',' : ')'));
246  dyn_rank_view_error_operator_bounds<R + 1>(buf + n, len - n, map, args...);
247 }
248 
249 // op_rank = rank of the operator version that was called
250 template <typename MemorySpace, typename iType0, typename iType1, class MapType,
251  class... Args>
252 KOKKOS_INLINE_FUNCTION void dyn_rank_view_verify_operator_bounds(
253  const iType0& op_rank, const iType1& rank,
254  const Kokkos::Impl::SharedAllocationTracker& tracker, const MapType& map,
255  Args... args) {
256  if (static_cast<iType0>(rank) > op_rank) {
257  Kokkos::abort(
258  "DynRankView Bounds Checking Error: Need at least rank arguments to "
259  "the operator()");
260  }
261 
262  if (!dyn_rank_view_verify_operator_bounds<0>(rank, map, args...)) {
263  KOKKOS_IF_ON_HOST(
264  (enum {LEN = 1024}; char buffer[LEN];
265  const std::string label = tracker.template get_label<MemorySpace>();
266  int n = snprintf(buffer, LEN, "DynRankView bounds error of view %s (",
267  label.c_str());
268  dyn_rank_view_error_operator_bounds<0>(buffer + n, LEN - n, map,
269  args...);
270  Kokkos::Impl::throw_runtime_exception(std::string(buffer));))
271 
272  KOKKOS_IF_ON_DEVICE(
273  ((void)tracker; Kokkos::abort("DynRankView bounds error");))
274  }
275 }
276 
279 
280 } // namespace Impl
281 
282 namespace Impl {
283 
284 template <class DstTraits, class SrcTraits>
285 class ViewMapping<
286  DstTraits, SrcTraits,
287  std::enable_if_t<(std::is_same<typename DstTraits::memory_space,
288  typename SrcTraits::memory_space>::value &&
289  std::is_void<typename DstTraits::specialize>::value &&
290  std::is_void<typename SrcTraits::specialize>::value &&
291  (std::is_same<typename DstTraits::array_layout,
292  typename SrcTraits::array_layout>::value ||
293  ((std::is_same<typename DstTraits::array_layout,
294  Kokkos::LayoutLeft>::value ||
295  std::is_same<typename DstTraits::array_layout,
296  Kokkos::LayoutRight>::value ||
297  std::is_same<typename DstTraits::array_layout,
298  Kokkos::LayoutStride>::value) &&
299  (std::is_same<typename SrcTraits::array_layout,
300  Kokkos::LayoutLeft>::value ||
301  std::is_same<typename SrcTraits::array_layout,
302  Kokkos::LayoutRight>::value ||
303  std::is_same<typename SrcTraits::array_layout,
304  Kokkos::LayoutStride>::value)))),
305  Kokkos::Impl::ViewToDynRankViewTag>> {
306  private:
307  enum {
308  is_assignable_value_type =
309  std::is_same<typename DstTraits::value_type,
310  typename SrcTraits::value_type>::value ||
311  std::is_same<typename DstTraits::value_type,
312  typename SrcTraits::const_value_type>::value
313  };
314 
315  enum {
316  is_assignable_layout =
317  std::is_same<typename DstTraits::array_layout,
318  typename SrcTraits::array_layout>::value ||
319  std::is_same<typename DstTraits::array_layout,
320  Kokkos::LayoutStride>::value
321  };
322 
323  public:
324  enum { is_assignable = is_assignable_value_type && is_assignable_layout };
325 
326  using DstType = ViewMapping<DstTraits, typename DstTraits::specialize>;
327  using SrcType = ViewMapping<SrcTraits, typename SrcTraits::specialize>;
328 
329  template <typename DT, typename... DP, typename ST, typename... SP>
330  KOKKOS_INLINE_FUNCTION static void assign(
331  Kokkos::DynRankView<DT, DP...>& dst, const Kokkos::View<ST, SP...>& src) {
332  static_assert(
333  is_assignable_value_type,
334  "View assignment must have same value type or const = non-const");
335 
336  static_assert(
337  is_assignable_layout,
338  "View assignment must have compatible layout or have rank <= 1");
339 
340  // Removed dimension checks...
341 
342  using dst_offset_type = typename DstType::offset_type;
343  dst.m_map.m_impl_offset = dst_offset_type(
344  std::integral_constant<unsigned, 0>(),
345  src.layout()); // Check this for integer input1 for padding, etc
346  dst.m_map.m_impl_handle = Kokkos::Impl::ViewDataHandle<DstTraits>::assign(
347  src.m_map.m_impl_handle, src.m_track.m_tracker);
348  dst.m_track.assign(src.m_track.m_tracker, DstTraits::is_managed);
349  dst.m_rank = Kokkos::View<ST, SP...>::rank();
350  }
351 };
352 
353 } // namespace Impl
354 
355 /* \class DynRankView
356  * \brief Container that creates a Kokkos view with rank determined at runtime.
357  * Essentially this is a rank 7 view
358  *
359  * Changes from View
360  * 1. The rank of the DynRankView is returned by the method rank()
361  * 2. Max rank of a DynRankView is 7
362  * 3. subview called with 'subview(...)' or 'subdynrankview(...)' (backward
363  * compatibility)
364  * 4. Every subview is returned with LayoutStride
365  * 5. Copy and Copy-Assign View to DynRankView
366  * 6. deep_copy between Views and DynRankViews
367  * 7. rank( view ); returns the rank of View or DynRankView
368  *
369  */
370 
371 template <class>
372 struct is_dyn_rank_view : public std::false_type {};
373 
374 template <class D, class... P>
375 struct is_dyn_rank_view<Kokkos::DynRankView<D, P...>> : public std::true_type {
376 };
377 
378 template <class T>
379 inline constexpr bool is_dyn_rank_view_v = is_dyn_rank_view<T>::value;
380 
381 template <typename DataType, class... Properties>
382 class DynRankView : public ViewTraits<DataType, Properties...> {
383  static_assert(!std::is_array<DataType>::value &&
384  !std::is_pointer<DataType>::value,
385  "Cannot template DynRankView with array or pointer datatype - "
386  "must be pod");
387 
388  private:
389  template <class, class...>
390  friend class DynRankView;
391  template <class, class...>
392  friend class Kokkos::Impl::ViewMapping;
393 
394  public:
395  using drvtraits = ViewTraits<DataType, Properties...>;
396 
397  using view_type = View<DataType*******, Properties...>;
398 
399  using traits = ViewTraits<DataType*******, Properties...>;
400 
401  private:
402  using map_type =
403  Kokkos::Impl::ViewMapping<traits, typename traits::specialize>;
404  using track_type = Kokkos::Impl::SharedAllocationTracker;
405 
406  track_type m_track;
407  map_type m_map;
408  unsigned m_rank;
409 
410  public:
411  KOKKOS_INLINE_FUNCTION
412  view_type& DownCast() const { return (view_type&)(*this); }
413  KOKKOS_INLINE_FUNCTION
414  const view_type& ConstDownCast() const { return (const view_type&)(*this); }
415 
416  // Types below - at least the HostMirror requires the value_type, NOT the rank
417  // 7 data_type of the traits
418 
420  using array_type = DynRankView<
421  typename drvtraits::scalar_array_type, typename drvtraits::array_layout,
422  typename drvtraits::device_type, typename drvtraits::memory_traits>;
423 
425  using const_type = DynRankView<
426  typename drvtraits::const_data_type, typename drvtraits::array_layout,
427  typename drvtraits::device_type, typename drvtraits::memory_traits>;
428 
430  using non_const_type = DynRankView<
431  typename drvtraits::non_const_data_type, typename drvtraits::array_layout,
432  typename drvtraits::device_type, typename drvtraits::memory_traits>;
433 
435  using HostMirror = DynRankView<typename drvtraits::non_const_data_type,
436  typename drvtraits::array_layout,
437  typename drvtraits::host_mirror_space>;
438 
439  //----------------------------------------
440  // Domain rank and extents
441 
442  // enum { Rank = map_type::Rank }; //Will be dyn rank of 7 always, keep the
443  // enum?
444 
445  template <typename iType>
446  KOKKOS_INLINE_FUNCTION constexpr std::enable_if_t<
447  std::is_integral<iType>::value, size_t>
448  extent(const iType& r) const {
449  return m_map.extent(r);
450  }
451 
452  template <typename iType>
453  KOKKOS_INLINE_FUNCTION constexpr std::enable_if_t<
454  std::is_integral<iType>::value, int>
455  extent_int(const iType& r) const {
456  return static_cast<int>(m_map.extent(r));
457  }
458 
459  KOKKOS_INLINE_FUNCTION constexpr typename traits::array_layout layout() const;
460 
461  //----------------------------------------
462  /* Deprecate all 'dimension' functions in favor of
463  * ISO/C++ vocabulary 'extent'.
464  */
465 
466  KOKKOS_INLINE_FUNCTION constexpr size_t size() const {
467  return m_map.extent(0) * m_map.extent(1) * m_map.extent(2) *
468  m_map.extent(3) * m_map.extent(4) * m_map.extent(5) *
469  m_map.extent(6) * m_map.extent(7);
470  }
471 
472  KOKKOS_INLINE_FUNCTION constexpr size_t stride_0() const {
473  return m_map.stride_0();
474  }
475  KOKKOS_INLINE_FUNCTION constexpr size_t stride_1() const {
476  return m_map.stride_1();
477  }
478  KOKKOS_INLINE_FUNCTION constexpr size_t stride_2() const {
479  return m_map.stride_2();
480  }
481  KOKKOS_INLINE_FUNCTION constexpr size_t stride_3() const {
482  return m_map.stride_3();
483  }
484  KOKKOS_INLINE_FUNCTION constexpr size_t stride_4() const {
485  return m_map.stride_4();
486  }
487  KOKKOS_INLINE_FUNCTION constexpr size_t stride_5() const {
488  return m_map.stride_5();
489  }
490  KOKKOS_INLINE_FUNCTION constexpr size_t stride_6() const {
491  return m_map.stride_6();
492  }
493  KOKKOS_INLINE_FUNCTION constexpr size_t stride_7() const {
494  return m_map.stride_7();
495  }
496 
497  template <typename iType>
498  KOKKOS_INLINE_FUNCTION void stride(iType* const s) const {
499  m_map.stride(s);
500  }
501 
502  //----------------------------------------
503  // Range span is the span which contains all members.
504 
505  using reference_type = typename map_type::reference_type;
506  using pointer_type = typename map_type::pointer_type;
507 
508  enum {
509  reference_type_is_lvalue_reference =
510  std::is_lvalue_reference<reference_type>::value
511  };
512 
513  KOKKOS_INLINE_FUNCTION constexpr size_t span() const { return m_map.span(); }
514  KOKKOS_INLINE_FUNCTION constexpr bool span_is_contiguous() const {
515  return m_map.span_is_contiguous();
516  }
517  KOKKOS_INLINE_FUNCTION constexpr pointer_type data() const {
518  return m_map.data();
519  }
520  KOKKOS_INLINE_FUNCTION constexpr bool is_allocated() const {
521  return (m_map.data() != nullptr);
522  }
523 
524  //----------------------------------------
525  // Allow specializations to query their specialized map
526  KOKKOS_INLINE_FUNCTION
527  const Kokkos::Impl::ViewMapping<traits, typename traits::specialize>&
528  impl_map() const {
529  return m_map;
530  }
531 
532  //----------------------------------------
533 
534  private:
535  enum {
536  is_layout_left =
537  std::is_same<typename traits::array_layout, Kokkos::LayoutLeft>::value,
538 
539  is_layout_right =
540  std::is_same<typename traits::array_layout, Kokkos::LayoutRight>::value,
541 
542  is_layout_stride = std::is_same<typename traits::array_layout,
543  Kokkos::LayoutStride>::value,
544 
545  is_default_map = std::is_void<typename traits::specialize>::value &&
546  (is_layout_left || is_layout_right || is_layout_stride)
547  };
548 
549 // Bounds checking macros
550 #if defined(KOKKOS_ENABLE_DEBUG_BOUNDS_CHECK)
551 
552 // rank of the calling operator - included as first argument in ARG
553 #define KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(ARG) \
554  Kokkos::Impl::runtime_check_memory_access_violation< \
555  typename traits::memory_space>( \
556  "Kokkos::DynRankView ERROR: attempt to access inaccessible memory " \
557  "space"); \
558  Kokkos::Impl::dyn_rank_view_verify_operator_bounds< \
559  typename traits::memory_space> \
560  ARG;
561 
562 #else
563 
564 #define KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(ARG) \
565  Kokkos::Impl::runtime_check_memory_access_violation< \
566  typename traits::memory_space>( \
567  "Kokkos::DynRankView ERROR: attempt to access inaccessible memory " \
568  "space");
569 
570 #endif
571 
572  public:
573  KOKKOS_INLINE_FUNCTION
574  constexpr unsigned rank() const { return m_rank; }
575 
576  // operators ()
577  // Rank 0
578  KOKKOS_INLINE_FUNCTION
579  reference_type operator()() const {
580  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((0, this->rank(), m_track, m_map))
581  return impl_map().reference();
582  // return m_map.reference(0,0,0,0,0,0,0);
583  }
584 
585  // Rank 1
586  // This assumes a contiguous underlying memory (i.e. no padding, no
587  // striding...)
588  template <typename iType>
589  KOKKOS_INLINE_FUNCTION std::enable_if_t<
590  std::is_same<typename drvtraits::value_type,
591  typename drvtraits::scalar_array_type>::value &&
592  std::is_integral<iType>::value,
593  reference_type>
594  operator[](const iType& i0) const {
595  // Phalanx is violating this, since they use the operator to access ALL
596  // elements in the allocation KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (1 ,
597  // this->rank(), m_track, m_map) )
598  return data()[i0];
599  }
600 
601  // This assumes a contiguous underlying memory (i.e. no padding, no
602  // striding... AND a Trilinos/Sacado scalar type )
603  template <typename iType>
604  KOKKOS_INLINE_FUNCTION std::enable_if_t<
605  !std::is_same<typename drvtraits::value_type,
606  typename drvtraits::scalar_array_type>::value &&
607  std::is_integral<iType>::value,
608  reference_type>
609  operator[](const iType& i0) const {
610  // auto map = impl_map();
611  const size_t dim_scalar = m_map.dimension_scalar();
612  const size_t bytes = this->span() / dim_scalar;
613 
614  using tmp_view_type = Kokkos::View<
615  DataType*, typename traits::array_layout, typename traits::device_type,
616  Kokkos::MemoryTraits<traits::memory_traits::is_unmanaged |
617  traits::memory_traits::is_random_access |
618  traits::memory_traits::is_atomic>>;
619  tmp_view_type rankone_view(this->data(), bytes, dim_scalar);
620  return rankone_view(i0);
621  }
622 
623  // Rank 1 parenthesis
624  template <typename iType>
625  KOKKOS_INLINE_FUNCTION
626  std::enable_if_t<(std::is_void<typename traits::specialize>::value &&
627  std::is_integral<iType>::value),
628  reference_type>
629  operator()(const iType& i0) const {
630  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((1, this->rank(), m_track, m_map, i0))
631  return m_map.reference(i0);
632  }
633 
634  template <typename iType>
635  KOKKOS_INLINE_FUNCTION
636  std::enable_if_t<!(std::is_void<typename traits::specialize>::value &&
637  std::is_integral<iType>::value),
638  reference_type>
639  operator()(const iType& i0) const {
640  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((1, this->rank(), m_track, m_map, i0))
641  return m_map.reference(i0, 0, 0, 0, 0, 0, 0);
642  }
643 
644  // Rank 2
645  template <typename iType0, typename iType1>
646  KOKKOS_INLINE_FUNCTION std::enable_if_t<
647  (std::is_void<typename traits::specialize>::value &&
648  std::is_integral<iType0>::value && std::is_integral<iType1>::value),
649  reference_type>
650  operator()(const iType0& i0, const iType1& i1) const {
651  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((2, this->rank(), m_track, m_map, i0, i1))
652  return m_map.reference(i0, i1);
653  }
654 
655  template <typename iType0, typename iType1>
656  KOKKOS_INLINE_FUNCTION
657  std::enable_if_t<!(std::is_void<typename drvtraits::specialize>::value &&
658  std::is_integral<iType0>::value),
659  reference_type>
660  operator()(const iType0& i0, const iType1& i1) const {
661  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((2, this->rank(), m_track, m_map, i0, i1))
662  return m_map.reference(i0, i1, 0, 0, 0, 0, 0);
663  }
664 
665  // Rank 3
666  template <typename iType0, typename iType1, typename iType2>
667  KOKKOS_INLINE_FUNCTION std::enable_if_t<
668  (std::is_void<typename traits::specialize>::value &&
669  std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
670  std::is_integral<iType2>::value),
671  reference_type>
672  operator()(const iType0& i0, const iType1& i1, const iType2& i2) const {
673  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
674  (3, this->rank(), m_track, m_map, i0, i1, i2))
675  return m_map.reference(i0, i1, i2);
676  }
677 
678  template <typename iType0, typename iType1, typename iType2>
679  KOKKOS_INLINE_FUNCTION
680  std::enable_if_t<!(std::is_void<typename drvtraits::specialize>::value &&
681  std::is_integral<iType0>::value),
682  reference_type>
683  operator()(const iType0& i0, const iType1& i1, const iType2& i2) const {
684  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
685  (3, this->rank(), m_track, m_map, i0, i1, i2))
686  return m_map.reference(i0, i1, i2, 0, 0, 0, 0);
687  }
688 
689  // Rank 4
690  template <typename iType0, typename iType1, typename iType2, typename iType3>
691  KOKKOS_INLINE_FUNCTION std::enable_if_t<
692  (std::is_void<typename traits::specialize>::value &&
693  std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
694  std::is_integral<iType2>::value && std::is_integral<iType3>::value),
695  reference_type>
696  operator()(const iType0& i0, const iType1& i1, const iType2& i2,
697  const iType3& i3) const {
698  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
699  (4, this->rank(), m_track, m_map, i0, i1, i2, i3))
700  return m_map.reference(i0, i1, i2, i3);
701  }
702 
703  template <typename iType0, typename iType1, typename iType2, typename iType3>
704  KOKKOS_INLINE_FUNCTION
705  std::enable_if_t<!(std::is_void<typename drvtraits::specialize>::value &&
706  std::is_integral<iType0>::value),
707  reference_type>
708  operator()(const iType0& i0, const iType1& i1, const iType2& i2,
709  const iType3& i3) const {
710  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
711  (4, this->rank(), m_track, m_map, i0, i1, i2, i3))
712  return m_map.reference(i0, i1, i2, i3, 0, 0, 0);
713  }
714 
715  // Rank 5
716  template <typename iType0, typename iType1, typename iType2, typename iType3,
717  typename iType4>
718  KOKKOS_INLINE_FUNCTION std::enable_if_t<
719  (std::is_void<typename traits::specialize>::value &&
720  std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
721  std::is_integral<iType2>::value && std::is_integral<iType3>::value &&
722  std::is_integral<iType4>::value),
723  reference_type>
724  operator()(const iType0& i0, const iType1& i1, const iType2& i2,
725  const iType3& i3, const iType4& i4) const {
726  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
727  (5, this->rank(), m_track, m_map, i0, i1, i2, i3, i4))
728  return m_map.reference(i0, i1, i2, i3, i4);
729  }
730 
731  template <typename iType0, typename iType1, typename iType2, typename iType3,
732  typename iType4>
733  KOKKOS_INLINE_FUNCTION
734  std::enable_if_t<!(std::is_void<typename drvtraits::specialize>::value &&
735  std::is_integral<iType0>::value),
736  reference_type>
737  operator()(const iType0& i0, const iType1& i1, const iType2& i2,
738  const iType3& i3, const iType4& i4) const {
739  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
740  (5, this->rank(), m_track, m_map, i0, i1, i2, i3, i4))
741  return m_map.reference(i0, i1, i2, i3, i4, 0, 0);
742  }
743 
744  // Rank 6
745  template <typename iType0, typename iType1, typename iType2, typename iType3,
746  typename iType4, typename iType5>
747  KOKKOS_INLINE_FUNCTION std::enable_if_t<
748  (std::is_void<typename traits::specialize>::value &&
749  std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
750  std::is_integral<iType2>::value && std::is_integral<iType3>::value &&
751  std::is_integral<iType4>::value && std::is_integral<iType5>::value),
752  reference_type>
753  operator()(const iType0& i0, const iType1& i1, const iType2& i2,
754  const iType3& i3, const iType4& i4, const iType5& i5) const {
755  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
756  (6, this->rank(), m_track, m_map, i0, i1, i2, i3, i4, i5))
757  return m_map.reference(i0, i1, i2, i3, i4, i5);
758  }
759 
760  template <typename iType0, typename iType1, typename iType2, typename iType3,
761  typename iType4, typename iType5>
762  KOKKOS_INLINE_FUNCTION
763  std::enable_if_t<!(std::is_void<typename drvtraits::specialize>::value &&
764  std::is_integral<iType0>::value),
765  reference_type>
766  operator()(const iType0& i0, const iType1& i1, const iType2& i2,
767  const iType3& i3, const iType4& i4, const iType5& i5) const {
768  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
769  (6, this->rank(), m_track, m_map, i0, i1, i2, i3, i4, i5))
770  return m_map.reference(i0, i1, i2, i3, i4, i5, 0);
771  }
772 
773  // Rank 7
774  template <typename iType0, typename iType1, typename iType2, typename iType3,
775  typename iType4, typename iType5, typename iType6>
776  KOKKOS_INLINE_FUNCTION std::enable_if_t<
777  (std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
778  std::is_integral<iType2>::value && std::is_integral<iType3>::value &&
779  std::is_integral<iType4>::value && std::is_integral<iType5>::value &&
780  std::is_integral<iType6>::value),
781  reference_type>
782  operator()(const iType0& i0, const iType1& i1, const iType2& i2,
783  const iType3& i3, const iType4& i4, const iType5& i5,
784  const iType6& i6) const {
785  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
786  (7, this->rank(), m_track, m_map, i0, i1, i2, i3, i4, i5, i6))
787  return m_map.reference(i0, i1, i2, i3, i4, i5, i6);
788  }
789 
790  // Rank 0
791  KOKKOS_INLINE_FUNCTION
792  reference_type access() const {
793  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((0, this->rank(), m_track, m_map))
794  return impl_map().reference();
795  // return m_map.reference(0,0,0,0,0,0,0);
796  }
797 
798  // Rank 1
799  // Rank 1 parenthesis
800  template <typename iType>
801  KOKKOS_INLINE_FUNCTION
802  std::enable_if_t<(std::is_void<typename traits::specialize>::value &&
803  std::is_integral<iType>::value),
804  reference_type>
805  access(const iType& i0) const {
806  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((1, this->rank(), m_track, m_map, i0))
807  return m_map.reference(i0);
808  }
809 
810  template <typename iType>
811  KOKKOS_INLINE_FUNCTION
812  std::enable_if_t<!(std::is_void<typename traits::specialize>::value &&
813  std::is_integral<iType>::value),
814  reference_type>
815  access(const iType& i0) const {
816  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((1, this->rank(), m_track, m_map, i0))
817  return m_map.reference(i0, 0, 0, 0, 0, 0, 0);
818  }
819 
820  // Rank 2
821  template <typename iType0, typename iType1>
822  KOKKOS_INLINE_FUNCTION std::enable_if_t<
823  (std::is_void<typename traits::specialize>::value &&
824  std::is_integral<iType0>::value && std::is_integral<iType1>::value),
825  reference_type>
826  access(const iType0& i0, const iType1& i1) const {
827  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((2, this->rank(), m_track, m_map, i0, i1))
828  return m_map.reference(i0, i1);
829  }
830 
831  template <typename iType0, typename iType1>
832  KOKKOS_INLINE_FUNCTION
833  std::enable_if_t<!(std::is_void<typename drvtraits::specialize>::value &&
834  std::is_integral<iType0>::value),
835  reference_type>
836  access(const iType0& i0, const iType1& i1) const {
837  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY((2, this->rank(), m_track, m_map, i0, i1))
838  return m_map.reference(i0, i1, 0, 0, 0, 0, 0);
839  }
840 
841  // Rank 3
842  template <typename iType0, typename iType1, typename iType2>
843  KOKKOS_INLINE_FUNCTION std::enable_if_t<
844  (std::is_void<typename traits::specialize>::value &&
845  std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
846  std::is_integral<iType2>::value),
847  reference_type>
848  access(const iType0& i0, const iType1& i1, const iType2& i2) const {
849  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
850  (3, this->rank(), m_track, m_map, i0, i1, i2))
851  return m_map.reference(i0, i1, i2);
852  }
853 
854  template <typename iType0, typename iType1, typename iType2>
855  KOKKOS_INLINE_FUNCTION
856  std::enable_if_t<!(std::is_void<typename drvtraits::specialize>::value &&
857  std::is_integral<iType0>::value),
858  reference_type>
859  access(const iType0& i0, const iType1& i1, const iType2& i2) const {
860  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
861  (3, this->rank(), m_track, m_map, i0, i1, i2))
862  return m_map.reference(i0, i1, i2, 0, 0, 0, 0);
863  }
864 
865  // Rank 4
866  template <typename iType0, typename iType1, typename iType2, typename iType3>
867  KOKKOS_INLINE_FUNCTION std::enable_if_t<
868  (std::is_void<typename traits::specialize>::value &&
869  std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
870  std::is_integral<iType2>::value && std::is_integral<iType3>::value),
871  reference_type>
872  access(const iType0& i0, const iType1& i1, const iType2& i2,
873  const iType3& i3) const {
874  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
875  (4, this->rank(), m_track, m_map, i0, i1, i2, i3))
876  return m_map.reference(i0, i1, i2, i3);
877  }
878 
879  template <typename iType0, typename iType1, typename iType2, typename iType3>
880  KOKKOS_INLINE_FUNCTION
881  std::enable_if_t<!(std::is_void<typename drvtraits::specialize>::value &&
882  std::is_integral<iType0>::value),
883  reference_type>
884  access(const iType0& i0, const iType1& i1, const iType2& i2,
885  const iType3& i3) const {
886  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
887  (4, this->rank(), m_track, m_map, i0, i1, i2, i3))
888  return m_map.reference(i0, i1, i2, i3, 0, 0, 0);
889  }
890 
891  // Rank 5
892  template <typename iType0, typename iType1, typename iType2, typename iType3,
893  typename iType4>
894  KOKKOS_INLINE_FUNCTION std::enable_if_t<
895  (std::is_void<typename traits::specialize>::value &&
896  std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
897  std::is_integral<iType2>::value && std::is_integral<iType3>::value &&
898  std::is_integral<iType4>::value),
899  reference_type>
900  access(const iType0& i0, const iType1& i1, const iType2& i2, const iType3& i3,
901  const iType4& i4) const {
902  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
903  (5, this->rank(), m_track, m_map, i0, i1, i2, i3, i4))
904  return m_map.reference(i0, i1, i2, i3, i4);
905  }
906 
907  template <typename iType0, typename iType1, typename iType2, typename iType3,
908  typename iType4>
909  KOKKOS_INLINE_FUNCTION
910  std::enable_if_t<!(std::is_void<typename drvtraits::specialize>::value &&
911  std::is_integral<iType0>::value),
912  reference_type>
913  access(const iType0& i0, const iType1& i1, const iType2& i2,
914  const iType3& i3, const iType4& i4) const {
915  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
916  (5, this->rank(), m_track, m_map, i0, i1, i2, i3, i4))
917  return m_map.reference(i0, i1, i2, i3, i4, 0, 0);
918  }
919 
920  // Rank 6
921  template <typename iType0, typename iType1, typename iType2, typename iType3,
922  typename iType4, typename iType5>
923  KOKKOS_INLINE_FUNCTION std::enable_if_t<
924  (std::is_void<typename traits::specialize>::value &&
925  std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
926  std::is_integral<iType2>::value && std::is_integral<iType3>::value &&
927  std::is_integral<iType4>::value && std::is_integral<iType5>::value),
928  reference_type>
929  access(const iType0& i0, const iType1& i1, const iType2& i2, const iType3& i3,
930  const iType4& i4, const iType5& i5) const {
931  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
932  (6, this->rank(), m_track, m_map, i0, i1, i2, i3, i4, i5))
933  return m_map.reference(i0, i1, i2, i3, i4, i5);
934  }
935 
936  template <typename iType0, typename iType1, typename iType2, typename iType3,
937  typename iType4, typename iType5>
938  KOKKOS_INLINE_FUNCTION
939  std::enable_if_t<!(std::is_void<typename drvtraits::specialize>::value &&
940  std::is_integral<iType0>::value),
941  reference_type>
942  access(const iType0& i0, const iType1& i1, const iType2& i2,
943  const iType3& i3, const iType4& i4, const iType5& i5) const {
944  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
945  (6, this->rank(), m_track, m_map, i0, i1, i2, i3, i4, i5))
946  return m_map.reference(i0, i1, i2, i3, i4, i5, 0);
947  }
948 
949  // Rank 7
950  template <typename iType0, typename iType1, typename iType2, typename iType3,
951  typename iType4, typename iType5, typename iType6>
952  KOKKOS_INLINE_FUNCTION std::enable_if_t<
953  (std::is_integral<iType0>::value && std::is_integral<iType1>::value &&
954  std::is_integral<iType2>::value && std::is_integral<iType3>::value &&
955  std::is_integral<iType4>::value && std::is_integral<iType5>::value &&
956  std::is_integral<iType6>::value),
957  reference_type>
958  access(const iType0& i0, const iType1& i1, const iType2& i2, const iType3& i3,
959  const iType4& i4, const iType5& i5, const iType6& i6) const {
960  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY(
961  (7, this->rank(), m_track, m_map, i0, i1, i2, i3, i4, i5, i6))
962  return m_map.reference(i0, i1, i2, i3, i4, i5, i6);
963  }
964 
965 #undef KOKKOS_IMPL_VIEW_OPERATOR_VERIFY
966 
967  //----------------------------------------
968  // Standard constructor, destructor, and assignment operators...
969 
970  KOKKOS_DEFAULTED_FUNCTION
971  ~DynRankView() = default;
972 
973  KOKKOS_INLINE_FUNCTION
974  DynRankView() : m_track(), m_map(), m_rank() {} // Default ctor
975 
976  KOKKOS_INLINE_FUNCTION
977  DynRankView(const DynRankView& rhs)
978  : m_track(rhs.m_track), m_map(rhs.m_map), m_rank(rhs.m_rank) {}
979 
980  KOKKOS_INLINE_FUNCTION
981  DynRankView(DynRankView&& rhs)
982  : m_track(rhs.m_track), m_map(rhs.m_map), m_rank(rhs.m_rank) {}
983 
984  KOKKOS_INLINE_FUNCTION
985  DynRankView& operator=(const DynRankView& rhs) {
986  m_track = rhs.m_track;
987  m_map = rhs.m_map;
988  m_rank = rhs.m_rank;
989  return *this;
990  }
991 
992  KOKKOS_INLINE_FUNCTION
993  DynRankView& operator=(DynRankView&& rhs) {
994  m_track = rhs.m_track;
995  m_map = rhs.m_map;
996  m_rank = rhs.m_rank;
997  return *this;
998  }
999 
1000  //----------------------------------------
1001  // Compatible view copy constructor and assignment
1002  // may assign unmanaged from managed.
1003  template <class RT, class... RP>
1004  KOKKOS_INLINE_FUNCTION DynRankView(const DynRankView<RT, RP...>& rhs)
1005  : m_track(rhs.m_track, traits::is_managed), m_map(), m_rank(rhs.m_rank) {
1006  using SrcTraits = typename DynRankView<RT, RP...>::traits;
1007  using Mapping = Kokkos::Impl::ViewMapping<traits, SrcTraits,
1008  typename traits::specialize>;
1009  static_assert(Mapping::is_assignable,
1010  "Incompatible DynRankView copy construction");
1011  Mapping::assign(m_map, rhs.m_map, rhs.m_track);
1012  }
1013 
1014  template <class RT, class... RP>
1015  KOKKOS_INLINE_FUNCTION DynRankView& operator=(
1016  const DynRankView<RT, RP...>& rhs) {
1017  using SrcTraits = typename DynRankView<RT, RP...>::traits;
1018  using Mapping = Kokkos::Impl::ViewMapping<traits, SrcTraits,
1019  typename traits::specialize>;
1020  static_assert(Mapping::is_assignable,
1021  "Incompatible DynRankView copy construction");
1022  Mapping::assign(m_map, rhs.m_map, rhs.m_track);
1023  m_track.assign(rhs.m_track, traits::is_managed);
1024  m_rank = rhs.rank();
1025  return *this;
1026  }
1027 
1028  // Copy/Assign View to DynRankView
1029  template <class RT, class... RP>
1030  KOKKOS_INLINE_FUNCTION DynRankView(const View<RT, RP...>& rhs)
1031  : m_track(), m_map(), m_rank(View<RT, RP...>::rank()) {
1032  using SrcTraits = typename View<RT, RP...>::traits;
1033  using Mapping =
1034  Kokkos::Impl::ViewMapping<traits, SrcTraits,
1036  static_assert(Mapping::is_assignable,
1037  "Incompatible View to DynRankView copy construction");
1038  Mapping::assign(*this, rhs);
1039  }
1040 
1041  template <class RT, class... RP>
1042  KOKKOS_INLINE_FUNCTION DynRankView& operator=(const View<RT, RP...>& rhs) {
1043  using SrcTraits = typename View<RT, RP...>::traits;
1044  using Mapping =
1045  Kokkos::Impl::ViewMapping<traits, SrcTraits,
1047  static_assert(Mapping::is_assignable,
1048  "Incompatible View to DynRankView copy assignment");
1049  Mapping::assign(*this, rhs);
1050  return *this;
1051  }
1052 
1053  //----------------------------------------
1054  // Allocation tracking properties
1055 
1056  KOKKOS_INLINE_FUNCTION
1057  int use_count() const { return m_track.use_count(); }
1058 
1059  inline const std::string label() const {
1060  return m_track.template get_label<typename traits::memory_space>();
1061  }
1062 
1063  //----------------------------------------
1064  // Allocation according to allocation properties and array layout
1065  // unused arg_layout dimensions must be set to KOKKOS_INVALID_INDEX so that
1066  // rank deduction can properly take place
1067  template <class... P>
1068  explicit inline DynRankView(
1069  const Kokkos::Impl::ViewCtorProp<P...>& arg_prop,
1070  std::enable_if_t<!Kokkos::Impl::ViewCtorProp<P...>::has_pointer,
1071  typename traits::array_layout> const& arg_layout)
1072  : m_track(),
1073  m_map(),
1074  m_rank(Impl::DynRankDimTraits<typename traits::specialize>::
1075  template computeRank<typename traits::array_layout, P...>(
1076  arg_prop, arg_layout)) {
1077  // Copy the input allocation properties with possibly defaulted properties
1078  auto prop_copy = Impl::with_properties_if_unset(
1079  arg_prop, std::string{}, typename traits::device_type::memory_space{},
1080  typename traits::device_type::execution_space{});
1081  using alloc_prop = decltype(prop_copy);
1082 
1083  static_assert(traits::is_managed,
1084  "View allocation constructor requires managed memory");
1085 
1086  if (alloc_prop::initialize &&
1087  !alloc_prop::execution_space::impl_is_initialized()) {
1088  // If initializing view data then
1089  // the execution space must be initialized.
1090  Kokkos::Impl::throw_runtime_exception(
1091  "Constructing DynRankView and initializing data with uninitialized "
1092  "execution space");
1093  }
1094 
1095  Kokkos::Impl::SharedAllocationRecord<>* record = m_map.allocate_shared(
1096  prop_copy,
1097  Impl::DynRankDimTraits<typename traits::specialize>::
1098  template createLayout<traits, P...>(arg_prop, arg_layout),
1099  Impl::ViewCtorProp<P...>::has_execution_space);
1100 
1101  // Setup and initialization complete, start tracking
1102  m_track.assign_allocated_record_to_uninitialized(record);
1103  }
1104 
1105  // Wrappers
1106  template <class... P>
1107  explicit KOKKOS_INLINE_FUNCTION DynRankView(
1108  const Kokkos::Impl::ViewCtorProp<P...>& arg_prop,
1109  std::enable_if_t<Kokkos::Impl::ViewCtorProp<P...>::has_pointer,
1110  typename traits::array_layout> const& arg_layout)
1111  : m_track() // No memory tracking
1112  ,
1113  m_map(arg_prop,
1114  Impl::DynRankDimTraits<typename traits::specialize>::
1115  template createLayout<traits, P...>(arg_prop, arg_layout)),
1116  m_rank(Impl::DynRankDimTraits<typename traits::specialize>::
1117  template computeRank<typename traits::array_layout, P...>(
1118  arg_prop, arg_layout)) {
1119  static_assert(
1120  std::is_same<pointer_type,
1121  typename Impl::ViewCtorProp<P...>::pointer_type>::value,
1122  "Constructing DynRankView to wrap user memory must supply matching "
1123  "pointer type");
1124  }
1125 
1126  //----------------------------------------
1127  // Constructor(s)
1128 
1129  // Simple dimension-only layout
1130  template <class... P>
1131  explicit inline DynRankView(
1132  const Kokkos::Impl::ViewCtorProp<P...>& arg_prop,
1133  std::enable_if_t<!Kokkos::Impl::ViewCtorProp<P...>::has_pointer,
1134  size_t> const arg_N0 = KOKKOS_INVALID_INDEX,
1135  const size_t arg_N1 = KOKKOS_INVALID_INDEX,
1136  const size_t arg_N2 = KOKKOS_INVALID_INDEX,
1137  const size_t arg_N3 = KOKKOS_INVALID_INDEX,
1138  const size_t arg_N4 = KOKKOS_INVALID_INDEX,
1139  const size_t arg_N5 = KOKKOS_INVALID_INDEX,
1140  const size_t arg_N6 = KOKKOS_INVALID_INDEX,
1141  const size_t arg_N7 = KOKKOS_INVALID_INDEX)
1142  : DynRankView(arg_prop, typename traits::array_layout(
1143  arg_N0, arg_N1, arg_N2, arg_N3, arg_N4,
1144  arg_N5, arg_N6, arg_N7)) {}
1145 
1146  template <class... P>
1147  explicit KOKKOS_INLINE_FUNCTION DynRankView(
1148  const Kokkos::Impl::ViewCtorProp<P...>& arg_prop,
1149  std::enable_if_t<Kokkos::Impl::ViewCtorProp<P...>::has_pointer,
1150  size_t> const arg_N0 = KOKKOS_INVALID_INDEX,
1151  const size_t arg_N1 = KOKKOS_INVALID_INDEX,
1152  const size_t arg_N2 = KOKKOS_INVALID_INDEX,
1153  const size_t arg_N3 = KOKKOS_INVALID_INDEX,
1154  const size_t arg_N4 = KOKKOS_INVALID_INDEX,
1155  const size_t arg_N5 = KOKKOS_INVALID_INDEX,
1156  const size_t arg_N6 = KOKKOS_INVALID_INDEX,
1157  const size_t arg_N7 = KOKKOS_INVALID_INDEX)
1158  : DynRankView(arg_prop, typename traits::array_layout(
1159  arg_N0, arg_N1, arg_N2, arg_N3, arg_N4,
1160  arg_N5, arg_N6, arg_N7)) {}
1161 
1162  // Allocate with label and layout
1163  template <typename Label>
1164  explicit inline DynRankView(
1165  const Label& arg_label,
1166  std::enable_if_t<Kokkos::Impl::is_view_label<Label>::value,
1167  typename traits::array_layout> const& arg_layout)
1168  : DynRankView(Kokkos::Impl::ViewCtorProp<std::string>(arg_label),
1169  arg_layout) {}
1170 
1171  // Allocate label and layout, must disambiguate from subview constructor
1172  template <typename Label>
1173  explicit inline DynRankView(
1174  const Label& arg_label,
1175  std::enable_if_t<Kokkos::Impl::is_view_label<Label>::value, const size_t>
1176  arg_N0 = KOKKOS_INVALID_INDEX,
1177  const size_t arg_N1 = KOKKOS_INVALID_INDEX,
1178  const size_t arg_N2 = KOKKOS_INVALID_INDEX,
1179  const size_t arg_N3 = KOKKOS_INVALID_INDEX,
1180  const size_t arg_N4 = KOKKOS_INVALID_INDEX,
1181  const size_t arg_N5 = KOKKOS_INVALID_INDEX,
1182  const size_t arg_N6 = KOKKOS_INVALID_INDEX,
1183  const size_t arg_N7 = KOKKOS_INVALID_INDEX)
1184  : DynRankView(
1185  Kokkos::Impl::ViewCtorProp<std::string>(arg_label),
1186  typename traits::array_layout(arg_N0, arg_N1, arg_N2, arg_N3,
1187  arg_N4, arg_N5, arg_N6, arg_N7)) {}
1188 
1189  //----------------------------------------
1190  // Memory span required to wrap these dimensions.
1191  static constexpr size_t required_allocation_size(
1192  const size_t arg_N0 = 0, const size_t arg_N1 = 0, const size_t arg_N2 = 0,
1193  const size_t arg_N3 = 0, const size_t arg_N4 = 0, const size_t arg_N5 = 0,
1194  const size_t arg_N6 = 0, const size_t arg_N7 = 0) {
1195  return map_type::memory_span(typename traits::array_layout(
1196  arg_N0, arg_N1, arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7));
1197  }
1198 
1199  explicit KOKKOS_INLINE_FUNCTION DynRankView(
1200  pointer_type arg_ptr, const size_t arg_N0 = KOKKOS_INVALID_INDEX,
1201  const size_t arg_N1 = KOKKOS_INVALID_INDEX,
1202  const size_t arg_N2 = KOKKOS_INVALID_INDEX,
1203  const size_t arg_N3 = KOKKOS_INVALID_INDEX,
1204  const size_t arg_N4 = KOKKOS_INVALID_INDEX,
1205  const size_t arg_N5 = KOKKOS_INVALID_INDEX,
1206  const size_t arg_N6 = KOKKOS_INVALID_INDEX,
1207  const size_t arg_N7 = KOKKOS_INVALID_INDEX)
1208  : DynRankView(Kokkos::Impl::ViewCtorProp<pointer_type>(arg_ptr), arg_N0,
1209  arg_N1, arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7) {}
1210 
1211  explicit KOKKOS_INLINE_FUNCTION DynRankView(
1212  pointer_type arg_ptr, typename traits::array_layout& arg_layout)
1213  : DynRankView(Kokkos::Impl::ViewCtorProp<pointer_type>(arg_ptr),
1214  arg_layout) {}
1215 
1216  //----------------------------------------
1217  // Shared scratch memory constructor
1218 
1219  static inline size_t shmem_size(const size_t arg_N0 = KOKKOS_INVALID_INDEX,
1220  const size_t arg_N1 = KOKKOS_INVALID_INDEX,
1221  const size_t arg_N2 = KOKKOS_INVALID_INDEX,
1222  const size_t arg_N3 = KOKKOS_INVALID_INDEX,
1223  const size_t arg_N4 = KOKKOS_INVALID_INDEX,
1224  const size_t arg_N5 = KOKKOS_INVALID_INDEX,
1225  const size_t arg_N6 = KOKKOS_INVALID_INDEX,
1226  const size_t arg_N7 = KOKKOS_INVALID_INDEX) {
1227  const size_t num_passed_args =
1228  (arg_N0 != KOKKOS_INVALID_INDEX) + (arg_N1 != KOKKOS_INVALID_INDEX) +
1229  (arg_N2 != KOKKOS_INVALID_INDEX) + (arg_N3 != KOKKOS_INVALID_INDEX) +
1230  (arg_N4 != KOKKOS_INVALID_INDEX) + (arg_N5 != KOKKOS_INVALID_INDEX) +
1231  (arg_N6 != KOKKOS_INVALID_INDEX) + (arg_N7 != KOKKOS_INVALID_INDEX);
1232 
1233  if (std::is_void<typename traits::specialize>::value &&
1234  num_passed_args != traits::rank_dynamic) {
1235  Kokkos::abort(
1236  "Kokkos::View::shmem_size() rank_dynamic != number of arguments.\n");
1237  }
1238  {}
1239 
1240  return map_type::memory_span(typename traits::array_layout(
1241  arg_N0, arg_N1, arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7));
1242  }
1243 
1244  explicit KOKKOS_INLINE_FUNCTION DynRankView(
1245  const typename traits::execution_space::scratch_memory_space& arg_space,
1246  const typename traits::array_layout& arg_layout)
1247  : DynRankView(
1248  Kokkos::Impl::ViewCtorProp<pointer_type>(
1249  reinterpret_cast<pointer_type>(
1250  arg_space.get_shmem(map_type::memory_span(
1251  Impl::DynRankDimTraits<typename traits::specialize>::
1252  createLayout(arg_layout) // is this correct?
1253  )))),
1254  arg_layout) {}
1255 
1256  explicit KOKKOS_INLINE_FUNCTION DynRankView(
1257  const typename traits::execution_space::scratch_memory_space& arg_space,
1258  const size_t arg_N0 = KOKKOS_INVALID_INDEX,
1259  const size_t arg_N1 = KOKKOS_INVALID_INDEX,
1260  const size_t arg_N2 = KOKKOS_INVALID_INDEX,
1261  const size_t arg_N3 = KOKKOS_INVALID_INDEX,
1262  const size_t arg_N4 = KOKKOS_INVALID_INDEX,
1263  const size_t arg_N5 = KOKKOS_INVALID_INDEX,
1264  const size_t arg_N6 = KOKKOS_INVALID_INDEX,
1265  const size_t arg_N7 = KOKKOS_INVALID_INDEX)
1266 
1267  : DynRankView(
1268  Kokkos::Impl::ViewCtorProp<pointer_type>(
1269  reinterpret_cast<pointer_type>(
1270  arg_space.get_shmem(map_type::memory_span(
1271  Impl::DynRankDimTraits<typename traits::specialize>::
1272  createLayout(typename traits::array_layout(
1273  arg_N0, arg_N1, arg_N2, arg_N3, arg_N4, arg_N5,
1274  arg_N6, arg_N7)))))),
1275  typename traits::array_layout(arg_N0, arg_N1, arg_N2, arg_N3,
1276  arg_N4, arg_N5, arg_N6, arg_N7)) {}
1277 };
1278 
1279 template <typename D, class... P>
1280 KOKKOS_INLINE_FUNCTION constexpr unsigned rank(
1281  const DynRankView<D, P...>& DRV) {
1282  return DRV.rank();
1283 } // needed for transition to common constexpr method in view and dynrankview
1284  // to return rank
1285 
1286 //----------------------------------------------------------------------------
1287 // Subview mapping.
1288 // Deduce destination view type from source view traits and subview arguments
1289 
1290 namespace Impl {
1291 
1292 struct DynRankSubviewTag {};
1293 
1294 } // namespace Impl
1295 
1296 namespace Impl {
1297 
1298 template <class SrcTraits, class... Args>
1299 class ViewMapping<
1300  std::enable_if_t<(std::is_void<typename SrcTraits::specialize>::value &&
1301  (std::is_same<typename SrcTraits::array_layout,
1302  Kokkos::LayoutLeft>::value ||
1303  std::is_same<typename SrcTraits::array_layout,
1304  Kokkos::LayoutRight>::value ||
1305  std::is_same<typename SrcTraits::array_layout,
1306  Kokkos::LayoutStride>::value)),
1307  Kokkos::Impl::DynRankSubviewTag>,
1308  SrcTraits, Args...> {
1309  private:
1310  enum {
1311  RZ = false,
1312  R0 = bool(is_integral_extent<0, Args...>::value),
1313  R1 = bool(is_integral_extent<1, Args...>::value),
1314  R2 = bool(is_integral_extent<2, Args...>::value),
1315  R3 = bool(is_integral_extent<3, Args...>::value),
1316  R4 = bool(is_integral_extent<4, Args...>::value),
1317  R5 = bool(is_integral_extent<5, Args...>::value),
1318  R6 = bool(is_integral_extent<6, Args...>::value)
1319  };
1320 
1321  enum {
1322  rank = unsigned(R0) + unsigned(R1) + unsigned(R2) + unsigned(R3) +
1323  unsigned(R4) + unsigned(R5) + unsigned(R6)
1324  };
1325 
1326  using array_layout = Kokkos::LayoutStride;
1327 
1328  using value_type = typename SrcTraits::value_type;
1329 
1330  using data_type = value_type*******;
1331 
1332  public:
1333  using traits_type = Kokkos::ViewTraits<data_type, array_layout,
1334  typename SrcTraits::device_type,
1335  typename SrcTraits::memory_traits>;
1336 
1337  using type =
1338  Kokkos::View<data_type, array_layout, typename SrcTraits::device_type,
1339  typename SrcTraits::memory_traits>;
1340 
1341  template <class MemoryTraits>
1342  struct apply {
1343  static_assert(Kokkos::is_memory_traits<MemoryTraits>::value);
1344 
1345  using traits_type =
1346  Kokkos::ViewTraits<data_type, array_layout,
1347  typename SrcTraits::device_type, MemoryTraits>;
1348 
1349  using type = Kokkos::View<data_type, array_layout,
1350  typename SrcTraits::device_type, MemoryTraits>;
1351  };
1352 
1353  using dimension = typename SrcTraits::dimension;
1354 
1355  template <class Arg0 = int, class Arg1 = int, class Arg2 = int,
1356  class Arg3 = int, class Arg4 = int, class Arg5 = int,
1357  class Arg6 = int>
1358  struct ExtentGenerator {
1359  KOKKOS_INLINE_FUNCTION
1360  static SubviewExtents<7, rank> generator(
1361  const dimension& dim, Arg0 arg0 = Arg0(), Arg1 arg1 = Arg1(),
1362  Arg2 arg2 = Arg2(), Arg3 arg3 = Arg3(), Arg4 arg4 = Arg4(),
1363  Arg5 arg5 = Arg5(), Arg6 arg6 = Arg6()) {
1364  return SubviewExtents<7, rank>(dim, arg0, arg1, arg2, arg3, arg4, arg5,
1365  arg6);
1366  }
1367  };
1368 
1369  using ret_type = Kokkos::DynRankView<value_type, array_layout,
1370  typename SrcTraits::device_type,
1371  typename SrcTraits::memory_traits>;
1372 
1373  template <typename T, class... P>
1374  KOKKOS_INLINE_FUNCTION static ret_type subview(
1375  const unsigned src_rank, Kokkos::DynRankView<T, P...> const& src,
1376  Args... args) {
1377  using DstType = ViewMapping<traits_type, typename traits_type::specialize>;
1378 
1379  using DstDimType = std::conditional_t<
1380  (rank == 0), ViewDimension<>,
1381  std::conditional_t<
1382  (rank == 1), ViewDimension<0>,
1383  std::conditional_t<
1384  (rank == 2), ViewDimension<0, 0>,
1385  std::conditional_t<
1386  (rank == 3), ViewDimension<0, 0, 0>,
1387  std::conditional_t<
1388  (rank == 4), ViewDimension<0, 0, 0, 0>,
1389  std::conditional_t<
1390  (rank == 5), ViewDimension<0, 0, 0, 0, 0>,
1391  std::conditional_t<
1392  (rank == 6), ViewDimension<0, 0, 0, 0, 0, 0>,
1393  ViewDimension<0, 0, 0, 0, 0, 0, 0>>>>>>>>;
1394 
1395  using dst_offset_type = ViewOffset<DstDimType, Kokkos::LayoutStride>;
1396  using dst_handle_type = typename DstType::handle_type;
1397 
1398  ret_type dst;
1399 
1400  const SubviewExtents<7, rank> extents = ExtentGenerator<Args...>::generator(
1401  src.m_map.m_impl_offset.m_dim, args...);
1402 
1403  dst_offset_type tempdst(src.m_map.m_impl_offset, extents);
1404 
1405  dst.m_track = src.m_track;
1406 
1407  dst.m_map.m_impl_offset.m_dim.N0 = tempdst.m_dim.N0;
1408  dst.m_map.m_impl_offset.m_dim.N1 = tempdst.m_dim.N1;
1409  dst.m_map.m_impl_offset.m_dim.N2 = tempdst.m_dim.N2;
1410  dst.m_map.m_impl_offset.m_dim.N3 = tempdst.m_dim.N3;
1411  dst.m_map.m_impl_offset.m_dim.N4 = tempdst.m_dim.N4;
1412  dst.m_map.m_impl_offset.m_dim.N5 = tempdst.m_dim.N5;
1413  dst.m_map.m_impl_offset.m_dim.N6 = tempdst.m_dim.N6;
1414 
1415  dst.m_map.m_impl_offset.m_stride.S0 = tempdst.m_stride.S0;
1416  dst.m_map.m_impl_offset.m_stride.S1 = tempdst.m_stride.S1;
1417  dst.m_map.m_impl_offset.m_stride.S2 = tempdst.m_stride.S2;
1418  dst.m_map.m_impl_offset.m_stride.S3 = tempdst.m_stride.S3;
1419  dst.m_map.m_impl_offset.m_stride.S4 = tempdst.m_stride.S4;
1420  dst.m_map.m_impl_offset.m_stride.S5 = tempdst.m_stride.S5;
1421  dst.m_map.m_impl_offset.m_stride.S6 = tempdst.m_stride.S6;
1422 
1423  dst.m_map.m_impl_handle =
1424  dst_handle_type(src.m_map.m_impl_handle +
1425  src.m_map.m_impl_offset(
1426  extents.domain_offset(0), extents.domain_offset(1),
1427  extents.domain_offset(2), extents.domain_offset(3),
1428  extents.domain_offset(4), extents.domain_offset(5),
1429  extents.domain_offset(6)));
1430 
1431  dst.m_rank =
1432  (src_rank > 0 ? unsigned(R0) : 0) + (src_rank > 1 ? unsigned(R1) : 0) +
1433  (src_rank > 2 ? unsigned(R2) : 0) + (src_rank > 3 ? unsigned(R3) : 0) +
1434  (src_rank > 4 ? unsigned(R4) : 0) + (src_rank > 5 ? unsigned(R5) : 0) +
1435  (src_rank > 6 ? unsigned(R6) : 0);
1436 
1437  return dst;
1438  }
1439 };
1440 
1441 } // namespace Impl
1442 
1443 template <class V, class... Args>
1444 using Subdynrankview =
1445  typename Kokkos::Impl::ViewMapping<Kokkos::Impl::DynRankSubviewTag, V,
1446  Args...>::ret_type;
1447 
1448 template <class D, class... P, class... Args>
1449 KOKKOS_INLINE_FUNCTION Subdynrankview<ViewTraits<D*******, P...>, Args...>
1450 subdynrankview(const Kokkos::DynRankView<D, P...>& src, Args... args) {
1451  if (src.rank() > sizeof...(Args)) // allow sizeof...(Args) >= src.rank(),
1452  // ignore the remaining args
1453  {
1454  Kokkos::abort(
1455  "subdynrankview: num of args must be >= rank of the source "
1456  "DynRankView");
1457  }
1458 
1459  using metafcn =
1460  Kokkos::Impl::ViewMapping<Kokkos::Impl::DynRankSubviewTag,
1461  Kokkos::ViewTraits<D*******, P...>, Args...>;
1462 
1463  return metafcn::subview(src.rank(), src, args...);
1464 }
1465 
1466 // Wrapper to allow subview function name
1467 template <class D, class... P, class... Args>
1468 KOKKOS_INLINE_FUNCTION Subdynrankview<ViewTraits<D*******, P...>, Args...>
1469 subview(const Kokkos::DynRankView<D, P...>& src, Args... args) {
1470  return subdynrankview(src, args...);
1471 }
1472 
1473 } // namespace Kokkos
1474 
1475 namespace Kokkos {
1476 
1477 // overload == and !=
1478 template <class LT, class... LP, class RT, class... RP>
1479 KOKKOS_INLINE_FUNCTION bool operator==(const DynRankView<LT, LP...>& lhs,
1480  const DynRankView<RT, RP...>& rhs) {
1481  // Same data, layout, dimensions
1482  using lhs_traits = ViewTraits<LT, LP...>;
1483  using rhs_traits = ViewTraits<RT, RP...>;
1484 
1485  return std::is_same<typename lhs_traits::const_value_type,
1486  typename rhs_traits::const_value_type>::value &&
1487  std::is_same<typename lhs_traits::array_layout,
1488  typename rhs_traits::array_layout>::value &&
1489  std::is_same<typename lhs_traits::memory_space,
1490  typename rhs_traits::memory_space>::value &&
1491  lhs.rank() == rhs.rank() && lhs.data() == rhs.data() &&
1492  lhs.span() == rhs.span() && lhs.extent(0) == rhs.extent(0) &&
1493  lhs.extent(1) == rhs.extent(1) && lhs.extent(2) == rhs.extent(2) &&
1494  lhs.extent(3) == rhs.extent(3) && lhs.extent(4) == rhs.extent(4) &&
1495  lhs.extent(5) == rhs.extent(5) && lhs.extent(6) == rhs.extent(6) &&
1496  lhs.extent(7) == rhs.extent(7);
1497 }
1498 
1499 template <class LT, class... LP, class RT, class... RP>
1500 KOKKOS_INLINE_FUNCTION bool operator!=(const DynRankView<LT, LP...>& lhs,
1501  const DynRankView<RT, RP...>& rhs) {
1502  return !(operator==(lhs, rhs));
1503 }
1504 
1505 } // namespace Kokkos
1506 
1507 //----------------------------------------------------------------------------
1508 //----------------------------------------------------------------------------
1509 namespace Kokkos {
1510 namespace Impl {
1511 
1512 template <class OutputView, class Enable = void>
1513 struct DynRankViewFill {
1514  using const_value_type = typename OutputView::traits::const_value_type;
1515 
1516  const OutputView output;
1517  const_value_type input;
1518 
1519  KOKKOS_INLINE_FUNCTION
1520  void operator()(const size_t i0) const {
1521  const size_t n1 = output.extent(1);
1522  const size_t n2 = output.extent(2);
1523  const size_t n3 = output.extent(3);
1524  const size_t n4 = output.extent(4);
1525  const size_t n5 = output.extent(5);
1526  const size_t n6 = output.extent(6);
1527 
1528  for (size_t i1 = 0; i1 < n1; ++i1) {
1529  for (size_t i2 = 0; i2 < n2; ++i2) {
1530  for (size_t i3 = 0; i3 < n3; ++i3) {
1531  for (size_t i4 = 0; i4 < n4; ++i4) {
1532  for (size_t i5 = 0; i5 < n5; ++i5) {
1533  for (size_t i6 = 0; i6 < n6; ++i6) {
1534  output.access(i0, i1, i2, i3, i4, i5, i6) = input;
1535  }
1536  }
1537  }
1538  }
1539  }
1540  }
1541  }
1542 
1543  DynRankViewFill(const OutputView& arg_out, const_value_type& arg_in)
1544  : output(arg_out), input(arg_in) {
1545  using execution_space = typename OutputView::execution_space;
1546  using Policy = Kokkos::RangePolicy<execution_space>;
1547 
1548  Kokkos::parallel_for("Kokkos::DynRankViewFill", Policy(0, output.extent(0)),
1549  *this);
1550  }
1551 };
1552 
1553 template <class OutputView>
1554 struct DynRankViewFill<OutputView, std::enable_if_t<OutputView::rank == 0>> {
1555  DynRankViewFill(const OutputView& dst,
1556  const typename OutputView::const_value_type& src) {
1557  Kokkos::Impl::DeepCopy<typename OutputView::memory_space,
1559  dst.data(), &src, sizeof(typename OutputView::const_value_type));
1560  }
1561 };
1562 
1563 template <class OutputView, class InputView,
1564  class ExecSpace = typename OutputView::execution_space>
1565 struct DynRankViewRemap {
1566  const OutputView output;
1567  const InputView input;
1568  const size_t n0;
1569  const size_t n1;
1570  const size_t n2;
1571  const size_t n3;
1572  const size_t n4;
1573  const size_t n5;
1574  const size_t n6;
1575  const size_t n7;
1576 
1577  DynRankViewRemap(const ExecSpace& exec_space, const OutputView& arg_out,
1578  const InputView& arg_in)
1579  : output(arg_out),
1580  input(arg_in),
1581  n0(std::min((size_t)arg_out.extent(0), (size_t)arg_in.extent(0))),
1582  n1(std::min((size_t)arg_out.extent(1), (size_t)arg_in.extent(1))),
1583  n2(std::min((size_t)arg_out.extent(2), (size_t)arg_in.extent(2))),
1584  n3(std::min((size_t)arg_out.extent(3), (size_t)arg_in.extent(3))),
1585  n4(std::min((size_t)arg_out.extent(4), (size_t)arg_in.extent(4))),
1586  n5(std::min((size_t)arg_out.extent(5), (size_t)arg_in.extent(5))),
1587  n6(std::min((size_t)arg_out.extent(6), (size_t)arg_in.extent(6))),
1588  n7(std::min((size_t)arg_out.extent(7), (size_t)arg_in.extent(7))) {
1589  using Policy = Kokkos::RangePolicy<ExecSpace>;
1590 
1591  Kokkos::parallel_for("Kokkos::DynRankViewRemap", Policy(exec_space, 0, n0),
1592  *this);
1593  }
1594 
1595  DynRankViewRemap(const OutputView& arg_out, const InputView& arg_in)
1596  : output(arg_out),
1597  input(arg_in),
1598  n0(std::min((size_t)arg_out.extent(0), (size_t)arg_in.extent(0))),
1599  n1(std::min((size_t)arg_out.extent(1), (size_t)arg_in.extent(1))),
1600  n2(std::min((size_t)arg_out.extent(2), (size_t)arg_in.extent(2))),
1601  n3(std::min((size_t)arg_out.extent(3), (size_t)arg_in.extent(3))),
1602  n4(std::min((size_t)arg_out.extent(4), (size_t)arg_in.extent(4))),
1603  n5(std::min((size_t)arg_out.extent(5), (size_t)arg_in.extent(5))),
1604  n6(std::min((size_t)arg_out.extent(6), (size_t)arg_in.extent(6))),
1605  n7(std::min((size_t)arg_out.extent(7), (size_t)arg_in.extent(7))) {
1606  using Policy = Kokkos::RangePolicy<ExecSpace>;
1607 
1608  Kokkos::parallel_for("Kokkos::DynRankViewRemap", Policy(0, n0), *this);
1609  }
1610 
1611  KOKKOS_INLINE_FUNCTION
1612  void operator()(const size_t i0) const {
1613  for (size_t i1 = 0; i1 < n1; ++i1) {
1614  for (size_t i2 = 0; i2 < n2; ++i2) {
1615  for (size_t i3 = 0; i3 < n3; ++i3) {
1616  for (size_t i4 = 0; i4 < n4; ++i4) {
1617  for (size_t i5 = 0; i5 < n5; ++i5) {
1618  for (size_t i6 = 0; i6 < n6; ++i6) {
1619  output.access(i0, i1, i2, i3, i4, i5, i6) =
1620  input.access(i0, i1, i2, i3, i4, i5, i6);
1621  }
1622  }
1623  }
1624  }
1625  }
1626  }
1627  }
1628 };
1629 
1630 } /* namespace Impl */
1631 } /* namespace Kokkos */
1632 
1633 namespace Kokkos {
1634 
1635 namespace Impl {
1636 
1637 /* \brief Returns a View of the requested rank, aliasing the
1638  underlying memory, to facilitate implementation of deep_copy() and
1639  other routines that are defined on View */
1640 template <unsigned N, typename T, typename... Args>
1641 KOKKOS_FUNCTION auto as_view_of_rank_n(
1642  DynRankView<T, Args...> v,
1643  typename std::enable_if<std::is_same<
1644  typename ViewTraits<T, Args...>::specialize, void>::value>::type* =
1645  nullptr) {
1646  if (v.rank() != N) {
1647  KOKKOS_IF_ON_HOST(
1648  const std::string message =
1649  "Converting DynRankView of rank " + std::to_string(v.rank()) +
1650  " to a View of mis-matched rank " + std::to_string(N) + "!";
1651  Kokkos::abort(message.c_str());)
1652  KOKKOS_IF_ON_DEVICE(
1653  Kokkos::abort("Converting DynRankView to a View of mis-matched rank!");)
1654  }
1655 
1656  auto layout = v.impl_map().layout();
1657 
1658  if constexpr (std::is_same_v<decltype(layout), Kokkos::LayoutLeft> ||
1659  std::is_same_v<decltype(layout), Kokkos::LayoutRight> ||
1660  std::is_same_v<decltype(layout), Kokkos::LayoutStride> ||
1661  is_layouttiled<decltype(layout)>::value) {
1662  for (int i = N; i < 7; ++i)
1663  layout.dimension[i] = KOKKOS_IMPL_CTOR_DEFAULT_ARG;
1664  }
1665 
1666  return View<typename RankDataType<T, N>::type, Args...>(v.data(), layout);
1667 }
1668 
1669 template <typename Function, typename... Args>
1670 void apply_to_view_of_static_rank(Function&& f, DynRankView<Args...> a) {
1671  switch (rank(a)) {
1672  case 0: f(as_view_of_rank_n<0>(a)); break;
1673  case 1: f(as_view_of_rank_n<1>(a)); break;
1674  case 2: f(as_view_of_rank_n<2>(a)); break;
1675  case 3: f(as_view_of_rank_n<3>(a)); break;
1676  case 4: f(as_view_of_rank_n<4>(a)); break;
1677  case 5: f(as_view_of_rank_n<5>(a)); break;
1678  case 6: f(as_view_of_rank_n<6>(a)); break;
1679  case 7: f(as_view_of_rank_n<7>(a)); break;
1680  default:
1681  KOKKOS_IF_ON_HOST(
1682  Kokkos::abort(
1683  std::string(
1684  "Trying to apply a function to a view of unexpected rank " +
1685  std::to_string(rank(a)))
1686  .c_str());)
1687  KOKKOS_IF_ON_DEVICE(
1688  Kokkos::abort(
1689  "Trying to apply a function to a view of unexpected rank");)
1690  }
1691 }
1692 
1693 } // namespace Impl
1694 
1695 template <typename D, class... P>
1696 KOKKOS_INLINE_FUNCTION constexpr auto DynRankView<D, P...>::layout() const ->
1697  typename traits::array_layout {
1698  switch (rank()) {
1699  case 0: return Impl::as_view_of_rank_n<0>(*this).layout();
1700  case 1: return Impl::as_view_of_rank_n<1>(*this).layout();
1701  case 2: return Impl::as_view_of_rank_n<2>(*this).layout();
1702  case 3: return Impl::as_view_of_rank_n<3>(*this).layout();
1703  case 4: return Impl::as_view_of_rank_n<4>(*this).layout();
1704  case 5: return Impl::as_view_of_rank_n<5>(*this).layout();
1705  case 6: return Impl::as_view_of_rank_n<6>(*this).layout();
1706  case 7: return Impl::as_view_of_rank_n<7>(*this).layout();
1707  default:
1708  KOKKOS_IF_ON_HOST(
1709  Kokkos::abort(
1710  std::string(
1711  "Calling DynRankView::layout on DRV of unexpected rank " +
1712  std::to_string(rank()))
1713  .c_str());)
1714  KOKKOS_IF_ON_DEVICE(
1715  Kokkos::abort(
1716  "Calling DynRankView::layout on DRV of unexpected rank");)
1717  }
1718  // control flow should never reach here
1719  return m_map.layout();
1720 }
1721 
1723 template <class ExecSpace, class DT, class... DP>
1724 inline void deep_copy(
1725  const ExecSpace& e, const DynRankView<DT, DP...>& dst,
1726  typename ViewTraits<DT, DP...>::const_value_type& value,
1727  std::enable_if_t<std::is_same<typename ViewTraits<DT, DP...>::specialize,
1728  void>::value>* = nullptr) {
1729  static_assert(
1730  std::is_same<typename ViewTraits<DT, DP...>::non_const_value_type,
1731  typename ViewTraits<DT, DP...>::value_type>::value,
1732  "deep_copy requires non-const type");
1733 
1734  Impl::apply_to_view_of_static_rank(
1735  [=](auto view) { deep_copy(e, view, value); }, dst);
1736 }
1737 
1738 template <class DT, class... DP>
1739 inline void deep_copy(
1740  const DynRankView<DT, DP...>& dst,
1741  typename ViewTraits<DT, DP...>::const_value_type& value,
1742  std::enable_if_t<std::is_same<typename ViewTraits<DT, DP...>::specialize,
1743  void>::value>* = nullptr) {
1744  Impl::apply_to_view_of_static_rank([=](auto view) { deep_copy(view, value); },
1745  dst);
1746 }
1747 
1749 template <class ExecSpace, class ST, class... SP>
1750 inline void deep_copy(
1751  const ExecSpace& e,
1752  typename ViewTraits<ST, SP...>::non_const_value_type& dst,
1753  const DynRankView<ST, SP...>& src,
1754  std::enable_if_t<std::is_same<typename ViewTraits<ST, SP...>::specialize,
1755  void>::value>* = 0) {
1756  deep_copy(e, dst, Impl::as_view_of_rank_n<0>(src));
1757 }
1758 
1759 template <class ST, class... SP>
1760 inline void deep_copy(
1761  typename ViewTraits<ST, SP...>::non_const_value_type& dst,
1762  const DynRankView<ST, SP...>& src,
1763  std::enable_if_t<std::is_same<typename ViewTraits<ST, SP...>::specialize,
1764  void>::value>* = 0) {
1765  deep_copy(dst, Impl::as_view_of_rank_n<0>(src));
1766 }
1767 
1768 //----------------------------------------------------------------------------
1774 template <class ExecSpace, class DstType, class SrcType>
1775 inline void deep_copy(
1776  const ExecSpace& exec_space, const DstType& dst, const SrcType& src,
1777  std::enable_if_t<
1778  (std::is_void<typename DstType::traits::specialize>::value &&
1779  std::is_void<typename SrcType::traits::specialize>::value &&
1780  (Kokkos::is_dyn_rank_view<DstType>::value ||
1781  Kokkos::is_dyn_rank_view<SrcType>::value))>* = nullptr) {
1782  static_assert(
1783  std::is_same<typename DstType::traits::value_type,
1784  typename DstType::traits::non_const_value_type>::value,
1785  "deep_copy requires non-const destination type");
1786 
1787  switch (rank(dst)) {
1788  case 0:
1789  deep_copy(exec_space, Impl::as_view_of_rank_n<0>(dst),
1790  Impl::as_view_of_rank_n<0>(src));
1791  break;
1792  case 1:
1793  deep_copy(exec_space, Impl::as_view_of_rank_n<1>(dst),
1794  Impl::as_view_of_rank_n<1>(src));
1795  break;
1796  case 2:
1797  deep_copy(exec_space, Impl::as_view_of_rank_n<2>(dst),
1798  Impl::as_view_of_rank_n<2>(src));
1799  break;
1800  case 3:
1801  deep_copy(exec_space, Impl::as_view_of_rank_n<3>(dst),
1802  Impl::as_view_of_rank_n<3>(src));
1803  break;
1804  case 4:
1805  deep_copy(exec_space, Impl::as_view_of_rank_n<4>(dst),
1806  Impl::as_view_of_rank_n<4>(src));
1807  break;
1808  case 5:
1809  deep_copy(exec_space, Impl::as_view_of_rank_n<5>(dst),
1810  Impl::as_view_of_rank_n<5>(src));
1811  break;
1812  case 6:
1813  deep_copy(exec_space, Impl::as_view_of_rank_n<6>(dst),
1814  Impl::as_view_of_rank_n<6>(src));
1815  break;
1816  case 7:
1817  deep_copy(exec_space, Impl::as_view_of_rank_n<7>(dst),
1818  Impl::as_view_of_rank_n<7>(src));
1819  break;
1820  default:
1821  Kokkos::Impl::throw_runtime_exception(
1822  "Calling DynRankView deep_copy with a view of unexpected rank " +
1823  std::to_string(rank(dst)));
1824  }
1825 }
1826 
1827 template <class DstType, class SrcType>
1828 inline void deep_copy(
1829  const DstType& dst, const SrcType& src,
1830  std::enable_if_t<
1831  (std::is_void<typename DstType::traits::specialize>::value &&
1832  std::is_void<typename SrcType::traits::specialize>::value &&
1833  (Kokkos::is_dyn_rank_view<DstType>::value ||
1834  Kokkos::is_dyn_rank_view<SrcType>::value))>* = nullptr) {
1835  static_assert(
1836  std::is_same<typename DstType::traits::value_type,
1837  typename DstType::traits::non_const_value_type>::value,
1838  "deep_copy requires non-const destination type");
1839 
1840  switch (rank(dst)) {
1841  case 0:
1842  deep_copy(Impl::as_view_of_rank_n<0>(dst),
1843  Impl::as_view_of_rank_n<0>(src));
1844  break;
1845  case 1:
1846  deep_copy(Impl::as_view_of_rank_n<1>(dst),
1847  Impl::as_view_of_rank_n<1>(src));
1848  break;
1849  case 2:
1850  deep_copy(Impl::as_view_of_rank_n<2>(dst),
1851  Impl::as_view_of_rank_n<2>(src));
1852  break;
1853  case 3:
1854  deep_copy(Impl::as_view_of_rank_n<3>(dst),
1855  Impl::as_view_of_rank_n<3>(src));
1856  break;
1857  case 4:
1858  deep_copy(Impl::as_view_of_rank_n<4>(dst),
1859  Impl::as_view_of_rank_n<4>(src));
1860  break;
1861  case 5:
1862  deep_copy(Impl::as_view_of_rank_n<5>(dst),
1863  Impl::as_view_of_rank_n<5>(src));
1864  break;
1865  case 6:
1866  deep_copy(Impl::as_view_of_rank_n<6>(dst),
1867  Impl::as_view_of_rank_n<6>(src));
1868  break;
1869  case 7:
1870  deep_copy(Impl::as_view_of_rank_n<7>(dst),
1871  Impl::as_view_of_rank_n<7>(src));
1872  break;
1873  default:
1874  Kokkos::Impl::throw_runtime_exception(
1875  "Calling DynRankView deep_copy with a view of unexpected rank " +
1876  std::to_string(rank(dst)));
1877  }
1878 }
1879 
1880 } // namespace Kokkos
1881 
1882 //----------------------------------------------------------------------------
1883 //----------------------------------------------------------------------------
1884 
1885 namespace Kokkos {
1886 namespace Impl {
1887 
1888 // Deduce Mirror Types
1889 template <class Space, class T, class... P>
1890 struct MirrorDRViewType {
1891  // The incoming view_type
1892  using src_view_type = typename Kokkos::DynRankView<T, P...>;
1893  // The memory space for the mirror view
1894  using memory_space = typename Space::memory_space;
1895  // Check whether it is the same memory space
1896  enum {
1897  is_same_memspace =
1898  std::is_same<memory_space, typename src_view_type::memory_space>::value
1899  };
1900  // The array_layout
1901  using array_layout = typename src_view_type::array_layout;
1902  // The data type (we probably want it non-const since otherwise we can't even
1903  // deep_copy to it.
1904  using data_type = typename src_view_type::non_const_data_type;
1905  // The destination view type if it is not the same memory space
1906  using dest_view_type = Kokkos::DynRankView<data_type, array_layout, Space>;
1907  // If it is the same memory_space return the existsing view_type
1908  // This will also keep the unmanaged trait if necessary
1909  using view_type =
1910  std::conditional_t<is_same_memspace, src_view_type, dest_view_type>;
1911 };
1912 
1913 template <class Space, class T, class... P>
1914 struct MirrorDRVType {
1915  // The incoming view_type
1916  using src_view_type = typename Kokkos::DynRankView<T, P...>;
1917  // The memory space for the mirror view
1918  using memory_space = typename Space::memory_space;
1919  // Check whether it is the same memory space
1920  enum {
1921  is_same_memspace =
1922  std::is_same<memory_space, typename src_view_type::memory_space>::value
1923  };
1924  // The array_layout
1925  using array_layout = typename src_view_type::array_layout;
1926  // The data type (we probably want it non-const since otherwise we can't even
1927  // deep_copy to it.
1928  using data_type = typename src_view_type::non_const_data_type;
1929  // The destination view type if it is not the same memory space
1930  using view_type = Kokkos::DynRankView<data_type, array_layout, Space>;
1931 };
1932 
1933 } // namespace Impl
1934 
1935 namespace Impl {
1936 template <class T, class... P, class... ViewCtorArgs>
1937 inline typename DynRankView<T, P...>::HostMirror create_mirror(
1938  const DynRankView<T, P...>& src,
1939  const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
1940  std::enable_if_t<!Impl::ViewCtorProp<ViewCtorArgs...>::has_memory_space>* =
1941  nullptr) {
1942  using src_type = DynRankView<T, P...>;
1943  using dst_type = typename src_type::HostMirror;
1944 
1945  using alloc_prop_input = Impl::ViewCtorProp<ViewCtorArgs...>;
1946 
1947  static_assert(
1948  !alloc_prop_input::has_label,
1949  "The view constructor arguments passed to Kokkos::create_mirror "
1950  "must not include a label!");
1951  static_assert(
1952  !alloc_prop_input::has_pointer,
1953  "The view constructor arguments passed to Kokkos::create_mirror must "
1954  "not include a pointer!");
1955  static_assert(
1956  !alloc_prop_input::allow_padding,
1957  "The view constructor arguments passed to Kokkos::create_mirror must "
1958  "not explicitly allow padding!");
1959 
1960  auto prop_copy = Impl::with_properties_if_unset(
1961  arg_prop, std::string(src.label()).append("_mirror"));
1962 
1963  return dst_type(prop_copy, Impl::reconstructLayout(src.layout(), src.rank()));
1964 }
1965 
1966 template <class T, class... P, class... ViewCtorArgs>
1967 inline auto create_mirror(
1968  const DynRankView<T, P...>& src,
1969  const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
1970  std::enable_if_t<Impl::ViewCtorProp<ViewCtorArgs...>::has_memory_space>* =
1971  nullptr) {
1972  using dst_type = typename Impl::MirrorDRVType<
1973  typename Impl::ViewCtorProp<ViewCtorArgs...>::memory_space, T,
1974  P...>::view_type;
1975 
1976  using alloc_prop_input = Impl::ViewCtorProp<ViewCtorArgs...>;
1977 
1978  static_assert(
1979  !alloc_prop_input::has_label,
1980  "The view constructor arguments passed to Kokkos::create_mirror "
1981  "must not include a label!");
1982  static_assert(
1983  !alloc_prop_input::has_pointer,
1984  "The view constructor arguments passed to Kokkos::create_mirror must "
1985  "not include a pointer!");
1986  static_assert(
1987  !alloc_prop_input::allow_padding,
1988  "The view constructor arguments passed to Kokkos::create_mirror must "
1989  "not explicitly allow padding!");
1990 
1991  auto prop_copy = Impl::with_properties_if_unset(
1992  arg_prop, std::string(src.label()).append("_mirror"));
1993 
1994  return dst_type(prop_copy, Impl::reconstructLayout(src.layout(), src.rank()));
1995 }
1996 
1997 } // namespace Impl
1998 
1999 // Create a mirror in host space
2000 template <class T, class... P>
2001 inline typename DynRankView<T, P...>::HostMirror create_mirror(
2002  const DynRankView<T, P...>& src,
2003  std::enable_if_t<std::is_same<typename ViewTraits<T, P...>::specialize,
2004  void>::value>* = nullptr) {
2005  return Impl::create_mirror(src, Kokkos::Impl::ViewCtorProp<>{});
2006 }
2007 
2008 template <class T, class... P>
2009 inline typename DynRankView<T, P...>::HostMirror create_mirror(
2010  Kokkos::Impl::WithoutInitializing_t wi, const DynRankView<T, P...>& src,
2011  std::enable_if_t<std::is_same<typename ViewTraits<T, P...>::specialize,
2012  void>::value>* = nullptr) {
2013  return Impl::create_mirror(src, Kokkos::view_alloc(wi));
2014 }
2015 
2016 template <class T, class... P, class... ViewCtorArgs>
2017 inline typename DynRankView<T, P...>::HostMirror create_mirror(
2018  const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
2019  const DynRankView<T, P...>& src,
2020  std::enable_if_t<
2021  std::is_void<typename ViewTraits<T, P...>::specialize>::value &&
2022  !Impl::ViewCtorProp<ViewCtorArgs...>::has_memory_space>* = nullptr) {
2023  return Impl::create_mirror(src, arg_prop);
2024 }
2025 
2026 // Create a mirror in a new space
2027 template <class Space, class T, class... P,
2028  typename Enable = std::enable_if_t<
2029  Kokkos::is_space<Space>::value &&
2030  std::is_void<typename ViewTraits<T, P...>::specialize>::value>>
2031 typename Impl::MirrorDRVType<Space, T, P...>::view_type create_mirror(
2032  const Space&, const Kokkos::DynRankView<T, P...>& src) {
2033  return Impl::create_mirror(
2034  src, Kokkos::view_alloc(typename Space::memory_space{}));
2035 }
2036 
2037 template <class Space, class T, class... P>
2038 typename Impl::MirrorDRVType<Space, T, P...>::view_type create_mirror(
2039  Kokkos::Impl::WithoutInitializing_t wi, const Space&,
2040  const Kokkos::DynRankView<T, P...>& src,
2041  std::enable_if_t<std::is_same<typename ViewTraits<T, P...>::specialize,
2042  void>::value>* = nullptr) {
2043  return Impl::create_mirror(
2044  src, Kokkos::view_alloc(wi, typename Space::memory_space{}));
2045 }
2046 
2047 template <class T, class... P, class... ViewCtorArgs>
2048 inline auto create_mirror(
2049  const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
2050  const DynRankView<T, P...>& src,
2051  std::enable_if_t<
2052  std::is_void<typename ViewTraits<T, P...>::specialize>::value &&
2053  Impl::ViewCtorProp<ViewCtorArgs...>::has_memory_space>* = nullptr) {
2054  using ReturnType = typename Impl::MirrorDRVType<
2055  typename Impl::ViewCtorProp<ViewCtorArgs...>::memory_space, T,
2056  P...>::view_type;
2057  return ReturnType{Impl::create_mirror(src, arg_prop)};
2058 }
2059 
2060 namespace Impl {
2061 template <class T, class... P, class... ViewCtorArgs>
2062 inline std::enable_if_t<
2063  !Impl::ViewCtorProp<ViewCtorArgs...>::has_memory_space &&
2064  std::is_same<
2065  typename DynRankView<T, P...>::memory_space,
2066  typename DynRankView<T, P...>::HostMirror::memory_space>::value &&
2067  std::is_same<
2068  typename DynRankView<T, P...>::data_type,
2069  typename DynRankView<T, P...>::HostMirror::data_type>::value,
2070  typename DynRankView<T, P...>::HostMirror>
2071 create_mirror_view(const DynRankView<T, P...>& src,
2072  const typename Impl::ViewCtorProp<ViewCtorArgs...>&) {
2073  return src;
2074 }
2075 
2076 template <class T, class... P, class... ViewCtorArgs>
2077 inline std::enable_if_t<
2078  !Impl::ViewCtorProp<ViewCtorArgs...>::has_memory_space &&
2079  !(std::is_same<
2080  typename DynRankView<T, P...>::memory_space,
2081  typename DynRankView<T, P...>::HostMirror::memory_space>::value &&
2082  std::is_same<
2083  typename DynRankView<T, P...>::data_type,
2084  typename DynRankView<T, P...>::HostMirror::data_type>::value),
2085  typename DynRankView<T, P...>::HostMirror>
2086 create_mirror_view(
2087  const DynRankView<T, P...>& src,
2088  const typename Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop) {
2089  return Kokkos::Impl::create_mirror(src, arg_prop);
2090 }
2091 
2092 template <class T, class... P, class... ViewCtorArgs,
2093  class = std::enable_if_t<
2094  Impl::ViewCtorProp<ViewCtorArgs...>::has_memory_space>>
2095 inline std::enable_if_t<
2096  Kokkos::is_space<
2097  typename Impl::ViewCtorProp<ViewCtorArgs...>::memory_space>::value &&
2098  Impl::MirrorDRViewType<
2099  typename Impl::ViewCtorProp<ViewCtorArgs...>::memory_space, T,
2100  P...>::is_same_memspace,
2101  typename Impl::MirrorDRViewType<
2102  typename Impl::ViewCtorProp<ViewCtorArgs...>::memory_space, T,
2103  P...>::view_type>
2104 create_mirror_view(const Kokkos::DynRankView<T, P...>& src,
2105  const typename Impl::ViewCtorProp<ViewCtorArgs...>&) {
2106  return src;
2107 }
2108 
2109 template <class T, class... P, class... ViewCtorArgs,
2110  class = std::enable_if_t<
2111  Impl::ViewCtorProp<ViewCtorArgs...>::has_memory_space>>
2112 inline std::enable_if_t<
2113  Kokkos::is_space<
2114  typename Impl::ViewCtorProp<ViewCtorArgs...>::memory_space>::value &&
2115  !Impl::MirrorDRViewType<
2116  typename Impl::ViewCtorProp<ViewCtorArgs...>::memory_space, T,
2117  P...>::is_same_memspace,
2118  typename Impl::MirrorDRViewType<
2119  typename Impl::ViewCtorProp<ViewCtorArgs...>::memory_space, T,
2120  P...>::view_type>
2121 create_mirror_view(
2122  const Kokkos::DynRankView<T, P...>& src,
2123  const typename Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop) {
2124  return Kokkos::Impl::create_mirror(src, arg_prop);
2125 }
2126 } // namespace Impl
2127 
2128 // Create a mirror view in host space
2129 template <class T, class... P>
2130 inline std::enable_if_t<
2131  (std::is_same<
2132  typename DynRankView<T, P...>::memory_space,
2133  typename DynRankView<T, P...>::HostMirror::memory_space>::value &&
2134  std::is_same<typename DynRankView<T, P...>::data_type,
2135  typename DynRankView<T, P...>::HostMirror::data_type>::value),
2136  typename DynRankView<T, P...>::HostMirror>
2137 create_mirror_view(const Kokkos::DynRankView<T, P...>& src) {
2138  return src;
2139 }
2140 
2141 template <class T, class... P>
2142 inline std::enable_if_t<
2143  !(std::is_same<
2144  typename DynRankView<T, P...>::memory_space,
2145  typename DynRankView<T, P...>::HostMirror::memory_space>::value &&
2146  std::is_same<
2147  typename DynRankView<T, P...>::data_type,
2148  typename DynRankView<T, P...>::HostMirror::data_type>::value),
2149  typename DynRankView<T, P...>::HostMirror>
2150 create_mirror_view(const Kokkos::DynRankView<T, P...>& src) {
2151  return Kokkos::create_mirror(src);
2152 }
2153 
2154 template <class T, class... P>
2155 inline auto create_mirror_view(Kokkos::Impl::WithoutInitializing_t wi,
2156  const DynRankView<T, P...>& src) {
2157  return Impl::create_mirror_view(src, Kokkos::view_alloc(wi));
2158 }
2159 
2160 // Create a mirror view in a new space
2161 // FIXME_C++17 Improve SFINAE here.
2162 template <class Space, class T, class... P,
2163  class Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
2164 inline typename Impl::MirrorDRViewType<Space, T, P...>::view_type
2165 create_mirror_view(
2166  const Space&, const Kokkos::DynRankView<T, P...>& src,
2167  std::enable_if_t<
2168  Impl::MirrorDRViewType<Space, T, P...>::is_same_memspace>* = nullptr) {
2169  return src;
2170 }
2171 
2172 // FIXME_C++17 Improve SFINAE here.
2173 template <class Space, class T, class... P,
2174  class Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
2175 inline typename Impl::MirrorDRViewType<Space, T, P...>::view_type
2176 create_mirror_view(
2177  const Space& space, const Kokkos::DynRankView<T, P...>& src,
2178  std::enable_if_t<
2179  !Impl::MirrorDRViewType<Space, T, P...>::is_same_memspace>* = nullptr) {
2180  return Kokkos::create_mirror(space, src);
2181 }
2182 
2183 template <class Space, class T, class... P>
2184 inline auto create_mirror_view(Kokkos::Impl::WithoutInitializing_t wi,
2185  const Space&,
2186  const Kokkos::DynRankView<T, P...>& src) {
2187  return Impl::create_mirror_view(
2188  src, Kokkos::view_alloc(typename Space::memory_space{}, wi));
2189 }
2190 
2191 template <class T, class... P, class... ViewCtorArgs>
2192 inline auto create_mirror_view(
2193  const typename Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
2194  const Kokkos::DynRankView<T, P...>& src) {
2195  return Impl::create_mirror_view(src, arg_prop);
2196 }
2197 
2198 template <class... ViewCtorArgs, class T, class... P>
2199 auto create_mirror_view_and_copy(
2200  const Impl::ViewCtorProp<ViewCtorArgs...>&,
2201  const Kokkos::DynRankView<T, P...>& src,
2202  std::enable_if_t<
2203  std::is_void<typename ViewTraits<T, P...>::specialize>::value &&
2204  Impl::MirrorDRViewType<
2205  typename Impl::ViewCtorProp<ViewCtorArgs...>::memory_space, T,
2206  P...>::is_same_memspace>* = nullptr) {
2207  using alloc_prop_input = Impl::ViewCtorProp<ViewCtorArgs...>;
2208  static_assert(
2209  alloc_prop_input::has_memory_space,
2210  "The view constructor arguments passed to "
2211  "Kokkos::create_mirror_view_and_copy must include a memory space!");
2212  static_assert(!alloc_prop_input::has_pointer,
2213  "The view constructor arguments passed to "
2214  "Kokkos::create_mirror_view_and_copy must "
2215  "not include a pointer!");
2216  static_assert(!alloc_prop_input::allow_padding,
2217  "The view constructor arguments passed to "
2218  "Kokkos::create_mirror_view_and_copy must "
2219  "not explicitly allow padding!");
2220 
2221  // same behavior as deep_copy(src, src)
2222  if (!alloc_prop_input::has_execution_space)
2223  fence(
2224  "Kokkos::create_mirror_view_and_copy: fence before returning src view");
2225  return src;
2226 }
2227 
2228 template <class... ViewCtorArgs, class T, class... P>
2229 auto create_mirror_view_and_copy(
2230  const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
2231  const Kokkos::DynRankView<T, P...>& src,
2232  std::enable_if_t<
2233  std::is_void<typename ViewTraits<T, P...>::specialize>::value &&
2234  !Impl::MirrorDRViewType<
2235  typename Impl::ViewCtorProp<ViewCtorArgs...>::memory_space, T,
2236  P...>::is_same_memspace>* = nullptr) {
2237  using alloc_prop_input = Impl::ViewCtorProp<ViewCtorArgs...>;
2238  static_assert(
2239  alloc_prop_input::has_memory_space,
2240  "The view constructor arguments passed to "
2241  "Kokkos::create_mirror_view_and_copy must include a memory space!");
2242  static_assert(!alloc_prop_input::has_pointer,
2243  "The view constructor arguments passed to "
2244  "Kokkos::create_mirror_view_and_copy must "
2245  "not include a pointer!");
2246  static_assert(!alloc_prop_input::allow_padding,
2247  "The view constructor arguments passed to "
2248  "Kokkos::create_mirror_view_and_copy must "
2249  "not explicitly allow padding!");
2250  using Space = typename alloc_prop_input::memory_space;
2251  using Mirror = typename Impl::MirrorDRViewType<Space, T, P...>::view_type;
2252 
2253  auto arg_prop_copy = Impl::with_properties_if_unset(
2254  arg_prop, std::string{}, WithoutInitializing,
2255  typename Space::execution_space{});
2256 
2257  std::string& label = Impl::get_property<Impl::LabelTag>(arg_prop_copy);
2258  if (label.empty()) label = src.label();
2259  auto mirror = typename Mirror::non_const_type{
2260  arg_prop_copy, Impl::reconstructLayout(src.layout(), src.rank())};
2261  if constexpr (alloc_prop_input::has_execution_space) {
2262  deep_copy(Impl::get_property<Impl::ExecutionSpaceTag>(arg_prop_copy),
2263  mirror, src);
2264  } else
2265  deep_copy(mirror, src);
2266  return mirror;
2267 }
2268 
2269 template <class Space, class T, class... P>
2270 auto create_mirror_view_and_copy(const Space&,
2271  const Kokkos::DynRankView<T, P...>& src,
2272  std::string const& name = "") {
2273  return create_mirror_view_and_copy(
2274  Kokkos::view_alloc(typename Space::memory_space{}, name), src);
2275 }
2276 
2277 } // namespace Kokkos
2278 
2279 //----------------------------------------------------------------------------
2280 //----------------------------------------------------------------------------
2281 
2282 namespace Kokkos {
2285 template <class... ViewCtorArgs, class T, class... P>
2286 inline void impl_resize(const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
2287  DynRankView<T, P...>& v, const size_t n0,
2288  const size_t n1, const size_t n2, const size_t n3,
2289  const size_t n4, const size_t n5, const size_t n6,
2290  const size_t n7) {
2291  using drview_type = DynRankView<T, P...>;
2292  using alloc_prop_input = Impl::ViewCtorProp<ViewCtorArgs...>;
2293 
2295  "Can only resize managed views");
2296  static_assert(!alloc_prop_input::has_label,
2297  "The view constructor arguments passed to Kokkos::resize "
2298  "must not include a label!");
2299  static_assert(!alloc_prop_input::has_pointer,
2300  "The view constructor arguments passed to Kokkos::resize must "
2301  "not include a pointer!");
2302  static_assert(!alloc_prop_input::has_memory_space,
2303  "The view constructor arguments passed to Kokkos::resize must "
2304  "not include a memory space instance!");
2305 
2306  auto prop_copy = Impl::with_properties_if_unset(
2307  arg_prop, v.label(), typename drview_type::execution_space{});
2308 
2309  drview_type v_resized(prop_copy, n0, n1, n2, n3, n4, n5, n6, n7);
2310 
2311  if constexpr (alloc_prop_input::has_execution_space)
2312  Kokkos::Impl::DynRankViewRemap<drview_type, drview_type>(
2313  Impl::get_property<Impl::ExecutionSpaceTag>(prop_copy), v_resized, v);
2314  else {
2315  Kokkos::Impl::DynRankViewRemap<drview_type, drview_type>(v_resized, v);
2316  Kokkos::fence("Kokkos::resize(DynRankView)");
2317  }
2318  v = v_resized;
2319 }
2320 
2321 template <class T, class... P>
2322 inline void resize(DynRankView<T, P...>& v,
2323  const size_t n0 = KOKKOS_INVALID_INDEX,
2324  const size_t n1 = KOKKOS_INVALID_INDEX,
2325  const size_t n2 = KOKKOS_INVALID_INDEX,
2326  const size_t n3 = KOKKOS_INVALID_INDEX,
2327  const size_t n4 = KOKKOS_INVALID_INDEX,
2328  const size_t n5 = KOKKOS_INVALID_INDEX,
2329  const size_t n6 = KOKKOS_INVALID_INDEX,
2330  const size_t n7 = KOKKOS_INVALID_INDEX) {
2331  impl_resize(Impl::ViewCtorProp<>{}, v, n0, n1, n2, n3, n4, n5, n6, n7);
2332 }
2333 
2334 template <class... ViewCtorArgs, class T, class... P>
2335 void resize(const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
2336  DynRankView<T, P...>& v,
2337  const size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2338  const size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2339  const size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2340  const size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2341  const size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2342  const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2343  const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
2344  const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) {
2345  impl_resize(arg_prop, v, n0, n1, n2, n3, n4, n5, n6, n7);
2346 }
2347 
2348 template <class I, class T, class... P>
2349 inline std::enable_if_t<Impl::is_view_ctor_property<I>::value> resize(
2350  const I& arg_prop, DynRankView<T, P...>& v,
2351  const size_t n0 = KOKKOS_INVALID_INDEX,
2352  const size_t n1 = KOKKOS_INVALID_INDEX,
2353  const size_t n2 = KOKKOS_INVALID_INDEX,
2354  const size_t n3 = KOKKOS_INVALID_INDEX,
2355  const size_t n4 = KOKKOS_INVALID_INDEX,
2356  const size_t n5 = KOKKOS_INVALID_INDEX,
2357  const size_t n6 = KOKKOS_INVALID_INDEX,
2358  const size_t n7 = KOKKOS_INVALID_INDEX) {
2359  impl_resize(Kokkos::view_alloc(arg_prop), v, n0, n1, n2, n3, n4, n5, n6, n7);
2360 }
2361 
2364 template <class... ViewCtorArgs, class T, class... P>
2365 inline void impl_realloc(DynRankView<T, P...>& v, const size_t n0,
2366  const size_t n1, const size_t n2, const size_t n3,
2367  const size_t n4, const size_t n5, const size_t n6,
2368  const size_t n7,
2369  const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop) {
2370  using drview_type = DynRankView<T, P...>;
2371  using alloc_prop_input = Impl::ViewCtorProp<ViewCtorArgs...>;
2372 
2374  "Can only realloc managed views");
2375  static_assert(!alloc_prop_input::has_label,
2376  "The view constructor arguments passed to Kokkos::realloc must "
2377  "not include a label!");
2378  static_assert(!alloc_prop_input::has_pointer,
2379  "The view constructor arguments passed to Kokkos::realloc must "
2380  "not include a pointer!");
2381  static_assert(!alloc_prop_input::has_memory_space,
2382  "The view constructor arguments passed to Kokkos::realloc must "
2383  "not include a memory space instance!");
2384 
2385  auto arg_prop_copy = Impl::with_properties_if_unset(arg_prop, v.label());
2386 
2387  v = drview_type(); // Deallocate first, if the only view to allocation
2388  v = drview_type(arg_prop_copy, n0, n1, n2, n3, n4, n5, n6, n7);
2389 }
2390 
2391 template <class T, class... P, class... ViewCtorArgs>
2392 inline void realloc(const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
2393  DynRankView<T, P...>& v,
2394  const size_t n0 = KOKKOS_INVALID_INDEX,
2395  const size_t n1 = KOKKOS_INVALID_INDEX,
2396  const size_t n2 = KOKKOS_INVALID_INDEX,
2397  const size_t n3 = KOKKOS_INVALID_INDEX,
2398  const size_t n4 = KOKKOS_INVALID_INDEX,
2399  const size_t n5 = KOKKOS_INVALID_INDEX,
2400  const size_t n6 = KOKKOS_INVALID_INDEX,
2401  const size_t n7 = KOKKOS_INVALID_INDEX) {
2402  impl_realloc(v, n0, n1, n2, n3, n4, n5, n6, n7, arg_prop);
2403 }
2404 
2405 template <class T, class... P>
2406 inline void realloc(DynRankView<T, P...>& v,
2407  const size_t n0 = KOKKOS_INVALID_INDEX,
2408  const size_t n1 = KOKKOS_INVALID_INDEX,
2409  const size_t n2 = KOKKOS_INVALID_INDEX,
2410  const size_t n3 = KOKKOS_INVALID_INDEX,
2411  const size_t n4 = KOKKOS_INVALID_INDEX,
2412  const size_t n5 = KOKKOS_INVALID_INDEX,
2413  const size_t n6 = KOKKOS_INVALID_INDEX,
2414  const size_t n7 = KOKKOS_INVALID_INDEX) {
2415  impl_realloc(v, n0, n1, n2, n3, n4, n5, n6, n7, Impl::ViewCtorProp<>{});
2416 }
2417 
2418 template <class I, class T, class... P>
2419 inline std::enable_if_t<Impl::is_view_ctor_property<I>::value> realloc(
2420  const I& arg_prop, DynRankView<T, P...>& v,
2421  const size_t n0 = KOKKOS_INVALID_INDEX,
2422  const size_t n1 = KOKKOS_INVALID_INDEX,
2423  const size_t n2 = KOKKOS_INVALID_INDEX,
2424  const size_t n3 = KOKKOS_INVALID_INDEX,
2425  const size_t n4 = KOKKOS_INVALID_INDEX,
2426  const size_t n5 = KOKKOS_INVALID_INDEX,
2427  const size_t n6 = KOKKOS_INVALID_INDEX,
2428  const size_t n7 = KOKKOS_INVALID_INDEX) {
2429  impl_realloc(v, n0, n1, n2, n3, n4, n5, n6, n7, Kokkos::view_alloc(arg_prop));
2430 }
2431 
2432 } // namespace Kokkos
2433 
2434 #ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_DYNRANKVIEW
2435 #undef KOKKOS_IMPL_PUBLIC_INCLUDE
2436 #undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_DYNRANKVIEW
2437 #endif
2438 #endif
Memory layout tag indicating left-to-right (Fortran scheme) striding of multi-indices.
KOKKOS_INLINE_FUNCTION bool dyn_rank_view_verify_operator_bounds(const iType0 &, const MapType &)
Debug bounds-checking routines.
Memory layout tag indicated arbitrarily strided multi-index mapping into contiguous memory...
View to an array of data.
Memory management for host memory.
Memory layout tag indicating right-to-left (C or lexigraphical scheme) striding of multi-indices...
Assign compatible default mappings.
ReturnType
Execution policy for work over a range of an integral type.
Traits class for accessing attributes of a View.