47 #ifndef KOKKOS_LAYOUT_HPP 
   48 #define KOKKOS_LAYOUT_HPP 
   51 #include <impl/Kokkos_Traits.hpp> 
   52 #include <impl/Kokkos_Tags.hpp> 
   56 enum { ARRAY_LAYOUT_MAX_RANK = 8 };
 
   77   size_t dimension[ ARRAY_LAYOUT_MAX_RANK ];
 
   79   enum { is_extent_constructible = 
true };
 
   86   KOKKOS_INLINE_FUNCTION
 
   88   LayoutLeft( 
size_t N0 = 0 , 
size_t N1 = 0 , 
size_t N2 = 0 , 
size_t N3 = 0
 
   89             , 
size_t N4 = 0 , 
size_t N5 = 0 , 
size_t N6 = 0 , 
size_t N7 = 0 )
 
   90     : dimension { N0 , N1 , N2 , N3 , N4 , N5 , N6 , N7 } {}
 
  111   size_t dimension[ ARRAY_LAYOUT_MAX_RANK ];
 
  113   enum { is_extent_constructible = 
true };
 
  120   KOKKOS_INLINE_FUNCTION
 
  122   LayoutRight( 
size_t N0 = 0 , 
size_t N1 = 0 , 
size_t N2 = 0 , 
size_t N3 = 0
 
  123              , 
size_t N4 = 0 , 
size_t N5 = 0 , 
size_t N6 = 0 , 
size_t N7 = 0 )
 
  124     : dimension { N0 , N1 , N2 , N3 , N4 , N5 , N6 , N7 } {}
 
  136   size_t dimension[ ARRAY_LAYOUT_MAX_RANK ] ;
 
  137   size_t stride[ ARRAY_LAYOUT_MAX_RANK ] ;
 
  139   enum { is_extent_constructible = 
false };
 
  153   template< 
typename iTypeOrder , 
typename iTypeDimen >
 
  154   KOKKOS_INLINE_FUNCTION 
static 
  156                                , iTypeOrder 
const * 
const order
 
  157                                , iTypeDimen 
const * 
const dimen )
 
  161       int check_input = ARRAY_LAYOUT_MAX_RANK < rank ? 0 : int( 1 << rank ) - 1 ;
 
  162       for ( 
int r = 0 ; r < ARRAY_LAYOUT_MAX_RANK ; ++r ) {
 
  163         tmp.dimension[r] = 0 ;
 
  166       for ( 
int r = 0 ; r < 
rank ; ++r ) {
 
  167         check_input &= ~int( 1 << order[r] );
 
  169       if ( 0 == check_input ) {
 
  171         for ( 
int r = 0 ; r < 
rank ; ++r ) {
 
  172           tmp.stride[ order[r] ] = n ;
 
  173           n *= ( dimen[order[r]] );
 
  174           tmp.dimension[r] = dimen[r];
 
  180   KOKKOS_INLINE_FUNCTION
 
  183               , 
size_t N1 = 0 , 
size_t S1 = 0
 
  184               , 
size_t N2 = 0 , 
size_t S2 = 0
 
  185               , 
size_t N3 = 0 , 
size_t S3 = 0
 
  186               , 
size_t N4 = 0 , 
size_t S4 = 0
 
  187               , 
size_t N5 = 0 , 
size_t S5 = 0
 
  188               , 
size_t N6 = 0 , 
size_t S6 = 0
 
  189               , 
size_t N7 = 0 , 
size_t S7 = 0
 
  191     : dimension { N0 , N1 , N2 , N3 , N4 , N5 , N6 , N7 }
 
  192     , stride    { S0 , S1 , S2 , S3 , S4 , S5 , S6 , S7 }
 
  197 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE 
  216 template < 
unsigned ArgN0 , 
unsigned ArgN1 ,
 
  217            bool IsPowerOfTwo = ( Impl::is_integral_power_of_two(ArgN0) &&
 
  218                                  Impl::is_integral_power_of_two(ArgN1) )
 
  220 struct LayoutTileLeft {
 
  222   static_assert( Impl::is_integral_power_of_two(ArgN0) &&
 
  223                  Impl::is_integral_power_of_two(ArgN1)
 
  224                , 
"LayoutTileLeft must be given power-of-two tile dimensions" );
 
  227   typedef LayoutTileLeft<ArgN0,ArgN1,IsPowerOfTwo> array_layout ;
 
  232   size_t dimension[ ARRAY_LAYOUT_MAX_RANK ] ;
 
  234   enum { is_extent_constructible = 
true };
 
  236   LayoutTileLeft( LayoutTileLeft 
const & ) = default ;
 
  237   LayoutTileLeft( LayoutTileLeft && ) = default ;
 
  238   LayoutTileLeft & operator = ( LayoutTileLeft 
const & ) = default ;
 
  239   LayoutTileLeft & operator = ( LayoutTileLeft && ) = default ;
 
  241   KOKKOS_INLINE_FUNCTION
 
  243   LayoutTileLeft( 
size_t argN0 = 0 , 
size_t argN1 = 0 , 
size_t argN2 = 0 , 
size_t argN3 = 0
 
  244                 , 
size_t argN4 = 0 , 
size_t argN5 = 0 , 
size_t argN6 = 0 , 
size_t argN7 = 0
 
  246     : dimension { argN0 , argN1 , argN2 , argN3 , argN4 , argN5 , argN6 , argN7 } {}
 
  249 #endif   // KOKKOS_ENABLE_DEPRECATED_CODE 
  263 template < 
typename LayoutTiledCheck, 
class Enable = 
void >
 
  264 struct is_layouttiled : std::false_type {};
 
  266 #ifndef KOKKOS_ENABLE_DEPRECATED_CODE 
  267 template < 
typename LayoutTiledCheck >
 
  268 struct is_layouttiled< LayoutTiledCheck, typename std::enable_if<LayoutTiledCheck::is_array_layout_tiled>::type > : std::true_type {};
 
  270 namespace Experimental {
 
  274 template < Kokkos::Iterate OuterP, Kokkos::Iterate InnerP,
 
  275            unsigned ArgN0 , 
unsigned ArgN1 , 
unsigned ArgN2 = 0,  
unsigned ArgN3 = 0,  
unsigned ArgN4 = 0,  
unsigned ArgN5 = 0,  
unsigned ArgN6 = 0,  
unsigned ArgN7 = 0, 
 
  277            ( Kokkos::Impl::is_integral_power_of_two(ArgN0) &&
 
  278                Kokkos::Impl::is_integral_power_of_two(ArgN1) &&
 
  279              (Kokkos::Impl::is_integral_power_of_two(ArgN2) || (ArgN2 == 0) ) &&
 
  280              (Kokkos::Impl::is_integral_power_of_two(ArgN3) || (ArgN3 == 0) ) &&
 
  281              (Kokkos::Impl::is_integral_power_of_two(ArgN4) || (ArgN4 == 0) ) &&
 
  282              (Kokkos::Impl::is_integral_power_of_two(ArgN5) || (ArgN5 == 0) ) &&
 
  283              (Kokkos::Impl::is_integral_power_of_two(ArgN6) || (ArgN6 == 0) ) &&
 
  284              (Kokkos::Impl::is_integral_power_of_two(ArgN7) || (ArgN7 == 0) )
 
  289   static_assert( IsPowerOfTwo
 
  290                , 
"LayoutTiled must be given power-of-two tile dimensions" );
 
  293   static_assert( (Impl::is_integral_power_of_two(ArgN0) ) &&
 
  294                  (Impl::is_integral_power_of_two(ArgN1) ) &&
 
  295                  (Impl::is_integral_power_of_two(ArgN2) || (ArgN2 == 0) ) &&
 
  296                  (Impl::is_integral_power_of_two(ArgN3) || (ArgN3 == 0) ) &&
 
  297                  (Impl::is_integral_power_of_two(ArgN4) || (ArgN4 == 0) ) &&
 
  298                  (Impl::is_integral_power_of_two(ArgN5) || (ArgN5 == 0) ) &&
 
  299                  (Impl::is_integral_power_of_two(ArgN6) || (ArgN6 == 0) ) &&
 
  300                  (Impl::is_integral_power_of_two(ArgN7) || (ArgN7 == 0) )
 
  301                , 
"LayoutTiled must be given power-of-two tile dimensions" );
 
  304   typedef LayoutTiled<OuterP, InnerP, ArgN0, ArgN1, ArgN2, ArgN3, ArgN4, ArgN5, ArgN6, ArgN7, IsPowerOfTwo> array_layout ;
 
  305   static constexpr Iterate outer_pattern = OuterP;
 
  306   static constexpr Iterate inner_pattern = InnerP;
 
  317   size_t dimension[ ARRAY_LAYOUT_MAX_RANK ] ;
 
  319   enum { is_extent_constructible = 
true };
 
  326   KOKKOS_INLINE_FUNCTION
 
  328   LayoutTiled( 
size_t argN0 = 0 , 
size_t argN1 = 0 , 
size_t argN2 = 0 , 
size_t argN3 = 0
 
  329                 , 
size_t argN4 = 0 , 
size_t argN5 = 0 , 
size_t argN6 = 0 , 
size_t argN7 = 0
 
  331     : dimension { argN0 , argN1 , argN2 , argN3 , argN4 , argN5 , argN6 , argN7 } {}
 
  339 template < 
typename ... Layout >
 
  340 struct layout_iterate_type_selector {
 
  341   static const Kokkos::Iterate outer_iteration_pattern = Kokkos::Iterate::Default ;
 
  342   static const Kokkos::Iterate inner_iteration_pattern = Kokkos::Iterate::Default ;
 
  346 struct layout_iterate_type_selector< Kokkos::LayoutRight > {
 
  347   static const Kokkos::Iterate outer_iteration_pattern = Kokkos::Iterate::Right ;
 
  348   static const Kokkos::Iterate inner_iteration_pattern = Kokkos::Iterate::Right ;
 
  352 struct layout_iterate_type_selector< Kokkos::LayoutLeft > {
 
  353   static const Kokkos::Iterate outer_iteration_pattern = Kokkos::Iterate::Left ;
 
  354   static const Kokkos::Iterate inner_iteration_pattern = Kokkos::Iterate::Left ;
 
  358 struct layout_iterate_type_selector< Kokkos::LayoutStride > {
 
  359   static const Kokkos::Iterate outer_iteration_pattern = Kokkos::Iterate::Default ;
 
  360   static const Kokkos::Iterate inner_iteration_pattern = Kokkos::Iterate::Default ;
 
  363 #ifndef KOKKOS_ENABLE_DEPRECATED_CODE 
  364 template < 
unsigned ArgN0 , 
unsigned ArgN1 , 
unsigned ArgN2 ,  
unsigned ArgN3 ,  
unsigned ArgN4 ,  
unsigned ArgN5 ,  
unsigned ArgN6 ,  
unsigned ArgN7 >
 
  365 struct layout_iterate_type_selector< Kokkos::Experimental::LayoutTiled<Kokkos::Iterate::Left, Kokkos::Iterate::Left, ArgN0, ArgN1, ArgN2, ArgN3, ArgN4, ArgN5, ArgN6, ArgN7, true> > {
 
  366   static const Kokkos::Iterate outer_iteration_pattern = Kokkos::Iterate::Left ;
 
  367   static const Kokkos::Iterate inner_iteration_pattern = Kokkos::Iterate::Left ;
 
  370 template < 
unsigned ArgN0 , 
unsigned ArgN1 , 
unsigned ArgN2 ,  
unsigned ArgN3 ,  
unsigned ArgN4 ,  
unsigned ArgN5 ,  
unsigned ArgN6 ,  
unsigned ArgN7 >
 
  371 struct layout_iterate_type_selector< Kokkos::Experimental::LayoutTiled<Kokkos::Iterate::Right, Kokkos::Iterate::Left, ArgN0, ArgN1, ArgN2, ArgN3, ArgN4, ArgN5, ArgN6, ArgN7, true> > {
 
  372   static const Kokkos::Iterate outer_iteration_pattern = Kokkos::Iterate::Right ;
 
  373   static const Kokkos::Iterate inner_iteration_pattern = Kokkos::Iterate::Left ;
 
  376 template < 
unsigned ArgN0 , 
unsigned ArgN1 , 
unsigned ArgN2 ,  
unsigned ArgN3 ,  
unsigned ArgN4 ,  
unsigned ArgN5 ,  
unsigned ArgN6 ,  
unsigned ArgN7 >
 
  377 struct layout_iterate_type_selector< Kokkos::Experimental::LayoutTiled<Kokkos::Iterate::Left, Kokkos::Iterate::Right, ArgN0, ArgN1, ArgN2, ArgN3, ArgN4, ArgN5, ArgN6, ArgN7, true> > {
 
  378   static const Kokkos::Iterate outer_iteration_pattern = Kokkos::Iterate::Left ;
 
  379   static const Kokkos::Iterate inner_iteration_pattern = Kokkos::Iterate::Right ;
 
  382 template < 
unsigned ArgN0 , 
unsigned ArgN1 , 
unsigned ArgN2 ,  
unsigned ArgN3 ,  
unsigned ArgN4 ,  
unsigned ArgN5 ,  
unsigned ArgN6 ,  
unsigned ArgN7 >
 
  383 struct layout_iterate_type_selector< Kokkos::Experimental::LayoutTiled<Kokkos::Iterate::Right, Kokkos::Iterate::Right, ArgN0, ArgN1, ArgN2, ArgN3, ArgN4, ArgN5, ArgN6, ArgN7, true> > {
 
  384   static const Kokkos::Iterate outer_iteration_pattern = Kokkos::Iterate::Right ;
 
  385   static const Kokkos::Iterate inner_iteration_pattern = Kokkos::Iterate::Right ;
 
  391 #endif // #ifndef KOKKOS_LAYOUT_HPP 
LayoutLeft array_layout
Tag this class as a kokkos array layout. 
 
Memory layout tag indicating left-to-right (Fortran scheme) striding of multi-indices. 
 
Memory layout tag indicated arbitrarily strided multi-index mapping into contiguous memory...
 
LayoutStride array_layout
Tag this class as a kokkos array layout. 
 
Memory layout tag indicating right-to-left (C or lexigraphical scheme) striding of multi-indices...
 
static KOKKOS_INLINE_FUNCTION LayoutStride order_dimensions(int const rank, iTypeOrder const *const order, iTypeDimen const *const dimen)
Compute strides from ordered dimensions. 
 
KOKKOS_INLINE_FUNCTION constexpr unsigned rank(const View< D, P...> &V)
Temporary free function rank() until rank() is implemented in the View. 
 
LayoutRight array_layout
Tag this class as a kokkos array layout.