Kokkos Core Kernels Package  Version of the Day
Kokkos_View.hpp
1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Kokkos v. 2.0
6 // Copyright (2014) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact H. Carter Edwards (hcedwar@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 */
43 
44 #ifndef KOKKOS_VIEW_HPP
45 #define KOKKOS_VIEW_HPP
46 
47 #include <type_traits>
48 #include <string>
49 #include <algorithm>
50 #include <initializer_list>
51 
52 #include <Kokkos_Core_fwd.hpp>
53 #include <Kokkos_HostSpace.hpp>
54 #include <Kokkos_MemoryTraits.hpp>
55 #include <Kokkos_ExecPolicy.hpp>
56 
57 //----------------------------------------------------------------------------
58 //----------------------------------------------------------------------------
59 
60 namespace Kokkos {
61 namespace Experimental {
62 namespace Impl {
63 
64 template< class DataType >
65 struct ViewArrayAnalysis ;
66 
67 template< class DataType , class ArrayLayout
68  , typename ValueType =
69  typename ViewArrayAnalysis< DataType >::non_const_value_type
70  >
71 struct ViewDataAnalysis ;
72 
73 template< class , class ... >
74 class ViewMapping { public: enum { is_assignable = false }; };
75 
76 } /* namespace Impl */
77 } /* namespace Experimental */
78 } /* namespace Kokkos */
79 
80 namespace Kokkos {
81 namespace Impl {
82 
83 using Kokkos::Experimental::Impl::ViewMapping ;
84 using Kokkos::Experimental::Impl::ViewDataAnalysis ;
85 
86 } /* namespace Impl */
87 } /* namespace Kokkos */
88 
89 //----------------------------------------------------------------------------
90 //----------------------------------------------------------------------------
91 
92 namespace Kokkos {
93 
111 template< class DataType , class ... Properties >
112 struct ViewTraits ;
113 
114 template<>
115 struct ViewTraits< void >
116 {
117  typedef void execution_space ;
118  typedef void memory_space ;
119  typedef void HostMirrorSpace ;
120  typedef void array_layout ;
121  typedef void memory_traits ;
122 };
123 
124 template< class ... Prop >
125 struct ViewTraits< void , void , Prop ... >
126 {
127  // Ignore an extraneous 'void'
128  typedef typename ViewTraits<void,Prop...>::execution_space execution_space ;
129  typedef typename ViewTraits<void,Prop...>::memory_space memory_space ;
130  typedef typename ViewTraits<void,Prop...>::HostMirrorSpace HostMirrorSpace ;
131  typedef typename ViewTraits<void,Prop...>::array_layout array_layout ;
132  typedef typename ViewTraits<void,Prop...>::memory_traits memory_traits ;
133 };
134 
135 template< class ArrayLayout , class ... Prop >
136 struct ViewTraits< typename std::enable_if< Kokkos::Impl::is_array_layout<ArrayLayout>::value >::type , ArrayLayout , Prop ... >
137 {
138  // Specify layout, keep subsequent space and memory traits arguments
139 
140  typedef typename ViewTraits<void,Prop...>::execution_space execution_space ;
141  typedef typename ViewTraits<void,Prop...>::memory_space memory_space ;
142  typedef typename ViewTraits<void,Prop...>::HostMirrorSpace HostMirrorSpace ;
143  typedef ArrayLayout array_layout ;
144  typedef typename ViewTraits<void,Prop...>::memory_traits memory_traits ;
145 };
146 
147 template< class Space , class ... Prop >
148 struct ViewTraits< typename std::enable_if< Kokkos::Impl::is_space<Space>::value >::type , Space , Prop ... >
149 {
150  // Specify Space, memory traits should be the only subsequent argument.
151 
152  static_assert( std::is_same< typename ViewTraits<void,Prop...>::execution_space , void >::value &&
153  std::is_same< typename ViewTraits<void,Prop...>::memory_space , void >::value &&
154  std::is_same< typename ViewTraits<void,Prop...>::HostMirrorSpace , void >::value &&
155  std::is_same< typename ViewTraits<void,Prop...>::array_layout , void >::value
156  , "Only one View Execution or Memory Space template argument" );
157 
158  typedef typename Space::execution_space execution_space ;
159  typedef typename Space::memory_space memory_space ;
160  typedef typename Kokkos::Impl::HostMirror< Space >::Space HostMirrorSpace ;
161  typedef typename execution_space::array_layout array_layout ;
162  typedef typename ViewTraits<void,Prop...>::memory_traits memory_traits ;
163 };
164 
165 template< class MemoryTraits , class ... Prop >
166 struct ViewTraits< typename std::enable_if< Kokkos::Impl::is_memory_traits<MemoryTraits>::value >::type , MemoryTraits , Prop ... >
167 {
168  // Specify memory trait, should not be any subsequent arguments
169 
170  static_assert( std::is_same< typename ViewTraits<void,Prop...>::execution_space , void >::value &&
171  std::is_same< typename ViewTraits<void,Prop...>::memory_space , void >::value &&
172  std::is_same< typename ViewTraits<void,Prop...>::array_layout , void >::value &&
173  std::is_same< typename ViewTraits<void,Prop...>::memory_traits , void >::value
174  , "MemoryTrait is the final optional template argument for a View" );
175 
176  typedef void execution_space ;
177  typedef void memory_space ;
178  typedef void HostMirrorSpace ;
179  typedef void array_layout ;
180  typedef MemoryTraits memory_traits ;
181 };
182 
183 
184 template< class DataType , class ... Properties >
185 struct ViewTraits {
186 private:
187 
188  // Unpack the properties arguments
189  typedef ViewTraits< void , Properties ... > prop ;
190 
191  typedef typename
192  std::conditional< ! std::is_same< typename prop::execution_space , void >::value
193  , typename prop::execution_space
194  , Kokkos::DefaultExecutionSpace
195  >::type
196  ExecutionSpace ;
197 
198  typedef typename
199  std::conditional< ! std::is_same< typename prop::memory_space , void >::value
200  , typename prop::memory_space
201  , typename ExecutionSpace::memory_space
202  >::type
203  MemorySpace ;
204 
205  typedef typename
206  std::conditional< ! std::is_same< typename prop::array_layout , void >::value
207  , typename prop::array_layout
208  , typename ExecutionSpace::array_layout
209  >::type
210  ArrayLayout ;
211 
212  typedef typename
213  std::conditional
214  < ! std::is_same< typename prop::HostMirrorSpace , void >::value
215  , typename prop::HostMirrorSpace
216  , typename Kokkos::Impl::HostMirror< ExecutionSpace >::Space
217  >::type
218  HostMirrorSpace ;
219 
220  typedef typename
221  std::conditional< ! std::is_same< typename prop::memory_traits , void >::value
222  , typename prop::memory_traits
223  , typename Kokkos::MemoryManaged
224  >::type
225  MemoryTraits ;
226 
227  // Analyze data type's properties,
228  // May be specialized based upon the layout and value type
229  typedef Kokkos::Impl::ViewDataAnalysis< DataType , ArrayLayout > data_analysis ;
230 
231 public:
232 
233  //------------------------------------
234  // Data type traits:
235 
236  typedef typename data_analysis::type data_type ;
237  typedef typename data_analysis::const_type const_data_type ;
238  typedef typename data_analysis::non_const_type non_const_data_type ;
239 
240  //------------------------------------
241  // Compatible array of trivial type traits:
242 
243  typedef typename data_analysis::scalar_array_type scalar_array_type ;
244  typedef typename data_analysis::const_scalar_array_type const_scalar_array_type ;
245  typedef typename data_analysis::non_const_scalar_array_type non_const_scalar_array_type ;
246 
247  //------------------------------------
248  // Value type traits:
249 
250  typedef typename data_analysis::value_type value_type ;
251  typedef typename data_analysis::const_value_type const_value_type ;
252  typedef typename data_analysis::non_const_value_type non_const_value_type ;
253 
254  //------------------------------------
255  // Mapping traits:
256 
257  typedef ArrayLayout array_layout ;
258  typedef typename data_analysis::dimension dimension ;
259  typedef typename data_analysis::specialize specialize /* mapping specialization tag */ ;
260 
261  enum { rank = dimension::rank };
262  enum { rank_dynamic = dimension::rank_dynamic };
263 
264  //------------------------------------
265  // Execution space, memory space, memory access traits, and host mirror space.
266 
267  typedef ExecutionSpace execution_space ;
268  typedef MemorySpace memory_space ;
270  typedef MemoryTraits memory_traits ;
271  typedef HostMirrorSpace host_mirror_space ;
272 
273  typedef typename MemorySpace::size_type size_type ;
274 
275  enum { is_hostspace = std::is_same< MemorySpace , HostSpace >::value };
276  enum { is_managed = MemoryTraits::Unmanaged == 0 };
277  enum { is_random_access = MemoryTraits::RandomAccess == 1 };
278 
279  //------------------------------------
280 };
281 
364 template< class DataType , class ... Properties >
365 class View ;
366 
367 } /* namespace Kokkos */
368 
369 //----------------------------------------------------------------------------
370 //----------------------------------------------------------------------------
371 
372 #include <impl/Kokkos_ViewMapping.hpp>
373 #include <impl/Kokkos_ViewArray.hpp>
374 
375 //----------------------------------------------------------------------------
376 //----------------------------------------------------------------------------
377 
378 namespace Kokkos {
379 
380 namespace {
381 
382 constexpr Kokkos::Impl::ALL_t
383  ALL = Kokkos::Impl::ALL_t();
384 
385 constexpr Kokkos::Impl::WithoutInitializing_t
386  WithoutInitializing = Kokkos::Impl::WithoutInitializing_t();
387 
388 constexpr Kokkos::Impl::AllowPadding_t
389  AllowPadding = Kokkos::Impl::AllowPadding_t();
390 
391 }
392 
402 template< class ... Args >
403 inline
404 Impl::ViewCtorProp< typename Impl::ViewCtorProp< void , Args >::type ... >
405 view_alloc( Args const & ... args )
406 {
407  typedef
408  Impl::ViewCtorProp< typename Impl::ViewCtorProp< void , Args >::type ... >
409  return_type ;
410 
411  static_assert( ! return_type::has_pointer
412  , "Cannot give pointer-to-memory for view allocation" );
413 
414  return return_type( args... );
415 }
416 
417 template< class ... Args >
418 inline
419 Impl::ViewCtorProp< typename Impl::ViewCtorProp< void , Args >::type ... >
420 view_wrap( Args const & ... args )
421 {
422  typedef
423  Impl::ViewCtorProp< typename Impl::ViewCtorProp< void , Args >::type ... >
424  return_type ;
425 
426  static_assert( ! return_type::has_memory_space &&
427  ! return_type::has_execution_space &&
428  ! return_type::has_label &&
429  return_type::has_pointer
430  , "Must only give pointer-to-memory for view wrapping" );
431 
432  return return_type( args... );
433 }
434 
435 } /* namespace Kokkos */
436 
437 //----------------------------------------------------------------------------
438 //----------------------------------------------------------------------------
439 
440 namespace Kokkos {
441 
442 template< class DataType , class ... Properties >
443 class View ;
444 
445 template< class > struct is_view : public std::false_type {};
446 
447 template< class D, class ... P >
448 struct is_view< View<D,P...> > : public std::true_type {};
449 
450 template< class D, class ... P >
451 struct is_view< const View<D,P...> > : public std::true_type {};
452 
453 template< class DataType , class ... Properties >
454 class View : public ViewTraits< DataType , Properties ... > {
455 private:
456 
457  template< class , class ... > friend class View ;
458  template< class , class ... > friend class Kokkos::Impl::ViewMapping ;
459 
460 public:
461 
462  typedef ViewTraits< DataType , Properties ... > traits ;
463 
464 private:
465 
466  typedef Kokkos::Impl::ViewMapping< traits , void > map_type ;
467  typedef Kokkos::Impl::SharedAllocationTracker track_type ;
468 
469  track_type m_track ;
470  map_type m_map ;
471 
472 public:
473 
474  //----------------------------------------
476  typedef View< typename traits::scalar_array_type ,
477  typename traits::array_layout ,
478  typename traits::device_type ,
479  typename traits::memory_traits >
481 
483  typedef View< typename traits::const_data_type ,
484  typename traits::array_layout ,
485  typename traits::device_type ,
486  typename traits::memory_traits >
488 
490  typedef View< typename traits::non_const_data_type ,
491  typename traits::array_layout ,
492  typename traits::device_type ,
493  typename traits::memory_traits >
495 
497  typedef View< typename traits::non_const_data_type ,
498  typename traits::array_layout ,
499  typename traits::host_mirror_space >
501 
502  //----------------------------------------
503  // Domain rank and extents
504 
505  enum { Rank = map_type::Rank };
506 
509  //KOKKOS_INLINE_FUNCTION
510  //static
511  //constexpr unsigned rank() { return map_type::Rank; }
512 
513  template< typename iType >
514  KOKKOS_INLINE_FUNCTION constexpr
515  typename std::enable_if< std::is_integral<iType>::value , size_t >::type
516  extent( const iType & r ) const
517  { return m_map.extent(r); }
518 
519  template< typename iType >
520  KOKKOS_INLINE_FUNCTION constexpr
521  typename std::enable_if< std::is_integral<iType>::value , int >::type
522  extent_int( const iType & r ) const
523  { return static_cast<int>(m_map.extent(r)); }
524 
525  KOKKOS_INLINE_FUNCTION constexpr
526  typename traits::array_layout layout() const
527  { return m_map.layout(); }
528 
529  //----------------------------------------
530  /* Deprecate all 'dimension' functions in favor of
531  * ISO/C++ vocabulary 'extent'.
532  */
533 
534  template< typename iType >
535  KOKKOS_INLINE_FUNCTION constexpr
536  typename std::enable_if< std::is_integral<iType>::value , size_t >::type
537  dimension( const iType & r ) const { return extent( r ); }
538 
539  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_0() const { return m_map.dimension_0(); }
540  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_1() const { return m_map.dimension_1(); }
541  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_2() const { return m_map.dimension_2(); }
542  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_3() const { return m_map.dimension_3(); }
543  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_4() const { return m_map.dimension_4(); }
544  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_5() const { return m_map.dimension_5(); }
545  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_6() const { return m_map.dimension_6(); }
546  KOKKOS_INLINE_FUNCTION constexpr size_t dimension_7() const { return m_map.dimension_7(); }
547 
548  //----------------------------------------
549 
550  KOKKOS_INLINE_FUNCTION constexpr size_t size() const { return m_map.dimension_0() *
551  m_map.dimension_1() *
552  m_map.dimension_2() *
553  m_map.dimension_3() *
554  m_map.dimension_4() *
555  m_map.dimension_5() *
556  m_map.dimension_6() *
557  m_map.dimension_7(); }
558 
559  KOKKOS_INLINE_FUNCTION constexpr size_t stride_0() const { return m_map.stride_0(); }
560  KOKKOS_INLINE_FUNCTION constexpr size_t stride_1() const { return m_map.stride_1(); }
561  KOKKOS_INLINE_FUNCTION constexpr size_t stride_2() const { return m_map.stride_2(); }
562  KOKKOS_INLINE_FUNCTION constexpr size_t stride_3() const { return m_map.stride_3(); }
563  KOKKOS_INLINE_FUNCTION constexpr size_t stride_4() const { return m_map.stride_4(); }
564  KOKKOS_INLINE_FUNCTION constexpr size_t stride_5() const { return m_map.stride_5(); }
565  KOKKOS_INLINE_FUNCTION constexpr size_t stride_6() const { return m_map.stride_6(); }
566  KOKKOS_INLINE_FUNCTION constexpr size_t stride_7() const { return m_map.stride_7(); }
567 
568  template< typename iType >
569  KOKKOS_INLINE_FUNCTION void stride( iType * const s ) const { m_map.stride(s); }
570 
571  //----------------------------------------
572  // Range span is the span which contains all members.
573 
574  typedef typename map_type::reference_type reference_type ;
575  typedef typename map_type::pointer_type pointer_type ;
576 
577  enum { reference_type_is_lvalue_reference = std::is_lvalue_reference< reference_type >::value };
578 
579  KOKKOS_INLINE_FUNCTION constexpr size_t span() const { return m_map.span(); }
580  // Deprecated, use 'span()' instead
581  KOKKOS_INLINE_FUNCTION constexpr size_t capacity() const { return m_map.span(); }
582  KOKKOS_INLINE_FUNCTION constexpr bool span_is_contiguous() const { return m_map.span_is_contiguous(); }
583  KOKKOS_INLINE_FUNCTION constexpr pointer_type data() const { return m_map.data(); }
584 
585  // Deprecated, use 'span_is_contigous()' instead
586  KOKKOS_INLINE_FUNCTION constexpr bool is_contiguous() const { return m_map.span_is_contiguous(); }
587  // Deprecated, use 'data()' instead
588  KOKKOS_INLINE_FUNCTION constexpr pointer_type ptr_on_device() const { return m_map.data(); }
589 
590  //----------------------------------------
591  // Allow specializations to query their specialized map
592 
593  KOKKOS_INLINE_FUNCTION
594  const Kokkos::Impl::ViewMapping< traits , void > &
595  implementation_map() const { return m_map ; }
596 
597  //----------------------------------------
598 
599 private:
600 
601  enum {
602  is_layout_left = std::is_same< typename traits::array_layout
603  , Kokkos::LayoutLeft >::value ,
604 
605  is_layout_right = std::is_same< typename traits::array_layout
606  , Kokkos::LayoutRight >::value ,
607 
608  is_layout_stride = std::is_same< typename traits::array_layout
609  , Kokkos::LayoutStride >::value ,
610 
611  is_default_map =
612  std::is_same< typename traits::specialize , void >::value &&
613  ( is_layout_left || is_layout_right || is_layout_stride )
614  };
615 
616  template< class Space , bool = Kokkos::Impl::MemorySpaceAccess< Space , typename traits::memory_space >::accessible > struct verify_space
617  { KOKKOS_FORCEINLINE_FUNCTION static void check() {} };
618 
619  template< class Space > struct verify_space<Space,false>
620  { KOKKOS_FORCEINLINE_FUNCTION static void check()
621  { Kokkos::abort("Kokkos::View ERROR: attempt to access inaccessible memory space"); };
622  };
623 
624 #if defined( KOKKOS_ENABLE_DEBUG_BOUNDS_CHECK )
625 
626 #define KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( ARG ) \
627  View::template verify_space< Kokkos::Impl::ActiveExecutionMemorySpace >::check(); \
628  Kokkos::Impl::view_verify_operator_bounds< typename traits::memory_space > ARG ;
629 
630 #else
631 
632 #define KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( ARG ) \
633  View::template verify_space< Kokkos::Impl::ActiveExecutionMemorySpace >::check();
634 
635 #endif
636 
637 public:
638 
639  //------------------------------
640  // Rank 0 operator()
641 
642  template< class ... Args >
643  KOKKOS_FORCEINLINE_FUNCTION
644  typename std::enable_if<( Kokkos::Impl::are_integral<Args...>::value
645  && ( 0 == Rank )
646  ), reference_type >::type
647  operator()( Args ... args ) const
648  {
649  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,args...) )
650  return m_map.reference();
651  }
652 
653  //------------------------------
654  // Rank 1 operator()
655 
656  template< typename I0
657  , class ... Args >
658  KOKKOS_FORCEINLINE_FUNCTION
659  typename std::enable_if<
660  ( Kokkos::Impl::are_integral<I0,Args...>::value
661  && ( 1 == Rank )
662  && ! is_default_map
663  ), reference_type >::type
664  operator()( const I0 & i0
665  , Args ... args ) const
666  {
667  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,args...) )
668  return m_map.reference(i0);
669  }
670 
671  template< typename I0
672  , class ... Args >
673  KOKKOS_FORCEINLINE_FUNCTION
674  typename std::enable_if<
675  ( Kokkos::Impl::are_integral<I0,Args...>::value
676  && ( 1 == Rank )
677  && is_default_map
678  && ! is_layout_stride
679  ), reference_type >::type
680  operator()( const I0 & i0
681  , Args ... args ) const
682  {
683  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,args...) )
684  return m_map.m_handle[ i0 ];
685  }
686 
687  template< typename I0
688  , class ... Args >
689  KOKKOS_FORCEINLINE_FUNCTION
690  typename std::enable_if<
691  ( Kokkos::Impl::are_integral<I0,Args...>::value
692  && ( 1 == Rank )
693  && is_default_map
694  && is_layout_stride
695  ), reference_type >::type
696  operator()( const I0 & i0
697  , Args ... args ) const
698  {
699  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,args...) )
700  return m_map.m_handle[ m_map.m_offset.m_stride.S0 * i0 ];
701  }
702 
703  //------------------------------
704  // Rank 1 operator[]
705 
706  template< typename I0 >
707  KOKKOS_FORCEINLINE_FUNCTION
708  typename std::enable_if<
709  ( Kokkos::Impl::are_integral<I0>::value
710  && ( 1 == Rank )
711  && ! is_default_map
712  ), reference_type >::type
713  operator[]( const I0 & i0 ) const
714  {
715  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0) )
716  return m_map.reference(i0);
717  }
718 
719  template< typename I0 >
720  KOKKOS_FORCEINLINE_FUNCTION
721  typename std::enable_if<
722  ( Kokkos::Impl::are_integral<I0>::value
723  && ( 1 == Rank )
724  && is_default_map
725  && ! is_layout_stride
726  ), reference_type >::type
727  operator[]( const I0 & i0 ) const
728  {
729  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0) )
730  return m_map.m_handle[ i0 ];
731  }
732 
733  template< typename I0 >
734  KOKKOS_FORCEINLINE_FUNCTION
735  typename std::enable_if<
736  ( Kokkos::Impl::are_integral<I0>::value
737  && ( 1 == Rank )
738  && is_default_map
739  && is_layout_stride
740  ), reference_type >::type
741  operator[]( const I0 & i0 ) const
742  {
743  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0) )
744  return m_map.m_handle[ m_map.m_offset.m_stride.S0 * i0 ];
745  }
746 
747  //------------------------------
748  // Rank 2
749 
750  template< typename I0 , typename I1
751  , class ... Args >
752  KOKKOS_FORCEINLINE_FUNCTION
753  typename std::enable_if<
754  ( Kokkos::Impl::are_integral<I0,I1,Args...>::value
755  && ( 2 == Rank )
756  && ! is_default_map
757  ), reference_type >::type
758  operator()( const I0 & i0 , const I1 & i1
759  , Args ... args ) const
760  {
761  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,args...) )
762  return m_map.reference(i0,i1);
763  }
764 
765  template< typename I0 , typename I1
766  , class ... Args >
767  KOKKOS_FORCEINLINE_FUNCTION
768  typename std::enable_if<
769  ( Kokkos::Impl::are_integral<I0,I1,Args...>::value
770  && ( 2 == Rank )
771  && is_default_map
772  && is_layout_left && ( traits::rank_dynamic == 0 )
773  ), reference_type >::type
774  operator()( const I0 & i0 , const I1 & i1
775  , Args ... args ) const
776  {
777  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,args...) )
778  return m_map.m_handle[ i0 + m_map.m_offset.m_dim.N0 * i1 ];
779  }
780 
781  template< typename I0 , typename I1
782  , class ... Args >
783  KOKKOS_FORCEINLINE_FUNCTION
784  typename std::enable_if<
785  ( Kokkos::Impl::are_integral<I0,I1,Args...>::value
786  && ( 2 == Rank )
787  && is_default_map
788  && is_layout_left && ( traits::rank_dynamic != 0 )
789  ), reference_type >::type
790  operator()( const I0 & i0 , const I1 & i1
791  , Args ... args ) const
792  {
793  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,args...) )
794  return m_map.m_handle[ i0 + m_map.m_offset.m_stride * i1 ];
795  }
796 
797  template< typename I0 , typename I1
798  , class ... Args >
799  KOKKOS_FORCEINLINE_FUNCTION
800  typename std::enable_if<
801  ( Kokkos::Impl::are_integral<I0,I1,Args...>::value
802  && ( 2 == Rank )
803  && is_default_map
804  && is_layout_right && ( traits::rank_dynamic == 0 )
805  ), reference_type >::type
806  operator()( const I0 & i0 , const I1 & i1
807  , Args ... args ) const
808  {
809  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,args...) )
810  return m_map.m_handle[ i1 + m_map.m_offset.m_dim.N1 * i0 ];
811  }
812 
813  template< typename I0 , typename I1
814  , class ... Args >
815  KOKKOS_FORCEINLINE_FUNCTION
816  typename std::enable_if<
817  ( Kokkos::Impl::are_integral<I0,I1,Args...>::value
818  && ( 2 == Rank )
819  && is_default_map
820  && is_layout_right && ( traits::rank_dynamic != 0 )
821  ), reference_type >::type
822  operator()( const I0 & i0 , const I1 & i1
823  , Args ... args ) const
824  {
825  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,args...) )
826  return m_map.m_handle[ i1 + m_map.m_offset.m_stride * i0 ];
827  }
828 
829  template< typename I0 , typename I1
830  , class ... Args >
831  KOKKOS_FORCEINLINE_FUNCTION
832  typename std::enable_if<
833  ( Kokkos::Impl::are_integral<I0,I1,Args...>::value
834  && ( 2 == Rank )
835  && is_default_map
836  && is_layout_stride
837  ), reference_type >::type
838  operator()( const I0 & i0 , const I1 & i1
839  , Args ... args ) const
840  {
841  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,args...) )
842  return m_map.m_handle[ i0 * m_map.m_offset.m_stride.S0 +
843  i1 * m_map.m_offset.m_stride.S1 ];
844  }
845 
846  //------------------------------
847  // Rank 3
848 
849  template< typename I0 , typename I1 , typename I2
850  , class ... Args >
851  KOKKOS_FORCEINLINE_FUNCTION
852  typename std::enable_if<
853  ( Kokkos::Impl::are_integral<I0,I1,I2,Args...>::value
854  && ( 3 == Rank )
855  && is_default_map
856  ), reference_type >::type
857  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2
858  , Args ... args ) const
859  {
860  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,i2,args...) )
861  return m_map.m_handle[ m_map.m_offset(i0,i1,i2) ];
862  }
863 
864  template< typename I0 , typename I1 , typename I2
865  , class ... Args >
866  KOKKOS_FORCEINLINE_FUNCTION
867  typename std::enable_if<
868  ( Kokkos::Impl::are_integral<I0,I1,I2,Args...>::value
869  && ( 3 == Rank )
870  && ! is_default_map
871  ), reference_type >::type
872  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2
873  , Args ... args ) const
874  {
875  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,i2,args...) )
876  return m_map.reference(i0,i1,i2);
877  }
878 
879  //------------------------------
880  // Rank 4
881 
882  template< typename I0 , typename I1 , typename I2 , typename I3
883  , class ... Args >
884  KOKKOS_FORCEINLINE_FUNCTION
885  typename std::enable_if<
886  ( Kokkos::Impl::are_integral<I0,I1,I2,I3,Args...>::value
887  && ( 4 == Rank )
888  && is_default_map
889  ), reference_type >::type
890  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
891  , Args ... args ) const
892  {
893  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,i2,i3,args...) )
894  return m_map.m_handle[ m_map.m_offset(i0,i1,i2,i3) ];
895  }
896 
897  template< typename I0 , typename I1 , typename I2 , typename I3
898  , class ... Args >
899  KOKKOS_FORCEINLINE_FUNCTION
900  typename std::enable_if<
901  ( Kokkos::Impl::are_integral<I0,I1,I2,I3,Args...>::value
902  && ( 4 == Rank )
903  && ! is_default_map
904  ), reference_type >::type
905  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
906  , Args ... args ) const
907  {
908  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,i2,i3,args...) )
909  return m_map.reference(i0,i1,i2,i3);
910  }
911 
912  //------------------------------
913  // Rank 5
914 
915  template< typename I0 , typename I1 , typename I2 , typename I3
916  , typename I4
917  , class ... Args >
918  KOKKOS_FORCEINLINE_FUNCTION
919  typename std::enable_if<
920  ( Kokkos::Impl::are_integral<I0,I1,I2,I3,I4,Args...>::value
921  && ( 5 == Rank )
922  && is_default_map
923  ), reference_type >::type
924  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
925  , const I4 & i4
926  , Args ... args ) const
927  {
928  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,i2,i3,i4,args...) )
929  return m_map.m_handle[ m_map.m_offset(i0,i1,i2,i3,i4) ];
930  }
931 
932  template< typename I0 , typename I1 , typename I2 , typename I3
933  , typename I4
934  , class ... Args >
935  KOKKOS_FORCEINLINE_FUNCTION
936  typename std::enable_if<
937  ( Kokkos::Impl::are_integral<I0,I1,I2,I3,I4,Args...>::value
938  && ( 5 == Rank )
939  && ! is_default_map
940  ), reference_type >::type
941  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
942  , const I4 & i4
943  , Args ... args ) const
944  {
945  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,i2,i3,i4,args...) )
946  return m_map.reference(i0,i1,i2,i3,i4);
947  }
948 
949  //------------------------------
950  // Rank 6
951 
952  template< typename I0 , typename I1 , typename I2 , typename I3
953  , typename I4 , typename I5
954  , class ... Args >
955  KOKKOS_FORCEINLINE_FUNCTION
956  typename std::enable_if<
957  ( Kokkos::Impl::are_integral<I0,I1,I2,I3,I4,I5,Args...>::value
958  && ( 6 == Rank )
959  && is_default_map
960  ), reference_type >::type
961  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
962  , const I4 & i4 , const I5 & i5
963  , Args ... args ) const
964  {
965  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,i2,i3,i4,i5,args...) )
966  return m_map.m_handle[ m_map.m_offset(i0,i1,i2,i3,i4,i5) ];
967  }
968 
969  template< typename I0 , typename I1 , typename I2 , typename I3
970  , typename I4 , typename I5
971  , class ... Args >
972  KOKKOS_FORCEINLINE_FUNCTION
973  typename std::enable_if<
974  ( Kokkos::Impl::are_integral<I0,I1,I2,I3,I4,I5,Args...>::value
975  && ( 6 == Rank )
976  && ! is_default_map
977  ), reference_type >::type
978  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
979  , const I4 & i4 , const I5 & i5
980  , Args ... args ) const
981  {
982  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,i2,i3,i4,i5,args...) )
983  return m_map.reference(i0,i1,i2,i3,i4,i5);
984  }
985 
986  //------------------------------
987  // Rank 7
988 
989  template< typename I0 , typename I1 , typename I2 , typename I3
990  , typename I4 , typename I5 , typename I6
991  , class ... Args >
992  KOKKOS_FORCEINLINE_FUNCTION
993  typename std::enable_if<
994  ( Kokkos::Impl::are_integral<I0,I1,I2,I3,I4,I5,I6,Args...>::value
995  && ( 7 == Rank )
996  && is_default_map
997  ), reference_type >::type
998  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
999  , const I4 & i4 , const I5 & i5 , const I6 & i6
1000  , Args ... args ) const
1001  {
1002  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,i2,i3,i4,i5,i6,args...) )
1003  return m_map.m_handle[ m_map.m_offset(i0,i1,i2,i3,i4,i5,i6) ];
1004  }
1005 
1006  template< typename I0 , typename I1 , typename I2 , typename I3
1007  , typename I4 , typename I5 , typename I6
1008  , class ... Args >
1009  KOKKOS_FORCEINLINE_FUNCTION
1010  typename std::enable_if<
1011  ( Kokkos::Impl::are_integral<I0,I1,I2,I3,I4,I5,I6,Args...>::value
1012  && ( 7 == Rank )
1013  && ! is_default_map
1014  ), reference_type >::type
1015  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1016  , const I4 & i4 , const I5 & i5 , const I6 & i6
1017  , Args ... args ) const
1018  {
1019  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,i2,i3,i4,i5,i6,args...) )
1020  return m_map.reference(i0,i1,i2,i3,i4,i5,i6);
1021  }
1022 
1023  //------------------------------
1024  // Rank 8
1025 
1026  template< typename I0 , typename I1 , typename I2 , typename I3
1027  , typename I4 , typename I5 , typename I6 , typename I7
1028  , class ... Args >
1029  KOKKOS_FORCEINLINE_FUNCTION
1030  typename std::enable_if<
1031  ( Kokkos::Impl::are_integral<I0,I1,I2,I3,I4,I5,I6,I7,Args...>::value
1032  && ( 8 == Rank )
1033  && is_default_map
1034  ), reference_type >::type
1035  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1036  , const I4 & i4 , const I5 & i5 , const I6 & i6 , const I7 & i7
1037  , Args ... args ) const
1038  {
1039  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,i2,i3,i4,i5,i6,i7,args...) )
1040  return m_map.m_handle[ m_map.m_offset(i0,i1,i2,i3,i4,i5,i6,i7) ];
1041  }
1042 
1043  template< typename I0 , typename I1 , typename I2 , typename I3
1044  , typename I4 , typename I5 , typename I6 , typename I7
1045  , class ... Args >
1046  KOKKOS_FORCEINLINE_FUNCTION
1047  typename std::enable_if<
1048  ( Kokkos::Impl::are_integral<I0,I1,I2,I3,I4,I5,I6,I7,Args...>::value
1049  && ( 8 == Rank )
1050  && ! is_default_map
1051  ), reference_type >::type
1052  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1053  , const I4 & i4 , const I5 & i5 , const I6 & i6 , const I7 & i7
1054  , Args ... args ) const
1055  {
1056  KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (m_track,m_map,i0,i1,i2,i3,i4,i5,i6,i7,args...) )
1057  return m_map.reference(i0,i1,i2,i3,i4,i5,i6,i7);
1058  }
1059 
1060 #undef KOKKOS_IMPL_VIEW_OPERATOR_VERIFY
1061 
1062  //----------------------------------------
1063  // Standard destructor, constructors, and assignment operators
1064 
1065  KOKKOS_INLINE_FUNCTION
1066  ~View() {}
1067 
1068  KOKKOS_INLINE_FUNCTION
1069  View() : m_track(), m_map() {}
1070 
1071  KOKKOS_INLINE_FUNCTION
1072  View( const View & rhs ) : m_track( rhs.m_track ), m_map( rhs.m_map ) {}
1073 
1074  KOKKOS_INLINE_FUNCTION
1075  View( View && rhs ) : m_track( rhs.m_track ), m_map( rhs.m_map ) {}
1076 
1077  KOKKOS_INLINE_FUNCTION
1078  View & operator = ( const View & rhs ) { m_track = rhs.m_track ; m_map = rhs.m_map ; return *this ; }
1079 
1080  KOKKOS_INLINE_FUNCTION
1081  View & operator = ( View && rhs ) { m_track = rhs.m_track ; m_map = rhs.m_map ; return *this ; }
1082 
1083  //----------------------------------------
1084  // Compatible view copy constructor and assignment
1085  // may assign unmanaged from managed.
1086 
1087  template< class RT , class ... RP >
1088  KOKKOS_INLINE_FUNCTION
1089  View( const View<RT,RP...> & rhs )
1090  : m_track( rhs.m_track , traits::is_managed )
1091  , m_map()
1092  {
1093  typedef typename View<RT,RP...>::traits SrcTraits ;
1094  typedef Kokkos::Impl::ViewMapping< traits , SrcTraits , void > Mapping ;
1095  static_assert( Mapping::is_assignable , "Incompatible View copy construction" );
1096  Mapping::assign( m_map , rhs.m_map , rhs.m_track );
1097  }
1098 
1099  template< class RT , class ... RP >
1100  KOKKOS_INLINE_FUNCTION
1101  View & operator = ( const View<RT,RP...> & rhs )
1102  {
1103  typedef typename View<RT,RP...>::traits SrcTraits ;
1104  typedef Kokkos::Impl::ViewMapping< traits , SrcTraits , void > Mapping ;
1105  static_assert( Mapping::is_assignable , "Incompatible View copy assignment" );
1106  Mapping::assign( m_map , rhs.m_map , rhs.m_track );
1107  m_track.assign( rhs.m_track , traits::is_managed );
1108  return *this ;
1109  }
1110 
1111  //----------------------------------------
1112  // Compatible subview constructor
1113  // may assign unmanaged from managed.
1114 
1115  template< class RT , class ... RP , class Arg0 , class ... Args >
1116  KOKKOS_INLINE_FUNCTION
1117  View( const View< RT , RP... > & src_view
1118  , const Arg0 & arg0 , Args ... args )
1119  : m_track( src_view.m_track , traits::is_managed )
1120  , m_map()
1121  {
1122  typedef View< RT , RP... > SrcType ;
1123 
1124  typedef Kokkos::Impl::ViewMapping
1125  < void /* deduce destination view type from source view traits */
1126  , typename SrcType::traits
1127  , Arg0 , Args... > Mapping ;
1128 
1129  typedef typename Mapping::type DstType ;
1130 
1131  static_assert( Kokkos::Impl::ViewMapping< traits , typename DstType::traits , void >::is_assignable
1132  , "Subview construction requires compatible view and subview arguments" );
1133 
1134  Mapping::assign( m_map, src_view.m_map, arg0 , args... );
1135  }
1136 
1137  //----------------------------------------
1138  // Allocation tracking properties
1139 
1140  KOKKOS_INLINE_FUNCTION
1141  int use_count() const
1142  { return m_track.use_count(); }
1143 
1144  inline
1145  const std::string label() const
1146  { return m_track.template get_label< typename traits::memory_space >(); }
1147 
1148  //----------------------------------------
1149  // Allocation according to allocation properties and array layout
1150 
1151  template< class ... P >
1152  explicit inline
1153  View( const Impl::ViewCtorProp< P ... > & arg_prop
1154  , typename std::enable_if< ! Impl::ViewCtorProp< P... >::has_pointer
1155  , typename traits::array_layout
1156  >::type const & arg_layout
1157  )
1158  : m_track()
1159  , m_map()
1160  {
1161  // Append layout and spaces if not input
1162  typedef Impl::ViewCtorProp< P ... > alloc_prop_input ;
1163 
1164  // use 'std::integral_constant<unsigned,I>' for non-types
1165  // to avoid duplicate class error.
1166  typedef Impl::ViewCtorProp
1167  < P ...
1168  , typename std::conditional
1169  < alloc_prop_input::has_label
1170  , std::integral_constant<unsigned,0>
1171  , typename std::string
1172  >::type
1173  , typename std::conditional
1174  < alloc_prop_input::has_memory_space
1175  , std::integral_constant<unsigned,1>
1176  , typename traits::device_type::memory_space
1177  >::type
1178  , typename std::conditional
1179  < alloc_prop_input::has_execution_space
1180  , std::integral_constant<unsigned,2>
1181  , typename traits::device_type::execution_space
1182  >::type
1183  > alloc_prop ;
1184 
1185  static_assert( traits::is_managed
1186  , "View allocation constructor requires managed memory" );
1187 
1188  if ( alloc_prop::initialize &&
1189  ! alloc_prop::execution_space::is_initialized() ) {
1190  // If initializing view data then
1191  // the execution space must be initialized.
1192  Kokkos::Impl::throw_runtime_exception("Constructing View and initializing data with uninitialized execution space");
1193  }
1194 
1195  // Copy the input allocation properties with possibly defaulted properties
1196  alloc_prop prop( arg_prop );
1197 
1198 //------------------------------------------------------------
1199 #if defined( KOKKOS_ENABLE_CUDA )
1200  // If allocating in CudaUVMSpace must fence before and after
1201  // the allocation to protect against possible concurrent access
1202  // on the CPU and the GPU.
1203  // Fence using the trait's executon space (which will be Kokkos::Cuda)
1204  // to avoid incomplete type errors from usng Kokkos::Cuda directly.
1205  if ( std::is_same< Kokkos::CudaUVMSpace , typename traits::device_type::memory_space >::value ) {
1206  traits::device_type::memory_space::execution_space::fence();
1207  }
1208 #endif
1209 //------------------------------------------------------------
1210 
1211  Kokkos::Impl::SharedAllocationRecord<> *
1212  record = m_map.allocate_shared( prop , arg_layout );
1213 
1214 //------------------------------------------------------------
1215 #if defined( KOKKOS_ENABLE_CUDA )
1216  if ( std::is_same< Kokkos::CudaUVMSpace , typename traits::device_type::memory_space >::value ) {
1217  traits::device_type::memory_space::execution_space::fence();
1218  }
1219 #endif
1220 //------------------------------------------------------------
1221 
1222  // Setup and initialization complete, start tracking
1223  m_track.assign_allocated_record_to_uninitialized( record );
1224  }
1225 
1226  // Wrap memory according to properties and array layout
1227  template< class ... P >
1228  explicit KOKKOS_INLINE_FUNCTION
1229  View( const Impl::ViewCtorProp< P ... > & arg_prop
1230  , typename std::enable_if< Impl::ViewCtorProp< P... >::has_pointer
1231  , typename traits::array_layout
1232  >::type const & arg_layout
1233  )
1234  : m_track() // No memory tracking
1235  , m_map( arg_prop , arg_layout )
1236  {
1237  static_assert(
1238  std::is_same< pointer_type
1239  , typename Impl::ViewCtorProp< P... >::pointer_type
1240  >::value ,
1241  "Constructing View to wrap user memory must supply matching pointer type" );
1242  }
1243 
1244  // Simple dimension-only layout
1245  template< class ... P >
1246  explicit inline
1247  View( const Impl::ViewCtorProp< P ... > & arg_prop
1248  , typename std::enable_if< ! Impl::ViewCtorProp< P... >::has_pointer
1249  , size_t
1250  >::type const arg_N0 = 0
1251  , const size_t arg_N1 = 0
1252  , const size_t arg_N2 = 0
1253  , const size_t arg_N3 = 0
1254  , const size_t arg_N4 = 0
1255  , const size_t arg_N5 = 0
1256  , const size_t arg_N6 = 0
1257  , const size_t arg_N7 = 0
1258  )
1259  : View( arg_prop
1260  , typename traits::array_layout
1261  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1262  , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1263  )
1264  {}
1265 
1266  template< class ... P >
1267  explicit KOKKOS_INLINE_FUNCTION
1268  View( const Impl::ViewCtorProp< P ... > & arg_prop
1269  , typename std::enable_if< Impl::ViewCtorProp< P... >::has_pointer
1270  , size_t
1271  >::type const arg_N0 = 0
1272  , const size_t arg_N1 = 0
1273  , const size_t arg_N2 = 0
1274  , const size_t arg_N3 = 0
1275  , const size_t arg_N4 = 0
1276  , const size_t arg_N5 = 0
1277  , const size_t arg_N6 = 0
1278  , const size_t arg_N7 = 0
1279  )
1280  : View( arg_prop
1281  , typename traits::array_layout
1282  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1283  , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1284  )
1285  {}
1286 
1287  // Allocate with label and layout
1288  template< typename Label >
1289  explicit inline
1290  View( const Label & arg_label
1291  , typename std::enable_if<
1292  Kokkos::Impl::is_view_label<Label>::value ,
1293  typename traits::array_layout >::type const & arg_layout
1294  )
1295  : View( Impl::ViewCtorProp< std::string >( arg_label ) , arg_layout )
1296  {}
1297 
1298  // Allocate label and layout, must disambiguate from subview constructor.
1299  template< typename Label >
1300  explicit inline
1301  View( const Label & arg_label
1302  , typename std::enable_if<
1303  Kokkos::Impl::is_view_label<Label>::value ,
1304  const size_t >::type arg_N0 = 0
1305  , const size_t arg_N1 = 0
1306  , const size_t arg_N2 = 0
1307  , const size_t arg_N3 = 0
1308  , const size_t arg_N4 = 0
1309  , const size_t arg_N5 = 0
1310  , const size_t arg_N6 = 0
1311  , const size_t arg_N7 = 0
1312  )
1313  : View( Impl::ViewCtorProp< std::string >( arg_label )
1314  , typename traits::array_layout
1315  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1316  , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1317  )
1318  {}
1319 
1320  // For backward compatibility
1321  explicit inline
1322  View( const ViewAllocateWithoutInitializing & arg_prop
1323  , const typename traits::array_layout & arg_layout
1324  )
1325  : View( Impl::ViewCtorProp< std::string , Kokkos::Impl::WithoutInitializing_t >( arg_prop.label , Kokkos::WithoutInitializing )
1326  , arg_layout
1327  )
1328  {}
1329 
1330  explicit inline
1331  View( const ViewAllocateWithoutInitializing & arg_prop
1332  , const size_t arg_N0 = 0
1333  , const size_t arg_N1 = 0
1334  , const size_t arg_N2 = 0
1335  , const size_t arg_N3 = 0
1336  , const size_t arg_N4 = 0
1337  , const size_t arg_N5 = 0
1338  , const size_t arg_N6 = 0
1339  , const size_t arg_N7 = 0
1340  )
1341  : View( Impl::ViewCtorProp< std::string , Kokkos::Impl::WithoutInitializing_t >( arg_prop.label , Kokkos::WithoutInitializing )
1342  , typename traits::array_layout
1343  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1344  , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1345  )
1346  {}
1347 
1348  //----------------------------------------
1349  // Memory span required to wrap these dimensions.
1350  static constexpr size_t required_allocation_size(
1351  const size_t arg_N0 = 0
1352  , const size_t arg_N1 = 0
1353  , const size_t arg_N2 = 0
1354  , const size_t arg_N3 = 0
1355  , const size_t arg_N4 = 0
1356  , const size_t arg_N5 = 0
1357  , const size_t arg_N6 = 0
1358  , const size_t arg_N7 = 0
1359  )
1360  {
1361  return map_type::memory_span(
1362  typename traits::array_layout
1363  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1364  , arg_N4 , arg_N5 , arg_N6 , arg_N7 ) );
1365  }
1366 
1367  explicit KOKKOS_INLINE_FUNCTION
1368  View( pointer_type arg_ptr
1369  , const size_t arg_N0 = 0
1370  , const size_t arg_N1 = 0
1371  , const size_t arg_N2 = 0
1372  , const size_t arg_N3 = 0
1373  , const size_t arg_N4 = 0
1374  , const size_t arg_N5 = 0
1375  , const size_t arg_N6 = 0
1376  , const size_t arg_N7 = 0
1377  )
1378  : View( Impl::ViewCtorProp<pointer_type>(arg_ptr)
1379  , typename traits::array_layout
1380  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1381  , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1382  )
1383  {}
1384 
1385  explicit KOKKOS_INLINE_FUNCTION
1386  View( pointer_type arg_ptr
1387  , const typename traits::array_layout & arg_layout
1388  )
1389  : View( Impl::ViewCtorProp<pointer_type>(arg_ptr) , arg_layout )
1390  {}
1391 
1392  //----------------------------------------
1393  // Shared scratch memory constructor
1394 
1395  static inline
1396  size_t shmem_size( const size_t arg_N0 = ~size_t(0) ,
1397  const size_t arg_N1 = ~size_t(0) ,
1398  const size_t arg_N2 = ~size_t(0) ,
1399  const size_t arg_N3 = ~size_t(0) ,
1400  const size_t arg_N4 = ~size_t(0) ,
1401  const size_t arg_N5 = ~size_t(0) ,
1402  const size_t arg_N6 = ~size_t(0) ,
1403  const size_t arg_N7 = ~size_t(0) )
1404  {
1405  const size_t num_passed_args =
1406  ( arg_N0 != ~size_t(0) ) + ( arg_N1 != ~size_t(0) ) + ( arg_N2 != ~size_t(0) ) +
1407  ( arg_N3 != ~size_t(0) ) + ( arg_N4 != ~size_t(0) ) + ( arg_N5 != ~size_t(0) ) +
1408  ( arg_N6 != ~size_t(0) ) + ( arg_N7 != ~size_t(0) );
1409 
1410  if ( std::is_same<typename traits::specialize,void>::value && num_passed_args != traits::rank_dynamic ) {
1411  Kokkos::abort( "Kokkos::View::shmem_size() rank_dynamic != number of arguments.\n" );
1412  }
1413 
1414  return map_type::memory_span(
1415  typename traits::array_layout
1416  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1417  , arg_N4 , arg_N5 , arg_N6 , arg_N7 ) );
1418  }
1419 
1420  explicit KOKKOS_INLINE_FUNCTION
1421  View( const typename traits::execution_space::scratch_memory_space & arg_space
1422  , const typename traits::array_layout & arg_layout )
1423  : View( Impl::ViewCtorProp<pointer_type>(
1424  reinterpret_cast<pointer_type>(
1425  arg_space.get_shmem( map_type::memory_span( arg_layout ) ) ) )
1426  , arg_layout )
1427  {}
1428 
1429  explicit KOKKOS_INLINE_FUNCTION
1430  View( const typename traits::execution_space::scratch_memory_space & arg_space
1431  , const size_t arg_N0 = 0
1432  , const size_t arg_N1 = 0
1433  , const size_t arg_N2 = 0
1434  , const size_t arg_N3 = 0
1435  , const size_t arg_N4 = 0
1436  , const size_t arg_N5 = 0
1437  , const size_t arg_N6 = 0
1438  , const size_t arg_N7 = 0 )
1439  : View( Impl::ViewCtorProp<pointer_type>(
1440  reinterpret_cast<pointer_type>(
1441  arg_space.get_shmem(
1442  map_type::memory_span(
1443  typename traits::array_layout
1444  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1445  , arg_N4 , arg_N5 , arg_N6 , arg_N7 ) ) ) ) )
1446  , typename traits::array_layout
1447  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1448  , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1449  )
1450  {}
1451 };
1452 
1453 
1458  template < typename D , class ... P >
1459  KOKKOS_INLINE_FUNCTION
1460  constexpr unsigned rank( const View<D , P...> & V ) { return V.Rank; } //Temporary until added to view
1461 
1462 //----------------------------------------------------------------------------
1463 //----------------------------------------------------------------------------
1464 
1465 template< class V , class ... Args >
1466 using Subview =
1467  typename Kokkos::Impl::ViewMapping
1468  < void /* deduce subview type from source view traits */
1469  , typename V::traits
1470  , Args ...
1471  >::type ;
1472 
1473 template< class D, class ... P , class ... Args >
1474 KOKKOS_INLINE_FUNCTION
1475 typename Kokkos::Impl::ViewMapping
1476  < void /* deduce subview type from source view traits */
1477  , ViewTraits< D , P... >
1478  , Args ...
1479  >::type
1480 subview( const View< D, P... > & src , Args ... args )
1481 {
1482  static_assert( View< D , P... >::Rank == sizeof...(Args) ,
1483  "subview requires one argument for each source View rank" );
1484 
1485  return typename
1486  Kokkos::Impl::ViewMapping
1487  < void /* deduce subview type from source view traits */
1488  , ViewTraits< D , P ... >
1489  , Args ... >::type( src , args ... );
1490 }
1491 
1492 template< class MemoryTraits , class D, class ... P , class ... Args >
1493 KOKKOS_INLINE_FUNCTION
1494 typename Kokkos::Impl::ViewMapping
1495  < void /* deduce subview type from source view traits */
1496  , ViewTraits< D , P... >
1497  , Args ...
1498  >::template apply< MemoryTraits >::type
1499 subview( const View< D, P... > & src , Args ... args )
1500 {
1501  static_assert( View< D , P... >::Rank == sizeof...(Args) ,
1502  "subview requires one argument for each source View rank" );
1503 
1504  return typename
1505  Kokkos::Impl::ViewMapping
1506  < void /* deduce subview type from source view traits */
1507  , ViewTraits< D , P ... >
1508  , Args ... >
1509  ::template apply< MemoryTraits >
1510  ::type( src , args ... );
1511 }
1512 
1513 } /* namespace Kokkos */
1514 
1515 //----------------------------------------------------------------------------
1516 //----------------------------------------------------------------------------
1517 
1518 namespace Kokkos {
1519 
1520 template< class LT , class ... LP , class RT , class ... RP >
1521 KOKKOS_INLINE_FUNCTION
1522 bool operator == ( const View<LT,LP...> & lhs ,
1523  const View<RT,RP...> & rhs )
1524 {
1525  // Same data, layout, dimensions
1526  typedef ViewTraits<LT,LP...> lhs_traits ;
1527  typedef ViewTraits<RT,RP...> rhs_traits ;
1528 
1529  return
1530  std::is_same< typename lhs_traits::const_value_type ,
1531  typename rhs_traits::const_value_type >::value &&
1532  std::is_same< typename lhs_traits::array_layout ,
1533  typename rhs_traits::array_layout >::value &&
1534  std::is_same< typename lhs_traits::memory_space ,
1535  typename rhs_traits::memory_space >::value &&
1536  unsigned(lhs_traits::rank) == unsigned(rhs_traits::rank) &&
1537  lhs.data() == rhs.data() &&
1538  lhs.span() == rhs.span() &&
1539  lhs.dimension_0() == rhs.dimension_0() &&
1540  lhs.dimension_1() == rhs.dimension_1() &&
1541  lhs.dimension_2() == rhs.dimension_2() &&
1542  lhs.dimension_3() == rhs.dimension_3() &&
1543  lhs.dimension_4() == rhs.dimension_4() &&
1544  lhs.dimension_5() == rhs.dimension_5() &&
1545  lhs.dimension_6() == rhs.dimension_6() &&
1546  lhs.dimension_7() == rhs.dimension_7();
1547 }
1548 
1549 template< class LT , class ... LP , class RT , class ... RP >
1550 KOKKOS_INLINE_FUNCTION
1551 bool operator != ( const View<LT,LP...> & lhs ,
1552  const View<RT,RP...> & rhs )
1553 {
1554  return ! ( operator==(lhs,rhs) );
1555 }
1556 
1557 } /* namespace Kokkos */
1558 
1559 //----------------------------------------------------------------------------
1560 //----------------------------------------------------------------------------
1561 
1562 namespace Kokkos {
1563 namespace Impl {
1564 
1565 inline
1566 void shared_allocation_tracking_claim_and_disable()
1567 { Kokkos::Impl::SharedAllocationRecord<void,void>::tracking_claim_and_disable(); }
1568 
1569 inline
1570 void shared_allocation_tracking_release_and_enable()
1571 { Kokkos::Impl::SharedAllocationRecord<void,void>::tracking_release_and_enable(); }
1572 
1573 } /* namespace Impl */
1574 } /* namespace Kokkos */
1575 
1576 //----------------------------------------------------------------------------
1577 //----------------------------------------------------------------------------
1578 
1579 namespace Kokkos {
1580 namespace Impl {
1581 
1582 template< class OutputView , typename Enable = void >
1583 struct ViewFill {
1584 
1585  typedef typename OutputView::const_value_type const_value_type ;
1586 
1587  const OutputView output ;
1588  const_value_type input ;
1589 
1590  KOKKOS_INLINE_FUNCTION
1591  void operator()( const size_t i0 ) const
1592  {
1593  const size_t n1 = output.dimension_1();
1594  const size_t n2 = output.dimension_2();
1595  const size_t n3 = output.dimension_3();
1596  const size_t n4 = output.dimension_4();
1597  const size_t n5 = output.dimension_5();
1598  const size_t n6 = output.dimension_6();
1599  const size_t n7 = output.dimension_7();
1600 
1601  for ( size_t i1 = 0 ; i1 < n1 ; ++i1 ) {
1602  for ( size_t i2 = 0 ; i2 < n2 ; ++i2 ) {
1603  for ( size_t i3 = 0 ; i3 < n3 ; ++i3 ) {
1604  for ( size_t i4 = 0 ; i4 < n4 ; ++i4 ) {
1605  for ( size_t i5 = 0 ; i5 < n5 ; ++i5 ) {
1606  for ( size_t i6 = 0 ; i6 < n6 ; ++i6 ) {
1607  for ( size_t i7 = 0 ; i7 < n7 ; ++i7 ) {
1608  output(i0,i1,i2,i3,i4,i5,i6,i7) = input ;
1609  }}}}}}}
1610  }
1611 
1612  ViewFill( const OutputView & arg_out , const_value_type & arg_in )
1613  : output( arg_out ), input( arg_in )
1614  {
1615  typedef typename OutputView::execution_space execution_space ;
1617 
1618  const Kokkos::Impl::ParallelFor< ViewFill , Policy > closure( *this , Policy( 0 , output.dimension_0() ) );
1619 
1620  closure.execute();
1621 
1622  execution_space::fence();
1623  }
1624 };
1625 
1626 template< class OutputView >
1627 struct ViewFill< OutputView , typename std::enable_if< OutputView::Rank == 0 >::type > {
1628  ViewFill( const OutputView & dst , const typename OutputView::const_value_type & src )
1629  {
1630  Kokkos::Impl::DeepCopy< typename OutputView::memory_space , Kokkos::HostSpace >
1631  ( dst.data() , & src , sizeof(typename OutputView::const_value_type) );
1632  }
1633 };
1634 
1635 template< class OutputView , class InputView , class ExecSpace = typename OutputView::execution_space >
1636 struct ViewRemap {
1637 
1638  const OutputView output ;
1639  const InputView input ;
1640  const size_t n0 ;
1641  const size_t n1 ;
1642  const size_t n2 ;
1643  const size_t n3 ;
1644  const size_t n4 ;
1645  const size_t n5 ;
1646  const size_t n6 ;
1647  const size_t n7 ;
1648 
1649  ViewRemap( const OutputView & arg_out , const InputView & arg_in )
1650  : output( arg_out ), input( arg_in )
1651  , n0( std::min( (size_t)arg_out.dimension_0() , (size_t)arg_in.dimension_0() ) )
1652  , n1( std::min( (size_t)arg_out.dimension_1() , (size_t)arg_in.dimension_1() ) )
1653  , n2( std::min( (size_t)arg_out.dimension_2() , (size_t)arg_in.dimension_2() ) )
1654  , n3( std::min( (size_t)arg_out.dimension_3() , (size_t)arg_in.dimension_3() ) )
1655  , n4( std::min( (size_t)arg_out.dimension_4() , (size_t)arg_in.dimension_4() ) )
1656  , n5( std::min( (size_t)arg_out.dimension_5() , (size_t)arg_in.dimension_5() ) )
1657  , n6( std::min( (size_t)arg_out.dimension_6() , (size_t)arg_in.dimension_6() ) )
1658  , n7( std::min( (size_t)arg_out.dimension_7() , (size_t)arg_in.dimension_7() ) )
1659  {
1660  typedef Kokkos::RangePolicy< ExecSpace > Policy ;
1661  const Kokkos::Impl::ParallelFor< ViewRemap , Policy > closure( *this , Policy( 0 , n0 ) );
1662  closure.execute();
1663  }
1664 
1665  KOKKOS_INLINE_FUNCTION
1666  void operator()( const size_t i0 ) const
1667  {
1668  for ( size_t i1 = 0 ; i1 < n1 ; ++i1 ) {
1669  for ( size_t i2 = 0 ; i2 < n2 ; ++i2 ) {
1670  for ( size_t i3 = 0 ; i3 < n3 ; ++i3 ) {
1671  for ( size_t i4 = 0 ; i4 < n4 ; ++i4 ) {
1672  for ( size_t i5 = 0 ; i5 < n5 ; ++i5 ) {
1673  for ( size_t i6 = 0 ; i6 < n6 ; ++i6 ) {
1674  for ( size_t i7 = 0 ; i7 < n7 ; ++i7 ) {
1675  output(i0,i1,i2,i3,i4,i5,i6,i7) = input(i0,i1,i2,i3,i4,i5,i6,i7);
1676  }}}}}}}
1677  }
1678 };
1679 
1680 } /* namespace Impl */
1681 } /* namespace Kokkos */
1682 
1683 //----------------------------------------------------------------------------
1684 //----------------------------------------------------------------------------
1685 
1686 namespace Kokkos {
1687 
1689 template< class DT , class ... DP >
1690 inline
1691 void deep_copy
1692  ( const View<DT,DP...> & dst
1693  , typename ViewTraits<DT,DP...>::const_value_type & value
1694  , typename std::enable_if<
1695  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value
1696  >::type * = 0 )
1697 {
1698  static_assert(
1699  std::is_same< typename ViewTraits<DT,DP...>::non_const_value_type ,
1700  typename ViewTraits<DT,DP...>::value_type >::value
1701  , "deep_copy requires non-const type" );
1702 
1703  Kokkos::Impl::ViewFill< View<DT,DP...> >( dst , value );
1704 }
1705 
1707 template< class ST , class ... SP >
1708 inline
1709 void deep_copy
1710  ( typename ViewTraits<ST,SP...>::non_const_value_type & dst
1711  , const View<ST,SP...> & src
1712  , typename std::enable_if<
1713  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value
1714  >::type * = 0 )
1715 {
1716  static_assert( ViewTraits<ST,SP...>::rank == 0
1717  , "ERROR: Non-rank-zero view in deep_copy( value , View )" );
1718 
1719  typedef ViewTraits<ST,SP...> src_traits ;
1720  typedef typename src_traits::memory_space src_memory_space ;
1721  Kokkos::Impl::DeepCopy< HostSpace , src_memory_space >( & dst , src.data() , sizeof(ST) );
1722 }
1723 
1724 //----------------------------------------------------------------------------
1726 template< class DT , class ... DP , class ST , class ... SP >
1727 inline
1728 void deep_copy
1729  ( const View<DT,DP...> & dst
1730  , const View<ST,SP...> & src
1731  , typename std::enable_if<(
1732  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value &&
1733  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value &&
1734  ( unsigned(ViewTraits<DT,DP...>::rank) == unsigned(0) &&
1735  unsigned(ViewTraits<ST,SP...>::rank) == unsigned(0) )
1736  )>::type * = 0 )
1737 {
1738  static_assert(
1739  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
1740  typename ViewTraits<ST,SP...>::non_const_value_type >::value
1741  , "deep_copy requires matching non-const destination type" );
1742 
1743  typedef View<DT,DP...> dst_type ;
1744  typedef View<ST,SP...> src_type ;
1745 
1746  typedef typename dst_type::value_type value_type ;
1747  typedef typename dst_type::memory_space dst_memory_space ;
1748  typedef typename src_type::memory_space src_memory_space ;
1749 
1750  if ( dst.data() != src.data() ) {
1751  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , sizeof(value_type) );
1752  }
1753 }
1754 
1755 //----------------------------------------------------------------------------
1759 template< class DT , class ... DP , class ST , class ... SP >
1760 inline
1761 void deep_copy
1762  ( const View<DT,DP...> & dst
1763  , const View<ST,SP...> & src
1764  , typename std::enable_if<(
1765  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value &&
1766  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value &&
1767  ( unsigned(ViewTraits<DT,DP...>::rank) != 0 ||
1768  unsigned(ViewTraits<ST,SP...>::rank) != 0 )
1769  )>::type * = 0 )
1770 {
1771  static_assert(
1772  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
1773  typename ViewTraits<DT,DP...>::non_const_value_type >::value
1774  , "deep_copy requires non-const destination type" );
1775 
1776  static_assert(
1777  ( unsigned(ViewTraits<DT,DP...>::rank) ==
1778  unsigned(ViewTraits<ST,SP...>::rank) )
1779  , "deep_copy requires Views of equal rank" );
1780 
1781  typedef View<DT,DP...> dst_type ;
1782  typedef View<ST,SP...> src_type ;
1783 
1784  typedef typename dst_type::execution_space dst_execution_space ;
1785  typedef typename src_type::execution_space src_execution_space ;
1786  typedef typename dst_type::memory_space dst_memory_space ;
1787  typedef typename src_type::memory_space src_memory_space ;
1788 
1789  enum { DstExecCanAccessSrc =
1791 
1792  enum { SrcExecCanAccessDst =
1794 
1795 
1796  if ( (void *) dst.data() != (void*) src.data() ) {
1797 
1798  // Concern: If overlapping views then a parallel copy will be erroneous.
1799  // ...
1800 
1801  // If same type, equal layout, equal dimensions, equal span, and contiguous memory then can byte-wise copy
1802 
1803  if ( std::is_same< typename ViewTraits<DT,DP...>::value_type ,
1804  typename ViewTraits<ST,SP...>::non_const_value_type >::value &&
1805  (
1806  ( std::is_same< typename ViewTraits<DT,DP...>::array_layout ,
1807  typename ViewTraits<ST,SP...>::array_layout >::value
1808  &&
1809  ( std::is_same< typename ViewTraits<DT,DP...>::array_layout ,
1810  typename Kokkos::LayoutLeft>::value
1811  ||
1812  std::is_same< typename ViewTraits<DT,DP...>::array_layout ,
1813  typename Kokkos::LayoutRight>::value
1814  )
1815  )
1816  ||
1817  ( ViewTraits<DT,DP...>::rank == 1 &&
1819  ) &&
1820  dst.span_is_contiguous() &&
1821  src.span_is_contiguous() &&
1822  dst.span() == src.span() &&
1823  dst.dimension_0() == src.dimension_0() &&
1824  dst.dimension_1() == src.dimension_1() &&
1825  dst.dimension_2() == src.dimension_2() &&
1826  dst.dimension_3() == src.dimension_3() &&
1827  dst.dimension_4() == src.dimension_4() &&
1828  dst.dimension_5() == src.dimension_5() &&
1829  dst.dimension_6() == src.dimension_6() &&
1830  dst.dimension_7() == src.dimension_7() ) {
1831 
1832  const size_t nbytes = sizeof(typename dst_type::value_type) * dst.span();
1833 
1834  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1835  }
1836  else if ( std::is_same< typename ViewTraits<DT,DP...>::value_type ,
1837  typename ViewTraits<ST,SP...>::non_const_value_type >::value &&
1838  (
1839  ( std::is_same< typename ViewTraits<DT,DP...>::array_layout ,
1840  typename ViewTraits<ST,SP...>::array_layout >::value
1841  &&
1842  std::is_same< typename ViewTraits<DT,DP...>::array_layout ,
1843  typename Kokkos::LayoutStride>::value
1844  )
1845  ||
1846  ( ViewTraits<DT,DP...>::rank == 1 &&
1848  ) &&
1849  dst.span_is_contiguous() &&
1850  src.span_is_contiguous() &&
1851  dst.span() == src.span() &&
1852  dst.dimension_0() == src.dimension_0() &&
1853  dst.dimension_1() == src.dimension_1() &&
1854  dst.dimension_2() == src.dimension_2() &&
1855  dst.dimension_3() == src.dimension_3() &&
1856  dst.dimension_4() == src.dimension_4() &&
1857  dst.dimension_5() == src.dimension_5() &&
1858  dst.dimension_6() == src.dimension_6() &&
1859  dst.dimension_7() == src.dimension_7() &&
1860  dst.stride_0() == src.stride_0() &&
1861  dst.stride_1() == src.stride_1() &&
1862  dst.stride_2() == src.stride_2() &&
1863  dst.stride_3() == src.stride_3() &&
1864  dst.stride_4() == src.stride_4() &&
1865  dst.stride_5() == src.stride_5() &&
1866  dst.stride_6() == src.stride_6() &&
1867  dst.stride_7() == src.stride_7()
1868  ) {
1869 
1870  const size_t nbytes = sizeof(typename dst_type::value_type) * dst.span();
1871 
1872  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1873  }
1874  else if ( DstExecCanAccessSrc ) {
1875  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
1876  Kokkos::Impl::ViewRemap< dst_type , src_type >( dst , src );
1877  }
1878  else if ( SrcExecCanAccessDst ) {
1879  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
1880  Kokkos::Impl::ViewRemap< dst_type , src_type , src_execution_space >( dst , src );
1881  }
1882  else {
1883  Kokkos::Impl::throw_runtime_exception("deep_copy given views that would require a temporary allocation");
1884  }
1885  }
1886 }
1887 
1888 } /* namespace Kokkos */
1889 
1890 //----------------------------------------------------------------------------
1891 //----------------------------------------------------------------------------
1892 
1893 namespace Kokkos {
1894 
1896 template< class ExecSpace ,class DT , class ... DP >
1897 inline
1898 void deep_copy
1899  ( const ExecSpace &
1900  , const View<DT,DP...> & dst
1901  , typename ViewTraits<DT,DP...>::const_value_type & value
1902  , typename std::enable_if<
1903  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
1904  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value
1905  >::type * = 0 )
1906 {
1907  static_assert(
1908  std::is_same< typename ViewTraits<DT,DP...>::non_const_value_type ,
1909  typename ViewTraits<DT,DP...>::value_type >::value
1910  , "deep_copy requires non-const type" );
1911 
1912  Kokkos::Impl::ViewFill< View<DT,DP...> >( dst , value );
1913 }
1914 
1916 template< class ExecSpace , class ST , class ... SP >
1917 inline
1918 void deep_copy
1919  ( const ExecSpace & exec_space
1920  , typename ViewTraits<ST,SP...>::non_const_value_type & dst
1921  , const View<ST,SP...> & src
1922  , typename std::enable_if<
1923  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
1924  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value
1925  >::type * = 0 )
1926 {
1927  static_assert( ViewTraits<ST,SP...>::rank == 0
1928  , "ERROR: Non-rank-zero view in deep_copy( value , View )" );
1929 
1930  typedef ViewTraits<ST,SP...> src_traits ;
1931  typedef typename src_traits::memory_space src_memory_space ;
1932  Kokkos::Impl::DeepCopy< HostSpace , src_memory_space , ExecSpace >
1933  ( exec_space , & dst , src.data() , sizeof(ST) );
1934 }
1935 
1936 //----------------------------------------------------------------------------
1938 template< class ExecSpace , class DT , class ... DP , class ST , class ... SP >
1939 inline
1940 void deep_copy
1941  ( const ExecSpace & exec_space
1942  , const View<DT,DP...> & dst
1943  , const View<ST,SP...> & src
1944  , typename std::enable_if<(
1945  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
1946  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value &&
1947  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value &&
1948  ( unsigned(ViewTraits<DT,DP...>::rank) == unsigned(0) &&
1949  unsigned(ViewTraits<ST,SP...>::rank) == unsigned(0) )
1950  )>::type * = 0 )
1951 {
1952  static_assert(
1953  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
1954  typename ViewTraits<ST,SP...>::non_const_value_type >::value
1955  , "deep_copy requires matching non-const destination type" );
1956 
1957  typedef View<DT,DP...> dst_type ;
1958  typedef View<ST,SP...> src_type ;
1959 
1960  typedef typename dst_type::value_type value_type ;
1961  typedef typename dst_type::memory_space dst_memory_space ;
1962  typedef typename src_type::memory_space src_memory_space ;
1963 
1964  if ( dst.data() != src.data() ) {
1965  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space , ExecSpace >
1966  ( exec_space , dst.data() , src.data() , sizeof(value_type) );
1967  }
1968 }
1969 
1970 //----------------------------------------------------------------------------
1974 template< class ExecSpace , class DT, class ... DP, class ST, class ... SP >
1975 inline
1976 void deep_copy
1977  ( const ExecSpace & exec_space
1978  , const View<DT,DP...> & dst
1979  , const View<ST,SP...> & src
1980  , typename std::enable_if<(
1981  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
1982  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value &&
1983  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value &&
1984  ( unsigned(ViewTraits<DT,DP...>::rank) != 0 ||
1985  unsigned(ViewTraits<ST,SP...>::rank) != 0 )
1986  )>::type * = 0 )
1987 {
1988  static_assert(
1989  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
1990  typename ViewTraits<DT,DP...>::non_const_value_type >::value
1991  , "deep_copy requires non-const destination type" );
1992 
1993  static_assert(
1994  ( unsigned(ViewTraits<DT,DP...>::rank) ==
1995  unsigned(ViewTraits<ST,SP...>::rank) )
1996  , "deep_copy requires Views of equal rank" );
1997 
1998  typedef View<DT,DP...> dst_type ;
1999  typedef View<ST,SP...> src_type ;
2000 
2001  typedef typename dst_type::execution_space dst_execution_space ;
2002  typedef typename src_type::execution_space src_execution_space ;
2003  typedef typename dst_type::memory_space dst_memory_space ;
2004  typedef typename src_type::memory_space src_memory_space ;
2005 
2006  enum { DstExecCanAccessSrc =
2008 
2009  enum { SrcExecCanAccessDst =
2011 
2012  if ( (void *) dst.data() != (void*) src.data() ) {
2013 
2014  // Concern: If overlapping views then a parallel copy will be erroneous.
2015  // ...
2016 
2017  // If same type, equal layout, equal dimensions, equal span, and contiguous memory then can byte-wise copy
2018 
2019  if ( std::is_same< typename ViewTraits<DT,DP...>::value_type ,
2020  typename ViewTraits<ST,SP...>::non_const_value_type >::value &&
2021  (
2022  std::is_same< typename ViewTraits<DT,DP...>::array_layout ,
2023  typename ViewTraits<ST,SP...>::array_layout >::value
2024  ||
2025  ( ViewTraits<DT,DP...>::rank == 1 &&
2027  ) &&
2028  dst.span_is_contiguous() &&
2029  src.span_is_contiguous() &&
2030  dst.span() == src.span() &&
2031  dst.dimension_0() == src.dimension_0() &&
2032  dst.dimension_1() == src.dimension_1() &&
2033  dst.dimension_2() == src.dimension_2() &&
2034  dst.dimension_3() == src.dimension_3() &&
2035  dst.dimension_4() == src.dimension_4() &&
2036  dst.dimension_5() == src.dimension_5() &&
2037  dst.dimension_6() == src.dimension_6() &&
2038  dst.dimension_7() == src.dimension_7() ) {
2039 
2040  const size_t nbytes = sizeof(typename dst_type::value_type) * dst.span();
2041 
2042  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space , ExecSpace >
2043  ( exec_space , dst.data() , src.data() , nbytes );
2044  }
2045  else if ( DstExecCanAccessSrc ) {
2046  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
2047  Kokkos::Impl::ViewRemap< dst_type , src_type >( dst , src );
2048  }
2049  else if ( SrcExecCanAccessDst ) {
2050  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
2051  Kokkos::Impl::ViewRemap< dst_type , src_type , src_execution_space >( dst , src );
2052  }
2053  else {
2054  Kokkos::Impl::throw_runtime_exception("deep_copy given views that would require a temporary allocation");
2055  }
2056  }
2057 }
2058 
2059 } /* namespace Kokkos */
2060 
2061 //----------------------------------------------------------------------------
2062 //----------------------------------------------------------------------------
2063 
2064 namespace Kokkos {
2065 namespace Impl {
2066 
2067 // Deduce Mirror Types
2068 template<class Space, class T, class ... P>
2069 struct MirrorViewType {
2070  // The incoming view_type
2071  typedef typename Kokkos::View<T,P...> src_view_type;
2072  // The memory space for the mirror view
2073  typedef typename Space::memory_space memory_space;
2074  // Check whether it is the same memory space
2075  enum { is_same_memspace = std::is_same<memory_space,typename src_view_type::memory_space>::value };
2076  // The array_layout
2077  typedef typename src_view_type::array_layout array_layout;
2078  // The data type (we probably want it non-const since otherwise we can't even deep_copy to it.
2079  typedef typename src_view_type::non_const_data_type data_type;
2080  // The destination view type if it is not the same memory space
2081  typedef Kokkos::View<data_type,array_layout,Space> dest_view_type;
2082  // If it is the same memory_space return the existsing view_type
2083  // This will also keep the unmanaged trait if necessary
2084  typedef typename std::conditional<is_same_memspace,src_view_type,dest_view_type>::type view_type;
2085 };
2086 
2087 template<class Space, class T, class ... P>
2088 struct MirrorType {
2089  // The incoming view_type
2090  typedef typename Kokkos::View<T,P...> src_view_type;
2091  // The memory space for the mirror view
2092  typedef typename Space::memory_space memory_space;
2093  // Check whether it is the same memory space
2094  enum { is_same_memspace = std::is_same<memory_space,typename src_view_type::memory_space>::value };
2095  // The array_layout
2096  typedef typename src_view_type::array_layout array_layout;
2097  // The data type (we probably want it non-const since otherwise we can't even deep_copy to it.
2098  typedef typename src_view_type::non_const_data_type data_type;
2099  // The destination view type if it is not the same memory space
2101 };
2102 
2103 }
2104 
2105 template< class T , class ... P >
2106 inline
2107 typename Kokkos::View<T,P...>::HostMirror
2108 create_mirror( const Kokkos::View<T,P...> & src
2109  , typename std::enable_if<
2110  ! std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
2111  , Kokkos::LayoutStride >::value
2112  >::type * = 0
2113  )
2114 {
2115  typedef View<T,P...> src_type ;
2116  typedef typename src_type::HostMirror dst_type ;
2117 
2118  return dst_type( std::string( src.label() ).append("_mirror")
2119  , src.dimension_0()
2120  , src.dimension_1()
2121  , src.dimension_2()
2122  , src.dimension_3()
2123  , src.dimension_4()
2124  , src.dimension_5()
2125  , src.dimension_6()
2126  , src.dimension_7() );
2127 }
2128 
2129 template< class T , class ... P >
2130 inline
2131 typename Kokkos::View<T,P...>::HostMirror
2132 create_mirror( const Kokkos::View<T,P...> & src
2133  , typename std::enable_if<
2134  std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
2135  , Kokkos::LayoutStride >::value
2136  >::type * = 0
2137  )
2138 {
2139  typedef View<T,P...> src_type ;
2140  typedef typename src_type::HostMirror dst_type ;
2141 
2142  Kokkos::LayoutStride layout ;
2143 
2144  layout.dimension[0] = src.dimension_0();
2145  layout.dimension[1] = src.dimension_1();
2146  layout.dimension[2] = src.dimension_2();
2147  layout.dimension[3] = src.dimension_3();
2148  layout.dimension[4] = src.dimension_4();
2149  layout.dimension[5] = src.dimension_5();
2150  layout.dimension[6] = src.dimension_6();
2151  layout.dimension[7] = src.dimension_7();
2152 
2153  layout.stride[0] = src.stride_0();
2154  layout.stride[1] = src.stride_1();
2155  layout.stride[2] = src.stride_2();
2156  layout.stride[3] = src.stride_3();
2157  layout.stride[4] = src.stride_4();
2158  layout.stride[5] = src.stride_5();
2159  layout.stride[6] = src.stride_6();
2160  layout.stride[7] = src.stride_7();
2161 
2162  return dst_type( std::string( src.label() ).append("_mirror") , layout );
2163 }
2164 
2165 
2166 // Create a mirror in a new space (specialization for different space)
2167 template<class Space, class T, class ... P>
2168 typename Impl::MirrorType<Space,T,P ...>::view_type create_mirror(const Space& , const Kokkos::View<T,P...> & src) {
2169  return typename Impl::MirrorType<Space,T,P ...>::view_type(src.label(),src.layout());
2170 }
2171 
2172 template< class T , class ... P >
2173 inline
2174 typename Kokkos::View<T,P...>::HostMirror
2175 create_mirror_view( const Kokkos::View<T,P...> & src
2176  , typename std::enable_if<(
2177  std::is_same< typename Kokkos::View<T,P...>::memory_space
2178  , typename Kokkos::View<T,P...>::HostMirror::memory_space
2179  >::value
2180  &&
2181  std::is_same< typename Kokkos::View<T,P...>::data_type
2182  , typename Kokkos::View<T,P...>::HostMirror::data_type
2183  >::value
2184  )>::type * = 0
2185  )
2186 {
2187  return src ;
2188 }
2189 
2190 template< class T , class ... P >
2191 inline
2192 typename Kokkos::View<T,P...>::HostMirror
2193 create_mirror_view( const Kokkos::View<T,P...> & src
2194  , typename std::enable_if< ! (
2195  std::is_same< typename Kokkos::View<T,P...>::memory_space
2196  , typename Kokkos::View<T,P...>::HostMirror::memory_space
2197  >::value
2198  &&
2199  std::is_same< typename Kokkos::View<T,P...>::data_type
2200  , typename Kokkos::View<T,P...>::HostMirror::data_type
2201  >::value
2202  )>::type * = 0
2203  )
2204 {
2205  return Kokkos::create_mirror( src );
2206 }
2207 
2208 // Create a mirror view in a new space (specialization for same space)
2209 template<class Space, class T, class ... P>
2210 typename Impl::MirrorViewType<Space,T,P ...>::view_type
2211 create_mirror_view(const Space& , const Kokkos::View<T,P...> & src
2212  , typename std::enable_if<Impl::MirrorViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2213  return src;
2214 }
2215 
2216 // Create a mirror view in a new space (specialization for different space)
2217 template<class Space, class T, class ... P>
2218 typename Impl::MirrorViewType<Space,T,P ...>::view_type
2219 create_mirror_view(const Space& , const Kokkos::View<T,P...> & src
2220  , typename std::enable_if<!Impl::MirrorViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2221  return typename Impl::MirrorViewType<Space,T,P ...>::view_type(src.label(),src.layout());
2222 }
2223 
2224 } /* namespace Kokkos */
2225 
2226 //----------------------------------------------------------------------------
2227 //----------------------------------------------------------------------------
2228 
2229 namespace Kokkos {
2230 
2232 template< class T , class ... P >
2233 inline
2234 typename std::enable_if<
2235  std::is_same<typename Kokkos::View<T,P...>::array_layout,Kokkos::LayoutLeft>::value ||
2236  std::is_same<typename Kokkos::View<T,P...>::array_layout,Kokkos::LayoutRight>::value
2237 >::type
2239  const size_t n0 = 0 ,
2240  const size_t n1 = 0 ,
2241  const size_t n2 = 0 ,
2242  const size_t n3 = 0 ,
2243  const size_t n4 = 0 ,
2244  const size_t n5 = 0 ,
2245  const size_t n6 = 0 ,
2246  const size_t n7 = 0 )
2247 {
2248  typedef Kokkos::View<T,P...> view_type ;
2249 
2250  static_assert( Kokkos::ViewTraits<T,P...>::is_managed , "Can only resize managed views" );
2251 
2252  view_type v_resized( v.label(), n0, n1, n2, n3, n4, n5, n6, n7 );
2253 
2254  Kokkos::Impl::ViewRemap< view_type , view_type >( v_resized , v );
2255 
2256  v = v_resized ;
2257 }
2258 
2260 template< class T , class ... P >
2261 inline
2263  const typename Kokkos::View<T,P...>::array_layout & layout)
2264 {
2265  typedef Kokkos::View<T,P...> view_type ;
2266 
2267  static_assert( Kokkos::ViewTraits<T,P...>::is_managed , "Can only resize managed views" );
2268 
2269  view_type v_resized( v.label(), layout );
2270 
2271  Kokkos::Impl::ViewRemap< view_type , view_type >( v_resized , v );
2272 
2273  v = v_resized ;
2274 }
2275 
2277 template< class T , class ... P >
2278 inline
2279 typename std::enable_if<
2280  std::is_same<typename Kokkos::View<T,P...>::array_layout,Kokkos::LayoutLeft>::value ||
2281  std::is_same<typename Kokkos::View<T,P...>::array_layout,Kokkos::LayoutRight>::value
2282 >::type
2284  const size_t n0 = 0 ,
2285  const size_t n1 = 0 ,
2286  const size_t n2 = 0 ,
2287  const size_t n3 = 0 ,
2288  const size_t n4 = 0 ,
2289  const size_t n5 = 0 ,
2290  const size_t n6 = 0 ,
2291  const size_t n7 = 0 )
2292 {
2293  typedef Kokkos::View<T,P...> view_type ;
2294 
2295  static_assert( Kokkos::ViewTraits<T,P...>::is_managed , "Can only realloc managed views" );
2296 
2297  const std::string label = v.label();
2298 
2299  v = view_type(); // Deallocate first, if the only view to allocation
2300  v = view_type( label, n0, n1, n2, n3, n4, n5, n6, n7 );
2301 }
2302 
2304 template< class T , class ... P >
2305 inline
2307  const typename Kokkos::View<T,P...>::array_layout & layout)
2308 {
2309  typedef Kokkos::View<T,P...> view_type ;
2310 
2311  static_assert( Kokkos::ViewTraits<T,P...>::is_managed , "Can only realloc managed views" );
2312 
2313  const std::string label = v.label();
2314 
2315  v = view_type(); // Deallocate first, if the only view to allocation
2316  v = view_type( label, layout );
2317 }
2318 } /* namespace Kokkos */
2319 
2320 //----------------------------------------------------------------------------
2321 //----------------------------------------------------------------------------
2322 // For backward compatibility:
2323 
2324 namespace Kokkos {
2325 namespace Experimental {
2326 
2327 using Kokkos::ViewTraits ;
2328 using Kokkos::View ;
2329 using Kokkos::Subview ;
2330 using Kokkos::is_view ;
2331 using Kokkos::subview ;
2332 using Kokkos::ALL ;
2333 using Kokkos::WithoutInitializing ;
2334 using Kokkos::AllowPadding ;
2335 using Kokkos::view_alloc ;
2336 using Kokkos::view_wrap ;
2337 using Kokkos::deep_copy ;
2338 using Kokkos::create_mirror ;
2339 using Kokkos::create_mirror_view ;
2340 using Kokkos::resize ;
2341 using Kokkos::realloc ;
2342 
2343 namespace Impl {
2344 
2345 using Kokkos::Impl::ViewFill ;
2346 using Kokkos::Impl::ViewRemap ;
2347 using Kokkos::Impl::ViewCtorProp ;
2348 using Kokkos::Impl::is_view_label ;
2349 using Kokkos::Impl::WithoutInitializing_t ;
2350 using Kokkos::Impl::AllowPadding_t ;
2351 using Kokkos::Impl::SharedAllocationRecord ;
2352 using Kokkos::Impl::SharedAllocationTracker ;
2353 
2354 } /* namespace Impl */
2355 } /* namespace Experimental */
2356 } /* namespace Kokkos */
2357 
2358 namespace Kokkos {
2359 namespace Impl {
2360 
2361 using Kokkos::is_view ;
2362 
2363 template< class SrcViewType
2364  , class Arg0Type
2365  , class Arg1Type
2366  , class Arg2Type
2367  , class Arg3Type
2368  , class Arg4Type
2369  , class Arg5Type
2370  , class Arg6Type
2371  , class Arg7Type
2372  >
2373 struct ViewSubview /* { typedef ... type ; } */ ;
2374 
2375 } /* namespace Impl */
2376 } /* namespace Kokkos */
2377 
2378 #include <impl/Kokkos_Atomic_View.hpp>
2379 
2380 //----------------------------------------------------------------------------
2381 //----------------------------------------------------------------------------
2382 
2383 #endif /* #ifndef KOKKOS_VIEW_HPP */
2384 
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=0, const size_t n1=0, const size_t n2=0, const size_t n3=0, const size_t n4=0, const size_t n5=0, const size_t n6=0, const size_t n7=0)
Resize a view with copying old data to new data at the corresponding indices.
Memory layout tag indicating left-to-right (Fortran scheme) striding of multi-indices.
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=0, const size_t n1=0, const size_t n2=0, const size_t n3=0, const size_t n4=0, const size_t n5=0, const size_t n6=0, const size_t n7=0)
Resize a view with discarding old data.
KOKKOS_INLINE_FUNCTION bool operator!=(const complex< RealType > &x, const complex< RealType > &y)
Inequality operator for two complex numbers.
View< typename traits::scalar_array_type, typename traits::array_layout, typename traits::device_type, typename traits::memory_traits > array_type
Compatible view of array of scalar types.
Memory layout tag indicated arbitrarily strided multi-index mapping into contiguous memory...
View to an array of data.
Can AccessSpace access MemorySpace ?
Memory space for main process and CPU execution spaces.
Memory layout tag indicating right-to-left (C or lexigraphical scheme) striding of multi-indices...
Implementation of the ParallelFor operator that has a partial specialization for the device...
View< typename traits::non_const_data_type, typename traits::array_layout, typename traits::device_type, typename traits::memory_traits > non_const_type
Compatible view of non-const data type.
Impl::ViewCtorProp< typename Impl::ViewCtorProp< void, Args >::type ... > view_alloc(Args const &... args)
Create View allocation parameter bundle from argument list.
KOKKOS_INLINE_FUNCTION bool operator==(const complex< RealType > &x, const complex< RealType > &y)
Equality operator for two complex numbers.
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 *=0)
Deep copy a value from Host memory into a view.
Execution policy for work over a range of an integral type.
View< typename traits::non_const_data_type, typename traits::array_layout, typename traits::host_mirror_space > HostMirror
Compatible HostMirror view.
Traits class for accessing attributes of a View.
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< std::is_integral< iType >::value, size_t >::type extent(const iType &r) const
rank() to be implemented
KOKKOS_INLINE_FUNCTION constexpr unsigned rank(const View< D, P... > &V)
Temporary free function rank() until rank() is implemented in the View.
View< typename traits::const_data_type, typename traits::array_layout, typename traits::device_type, typename traits::memory_traits > const_type
Compatible view of const data type.