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 ;
269  typedef Kokkos::Device<ExecutionSpace,MemorySpace> device_type ;
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 #if defined( KOKKOS_ENABLE_DEBUG_BOUNDS_CHECK )
617 
618 #define KOKKOS_VIEW_OPERATOR_VERIFY( ARG ) \
619  Kokkos::Impl::VerifyExecutionCanAccessMemorySpace \
620  < Kokkos::Impl::ActiveExecutionMemorySpace , typename traits::memory_space >::verify(); \
621  Kokkos::Impl::view_verify_operator_bounds ARG ;
622 
623 #else
624 
625 #define KOKKOS_VIEW_OPERATOR_VERIFY( ARG ) \
626  Kokkos::Impl::VerifyExecutionCanAccessMemorySpace \
627  < Kokkos::Impl::ActiveExecutionMemorySpace , typename traits::memory_space >::verify();
628 
629 #endif
630 
631 public:
632 
633  //------------------------------
634  // Rank 0 operator()
635 
636  template< class ... Args >
637  KOKKOS_FORCEINLINE_FUNCTION
638  typename std::enable_if<( Kokkos::Impl::are_integral<Args...>::value
639  && ( 0 == Rank )
640  ), reference_type >::type
641  operator()( Args ... args ) const
642  {
643  #ifndef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
644  KOKKOS_VIEW_OPERATOR_VERIFY( (NULL,m_map,args...) )
645  #else
646  KOKKOS_VIEW_OPERATOR_VERIFY( (m_track.template get_label<typename traits::memory_space>().c_str(),m_map,args...) )
647  #endif
648 
649  return m_map.reference();
650  }
651 
652  //------------------------------
653  // Rank 1 operator()
654 
655  template< typename I0
656  , class ... Args >
657  KOKKOS_FORCEINLINE_FUNCTION
658  typename std::enable_if<
659  ( Kokkos::Impl::are_integral<I0,Args...>::value
660  && ( 1 == Rank )
661  && ! is_default_map
662  ), reference_type >::type
663  operator()( const I0 & i0
664  , Args ... args ) const
665  {
666  #ifndef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
667  KOKKOS_VIEW_OPERATOR_VERIFY( (NULL,m_map,i0,args...) )
668  #else
669  KOKKOS_VIEW_OPERATOR_VERIFY( (m_track.template get_label<typename traits::memory_space>().c_str(),m_map,i0,args...) )
670  #endif
671 
672  return m_map.reference(i0);
673  }
674 
675  template< typename I0
676  , class ... Args >
677  KOKKOS_FORCEINLINE_FUNCTION
678  typename std::enable_if<
679  ( Kokkos::Impl::are_integral<I0,Args...>::value
680  && ( 1 == Rank )
681  && is_default_map
682  && ! is_layout_stride
683  ), reference_type >::type
684  operator()( const I0 & i0
685  , Args ... args ) const
686  {
687 
688  #ifndef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
689  KOKKOS_VIEW_OPERATOR_VERIFY( (NULL,m_map,i0,args...) )
690  #else
691  KOKKOS_VIEW_OPERATOR_VERIFY( (m_track.template get_label<typename traits::memory_space>().c_str(),m_map,i0,args...) )
692  #endif
693 
694  return m_map.m_handle[ i0 ];
695  }
696 
697  template< typename I0
698  , class ... Args >
699  KOKKOS_FORCEINLINE_FUNCTION
700  typename std::enable_if<
701  ( Kokkos::Impl::are_integral<I0,Args...>::value
702  && ( 1 == Rank )
703  && is_default_map
704  && is_layout_stride
705  ), reference_type >::type
706  operator()( const I0 & i0
707  , Args ... args ) const
708  {
709  #ifndef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
710  KOKKOS_VIEW_OPERATOR_VERIFY( (NULL,m_map,i0,args...) )
711  #else
712  KOKKOS_VIEW_OPERATOR_VERIFY( (m_track.template get_label<typename traits::memory_space>().c_str(),m_map,i0,args...) )
713  #endif
714 
715  return m_map.m_handle[ m_map.m_offset.m_stride.S0 * i0 ];
716  }
717 
718  //------------------------------
719  // Rank 1 operator[]
720 
721  template< typename I0 >
722  KOKKOS_FORCEINLINE_FUNCTION
723  typename std::enable_if<
724  ( Kokkos::Impl::are_integral<I0>::value
725  && ( 1 == Rank )
726  && ! is_default_map
727  ), reference_type >::type
728  operator[]( const I0 & i0 ) const
729  {
730  #ifndef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
731  KOKKOS_VIEW_OPERATOR_VERIFY( (NULL,m_map,i0) )
732  #else
733  KOKKOS_VIEW_OPERATOR_VERIFY( (m_track.template get_label<typename traits::memory_space>().c_str(),m_map,i0) )
734  #endif
735 
736  return m_map.reference(i0);
737  }
738 
739  template< typename I0 >
740  KOKKOS_FORCEINLINE_FUNCTION
741  typename std::enable_if<
742  ( Kokkos::Impl::are_integral<I0>::value
743  && ( 1 == Rank )
744  && is_default_map
745  && ! is_layout_stride
746  ), reference_type >::type
747  operator[]( const I0 & i0 ) const
748  {
749  #ifndef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
750  KOKKOS_VIEW_OPERATOR_VERIFY( (NULL,m_map,i0) )
751  #else
752  KOKKOS_VIEW_OPERATOR_VERIFY( (m_track.template get_label<typename traits::memory_space>().c_str(),m_map,i0) )
753  #endif
754 
755  return m_map.m_handle[ i0 ];
756  }
757 
758  template< typename I0 >
759  KOKKOS_FORCEINLINE_FUNCTION
760  typename std::enable_if<
761  ( Kokkos::Impl::are_integral<I0>::value
762  && ( 1 == Rank )
763  && is_default_map
764  && is_layout_stride
765  ), reference_type >::type
766  operator[]( const I0 & i0 ) const
767  {
768  #ifndef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
769  KOKKOS_VIEW_OPERATOR_VERIFY( (NULL,m_map,i0) )
770  #else
771  KOKKOS_VIEW_OPERATOR_VERIFY( (m_track.template get_label<typename traits::memory_space>().c_str(),m_map,i0) )
772  #endif
773 
774  return m_map.m_handle[ m_map.m_offset.m_stride.S0 * i0 ];
775  }
776 
777  //------------------------------
778  // Rank 2
779 
780  template< typename I0 , typename I1
781  , class ... Args >
782  KOKKOS_FORCEINLINE_FUNCTION
783  typename std::enable_if<
784  ( Kokkos::Impl::are_integral<I0,I1,Args...>::value
785  && ( 2 == Rank )
786  && ! is_default_map
787  ), reference_type >::type
788  operator()( const I0 & i0 , const I1 & i1
789  , Args ... args ) const
790  {
791  #ifndef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
792  KOKKOS_VIEW_OPERATOR_VERIFY( (NULL,m_map,i0,i1,args...) )
793  #else
794  KOKKOS_VIEW_OPERATOR_VERIFY( (m_track.template get_label<typename traits::memory_space>().c_str(),m_map,i0,i1,args...) )
795  #endif
796 
797  return m_map.reference(i0,i1);
798  }
799 
800  template< typename I0 , typename I1
801  , class ... Args >
802  KOKKOS_FORCEINLINE_FUNCTION
803  typename std::enable_if<
804  ( Kokkos::Impl::are_integral<I0,I1,Args...>::value
805  && ( 2 == Rank )
806  && is_default_map
807  && is_layout_left && ( traits::rank_dynamic == 0 )
808  ), reference_type >::type
809  operator()( const I0 & i0 , const I1 & i1
810  , Args ... args ) const
811  {
812  #ifndef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
813  KOKKOS_VIEW_OPERATOR_VERIFY( (NULL,m_map,i0,i1,args...) )
814  #else
815  KOKKOS_VIEW_OPERATOR_VERIFY( (m_track.template get_label<typename traits::memory_space>().c_str(),m_map,i0,i1,args...) )
816  #endif
817 
818  return m_map.m_handle[ i0 + m_map.m_offset.m_dim.N0 * i1 ];
819  }
820 
821  template< typename I0 , typename I1
822  , class ... Args >
823  KOKKOS_FORCEINLINE_FUNCTION
824  typename std::enable_if<
825  ( Kokkos::Impl::are_integral<I0,I1,Args...>::value
826  && ( 2 == Rank )
827  && is_default_map
828  && is_layout_left && ( traits::rank_dynamic != 0 )
829  ), reference_type >::type
830  operator()( const I0 & i0 , const I1 & i1
831  , Args ... args ) const
832  {
833  #ifndef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
834  KOKKOS_VIEW_OPERATOR_VERIFY( (NULL,m_map,i0,i1,args...) )
835  #else
836  KOKKOS_VIEW_OPERATOR_VERIFY( (m_track.template get_label<typename traits::memory_space>().c_str(),m_map,i0,i1,args...) )
837  #endif
838 
839  return m_map.m_handle[ i0 + m_map.m_offset.m_stride * i1 ];
840  }
841 
842  template< typename I0 , typename I1
843  , class ... Args >
844  KOKKOS_FORCEINLINE_FUNCTION
845  typename std::enable_if<
846  ( Kokkos::Impl::are_integral<I0,I1,Args...>::value
847  && ( 2 == Rank )
848  && is_default_map
849  && is_layout_right && ( traits::rank_dynamic == 0 )
850  ), reference_type >::type
851  operator()( const I0 & i0 , const I1 & i1
852  , Args ... args ) const
853  {
854  #ifndef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
855  KOKKOS_VIEW_OPERATOR_VERIFY( (NULL,m_map,i0,i1,args...) )
856  #else
857  KOKKOS_VIEW_OPERATOR_VERIFY( (m_track.template get_label<typename traits::memory_space>().c_str(),m_map,i0,i1,args...) )
858  #endif
859 
860  return m_map.m_handle[ i1 + m_map.m_offset.m_dim.N1 * i0 ];
861  }
862 
863  template< typename I0 , typename I1
864  , class ... Args >
865  KOKKOS_FORCEINLINE_FUNCTION
866  typename std::enable_if<
867  ( Kokkos::Impl::are_integral<I0,I1,Args...>::value
868  && ( 2 == Rank )
869  && is_default_map
870  && is_layout_right && ( traits::rank_dynamic != 0 )
871  ), reference_type >::type
872  operator()( const I0 & i0 , const I1 & i1
873  , Args ... args ) const
874  {
875  #ifndef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
876  KOKKOS_VIEW_OPERATOR_VERIFY( (NULL,m_map,i0,i1,args...) )
877  #else
878  KOKKOS_VIEW_OPERATOR_VERIFY( (m_track.template get_label<typename traits::memory_space>().c_str(),m_map,i0,i1,args...) )
879  #endif
880 
881  return m_map.m_handle[ i1 + m_map.m_offset.m_stride * i0 ];
882  }
883 
884  template< typename I0 , typename I1
885  , class ... Args >
886  KOKKOS_FORCEINLINE_FUNCTION
887  typename std::enable_if<
888  ( Kokkos::Impl::are_integral<I0,I1,Args...>::value
889  && ( 2 == Rank )
890  && is_default_map
891  && is_layout_stride
892  ), reference_type >::type
893  operator()( const I0 & i0 , const I1 & i1
894  , Args ... args ) const
895  {
896  #ifndef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
897  KOKKOS_VIEW_OPERATOR_VERIFY( (NULL,m_map,i0,i1,args...) )
898  #else
899  KOKKOS_VIEW_OPERATOR_VERIFY( (m_track.template get_label<typename traits::memory_space>().c_str(),m_map,i0,i1,args...) )
900  #endif
901 
902  return m_map.m_handle[ i0 * m_map.m_offset.m_stride.S0 +
903  i1 * m_map.m_offset.m_stride.S1 ];
904  }
905 
906  //------------------------------
907  // Rank 3
908 
909  template< typename I0 , typename I1 , typename I2
910  , class ... Args >
911  KOKKOS_FORCEINLINE_FUNCTION
912  typename std::enable_if<
913  ( Kokkos::Impl::are_integral<I0,I1,I2,Args...>::value
914  && ( 3 == Rank )
915  && is_default_map
916  ), reference_type >::type
917  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2
918  , Args ... args ) const
919  {
920  #ifndef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
921  KOKKOS_VIEW_OPERATOR_VERIFY( (NULL,m_map,i0,i1,i2,args...) )
922  #else
923  KOKKOS_VIEW_OPERATOR_VERIFY( (m_track.template get_label<typename traits::memory_space>().c_str(),m_map,i0,i1,i2,args...) )
924  #endif
925 
926  return m_map.m_handle[ m_map.m_offset(i0,i1,i2) ];
927  }
928 
929  template< typename I0 , typename I1 , typename I2
930  , class ... Args >
931  KOKKOS_FORCEINLINE_FUNCTION
932  typename std::enable_if<
933  ( Kokkos::Impl::are_integral<I0,I1,I2,Args...>::value
934  && ( 3 == Rank )
935  && ! is_default_map
936  ), reference_type >::type
937  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2
938  , Args ... args ) const
939  {
940  #ifndef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
941  KOKKOS_VIEW_OPERATOR_VERIFY( (NULL,m_map,i0,i1,i2,args...) )
942  #else
943  KOKKOS_VIEW_OPERATOR_VERIFY( (m_track.template get_label<typename traits::memory_space>().c_str(),m_map,i0,i1,i2,args...) )
944  #endif
945 
946  return m_map.reference(i0,i1,i2);
947  }
948 
949  //------------------------------
950  // Rank 4
951 
952  template< typename I0 , typename I1 , typename I2 , typename I3
953  , class ... Args >
954  KOKKOS_FORCEINLINE_FUNCTION
955  typename std::enable_if<
956  ( Kokkos::Impl::are_integral<I0,I1,I2,I3,Args...>::value
957  && ( 4 == Rank )
958  && is_default_map
959  ), reference_type >::type
960  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
961  , Args ... args ) const
962  {
963  #ifndef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
964  KOKKOS_VIEW_OPERATOR_VERIFY( (NULL,m_map,i0,i1,i2,i3,args...) )
965  #else
966  KOKKOS_VIEW_OPERATOR_VERIFY( (m_track.template get_label<typename traits::memory_space>().c_str(),m_map,i0,i1,i2,i3,args...) )
967  #endif
968 
969  return m_map.m_handle[ m_map.m_offset(i0,i1,i2,i3) ];
970  }
971 
972  template< typename I0 , typename I1 , typename I2 , typename I3
973  , class ... Args >
974  KOKKOS_FORCEINLINE_FUNCTION
975  typename std::enable_if<
976  ( Kokkos::Impl::are_integral<I0,I1,I2,I3,Args...>::value
977  && ( 4 == Rank )
978  && ! is_default_map
979  ), reference_type >::type
980  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
981  , Args ... args ) const
982  {
983  #ifndef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
984  KOKKOS_VIEW_OPERATOR_VERIFY( (NULL,m_map,i0,i1,i2,i3,args...) )
985  #else
986  KOKKOS_VIEW_OPERATOR_VERIFY( (m_track.template get_label<typename traits::memory_space>().c_str(),m_map,i0,i1,i2,i3,args...) )
987  #endif
988 
989  return m_map.reference(i0,i1,i2,i3);
990  }
991 
992  //------------------------------
993  // Rank 5
994 
995  template< typename I0 , typename I1 , typename I2 , typename I3
996  , typename I4
997  , class ... Args >
998  KOKKOS_FORCEINLINE_FUNCTION
999  typename std::enable_if<
1000  ( Kokkos::Impl::are_integral<I0,I1,I2,I3,I4,Args...>::value
1001  && ( 5 == Rank )
1002  && is_default_map
1003  ), reference_type >::type
1004  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1005  , const I4 & i4
1006  , Args ... args ) const
1007  {
1008  #ifndef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
1009  KOKKOS_VIEW_OPERATOR_VERIFY( (NULL,m_map,i0,i1,i2,i3,i4,args...) )
1010  #else
1011  KOKKOS_VIEW_OPERATOR_VERIFY( (m_track.template get_label<typename traits::memory_space>().c_str(),m_map,i0,i1,i2,i3,i4,args...) )
1012  #endif
1013 
1014  return m_map.m_handle[ m_map.m_offset(i0,i1,i2,i3,i4) ];
1015  }
1016 
1017  template< typename I0 , typename I1 , typename I2 , typename I3
1018  , typename I4
1019  , class ... Args >
1020  KOKKOS_FORCEINLINE_FUNCTION
1021  typename std::enable_if<
1022  ( Kokkos::Impl::are_integral<I0,I1,I2,I3,I4,Args...>::value
1023  && ( 5 == Rank )
1024  && ! is_default_map
1025  ), reference_type >::type
1026  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1027  , const I4 & i4
1028  , Args ... args ) const
1029  {
1030  #ifndef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
1031  KOKKOS_VIEW_OPERATOR_VERIFY( (NULL,m_map,i0,i1,i2,i3,i4,args...) )
1032  #else
1033  KOKKOS_VIEW_OPERATOR_VERIFY( (m_track.template get_label<typename traits::memory_space>().c_str(),m_map,i0,i1,i2,i3,i4,args...) )
1034  #endif
1035 
1036  return m_map.reference(i0,i1,i2,i3,i4);
1037  }
1038 
1039  //------------------------------
1040  // Rank 6
1041 
1042  template< typename I0 , typename I1 , typename I2 , typename I3
1043  , typename I4 , typename I5
1044  , class ... Args >
1045  KOKKOS_FORCEINLINE_FUNCTION
1046  typename std::enable_if<
1047  ( Kokkos::Impl::are_integral<I0,I1,I2,I3,I4,I5,Args...>::value
1048  && ( 6 == Rank )
1049  && is_default_map
1050  ), reference_type >::type
1051  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1052  , const I4 & i4 , const I5 & i5
1053  , Args ... args ) const
1054  {
1055  #ifndef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
1056  KOKKOS_VIEW_OPERATOR_VERIFY( (NULL,m_map,i0,i1,i2,i3,i4,i5,args...) )
1057  #else
1058  KOKKOS_VIEW_OPERATOR_VERIFY( (m_track.template get_label<typename traits::memory_space>().c_str(),m_map,i0,i1,i2,i3,i4,i5,args...) )
1059  #endif
1060 
1061  return m_map.m_handle[ m_map.m_offset(i0,i1,i2,i3,i4,i5) ];
1062  }
1063 
1064  template< typename I0 , typename I1 , typename I2 , typename I3
1065  , typename I4 , typename I5
1066  , class ... Args >
1067  KOKKOS_FORCEINLINE_FUNCTION
1068  typename std::enable_if<
1069  ( Kokkos::Impl::are_integral<I0,I1,I2,I3,I4,I5,Args...>::value
1070  && ( 6 == Rank )
1071  && ! is_default_map
1072  ), reference_type >::type
1073  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1074  , const I4 & i4 , const I5 & i5
1075  , Args ... args ) const
1076  {
1077  #ifndef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
1078  KOKKOS_VIEW_OPERATOR_VERIFY( (NULL,m_map,i0,i1,i2,i3,i4,i5,args...) )
1079  #else
1080  KOKKOS_VIEW_OPERATOR_VERIFY( (m_track.template get_label<typename traits::memory_space>().c_str(),m_map,i0,i1,i2,i3,i4,i5,args...) )
1081  #endif
1082 
1083  return m_map.reference(i0,i1,i2,i3,i4,i5);
1084  }
1085 
1086  //------------------------------
1087  // Rank 7
1088 
1089  template< typename I0 , typename I1 , typename I2 , typename I3
1090  , typename I4 , typename I5 , typename I6
1091  , class ... Args >
1092  KOKKOS_FORCEINLINE_FUNCTION
1093  typename std::enable_if<
1094  ( Kokkos::Impl::are_integral<I0,I1,I2,I3,I4,I5,I6,Args...>::value
1095  && ( 7 == Rank )
1096  && is_default_map
1097  ), reference_type >::type
1098  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1099  , const I4 & i4 , const I5 & i5 , const I6 & i6
1100  , Args ... args ) const
1101  {
1102  #ifndef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
1103  KOKKOS_VIEW_OPERATOR_VERIFY( (NULL,m_map,i0,i1,i2,i3,i4,i5,i6,args...) )
1104  #else
1105  KOKKOS_VIEW_OPERATOR_VERIFY( (m_track.template get_label<typename traits::memory_space>().c_str(),m_map,i0,i1,i2,i3,i4,i5,i6,args...) )
1106  #endif
1107 
1108  return m_map.m_handle[ m_map.m_offset(i0,i1,i2,i3,i4,i5,i6) ];
1109  }
1110 
1111  template< typename I0 , typename I1 , typename I2 , typename I3
1112  , typename I4 , typename I5 , typename I6
1113  , class ... Args >
1114  KOKKOS_FORCEINLINE_FUNCTION
1115  typename std::enable_if<
1116  ( Kokkos::Impl::are_integral<I0,I1,I2,I3,I4,I5,I6,Args...>::value
1117  && ( 7 == Rank )
1118  && ! is_default_map
1119  ), reference_type >::type
1120  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1121  , const I4 & i4 , const I5 & i5 , const I6 & i6
1122  , Args ... args ) const
1123  {
1124  #ifndef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
1125  KOKKOS_VIEW_OPERATOR_VERIFY( (NULL,m_map,i0,i1,i2,i3,i4,i5,i6,args...) )
1126  #else
1127  KOKKOS_VIEW_OPERATOR_VERIFY( (m_track.template get_label<typename traits::memory_space>().c_str(),m_map,i0,i1,i2,i3,i4,i5,i6,args...) )
1128  #endif
1129 
1130  return m_map.reference(i0,i1,i2,i3,i4,i5,i6);
1131  }
1132 
1133  //------------------------------
1134  // Rank 8
1135 
1136  template< typename I0 , typename I1 , typename I2 , typename I3
1137  , typename I4 , typename I5 , typename I6 , typename I7
1138  , class ... Args >
1139  KOKKOS_FORCEINLINE_FUNCTION
1140  typename std::enable_if<
1141  ( Kokkos::Impl::are_integral<I0,I1,I2,I3,I4,I5,I6,I7,Args...>::value
1142  && ( 8 == Rank )
1143  && is_default_map
1144  ), reference_type >::type
1145  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1146  , const I4 & i4 , const I5 & i5 , const I6 & i6 , const I7 & i7
1147  , Args ... args ) const
1148  {
1149  #ifndef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
1150  KOKKOS_VIEW_OPERATOR_VERIFY( (NULL,m_map,i0,i1,i2,i3,i4,i5,i6,i7,args...) )
1151  #else
1152  KOKKOS_VIEW_OPERATOR_VERIFY( (m_track.template get_label<typename traits::memory_space>().c_str(),m_map,i0,i1,i2,i3,i4,i5,i6,i7,args...) )
1153  #endif
1154 
1155  return m_map.m_handle[ m_map.m_offset(i0,i1,i2,i3,i4,i5,i6,i7) ];
1156  }
1157 
1158  template< typename I0 , typename I1 , typename I2 , typename I3
1159  , typename I4 , typename I5 , typename I6 , typename I7
1160  , class ... Args >
1161  KOKKOS_FORCEINLINE_FUNCTION
1162  typename std::enable_if<
1163  ( Kokkos::Impl::are_integral<I0,I1,I2,I3,I4,I5,I6,I7,Args...>::value
1164  && ( 8 == Rank )
1165  && ! is_default_map
1166  ), reference_type >::type
1167  operator()( const I0 & i0 , const I1 & i1 , const I2 & i2 , const I3 & i3
1168  , const I4 & i4 , const I5 & i5 , const I6 & i6 , const I7 & i7
1169  , Args ... args ) const
1170  {
1171  #ifndef KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST
1172  KOKKOS_VIEW_OPERATOR_VERIFY( (NULL,m_map,i0,i1,i2,i3,i4,i5,i6,i7,args...) )
1173  #else
1174  KOKKOS_VIEW_OPERATOR_VERIFY( (m_track.template get_label<typename traits::memory_space>().c_str(),m_map,i0,i1,i2,i3,i4,i5,i6,i7,args...) )
1175  #endif
1176 
1177  return m_map.reference(i0,i1,i2,i3,i4,i5,i6,i7);
1178  }
1179 
1180 #undef KOKKOS_VIEW_OPERATOR_VERIFY
1181 
1182  //----------------------------------------
1183  // Standard destructor, constructors, and assignment operators
1184 
1185  KOKKOS_INLINE_FUNCTION
1186  ~View() {}
1187 
1188  KOKKOS_INLINE_FUNCTION
1189  View() : m_track(), m_map() {}
1190 
1191  KOKKOS_INLINE_FUNCTION
1192  View( const View & rhs ) : m_track( rhs.m_track ), m_map( rhs.m_map ) {}
1193 
1194  KOKKOS_INLINE_FUNCTION
1195  View( View && rhs ) : m_track( rhs.m_track ), m_map( rhs.m_map ) {}
1196 
1197  KOKKOS_INLINE_FUNCTION
1198  View & operator = ( const View & rhs ) { m_track = rhs.m_track ; m_map = rhs.m_map ; return *this ; }
1199 
1200  KOKKOS_INLINE_FUNCTION
1201  View & operator = ( View && rhs ) { m_track = rhs.m_track ; m_map = rhs.m_map ; return *this ; }
1202 
1203  //----------------------------------------
1204  // Compatible view copy constructor and assignment
1205  // may assign unmanaged from managed.
1206 
1207  template< class RT , class ... RP >
1208  KOKKOS_INLINE_FUNCTION
1209  View( const View<RT,RP...> & rhs )
1210  : m_track( rhs.m_track , traits::is_managed )
1211  , m_map()
1212  {
1213  typedef typename View<RT,RP...>::traits SrcTraits ;
1214  typedef Kokkos::Impl::ViewMapping< traits , SrcTraits , void > Mapping ;
1215  static_assert( Mapping::is_assignable , "Incompatible View copy construction" );
1216  Mapping::assign( m_map , rhs.m_map , rhs.m_track );
1217  }
1218 
1219  template< class RT , class ... RP >
1220  KOKKOS_INLINE_FUNCTION
1221  View & operator = ( const View<RT,RP...> & rhs )
1222  {
1223  typedef typename View<RT,RP...>::traits SrcTraits ;
1224  typedef Kokkos::Impl::ViewMapping< traits , SrcTraits , void > Mapping ;
1225  static_assert( Mapping::is_assignable , "Incompatible View copy assignment" );
1226  Mapping::assign( m_map , rhs.m_map , rhs.m_track );
1227  m_track.assign( rhs.m_track , traits::is_managed );
1228  return *this ;
1229  }
1230 
1231  //----------------------------------------
1232  // Compatible subview constructor
1233  // may assign unmanaged from managed.
1234 
1235  template< class RT , class ... RP , class Arg0 , class ... Args >
1236  KOKKOS_INLINE_FUNCTION
1237  View( const View< RT , RP... > & src_view
1238  , const Arg0 & arg0 , Args ... args )
1239  : m_track( src_view.m_track , traits::is_managed )
1240  , m_map()
1241  {
1242  typedef View< RT , RP... > SrcType ;
1243 
1244  typedef Kokkos::Impl::ViewMapping
1245  < void /* deduce destination view type from source view traits */
1246  , typename SrcType::traits
1247  , Arg0 , Args... > Mapping ;
1248 
1249  typedef typename Mapping::type DstType ;
1250 
1251  static_assert( Kokkos::Impl::ViewMapping< traits , typename DstType::traits , void >::is_assignable
1252  , "Subview construction requires compatible view and subview arguments" );
1253 
1254  Mapping::assign( m_map, src_view.m_map, arg0 , args... );
1255  }
1256 
1257  //----------------------------------------
1258  // Allocation tracking properties
1259 
1260  KOKKOS_INLINE_FUNCTION
1261  int use_count() const
1262  { return m_track.use_count(); }
1263 
1264  inline
1265  const std::string label() const
1266  { return m_track.template get_label< typename traits::memory_space >(); }
1267 
1268  //----------------------------------------
1269  // Allocation according to allocation properties and array layout
1270 
1271  template< class ... P >
1272  explicit inline
1273  View( const Impl::ViewCtorProp< P ... > & arg_prop
1274  , typename std::enable_if< ! Impl::ViewCtorProp< P... >::has_pointer
1275  , typename traits::array_layout
1276  >::type const & arg_layout
1277  )
1278  : m_track()
1279  , m_map()
1280  {
1281  // Append layout and spaces if not input
1282  typedef Impl::ViewCtorProp< P ... > alloc_prop_input ;
1283 
1284  // use 'std::integral_constant<unsigned,I>' for non-types
1285  // to avoid duplicate class error.
1286  typedef Impl::ViewCtorProp
1287  < P ...
1288  , typename std::conditional
1289  < alloc_prop_input::has_label
1290  , std::integral_constant<unsigned,0>
1291  , typename std::string
1292  >::type
1293  , typename std::conditional
1294  < alloc_prop_input::has_memory_space
1295  , std::integral_constant<unsigned,1>
1296  , typename traits::device_type::memory_space
1297  >::type
1298  , typename std::conditional
1299  < alloc_prop_input::has_execution_space
1300  , std::integral_constant<unsigned,2>
1301  , typename traits::device_type::execution_space
1302  >::type
1303  > alloc_prop ;
1304 
1305  static_assert( traits::is_managed
1306  , "View allocation constructor requires managed memory" );
1307 
1308  if ( alloc_prop::initialize &&
1309  ! alloc_prop::execution_space::is_initialized() ) {
1310  // If initializing view data then
1311  // the execution space must be initialized.
1312  Kokkos::Impl::throw_runtime_exception("Constructing View and initializing data with uninitialized execution space");
1313  }
1314 
1315  // Copy the input allocation properties with possibly defaulted properties
1316  alloc_prop prop( arg_prop );
1317 
1318 //------------------------------------------------------------
1319 #if defined( KOKKOS_HAVE_CUDA )
1320  // If allocating in CudaUVMSpace must fence before and after
1321  // the allocation to protect against possible concurrent access
1322  // on the CPU and the GPU.
1323  // Fence using the trait's executon space (which will be Kokkos::Cuda)
1324  // to avoid incomplete type errors from usng Kokkos::Cuda directly.
1325  if ( std::is_same< Kokkos::CudaUVMSpace , typename traits::device_type::memory_space >::value ) {
1326  traits::device_type::memory_space::execution_space::fence();
1327  }
1328 #endif
1329 //------------------------------------------------------------
1330 
1331  Kokkos::Impl::SharedAllocationRecord<> *
1332  record = m_map.allocate_shared( prop , arg_layout );
1333 
1334 //------------------------------------------------------------
1335 #if defined( KOKKOS_HAVE_CUDA )
1336  if ( std::is_same< Kokkos::CudaUVMSpace , typename traits::device_type::memory_space >::value ) {
1337  traits::device_type::memory_space::execution_space::fence();
1338  }
1339 #endif
1340 //------------------------------------------------------------
1341 
1342  // Setup and initialization complete, start tracking
1343  m_track.assign_allocated_record_to_uninitialized( record );
1344  }
1345 
1346  // Wrap memory according to properties and array layout
1347  template< class ... P >
1348  explicit KOKKOS_INLINE_FUNCTION
1349  View( const Impl::ViewCtorProp< P ... > & arg_prop
1350  , typename std::enable_if< Impl::ViewCtorProp< P... >::has_pointer
1351  , typename traits::array_layout
1352  >::type const & arg_layout
1353  )
1354  : m_track() // No memory tracking
1355  , m_map( arg_prop , arg_layout )
1356  {
1357  static_assert(
1358  std::is_same< pointer_type
1359  , typename Impl::ViewCtorProp< P... >::pointer_type
1360  >::value ,
1361  "Constructing View to wrap user memory must supply matching pointer type" );
1362  }
1363 
1364  // Simple dimension-only layout
1365  template< class ... P >
1366  explicit inline
1367  View( const Impl::ViewCtorProp< P ... > & arg_prop
1368  , typename std::enable_if< ! Impl::ViewCtorProp< P... >::has_pointer
1369  , size_t
1370  >::type const arg_N0 = 0
1371  , const size_t arg_N1 = 0
1372  , const size_t arg_N2 = 0
1373  , const size_t arg_N3 = 0
1374  , const size_t arg_N4 = 0
1375  , const size_t arg_N5 = 0
1376  , const size_t arg_N6 = 0
1377  , const size_t arg_N7 = 0
1378  )
1379  : View( arg_prop
1380  , typename traits::array_layout
1381  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1382  , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1383  )
1384  {}
1385 
1386  template< class ... P >
1387  explicit KOKKOS_INLINE_FUNCTION
1388  View( const Impl::ViewCtorProp< P ... > & arg_prop
1389  , typename std::enable_if< Impl::ViewCtorProp< P... >::has_pointer
1390  , size_t
1391  >::type const arg_N0 = 0
1392  , const size_t arg_N1 = 0
1393  , const size_t arg_N2 = 0
1394  , const size_t arg_N3 = 0
1395  , const size_t arg_N4 = 0
1396  , const size_t arg_N5 = 0
1397  , const size_t arg_N6 = 0
1398  , const size_t arg_N7 = 0
1399  )
1400  : View( arg_prop
1401  , typename traits::array_layout
1402  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1403  , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1404  )
1405  {}
1406 
1407  // Allocate with label and layout
1408  template< typename Label >
1409  explicit inline
1410  View( const Label & arg_label
1411  , typename std::enable_if<
1412  Kokkos::Impl::is_view_label<Label>::value ,
1413  typename traits::array_layout >::type const & arg_layout
1414  )
1415  : View( Impl::ViewCtorProp< std::string >( arg_label ) , arg_layout )
1416  {}
1417 
1418  // Allocate label and layout, must disambiguate from subview constructor.
1419  template< typename Label >
1420  explicit inline
1421  View( const Label & arg_label
1422  , typename std::enable_if<
1423  Kokkos::Impl::is_view_label<Label>::value ,
1424  const size_t >::type arg_N0 = 0
1425  , const size_t arg_N1 = 0
1426  , const size_t arg_N2 = 0
1427  , const size_t arg_N3 = 0
1428  , const size_t arg_N4 = 0
1429  , const size_t arg_N5 = 0
1430  , const size_t arg_N6 = 0
1431  , const size_t arg_N7 = 0
1432  )
1433  : View( Impl::ViewCtorProp< std::string >( arg_label )
1434  , typename traits::array_layout
1435  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1436  , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1437  )
1438  {}
1439 
1440  // For backward compatibility
1441  explicit inline
1442  View( const ViewAllocateWithoutInitializing & arg_prop
1443  , const typename traits::array_layout & arg_layout
1444  )
1445  : View( Impl::ViewCtorProp< std::string , Kokkos::Impl::WithoutInitializing_t >( arg_prop.label , Kokkos::WithoutInitializing )
1446  , arg_layout
1447  )
1448  {}
1449 
1450  explicit inline
1451  View( const ViewAllocateWithoutInitializing & arg_prop
1452  , const size_t arg_N0 = 0
1453  , const size_t arg_N1 = 0
1454  , const size_t arg_N2 = 0
1455  , const size_t arg_N3 = 0
1456  , const size_t arg_N4 = 0
1457  , const size_t arg_N5 = 0
1458  , const size_t arg_N6 = 0
1459  , const size_t arg_N7 = 0
1460  )
1461  : View( Impl::ViewCtorProp< std::string , Kokkos::Impl::WithoutInitializing_t >( arg_prop.label , Kokkos::WithoutInitializing )
1462  , typename traits::array_layout
1463  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1464  , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1465  )
1466  {}
1467 
1468  //----------------------------------------
1469  // Memory span required to wrap these dimensions.
1470  static constexpr size_t required_allocation_size(
1471  const size_t arg_N0 = 0
1472  , const size_t arg_N1 = 0
1473  , const size_t arg_N2 = 0
1474  , const size_t arg_N3 = 0
1475  , const size_t arg_N4 = 0
1476  , const size_t arg_N5 = 0
1477  , const size_t arg_N6 = 0
1478  , const size_t arg_N7 = 0
1479  )
1480  {
1481  return map_type::memory_span(
1482  typename traits::array_layout
1483  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1484  , arg_N4 , arg_N5 , arg_N6 , arg_N7 ) );
1485  }
1486 
1487  explicit KOKKOS_INLINE_FUNCTION
1488  View( pointer_type arg_ptr
1489  , const size_t arg_N0 = 0
1490  , const size_t arg_N1 = 0
1491  , const size_t arg_N2 = 0
1492  , const size_t arg_N3 = 0
1493  , const size_t arg_N4 = 0
1494  , const size_t arg_N5 = 0
1495  , const size_t arg_N6 = 0
1496  , const size_t arg_N7 = 0
1497  )
1498  : View( Impl::ViewCtorProp<pointer_type>(arg_ptr)
1499  , typename traits::array_layout
1500  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1501  , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1502  )
1503  {}
1504 
1505  explicit KOKKOS_INLINE_FUNCTION
1506  View( pointer_type arg_ptr
1507  , const typename traits::array_layout & arg_layout
1508  )
1509  : View( Impl::ViewCtorProp<pointer_type>(arg_ptr) , arg_layout )
1510  {}
1511 
1512  //----------------------------------------
1513  // Shared scratch memory constructor
1514 
1515  static inline
1516  size_t shmem_size( const size_t arg_N0 = ~size_t(0) ,
1517  const size_t arg_N1 = ~size_t(0) ,
1518  const size_t arg_N2 = ~size_t(0) ,
1519  const size_t arg_N3 = ~size_t(0) ,
1520  const size_t arg_N4 = ~size_t(0) ,
1521  const size_t arg_N5 = ~size_t(0) ,
1522  const size_t arg_N6 = ~size_t(0) ,
1523  const size_t arg_N7 = ~size_t(0) )
1524  {
1525  const size_t num_passed_args =
1526  ( arg_N0 != ~size_t(0) ) + ( arg_N1 != ~size_t(0) ) + ( arg_N2 != ~size_t(0) ) +
1527  ( arg_N3 != ~size_t(0) ) + ( arg_N4 != ~size_t(0) ) + ( arg_N5 != ~size_t(0) ) +
1528  ( arg_N6 != ~size_t(0) ) + ( arg_N7 != ~size_t(0) );
1529 
1530  if ( std::is_same<typename traits::specialize,void>::value && num_passed_args != traits::rank_dynamic ) {
1531  Kokkos::abort( "Kokkos::View::shmem_size() rank_dynamic != number of arguments.\n" );
1532  }
1533 
1534  return map_type::memory_span(
1535  typename traits::array_layout
1536  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1537  , arg_N4 , arg_N5 , arg_N6 , arg_N7 ) );
1538  }
1539 
1540  explicit KOKKOS_INLINE_FUNCTION
1541  View( const typename traits::execution_space::scratch_memory_space & arg_space
1542  , const typename traits::array_layout & arg_layout )
1543  : View( Impl::ViewCtorProp<pointer_type>(
1544  reinterpret_cast<pointer_type>(
1545  arg_space.get_shmem( map_type::memory_span( arg_layout ) ) ) )
1546  , arg_layout )
1547  {}
1548 
1549  explicit KOKKOS_INLINE_FUNCTION
1550  View( const typename traits::execution_space::scratch_memory_space & arg_space
1551  , const size_t arg_N0 = 0
1552  , const size_t arg_N1 = 0
1553  , const size_t arg_N2 = 0
1554  , const size_t arg_N3 = 0
1555  , const size_t arg_N4 = 0
1556  , const size_t arg_N5 = 0
1557  , const size_t arg_N6 = 0
1558  , const size_t arg_N7 = 0 )
1559  : View( Impl::ViewCtorProp<pointer_type>(
1560  reinterpret_cast<pointer_type>(
1561  arg_space.get_shmem(
1562  map_type::memory_span(
1563  typename traits::array_layout
1564  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1565  , arg_N4 , arg_N5 , arg_N6 , arg_N7 ) ) ) ) )
1566  , typename traits::array_layout
1567  ( arg_N0 , arg_N1 , arg_N2 , arg_N3
1568  , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
1569  )
1570  {}
1571 };
1572 
1573 
1578  template < typename D , class ... P >
1579  KOKKOS_INLINE_FUNCTION
1580  constexpr unsigned rank( const View<D , P...> & V ) { return V.Rank; } //Temporary until added to view
1581 
1582 //----------------------------------------------------------------------------
1583 //----------------------------------------------------------------------------
1584 
1585 template< class V , class ... Args >
1586 using Subview =
1587  typename Kokkos::Impl::ViewMapping
1588  < void /* deduce subview type from source view traits */
1589  , typename V::traits
1590  , Args ...
1591  >::type ;
1592 
1593 template< class D, class ... P , class ... Args >
1594 KOKKOS_INLINE_FUNCTION
1595 typename Kokkos::Impl::ViewMapping
1596  < void /* deduce subview type from source view traits */
1597  , ViewTraits< D , P... >
1598  , Args ...
1599  >::type
1600 subview( const View< D, P... > & src , Args ... args )
1601 {
1602  static_assert( View< D , P... >::Rank == sizeof...(Args) ,
1603  "subview requires one argument for each source View rank" );
1604 
1605  return typename
1606  Kokkos::Impl::ViewMapping
1607  < void /* deduce subview type from source view traits */
1608  , ViewTraits< D , P ... >
1609  , Args ... >::type( src , args ... );
1610 }
1611 
1612 template< class MemoryTraits , class D, class ... P , class ... Args >
1613 KOKKOS_INLINE_FUNCTION
1614 typename Kokkos::Impl::ViewMapping
1615  < void /* deduce subview type from source view traits */
1616  , ViewTraits< D , P... >
1617  , Args ...
1618  >::template apply< MemoryTraits >::type
1619 subview( const View< D, P... > & src , Args ... args )
1620 {
1621  static_assert( View< D , P... >::Rank == sizeof...(Args) ,
1622  "subview requires one argument for each source View rank" );
1623 
1624  return typename
1625  Kokkos::Impl::ViewMapping
1626  < void /* deduce subview type from source view traits */
1627  , ViewTraits< D , P ... >
1628  , Args ... >
1629  ::template apply< MemoryTraits >
1630  ::type( src , args ... );
1631 }
1632 
1633 } /* namespace Kokkos */
1634 
1635 //----------------------------------------------------------------------------
1636 //----------------------------------------------------------------------------
1637 
1638 namespace Kokkos {
1639 
1640 template< class LT , class ... LP , class RT , class ... RP >
1641 KOKKOS_INLINE_FUNCTION
1642 bool operator == ( const View<LT,LP...> & lhs ,
1643  const View<RT,RP...> & rhs )
1644 {
1645  // Same data, layout, dimensions
1646  typedef ViewTraits<LT,LP...> lhs_traits ;
1647  typedef ViewTraits<RT,RP...> rhs_traits ;
1648 
1649  return
1650  std::is_same< typename lhs_traits::const_value_type ,
1651  typename rhs_traits::const_value_type >::value &&
1652  std::is_same< typename lhs_traits::array_layout ,
1653  typename rhs_traits::array_layout >::value &&
1654  std::is_same< typename lhs_traits::memory_space ,
1655  typename rhs_traits::memory_space >::value &&
1656  unsigned(lhs_traits::rank) == unsigned(rhs_traits::rank) &&
1657  lhs.data() == rhs.data() &&
1658  lhs.span() == rhs.span() &&
1659  lhs.dimension_0() == rhs.dimension_0() &&
1660  lhs.dimension_1() == rhs.dimension_1() &&
1661  lhs.dimension_2() == rhs.dimension_2() &&
1662  lhs.dimension_3() == rhs.dimension_3() &&
1663  lhs.dimension_4() == rhs.dimension_4() &&
1664  lhs.dimension_5() == rhs.dimension_5() &&
1665  lhs.dimension_6() == rhs.dimension_6() &&
1666  lhs.dimension_7() == rhs.dimension_7();
1667 }
1668 
1669 template< class LT , class ... LP , class RT , class ... RP >
1670 KOKKOS_INLINE_FUNCTION
1671 bool operator != ( const View<LT,LP...> & lhs ,
1672  const View<RT,RP...> & rhs )
1673 {
1674  return ! ( operator==(lhs,rhs) );
1675 }
1676 
1677 } /* namespace Kokkos */
1678 
1679 //----------------------------------------------------------------------------
1680 //----------------------------------------------------------------------------
1681 
1682 namespace Kokkos {
1683 namespace Impl {
1684 
1685 inline
1686 void shared_allocation_tracking_claim_and_disable()
1687 { Kokkos::Impl::SharedAllocationRecord<void,void>::tracking_claim_and_disable(); }
1688 
1689 inline
1690 void shared_allocation_tracking_release_and_enable()
1691 { Kokkos::Impl::SharedAllocationRecord<void,void>::tracking_release_and_enable(); }
1692 
1693 } /* namespace Impl */
1694 } /* namespace Kokkos */
1695 
1696 //----------------------------------------------------------------------------
1697 //----------------------------------------------------------------------------
1698 
1699 namespace Kokkos {
1700 namespace Impl {
1701 
1702 template< class OutputView , typename Enable = void >
1703 struct ViewFill {
1704 
1705  typedef typename OutputView::const_value_type const_value_type ;
1706 
1707  const OutputView output ;
1708  const_value_type input ;
1709 
1710  KOKKOS_INLINE_FUNCTION
1711  void operator()( const size_t i0 ) const
1712  {
1713  const size_t n1 = output.dimension_1();
1714  const size_t n2 = output.dimension_2();
1715  const size_t n3 = output.dimension_3();
1716  const size_t n4 = output.dimension_4();
1717  const size_t n5 = output.dimension_5();
1718  const size_t n6 = output.dimension_6();
1719  const size_t n7 = output.dimension_7();
1720 
1721  for ( size_t i1 = 0 ; i1 < n1 ; ++i1 ) {
1722  for ( size_t i2 = 0 ; i2 < n2 ; ++i2 ) {
1723  for ( size_t i3 = 0 ; i3 < n3 ; ++i3 ) {
1724  for ( size_t i4 = 0 ; i4 < n4 ; ++i4 ) {
1725  for ( size_t i5 = 0 ; i5 < n5 ; ++i5 ) {
1726  for ( size_t i6 = 0 ; i6 < n6 ; ++i6 ) {
1727  for ( size_t i7 = 0 ; i7 < n7 ; ++i7 ) {
1728  output(i0,i1,i2,i3,i4,i5,i6,i7) = input ;
1729  }}}}}}}
1730  }
1731 
1732  ViewFill( const OutputView & arg_out , const_value_type & arg_in )
1733  : output( arg_out ), input( arg_in )
1734  {
1735  typedef typename OutputView::execution_space execution_space ;
1737 
1738  const Kokkos::Impl::ParallelFor< ViewFill , Policy > closure( *this , Policy( 0 , output.dimension_0() ) );
1739 
1740  closure.execute();
1741 
1742  execution_space::fence();
1743  }
1744 };
1745 
1746 template< class OutputView >
1747 struct ViewFill< OutputView , typename std::enable_if< OutputView::Rank == 0 >::type > {
1748  ViewFill( const OutputView & dst , const typename OutputView::const_value_type & src )
1749  {
1750  Kokkos::Impl::DeepCopy< typename OutputView::memory_space , Kokkos::HostSpace >
1751  ( dst.data() , & src , sizeof(typename OutputView::const_value_type) );
1752  }
1753 };
1754 
1755 template< class OutputView , class InputView , class ExecSpace = typename OutputView::execution_space >
1756 struct ViewRemap {
1757 
1758  const OutputView output ;
1759  const InputView input ;
1760  const size_t n0 ;
1761  const size_t n1 ;
1762  const size_t n2 ;
1763  const size_t n3 ;
1764  const size_t n4 ;
1765  const size_t n5 ;
1766  const size_t n6 ;
1767  const size_t n7 ;
1768 
1769  ViewRemap( const OutputView & arg_out , const InputView & arg_in )
1770  : output( arg_out ), input( arg_in )
1771  , n0( std::min( (size_t)arg_out.dimension_0() , (size_t)arg_in.dimension_0() ) )
1772  , n1( std::min( (size_t)arg_out.dimension_1() , (size_t)arg_in.dimension_1() ) )
1773  , n2( std::min( (size_t)arg_out.dimension_2() , (size_t)arg_in.dimension_2() ) )
1774  , n3( std::min( (size_t)arg_out.dimension_3() , (size_t)arg_in.dimension_3() ) )
1775  , n4( std::min( (size_t)arg_out.dimension_4() , (size_t)arg_in.dimension_4() ) )
1776  , n5( std::min( (size_t)arg_out.dimension_5() , (size_t)arg_in.dimension_5() ) )
1777  , n6( std::min( (size_t)arg_out.dimension_6() , (size_t)arg_in.dimension_6() ) )
1778  , n7( std::min( (size_t)arg_out.dimension_7() , (size_t)arg_in.dimension_7() ) )
1779  {
1780  typedef Kokkos::RangePolicy< ExecSpace > Policy ;
1781  const Kokkos::Impl::ParallelFor< ViewRemap , Policy > closure( *this , Policy( 0 , n0 ) );
1782  closure.execute();
1783  }
1784 
1785  KOKKOS_INLINE_FUNCTION
1786  void operator()( const size_t i0 ) const
1787  {
1788  for ( size_t i1 = 0 ; i1 < n1 ; ++i1 ) {
1789  for ( size_t i2 = 0 ; i2 < n2 ; ++i2 ) {
1790  for ( size_t i3 = 0 ; i3 < n3 ; ++i3 ) {
1791  for ( size_t i4 = 0 ; i4 < n4 ; ++i4 ) {
1792  for ( size_t i5 = 0 ; i5 < n5 ; ++i5 ) {
1793  for ( size_t i6 = 0 ; i6 < n6 ; ++i6 ) {
1794  for ( size_t i7 = 0 ; i7 < n7 ; ++i7 ) {
1795  output(i0,i1,i2,i3,i4,i5,i6,i7) = input(i0,i1,i2,i3,i4,i5,i6,i7);
1796  }}}}}}}
1797  }
1798 };
1799 
1800 } /* namespace Impl */
1801 } /* namespace Kokkos */
1802 
1803 //----------------------------------------------------------------------------
1804 //----------------------------------------------------------------------------
1805 
1806 namespace Kokkos {
1807 
1809 template< class DT , class ... DP >
1810 inline
1811 void deep_copy
1812  ( const View<DT,DP...> & dst
1813  , typename ViewTraits<DT,DP...>::const_value_type & value
1814  , typename std::enable_if<
1815  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value
1816  >::type * = 0 )
1817 {
1818  static_assert(
1819  std::is_same< typename ViewTraits<DT,DP...>::non_const_value_type ,
1820  typename ViewTraits<DT,DP...>::value_type >::value
1821  , "deep_copy requires non-const type" );
1822 
1823  Kokkos::Impl::ViewFill< View<DT,DP...> >( dst , value );
1824 }
1825 
1827 template< class ST , class ... SP >
1828 inline
1829 void deep_copy
1830  ( typename ViewTraits<ST,SP...>::non_const_value_type & dst
1831  , const View<ST,SP...> & src
1832  , typename std::enable_if<
1833  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value
1834  >::type * = 0 )
1835 {
1836  static_assert( ViewTraits<ST,SP...>::rank == 0
1837  , "ERROR: Non-rank-zero view in deep_copy( value , View )" );
1838 
1839  typedef ViewTraits<ST,SP...> src_traits ;
1840  typedef typename src_traits::memory_space src_memory_space ;
1841  Kokkos::Impl::DeepCopy< HostSpace , src_memory_space >( & dst , src.data() , sizeof(ST) );
1842 }
1843 
1844 //----------------------------------------------------------------------------
1846 template< class DT , class ... DP , class ST , class ... SP >
1847 inline
1848 void deep_copy
1849  ( const View<DT,DP...> & dst
1850  , const View<ST,SP...> & src
1851  , typename std::enable_if<(
1852  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value &&
1853  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value &&
1854  ( unsigned(ViewTraits<DT,DP...>::rank) == unsigned(0) &&
1855  unsigned(ViewTraits<ST,SP...>::rank) == unsigned(0) )
1856  )>::type * = 0 )
1857 {
1858  static_assert(
1859  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
1860  typename ViewTraits<ST,SP...>::non_const_value_type >::value
1861  , "deep_copy requires matching non-const destination type" );
1862 
1863  typedef View<DT,DP...> dst_type ;
1864  typedef View<ST,SP...> src_type ;
1865 
1866  typedef typename dst_type::value_type value_type ;
1867  typedef typename dst_type::memory_space dst_memory_space ;
1868  typedef typename src_type::memory_space src_memory_space ;
1869 
1870  if ( dst.data() != src.data() ) {
1871  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , sizeof(value_type) );
1872  }
1873 }
1874 
1875 //----------------------------------------------------------------------------
1879 template< class DT , class ... DP , class ST , class ... SP >
1880 inline
1881 void deep_copy
1882  ( const View<DT,DP...> & dst
1883  , const View<ST,SP...> & src
1884  , typename std::enable_if<(
1885  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value &&
1886  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value &&
1887  ( unsigned(ViewTraits<DT,DP...>::rank) != 0 ||
1888  unsigned(ViewTraits<ST,SP...>::rank) != 0 )
1889  )>::type * = 0 )
1890 {
1891  static_assert(
1892  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
1893  typename ViewTraits<DT,DP...>::non_const_value_type >::value
1894  , "deep_copy requires non-const destination type" );
1895 
1896  static_assert(
1897  ( unsigned(ViewTraits<DT,DP...>::rank) ==
1898  unsigned(ViewTraits<ST,SP...>::rank) )
1899  , "deep_copy requires Views of equal rank" );
1900 
1901  typedef View<DT,DP...> dst_type ;
1902  typedef View<ST,SP...> src_type ;
1903 
1904  typedef typename dst_type::execution_space dst_execution_space ;
1905  typedef typename src_type::execution_space src_execution_space ;
1906  typedef typename dst_type::memory_space dst_memory_space ;
1907  typedef typename src_type::memory_space src_memory_space ;
1908 
1909  enum { DstExecCanAccessSrc =
1910  Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< typename dst_execution_space::memory_space , src_memory_space >::value };
1911 
1912  enum { SrcExecCanAccessDst =
1913  Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< typename src_execution_space::memory_space , dst_memory_space >::value };
1914 
1915 
1916  if ( (void *) dst.data() != (void*) src.data() ) {
1917 
1918  // Concern: If overlapping views then a parallel copy will be erroneous.
1919  // ...
1920 
1921  // If same type, equal layout, equal dimensions, equal span, and contiguous memory then can byte-wise copy
1922 
1923  if ( std::is_same< typename ViewTraits<DT,DP...>::value_type ,
1924  typename ViewTraits<ST,SP...>::non_const_value_type >::value &&
1925  (
1926  ( std::is_same< typename ViewTraits<DT,DP...>::array_layout ,
1927  typename ViewTraits<ST,SP...>::array_layout >::value
1928  &&
1929  ( std::is_same< typename ViewTraits<DT,DP...>::array_layout ,
1930  typename Kokkos::LayoutLeft>::value
1931  ||
1932  std::is_same< typename ViewTraits<DT,DP...>::array_layout ,
1933  typename Kokkos::LayoutRight>::value
1934  )
1935  )
1936  ||
1937  ( ViewTraits<DT,DP...>::rank == 1 &&
1939  ) &&
1940  dst.span_is_contiguous() &&
1941  src.span_is_contiguous() &&
1942  dst.span() == src.span() &&
1943  dst.dimension_0() == src.dimension_0() &&
1944  dst.dimension_1() == src.dimension_1() &&
1945  dst.dimension_2() == src.dimension_2() &&
1946  dst.dimension_3() == src.dimension_3() &&
1947  dst.dimension_4() == src.dimension_4() &&
1948  dst.dimension_5() == src.dimension_5() &&
1949  dst.dimension_6() == src.dimension_6() &&
1950  dst.dimension_7() == src.dimension_7() ) {
1951 
1952  const size_t nbytes = sizeof(typename dst_type::value_type) * dst.span();
1953 
1954  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1955  }
1956  else if ( std::is_same< typename ViewTraits<DT,DP...>::value_type ,
1957  typename ViewTraits<ST,SP...>::non_const_value_type >::value &&
1958  (
1959  ( std::is_same< typename ViewTraits<DT,DP...>::array_layout ,
1960  typename ViewTraits<ST,SP...>::array_layout >::value
1961  &&
1962  std::is_same< typename ViewTraits<DT,DP...>::array_layout ,
1963  typename Kokkos::LayoutStride>::value
1964  )
1965  ||
1966  ( ViewTraits<DT,DP...>::rank == 1 &&
1968  ) &&
1969  dst.span_is_contiguous() &&
1970  src.span_is_contiguous() &&
1971  dst.span() == src.span() &&
1972  dst.dimension_0() == src.dimension_0() &&
1973  dst.dimension_1() == src.dimension_1() &&
1974  dst.dimension_2() == src.dimension_2() &&
1975  dst.dimension_3() == src.dimension_3() &&
1976  dst.dimension_4() == src.dimension_4() &&
1977  dst.dimension_5() == src.dimension_5() &&
1978  dst.dimension_6() == src.dimension_6() &&
1979  dst.dimension_7() == src.dimension_7() &&
1980  dst.stride_0() == src.stride_0() &&
1981  dst.stride_1() == src.stride_1() &&
1982  dst.stride_2() == src.stride_2() &&
1983  dst.stride_3() == src.stride_3() &&
1984  dst.stride_4() == src.stride_4() &&
1985  dst.stride_5() == src.stride_5() &&
1986  dst.stride_6() == src.stride_6() &&
1987  dst.stride_7() == src.stride_7()
1988  ) {
1989 
1990  const size_t nbytes = sizeof(typename dst_type::value_type) * dst.span();
1991 
1992  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1993  }
1994  else if ( DstExecCanAccessSrc ) {
1995  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
1996  Kokkos::Impl::ViewRemap< dst_type , src_type >( dst , src );
1997  }
1998  else if ( SrcExecCanAccessDst ) {
1999  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
2000  Kokkos::Impl::ViewRemap< dst_type , src_type , src_execution_space >( dst , src );
2001  }
2002  else {
2003  Kokkos::Impl::throw_runtime_exception("deep_copy given views that would require a temporary allocation");
2004  }
2005  }
2006 }
2007 
2008 } /* namespace Kokkos */
2009 
2010 //----------------------------------------------------------------------------
2011 //----------------------------------------------------------------------------
2012 
2013 namespace Kokkos {
2014 
2016 template< class ExecSpace ,class DT , class ... DP >
2017 inline
2018 void deep_copy
2019  ( const ExecSpace &
2020  , const View<DT,DP...> & dst
2021  , typename ViewTraits<DT,DP...>::const_value_type & value
2022  , typename std::enable_if<
2023  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
2024  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value
2025  >::type * = 0 )
2026 {
2027  static_assert(
2028  std::is_same< typename ViewTraits<DT,DP...>::non_const_value_type ,
2029  typename ViewTraits<DT,DP...>::value_type >::value
2030  , "deep_copy requires non-const type" );
2031 
2032  Kokkos::Impl::ViewFill< View<DT,DP...> >( dst , value );
2033 }
2034 
2036 template< class ExecSpace , class ST , class ... SP >
2037 inline
2038 void deep_copy
2039  ( const ExecSpace & exec_space
2040  , typename ViewTraits<ST,SP...>::non_const_value_type & dst
2041  , const View<ST,SP...> & src
2042  , typename std::enable_if<
2043  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
2044  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value
2045  >::type * = 0 )
2046 {
2047  static_assert( ViewTraits<ST,SP...>::rank == 0
2048  , "ERROR: Non-rank-zero view in deep_copy( value , View )" );
2049 
2050  typedef ViewTraits<ST,SP...> src_traits ;
2051  typedef typename src_traits::memory_space src_memory_space ;
2052  Kokkos::Impl::DeepCopy< HostSpace , src_memory_space , ExecSpace >
2053  ( exec_space , & dst , src.data() , sizeof(ST) );
2054 }
2055 
2056 //----------------------------------------------------------------------------
2058 template< class ExecSpace , class DT , class ... DP , class ST , class ... SP >
2059 inline
2060 void deep_copy
2061  ( const ExecSpace & exec_space
2062  , const View<DT,DP...> & dst
2063  , const View<ST,SP...> & src
2064  , typename std::enable_if<(
2065  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
2066  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value &&
2067  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value &&
2068  ( unsigned(ViewTraits<DT,DP...>::rank) == unsigned(0) &&
2069  unsigned(ViewTraits<ST,SP...>::rank) == unsigned(0) )
2070  )>::type * = 0 )
2071 {
2072  static_assert(
2073  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
2074  typename ViewTraits<ST,SP...>::non_const_value_type >::value
2075  , "deep_copy requires matching non-const destination type" );
2076 
2077  typedef View<DT,DP...> dst_type ;
2078  typedef View<ST,SP...> src_type ;
2079 
2080  typedef typename dst_type::value_type value_type ;
2081  typedef typename dst_type::memory_space dst_memory_space ;
2082  typedef typename src_type::memory_space src_memory_space ;
2083 
2084  if ( dst.data() != src.data() ) {
2085  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space , ExecSpace >
2086  ( exec_space , dst.data() , src.data() , sizeof(value_type) );
2087  }
2088 }
2089 
2090 //----------------------------------------------------------------------------
2094 template< class ExecSpace , class DT, class ... DP, class ST, class ... SP >
2095 inline
2096 void deep_copy
2097  ( const ExecSpace & exec_space
2098  , const View<DT,DP...> & dst
2099  , const View<ST,SP...> & src
2100  , typename std::enable_if<(
2101  Kokkos::Impl::is_execution_space< ExecSpace >::value &&
2102  std::is_same< typename ViewTraits<DT,DP...>::specialize , void >::value &&
2103  std::is_same< typename ViewTraits<ST,SP...>::specialize , void >::value &&
2104  ( unsigned(ViewTraits<DT,DP...>::rank) != 0 ||
2105  unsigned(ViewTraits<ST,SP...>::rank) != 0 )
2106  )>::type * = 0 )
2107 {
2108  static_assert(
2109  std::is_same< typename ViewTraits<DT,DP...>::value_type ,
2110  typename ViewTraits<DT,DP...>::non_const_value_type >::value
2111  , "deep_copy requires non-const destination type" );
2112 
2113  static_assert(
2114  ( unsigned(ViewTraits<DT,DP...>::rank) ==
2115  unsigned(ViewTraits<ST,SP...>::rank) )
2116  , "deep_copy requires Views of equal rank" );
2117 
2118  typedef View<DT,DP...> dst_type ;
2119  typedef View<ST,SP...> src_type ;
2120 
2121  typedef typename dst_type::execution_space dst_execution_space ;
2122  typedef typename src_type::execution_space src_execution_space ;
2123  typedef typename dst_type::memory_space dst_memory_space ;
2124  typedef typename src_type::memory_space src_memory_space ;
2125 
2126  enum { DstExecCanAccessSrc =
2127  Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< typename dst_execution_space::memory_space , src_memory_space >::value };
2128 
2129  enum { SrcExecCanAccessDst =
2130  Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< typename src_execution_space::memory_space , dst_memory_space >::value };
2131 
2132  if ( (void *) dst.data() != (void*) src.data() ) {
2133 
2134  // Concern: If overlapping views then a parallel copy will be erroneous.
2135  // ...
2136 
2137  // If same type, equal layout, equal dimensions, equal span, and contiguous memory then can byte-wise copy
2138 
2139  if ( std::is_same< typename ViewTraits<DT,DP...>::value_type ,
2140  typename ViewTraits<ST,SP...>::non_const_value_type >::value &&
2141  (
2142  std::is_same< typename ViewTraits<DT,DP...>::array_layout ,
2143  typename ViewTraits<ST,SP...>::array_layout >::value
2144  ||
2145  ( ViewTraits<DT,DP...>::rank == 1 &&
2147  ) &&
2148  dst.span_is_contiguous() &&
2149  src.span_is_contiguous() &&
2150  dst.span() == src.span() &&
2151  dst.dimension_0() == src.dimension_0() &&
2152  dst.dimension_1() == src.dimension_1() &&
2153  dst.dimension_2() == src.dimension_2() &&
2154  dst.dimension_3() == src.dimension_3() &&
2155  dst.dimension_4() == src.dimension_4() &&
2156  dst.dimension_5() == src.dimension_5() &&
2157  dst.dimension_6() == src.dimension_6() &&
2158  dst.dimension_7() == src.dimension_7() ) {
2159 
2160  const size_t nbytes = sizeof(typename dst_type::value_type) * dst.span();
2161 
2162  Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space , ExecSpace >
2163  ( exec_space , dst.data() , src.data() , nbytes );
2164  }
2165  else if ( DstExecCanAccessSrc ) {
2166  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
2167  Kokkos::Impl::ViewRemap< dst_type , src_type >( dst , src );
2168  }
2169  else if ( SrcExecCanAccessDst ) {
2170  // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
2171  Kokkos::Impl::ViewRemap< dst_type , src_type , src_execution_space >( dst , src );
2172  }
2173  else {
2174  Kokkos::Impl::throw_runtime_exception("deep_copy given views that would require a temporary allocation");
2175  }
2176  }
2177 }
2178 
2179 } /* namespace Kokkos */
2180 
2181 //----------------------------------------------------------------------------
2182 //----------------------------------------------------------------------------
2183 
2184 namespace Kokkos {
2185 namespace Impl {
2186 
2187 // Deduce Mirror Types
2188 template<class Space, class T, class ... P>
2189 struct MirrorViewType {
2190  // The incoming view_type
2191  typedef typename Kokkos::View<T,P...> src_view_type;
2192  // The memory space for the mirror view
2193  typedef typename Space::memory_space memory_space;
2194  // Check whether it is the same memory space
2195  enum { is_same_memspace = std::is_same<memory_space,typename src_view_type::memory_space>::value };
2196  // The array_layout
2197  typedef typename src_view_type::array_layout array_layout;
2198  // The data type (we probably want it non-const since otherwise we can't even deep_copy to it.
2199  typedef typename src_view_type::non_const_data_type data_type;
2200  // The destination view type if it is not the same memory space
2201  typedef Kokkos::View<data_type,array_layout,Space> dest_view_type;
2202  // If it is the same memory_space return the existsing view_type
2203  // This will also keep the unmanaged trait if necessary
2204  typedef typename std::conditional<is_same_memspace,src_view_type,dest_view_type>::type view_type;
2205 };
2206 
2207 template<class Space, class T, class ... P>
2208 struct MirrorType {
2209  // The incoming view_type
2210  typedef typename Kokkos::View<T,P...> src_view_type;
2211  // The memory space for the mirror view
2212  typedef typename Space::memory_space memory_space;
2213  // Check whether it is the same memory space
2214  enum { is_same_memspace = std::is_same<memory_space,typename src_view_type::memory_space>::value };
2215  // The array_layout
2216  typedef typename src_view_type::array_layout array_layout;
2217  // The data type (we probably want it non-const since otherwise we can't even deep_copy to it.
2218  typedef typename src_view_type::non_const_data_type data_type;
2219  // The destination view type if it is not the same memory space
2221 };
2222 
2223 }
2224 
2225 template< class T , class ... P >
2226 inline
2227 typename Kokkos::View<T,P...>::HostMirror
2228 create_mirror( const Kokkos::View<T,P...> & src
2229  , typename std::enable_if<
2230  ! std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
2231  , Kokkos::LayoutStride >::value
2232  >::type * = 0
2233  )
2234 {
2235  typedef View<T,P...> src_type ;
2236  typedef typename src_type::HostMirror dst_type ;
2237 
2238  return dst_type( std::string( src.label() ).append("_mirror")
2239  , src.dimension_0()
2240  , src.dimension_1()
2241  , src.dimension_2()
2242  , src.dimension_3()
2243  , src.dimension_4()
2244  , src.dimension_5()
2245  , src.dimension_6()
2246  , src.dimension_7() );
2247 }
2248 
2249 template< class T , class ... P >
2250 inline
2251 typename Kokkos::View<T,P...>::HostMirror
2252 create_mirror( const Kokkos::View<T,P...> & src
2253  , typename std::enable_if<
2254  std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
2255  , Kokkos::LayoutStride >::value
2256  >::type * = 0
2257  )
2258 {
2259  typedef View<T,P...> src_type ;
2260  typedef typename src_type::HostMirror dst_type ;
2261 
2262  Kokkos::LayoutStride layout ;
2263 
2264  layout.dimension[0] = src.dimension_0();
2265  layout.dimension[1] = src.dimension_1();
2266  layout.dimension[2] = src.dimension_2();
2267  layout.dimension[3] = src.dimension_3();
2268  layout.dimension[4] = src.dimension_4();
2269  layout.dimension[5] = src.dimension_5();
2270  layout.dimension[6] = src.dimension_6();
2271  layout.dimension[7] = src.dimension_7();
2272 
2273  layout.stride[0] = src.stride_0();
2274  layout.stride[1] = src.stride_1();
2275  layout.stride[2] = src.stride_2();
2276  layout.stride[3] = src.stride_3();
2277  layout.stride[4] = src.stride_4();
2278  layout.stride[5] = src.stride_5();
2279  layout.stride[6] = src.stride_6();
2280  layout.stride[7] = src.stride_7();
2281 
2282  return dst_type( std::string( src.label() ).append("_mirror") , layout );
2283 }
2284 
2285 
2286 // Create a mirror in a new space (specialization for different space)
2287 template<class Space, class T, class ... P>
2288 typename Impl::MirrorType<Space,T,P ...>::view_type create_mirror(const Space& , const Kokkos::View<T,P...> & src) {
2289  return typename Impl::MirrorType<Space,T,P ...>::view_type(src.label(),src.layout());
2290 }
2291 
2292 template< class T , class ... P >
2293 inline
2294 typename Kokkos::View<T,P...>::HostMirror
2295 create_mirror_view( const Kokkos::View<T,P...> & src
2296  , typename std::enable_if<(
2297  std::is_same< typename Kokkos::View<T,P...>::memory_space
2298  , typename Kokkos::View<T,P...>::HostMirror::memory_space
2299  >::value
2300  &&
2301  std::is_same< typename Kokkos::View<T,P...>::data_type
2302  , typename Kokkos::View<T,P...>::HostMirror::data_type
2303  >::value
2304  )>::type * = 0
2305  )
2306 {
2307  return src ;
2308 }
2309 
2310 template< class T , class ... P >
2311 inline
2312 typename Kokkos::View<T,P...>::HostMirror
2313 create_mirror_view( const Kokkos::View<T,P...> & src
2314  , typename std::enable_if< ! (
2315  std::is_same< typename Kokkos::View<T,P...>::memory_space
2316  , typename Kokkos::View<T,P...>::HostMirror::memory_space
2317  >::value
2318  &&
2319  std::is_same< typename Kokkos::View<T,P...>::data_type
2320  , typename Kokkos::View<T,P...>::HostMirror::data_type
2321  >::value
2322  )>::type * = 0
2323  )
2324 {
2325  return Kokkos::create_mirror( src );
2326 }
2327 
2328 // Create a mirror view in a new space (specialization for same space)
2329 template<class Space, class T, class ... P>
2330 typename Impl::MirrorViewType<Space,T,P ...>::view_type
2331 create_mirror_view(const Space& , const Kokkos::View<T,P...> & src
2332  , typename std::enable_if<Impl::MirrorViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2333  return src;
2334 }
2335 
2336 // Create a mirror view in a new space (specialization for different space)
2337 template<class Space, class T, class ... P>
2338 typename Impl::MirrorViewType<Space,T,P ...>::view_type
2339 create_mirror_view(const Space& , const Kokkos::View<T,P...> & src
2340  , typename std::enable_if<!Impl::MirrorViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
2341  return typename Impl::MirrorViewType<Space,T,P ...>::view_type(src.label(),src.layout());
2342 }
2343 
2344 } /* namespace Kokkos */
2345 
2346 //----------------------------------------------------------------------------
2347 //----------------------------------------------------------------------------
2348 
2349 namespace Kokkos {
2350 
2352 template< class T , class ... P >
2353 inline
2354 typename std::enable_if<
2355  std::is_same<typename Kokkos::View<T,P...>::array_layout,Kokkos::LayoutLeft>::value ||
2356  std::is_same<typename Kokkos::View<T,P...>::array_layout,Kokkos::LayoutRight>::value
2357 >::type
2359  const size_t n0 = 0 ,
2360  const size_t n1 = 0 ,
2361  const size_t n2 = 0 ,
2362  const size_t n3 = 0 ,
2363  const size_t n4 = 0 ,
2364  const size_t n5 = 0 ,
2365  const size_t n6 = 0 ,
2366  const size_t n7 = 0 )
2367 {
2368  typedef Kokkos::View<T,P...> view_type ;
2369 
2370  static_assert( Kokkos::ViewTraits<T,P...>::is_managed , "Can only resize managed views" );
2371 
2372  view_type v_resized( v.label(), n0, n1, n2, n3, n4, n5, n6, n7 );
2373 
2374  Kokkos::Impl::ViewRemap< view_type , view_type >( v_resized , v );
2375 
2376  v = v_resized ;
2377 }
2378 
2380 template< class T , class ... P >
2381 inline
2383  const typename Kokkos::View<T,P...>::array_layout & layout)
2384 {
2385  typedef Kokkos::View<T,P...> view_type ;
2386 
2387  static_assert( Kokkos::ViewTraits<T,P...>::is_managed , "Can only resize managed views" );
2388 
2389  view_type v_resized( v.label(), layout );
2390 
2391  Kokkos::Impl::ViewRemap< view_type , view_type >( v_resized , v );
2392 
2393  v = v_resized ;
2394 }
2395 
2397 template< class T , class ... P >
2398 inline
2399 typename std::enable_if<
2400  std::is_same<typename Kokkos::View<T,P...>::array_layout,Kokkos::LayoutLeft>::value ||
2401  std::is_same<typename Kokkos::View<T,P...>::array_layout,Kokkos::LayoutRight>::value
2402 >::type
2404  const size_t n0 = 0 ,
2405  const size_t n1 = 0 ,
2406  const size_t n2 = 0 ,
2407  const size_t n3 = 0 ,
2408  const size_t n4 = 0 ,
2409  const size_t n5 = 0 ,
2410  const size_t n6 = 0 ,
2411  const size_t n7 = 0 )
2412 {
2413  typedef Kokkos::View<T,P...> view_type ;
2414 
2415  static_assert( Kokkos::ViewTraits<T,P...>::is_managed , "Can only realloc managed views" );
2416 
2417  const std::string label = v.label();
2418 
2419  v = view_type(); // Deallocate first, if the only view to allocation
2420  v = view_type( label, n0, n1, n2, n3, n4, n5, n6, n7 );
2421 }
2422 
2424 template< class T , class ... P >
2425 inline
2427  const typename Kokkos::View<T,P...>::array_layout & layout)
2428 {
2429  typedef Kokkos::View<T,P...> view_type ;
2430 
2431  static_assert( Kokkos::ViewTraits<T,P...>::is_managed , "Can only realloc managed views" );
2432 
2433  const std::string label = v.label();
2434 
2435  v = view_type(); // Deallocate first, if the only view to allocation
2436  v = view_type( label, layout );
2437 }
2438 } /* namespace Kokkos */
2439 
2440 //----------------------------------------------------------------------------
2441 //----------------------------------------------------------------------------
2442 // For backward compatibility:
2443 
2444 namespace Kokkos {
2445 namespace Experimental {
2446 
2447 using Kokkos::ViewTraits ;
2448 using Kokkos::View ;
2449 using Kokkos::Subview ;
2450 using Kokkos::is_view ;
2451 using Kokkos::subview ;
2452 using Kokkos::ALL ;
2453 using Kokkos::WithoutInitializing ;
2454 using Kokkos::AllowPadding ;
2455 using Kokkos::view_alloc ;
2456 using Kokkos::view_wrap ;
2457 using Kokkos::deep_copy ;
2458 using Kokkos::create_mirror ;
2459 using Kokkos::create_mirror_view ;
2460 using Kokkos::resize ;
2461 using Kokkos::realloc ;
2462 
2463 namespace Impl {
2464 
2465 using Kokkos::Impl::ViewFill ;
2466 using Kokkos::Impl::ViewRemap ;
2467 using Kokkos::Impl::ViewCtorProp ;
2468 using Kokkos::Impl::is_view_label ;
2469 using Kokkos::Impl::WithoutInitializing_t ;
2470 using Kokkos::Impl::AllowPadding_t ;
2471 using Kokkos::Impl::SharedAllocationRecord ;
2472 using Kokkos::Impl::SharedAllocationTracker ;
2473 
2474 } /* namespace Impl */
2475 } /* namespace Experimental */
2476 } /* namespace Kokkos */
2477 
2478 namespace Kokkos {
2479 namespace Impl {
2480 
2481 using Kokkos::is_view ;
2482 
2483 template< class SrcViewType
2484  , class Arg0Type
2485  , class Arg1Type
2486  , class Arg2Type
2487  , class Arg3Type
2488  , class Arg4Type
2489  , class Arg5Type
2490  , class Arg6Type
2491  , class Arg7Type
2492  >
2493 struct ViewSubview /* { typedef ... type ; } */ ;
2494 
2495 } /* namespace Impl */
2496 } /* namespace Kokkos */
2497 
2498 #include <impl/Kokkos_Atomic_View.hpp>
2499 
2500 //----------------------------------------------------------------------------
2501 //----------------------------------------------------------------------------
2502 
2503 #endif /* #ifndef KOKKOS_VIEW_HPP */
2504 
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.
Memory space for main process and CPU execution spaces.
Memory layout tag indicating right-to-left (C or lexigraphical scheme) striding of multi-indices...
View
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.