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 #include "Kokkos_Core_fwd.hpp"
34 #include "Kokkos_Layout.hpp"
35 
36 namespace Kokkos {
37 
38 // Contiguous layout for scalar types -- equivalent to the wrapped
39 // layout type
40 template <typename Layout, unsigned Stride = 1>
41 struct LayoutContiguous : public Layout {
42 
43  enum { scalar_stride = Stride };
44 
47 
48  // Pull in Layout's constructors
49  using Layout::Layout;
50 
52  constexpr LayoutContiguous( Layout const & layout ) : Layout(layout) {}
54  constexpr LayoutContiguous( Layout && layout ) : Layout(layout) {}
55 };
56 
57 // Is Layout == LayoutContiguous<L> for some L
58 template <class Layout>
60  static const bool value = false;
61 };
62 
63 template <class Layout>
65  static const bool value = true;
66 };
67 
68 // Extract inner layout from LayoutContiguous
69 template <class Layout>
70 struct inner_layout {
71  typedef Layout type;
72 };
73 
74 template <class Layout>
75 struct inner_layout< LayoutContiguous<Layout> > {
76  typedef Layout type;
77 };
78 
79 template <class Layout, unsigned Stride>
80 struct inner_layout< LayoutContiguous<Layout, Stride> > {
81  typedef Layout type;
82 };
83 
84 } // namespace Kokkos
85 
86 // Make LayoutContiguous<Layout> equivalent to Layout
87 namespace std {
88 
89  template <class Layout, unsigned Stride>
90  struct is_same< Kokkos::LayoutContiguous<Layout,Stride>, Layout> {
91  static const bool value = true;
92  };
93 
94  template <class Layout, unsigned Stride>
95  struct is_same< Layout, Kokkos::LayoutContiguous<Layout,Stride> > {
96  static const bool value = true;
97  };
98 
99 }
100 
101 #include "impl/Kokkos_ViewMapping.hpp"
102 
103 namespace Kokkos {
104 namespace Impl {
105 
106 // Implement ViewOffset for LayoutContiguous
107 template < class Dimension , class Layout , unsigned Stride >
108 struct ViewOffset<Dimension, LayoutContiguous<Layout,Stride>, void>
109  : public ViewOffset<Dimension,Layout> {
110 public:
111 
112  // Would like to use inherited constructors, but gcc 4.7 doesn't support it
113  //using ViewOffset<Dimension,Layout>::ViewOffset;
114 
115  typedef ViewOffset<Dimension,Layout> Base;
116 
117  ViewOffset() = default ;
118  ViewOffset( const ViewOffset & ) = default ;
119  ViewOffset & operator = ( const ViewOffset & ) = default ;
120 
121  // All constructors take one or two arguments
122 
123  template <typename Arg1>
125  constexpr ViewOffset(const Arg1& arg1) : Base(arg1) {}
126 
127  template <typename Arg1, typename Arg2>
129  constexpr ViewOffset(const Arg1& arg1, const Arg2& arg2) : Base(arg1,arg2) {}
130 };
131 
132 template <typename Layout>
134  static const unsigned stride = 1;
135  static const bool is_unit_stride = true;
136 };
137 
138 template <typename Layout, unsigned Stride>
139 struct LayoutScalarStride< LayoutContiguous<Layout,Stride> > {
140  static const unsigned stride = Stride;
141  static const bool is_unit_stride = (Stride == 1);
142 };
143 
144 } // namespace Impl
145 } // namespace Kokkos
146 
147 #endif // #ifndef KOKKOS_LAYOUT_CONTIGUOUS_HPP
KOKKOS_INLINE_FUNCTION constexpr LayoutContiguous(Layout const &layout)
#define KOKKOS_INLINE_FUNCTION
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