Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Kokkos_LayoutContiguous.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Sacado Package
4 //
5 // Copyright 2006 NTESS and the Sacado contributors.
6 // SPDX-License-Identifier: LGPL-2.1-or-later
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef KOKKOS_LAYOUT_CONTIGUOUS_HPP
11 #define KOKKOS_LAYOUT_CONTIGUOUS_HPP
12 
13 // We are hooking into Kokkos Core internals here
14 // Need to define this macro since we include non-public headers
15 #ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
16 #define KOKKOS_IMPL_PUBLIC_INCLUDE
17 #define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
18 #endif
19 #include "Kokkos_Core_fwd.hpp"
20 #include "Kokkos_Layout.hpp"
21 #ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
22 #undef KOKKOS_IMPL_PUBLIC_INCLUDE
23 #undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
24 #endif
25 
26 namespace Kokkos {
27 
28 // Contiguous layout for scalar types -- equivalent to the wrapped
29 // layout type
30 template <typename Layout, unsigned Stride = 1>
31 struct LayoutContiguous : public Layout {
32 
33  enum { scalar_stride = Stride };
34 
37 
38  // Pull in Layout's constructors
39  using Layout::Layout;
40 
41  KOKKOS_INLINE_FUNCTION
42  constexpr LayoutContiguous( Layout const & layout ) : Layout(layout) {}
43  KOKKOS_INLINE_FUNCTION
44  constexpr LayoutContiguous( Layout && layout ) : Layout(layout) {}
45 };
46 
47 // Is Layout == LayoutContiguous<L> for some L
48 template <class Layout>
50  static const bool value = false;
51 };
52 
53 template <class Layout>
55  static const bool value = true;
56 };
57 
58 // Extract inner layout from LayoutContiguous
59 template <class Layout>
60 struct inner_layout {
61  typedef Layout type;
62 };
63 
64 template <class Layout>
65 struct inner_layout< LayoutContiguous<Layout> > {
66  typedef Layout type;
67 };
68 
69 template <class Layout, unsigned Stride>
70 struct inner_layout< LayoutContiguous<Layout, Stride> > {
71  typedef Layout type;
72 };
73 
74 } // namespace Kokkos
75 
76 // FIXME This is evil and needs refactoring urgently.
77 // Make LayoutContiguous<Layout> equivalent to Layout
78 namespace std {
79 
80  template <class Layout, unsigned Stride>
81  struct is_same< Kokkos::LayoutContiguous<Layout,Stride>, Layout> {
82  static const bool value = true;
83  };
84 
85  template <class Layout, unsigned Stride>
86 #if defined(KOKKOS_COMPILER_INTEL)
87  inline constexpr bool is_same_v< Kokkos::LayoutContiguous<Layout,Stride>, Layout> = is_same<Kokkos::LayoutContiguous<Layout,Stride>, Layout>::value;
88 #else
89  static constexpr bool is_same_v< Kokkos::LayoutContiguous<Layout,Stride>, Layout> = is_same<Kokkos::LayoutContiguous<Layout,Stride>, Layout>::value;
90 #endif
91 
92  template <class Layout, unsigned Stride>
93  struct is_same< Layout, Kokkos::LayoutContiguous<Layout,Stride> > {
94  static const bool value = true;
95  };
96 
97  template <class Layout, unsigned Stride>
98 #if defined(KOKKOS_COMPILER_INTEL)
99  inline constexpr bool is_same_v< Layout, Kokkos::LayoutContiguous<Layout,Stride>> = is_same<Kokkos::LayoutContiguous<Layout,Stride>, Layout>::value;
100 #else
101  static constexpr bool is_same_v< Layout, Kokkos::LayoutContiguous<Layout,Stride>> = is_same<Kokkos::LayoutContiguous<Layout,Stride>, Layout>::value;
102 #endif
103 }
104 
105 #if KOKKOS_VERSION >= 40499
106 #include "View/Kokkos_ViewMapping.hpp"
107 #else
108 #include "impl/Kokkos_ViewMapping.hpp"
109 #endif
110 
111 namespace Kokkos {
112 namespace Impl {
113 
114 // Implement ViewOffset for LayoutContiguous
115 template < class Dimension , class Layout , unsigned Stride >
116 struct ViewOffset<Dimension, LayoutContiguous<Layout,Stride>, void>
117  : public ViewOffset<Dimension,Layout> {
118 public:
119 
120  // Would like to use inherited constructors, but gcc 4.7 doesn't support it
121  //using ViewOffset<Dimension,Layout>::ViewOffset;
122 
123  typedef ViewOffset<Dimension,Layout> Base;
124 
125  ViewOffset() = default ;
126  ViewOffset( const ViewOffset & ) = default ;
127  ViewOffset & operator = ( const ViewOffset & ) = default ;
128 
129  // All constructors take one or two arguments
130 
131  template <typename Arg1>
132  KOKKOS_INLINE_FUNCTION
133  constexpr ViewOffset(const Arg1& arg1) : Base(arg1) {}
134 
135  template <typename Arg1, typename Arg2>
136  KOKKOS_INLINE_FUNCTION
137  constexpr ViewOffset(const Arg1& arg1, const Arg2& arg2) : Base(arg1,arg2) {}
138 };
139 
140 template <typename Layout>
142  static const unsigned stride = 1;
143  static const bool is_unit_stride = true;
144 };
145 
146 template <typename Layout, unsigned Stride>
147 struct LayoutScalarStride< LayoutContiguous<Layout,Stride> > {
148  static const unsigned stride = Stride;
149  static const bool is_unit_stride = (Stride == 1);
150 };
151 
152 } // namespace Impl
153 } // namespace Kokkos
154 
155 #endif // #ifndef KOKKOS_LAYOUT_CONTIGUOUS_HPP
KOKKOS_INLINE_FUNCTION constexpr LayoutContiguous(Layout const &layout)
KOKKOS_INLINE_FUNCTION constexpr ViewOffset(const Arg1 &arg1, const Arg2 &arg2)
LayoutContiguous array_layout
Tag this class as a kokkos array layout.
KOKKOS_INLINE_FUNCTION constexpr LayoutContiguous(Layout &&layout)
void
Definition: uninit.c:105
int value