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 //
4 // Sacado Package
5 // Copyright (2006) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
25 // (etphipp@sandia.gov).
26 //
27 // ***********************************************************************
28 // @HEADER
29 
30 #ifndef KOKKOS_LAYOUT_CONTIGUOUS_HPP
31 #define KOKKOS_LAYOUT_CONTIGUOUS_HPP
32 
33 // We are hooking into Kokkos Core internals here
34 // Need to define this macro since we include non-public headers
35 #ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
36 #define KOKKOS_IMPL_PUBLIC_INCLUDE
37 #define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
38 #endif
39 #include "Kokkos_Core_fwd.hpp"
40 #include "Kokkos_Layout.hpp"
41 #ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
42 #undef KOKKOS_IMPL_PUBLIC_INCLUDE
43 #undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
44 #endif
45 
46 namespace Kokkos {
47 
48 // Contiguous layout for scalar types -- equivalent to the wrapped
49 // layout type
50 template <typename Layout, unsigned Stride = 1>
51 struct LayoutContiguous : public Layout {
52 
53  enum { scalar_stride = Stride };
54 
57 
58  // Pull in Layout's constructors
59  using Layout::Layout;
60 
61  KOKKOS_INLINE_FUNCTION
62  constexpr LayoutContiguous( Layout const & layout ) : Layout(layout) {}
63  KOKKOS_INLINE_FUNCTION
64  constexpr LayoutContiguous( Layout && layout ) : Layout(layout) {}
65 };
66 
67 // Is Layout == LayoutContiguous<L> for some L
68 template <class Layout>
70  static const bool value = false;
71 };
72 
73 template <class Layout>
75  static const bool value = true;
76 };
77 
78 // Extract inner layout from LayoutContiguous
79 template <class Layout>
80 struct inner_layout {
81  typedef Layout type;
82 };
83 
84 template <class Layout>
85 struct inner_layout< LayoutContiguous<Layout> > {
86  typedef Layout type;
87 };
88 
89 template <class Layout, unsigned Stride>
90 struct inner_layout< LayoutContiguous<Layout, Stride> > {
91  typedef Layout type;
92 };
93 
94 } // namespace Kokkos
95 
96 // Make LayoutContiguous<Layout> equivalent to Layout
97 namespace std {
98 
99  template <class Layout, unsigned Stride>
100  struct is_same< Kokkos::LayoutContiguous<Layout,Stride>, Layout> {
101  static const bool value = true;
102  };
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 }
110 
111 #include "impl/Kokkos_ViewMapping.hpp"
112 
113 namespace Kokkos {
114 namespace Impl {
115 
116 // Implement ViewOffset for LayoutContiguous
117 template < class Dimension , class Layout , unsigned Stride >
118 struct ViewOffset<Dimension, LayoutContiguous<Layout,Stride>, void>
119  : public ViewOffset<Dimension,Layout> {
120 public:
121 
122  // Would like to use inherited constructors, but gcc 4.7 doesn't support it
123  //using ViewOffset<Dimension,Layout>::ViewOffset;
124 
125  typedef ViewOffset<Dimension,Layout> Base;
126 
127  ViewOffset() = default ;
128  ViewOffset( const ViewOffset & ) = default ;
129  ViewOffset & operator = ( const ViewOffset & ) = default ;
130 
131  // All constructors take one or two arguments
132 
133  template <typename Arg1>
134  KOKKOS_INLINE_FUNCTION
135  constexpr ViewOffset(const Arg1& arg1) : Base(arg1) {}
136 
137  template <typename Arg1, typename Arg2>
138  KOKKOS_INLINE_FUNCTION
139  constexpr ViewOffset(const Arg1& arg1, const Arg2& arg2) : Base(arg1,arg2) {}
140 };
141 
142 template <typename Layout>
144  static const unsigned stride = 1;
145  static const bool is_unit_stride = true;
146 };
147 
148 template <typename Layout, unsigned Stride>
149 struct LayoutScalarStride< LayoutContiguous<Layout,Stride> > {
150  static const unsigned stride = Stride;
151  static const bool is_unit_stride = (Stride == 1);
152 };
153 
154 } // namespace Impl
155 } // namespace Kokkos
156 
157 #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:96
int value