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  KOKKOS_INLINE_FUNCTION
47  Layout base_layout() const { return *this; }
48 };
49 
50 #ifdef SACADO_HAS_NEW_KOKKOS_VIEW_IMPL
51 namespace Impl {
52 template <class Layout, unsigned Stride>
53 struct LayoutFromArrayLayout<LayoutContiguous<Layout, Stride>> {
54  using type = typename LayoutFromArrayLayout<Layout>::type;
55 };
56 }
57 #endif
58 
59 // Is Layout == LayoutContiguous<L> for some L
60 template <class Layout>
62  static const bool value = false;
63 };
64 
65 template <class Layout, unsigned Stride>
66 struct is_layout_contiguous< LayoutContiguous<Layout, Stride> > {
67  static const bool value = true;
68 };
69 
70 // Extract inner layout from LayoutContiguous
71 template <class Layout>
72 struct inner_layout {
73  typedef Layout type;
74 };
75 
76 template <class Layout>
77 struct inner_layout< LayoutContiguous<Layout> > {
78  typedef Layout type;
79 };
80 
81 template <class Layout, unsigned Stride>
82 struct inner_layout< LayoutContiguous<Layout, Stride> > {
83  typedef Layout type;
84 };
85 
86 } // namespace Kokkos
87 
88 // FIXME This is evil and needs refactoring urgently.
89 // Make LayoutContiguous<Layout> equivalent to Layout
90 namespace std {
91 
92  template <class Layout, unsigned Stride>
93  struct is_same< Kokkos::LayoutContiguous<Layout,Stride>, Layout> {
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< Kokkos::LayoutContiguous<Layout,Stride>, Layout> = is_same<Kokkos::LayoutContiguous<Layout,Stride>, Layout>::value;
100 #else
101  static constexpr bool is_same_v< Kokkos::LayoutContiguous<Layout,Stride>, Layout> = is_same<Kokkos::LayoutContiguous<Layout,Stride>, Layout>::value;
102 #endif
103 
104  template <class Layout, unsigned Stride>
105  struct is_same< Layout, Kokkos::LayoutContiguous<Layout,Stride> > {
106  static const bool value = true;
107  };
108 
109  template <class Layout, unsigned Stride>
110 #if defined(KOKKOS_COMPILER_INTEL)
111  inline constexpr bool is_same_v< Layout, Kokkos::LayoutContiguous<Layout,Stride>> = is_same<Kokkos::LayoutContiguous<Layout,Stride>, Layout>::value;
112 #else
113  static constexpr bool is_same_v< Layout, Kokkos::LayoutContiguous<Layout,Stride>> = is_same<Kokkos::LayoutContiguous<Layout,Stride>, Layout>::value;
114 #endif
115 }
116 
117 #if KOKKOS_VERSION >= 40499
118 #include "View/Kokkos_ViewMapping.hpp"
119 #else
120 #include "impl/Kokkos_ViewMapping.hpp"
121 #endif
122 
123 namespace Kokkos {
124 namespace Impl {
125 
126 // Implement ViewOffset for LayoutContiguous
127 template < class Dimension , class Layout , unsigned Stride >
128 struct ViewOffset<Dimension, LayoutContiguous<Layout,Stride>, void>
129  : public ViewOffset<Dimension,Layout> {
130 public:
131 
132  // Would like to use inherited constructors, but gcc 4.7 doesn't support it
133  //using ViewOffset<Dimension,Layout>::ViewOffset;
134 
135  typedef ViewOffset<Dimension,Layout> Base;
136 
137  ViewOffset() = default ;
138  ViewOffset( const ViewOffset & ) = default ;
139  ViewOffset & operator = ( const ViewOffset & ) = default ;
140 
141  // All constructors take one or two arguments
142 
143  template <typename Arg1>
144  KOKKOS_INLINE_FUNCTION
145  constexpr ViewOffset(const Arg1& arg1) : Base(arg1) {}
146 
147  template <typename Arg1, typename Arg2>
148  KOKKOS_INLINE_FUNCTION
149  constexpr ViewOffset(const Arg1& arg1, const Arg2& arg2) : Base(arg1,arg2) {}
150 };
151 
152 template <typename Layout>
154  static const unsigned stride = 1;
155  static const bool is_unit_stride = true;
156 };
157 
158 template <typename Layout, unsigned Stride>
159 struct LayoutScalarStride< LayoutContiguous<Layout,Stride> > {
160  static const unsigned stride = Stride;
161  static const bool is_unit_stride = (Stride == 1);
162 };
163 
164 } // namespace Impl
165 } // namespace Kokkos
166 
167 #endif // #ifndef KOKKOS_LAYOUT_CONTIGUOUS_HPP
KOKKOS_INLINE_FUNCTION Layout base_layout() const
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.
int value
KOKKOS_INLINE_FUNCTION constexpr LayoutContiguous(Layout &&layout)
void
Definition: uninit.c:105