Kokkos Core Kernels Package  Version of the Day
Kokkos_Layout.hpp
Go to the documentation of this file.
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 
46 
47 #ifndef KOKKOS_LAYOUT_HPP
48 #define KOKKOS_LAYOUT_HPP
49 
50 #include <stddef.h>
51 #include <impl/Kokkos_Traits.hpp>
52 #include <impl/Kokkos_Tags.hpp>
53 
54 namespace Kokkos {
55 
56 //----------------------------------------------------------------------------
71 struct LayoutLeft {
74 };
75 
76 //----------------------------------------------------------------------------
90 struct LayoutRight {
93 };
94 
95 //----------------------------------------------------------------------------
99 struct LayoutStride {
100 
103 
104  enum { MAX_RANK = 8 };
105 
106  size_t dimension[ MAX_RANK ] ;
107  size_t stride[ MAX_RANK ] ;
108 
116  template< typename iTypeOrder , typename iTypeDimen >
117  KOKKOS_INLINE_FUNCTION static
119  , iTypeOrder const * const order
120  , iTypeDimen const * const dimen )
121  {
122  LayoutStride tmp ;
123  // Verify valid rank order:
124  int check_input = MAX_RANK < rank ? 0 : int( 1 << rank ) - 1 ;
125  for ( int r = 0 ; r < MAX_RANK ; ++r ) {
126  tmp.dimension[r] = 0 ;
127  tmp.stride[r] = 0 ;
128  check_input &= ~int( 1 << order[r] );
129  }
130  if ( 0 == check_input ) {
131  size_t n = 1 ;
132  for ( int r = 0 ; r < rank ; ++r ) {
133  tmp.stride[ order[r] ] = n ;
134  n *= ( dimen[order[r]] );
135  tmp.dimension[r] = dimen[r];
136  }
137  }
138  return tmp ;
139  }
140 };
141 
142 //----------------------------------------------------------------------------
159 template < unsigned ArgN0 , unsigned ArgN1 ,
160  bool IsPowerOfTwo = ( Impl::is_integral_power_of_two(ArgN0) &&
161  Impl::is_integral_power_of_two(ArgN1) )
162  >
164 
165  static_assert( Impl::is_integral_power_of_two(ArgN0) &&
166  Impl::is_integral_power_of_two(ArgN1)
167  , "LayoutTileLeft must be given power-of-two tile dimensions" );
168 
171 
172  enum { N0 = ArgN0 };
173  enum { N1 = ArgN1 };
174 };
175 
176 } // namespace Kokkos
177 
178 #endif // #ifndef KOKKOS_LAYOUT_HPP
179 
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.
LayoutTileLeft< ArgN0, ArgN1, IsPowerOfTwo > array_layout
Tag this class as a kokkos array layout.
Memory layout tag indicating left-to-right (Fortran scheme) striding of multi-indices by tiles...
LayoutRight array_layout
Tag this class as a kokkos array layout.