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