Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_StaticStorage.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef STOKHOS_STATIC_STORAGE_HPP
11 #define STOKHOS_STATIC_STORAGE_HPP
12 
14 
15 #include "Kokkos_Macros.hpp"
16 
17 #include "Sacado_Traits.hpp"
18 #include "Stokhos_KokkosTraits.hpp"
19 #include <sstream>
20 
21 namespace Stokhos {
22 
24  template <typename ordinal_t, typename value_t, int Num, typename device_t>
25  class StaticStorage {
26  public:
27 
28  static const bool is_static = false;
29  static const int static_size = 0;
30  static const bool supports_reset = false;
31 
32  typedef ordinal_t ordinal_type;
33  typedef value_t value_type;
34  typedef device_t execution_space;
36  typedef volatile value_type& volatile_reference;
37  typedef const value_type& const_reference;
38  typedef const volatile value_type& const_volatile_reference;
39  typedef value_type* pointer;
40  typedef volatile value_type* volatile_pointer;
41  typedef const value_type* const_pointer;
42  typedef const volatile value_type* const_volatile_pointer;
44 
46  template <typename ord_t, typename val_t = value_t , typename dev_t = device_t >
47  struct apply {
49  };
50 
52  KOKKOS_INLINE_FUNCTION
53  StaticStorage(const ordinal_type& sz = 1,
54  const value_type& x = value_type(0.0)) : sz_(sz) {
55  ss::fill(coeff_, sz_, x);
56  }
57 
59  KOKKOS_INLINE_FUNCTION
60  StaticStorage(const ordinal_type& sz, const value_type* x) : sz_(sz) {
61  ss::copy(x, coeff_, sz);
62  }
63 
65  KOKKOS_INLINE_FUNCTION
66  StaticStorage(const ordinal_type& sz, pointer v, bool owned) {}
67 
69  KOKKOS_INLINE_FUNCTION
71  ss::copy(s.coeff_, coeff_, sz_);
72  }
73 
75  KOKKOS_INLINE_FUNCTION
76  StaticStorage(const volatile StaticStorage& s) : sz_(s.sz_) {
77  ss::copy(s.coeff_, coeff_, sz_);
78  }
79 
81  KOKKOS_INLINE_FUNCTION
83 
85  KOKKOS_INLINE_FUNCTION
87  sz_ = s.sz_;
88  ss::copy(s.coeff_, coeff_, sz_);
89  return *this;
90  }
91 
93  KOKKOS_INLINE_FUNCTION
94  StaticStorage& operator=(const volatile StaticStorage& s) {
95  sz_ = s.sz_;
96  ss::copy(s.coeff_, coeff_, sz_);
97  return *this;
98  }
99 
101  KOKKOS_INLINE_FUNCTION
102  volatile StaticStorage& operator=(const StaticStorage& s) volatile {
103  sz_ = s.sz_;
104  ss::copy(s.coeff_, coeff_, sz_);
105  return *this;
106  }
107 
109  KOKKOS_INLINE_FUNCTION
110  volatile StaticStorage& operator=(const volatile StaticStorage& s) volatile {
111  sz_ = s.sz_;
112  ss::copy(s.coeff_, coeff_, sz_);
113  return *this;
114  }
115 
117  KOKKOS_INLINE_FUNCTION
119  ss::fill(coeff_, sz_, v);
120  }
121 
123  KOKKOS_INLINE_FUNCTION
124  void init(const_reference v) volatile {
125  ss::fill(coeff_, sz_, v);
126  }
127 
129  KOKKOS_INLINE_FUNCTION
130  void init(const_pointer v, const ordinal_type& sz = 0) {
131  if (sz == 0)
132  ss::copy(v, coeff_, sz_);
133  else
134  ss::copy(v, coeff_, sz);
135  }
136 
138  KOKKOS_INLINE_FUNCTION
139  void init(const_pointer v, const ordinal_type& sz = 0) volatile {
140  if (sz == 0)
141  ss::copy(v, coeff_, sz_);
142  else
143  ss::copy(v, coeff_, sz);
144  }
145 
147  KOKKOS_INLINE_FUNCTION
148  void load(pointer v) {
149  ss::copy(v, coeff_, sz_);
150  }
151 
153  KOKKOS_INLINE_FUNCTION
154  void load(pointer v) volatile {
155  ss::copy(v, coeff_, sz_);
156  }
157 
159  KOKKOS_INLINE_FUNCTION
160  void resize(const ordinal_type& sz) {
161  if (sz > sz_)
162  ss::fill(coeff_+sz_, sz-sz_, value_type(0.0));
163  sz_ = sz;
164  }
165 
167  KOKKOS_INLINE_FUNCTION
168  void resize(const ordinal_type& sz) volatile {
169  if (sz > sz_)
170  ss::fill(coeff_+sz_, sz-sz_, value_type(0.0));
171  sz_ = sz;
172  }
173 
175  KOKKOS_INLINE_FUNCTION
176  void shallowReset(pointer v, const ordinal_type& sz,
177  const ordinal_type& stride, bool owned) {}
178 
180  KOKKOS_INLINE_FUNCTION
181  void shallowReset(pointer v, const ordinal_type& sz,
182  const ordinal_type& stride, bool owned) volatile {}
183 
185  KOKKOS_INLINE_FUNCTION
186  ordinal_type size() const { return sz_; }
187 
189  KOKKOS_INLINE_FUNCTION
190  ordinal_type size() const volatile { return sz_; }
191 
193  KOKKOS_INLINE_FUNCTION
195  return coeff_[i];
196  }
197 
199  KOKKOS_INLINE_FUNCTION
201  return coeff_[i];
202  }
203 
205  KOKKOS_INLINE_FUNCTION
206  reference operator[] (const ordinal_type& i) { return coeff_[i]; }
207 
209  KOKKOS_INLINE_FUNCTION
211  return coeff_[i];
212  }
213 
214  template <int i>
215  KOKKOS_INLINE_FUNCTION
216  reference getCoeff() { return coeff_[i]; }
217 
218  template <int i>
219  KOKKOS_INLINE_FUNCTION
220  volatile_reference getCoeff() volatile { return coeff_[i]; }
221 
222  template <int i>
223  KOKKOS_INLINE_FUNCTION
224  const_volatile_reference getCoeff() const volatile { return coeff_[i]; }
225 
226  template <int i>
227  KOKKOS_INLINE_FUNCTION
228  const_reference getCoeff() const { return coeff_[i]; }
229 
231  KOKKOS_INLINE_FUNCTION
232  const_volatile_pointer coeff() const volatile { return coeff_; }
233 
235  KOKKOS_INLINE_FUNCTION
236  const_pointer coeff() const { return coeff_; }
237 
239  KOKKOS_INLINE_FUNCTION
240  volatile_pointer coeff() volatile { return coeff_; }
241 
243  KOKKOS_INLINE_FUNCTION
244  pointer coeff() { return coeff_; }
245 
246  private:
247 
250 
253 
254  };
255 
256 }
257 
260 
261 #endif // STOKHOS_STATIC_STORAGE_HPP
KOKKOS_INLINE_FUNCTION volatile StaticStorage & operator=(const volatile StaticStorage &s) volatile
Assignment operator.
KOKKOS_INLINE_FUNCTION ordinal_type size() const
Return size.
KOKKOS_INLINE_FUNCTION void init(const_reference v) volatile
Initialize values to a constant value.
KOKKOS_INLINE_FUNCTION const_volatile_reference getCoeff() const volatile
KOKKOS_INLINE_FUNCTION StaticStorage(const ordinal_type &sz, pointer v, bool owned)
Constructor for creating a view (not allowed)
KOKKOS_INLINE_FUNCTION StaticStorage(const ordinal_type &sz, const value_type *x)
Constructor from array.
const value_type & const_reference
KOKKOS_INLINE_FUNCTION ~StaticStorage()
Destructor.
KOKKOS_INLINE_FUNCTION void load(pointer v) volatile
Load values to an array of values.
Static array allocation class.
ordinal_type sz_
Size of array used.
KOKKOS_INLINE_FUNCTION const_reference operator[](const ordinal_type &i) const
Coefficient access (avoid if possible)
KOKKOS_INLINE_FUNCTION void init(const_pointer v, const ordinal_type &sz=0) volatile
Initialize values to an array of values.
std::enable_if< Kokkos::is_view_uq_pce< Kokkos::View< XD, XP...> >::value >::type fill(const Kokkos::View< XD, XP...> &x, const typename Kokkos::View< XD, XP...>::non_const_value_type &val)
KOKKOS_INLINE_FUNCTION ordinal_type size() const volatile
Return size.
KOKKOS_INLINE_FUNCTION void load(pointer v)
Load values to an array of values.
value_type coeff_[Num]
Coefficient values.
KOKKOS_INLINE_FUNCTION const_reference getCoeff() const
KOKKOS_INLINE_FUNCTION StaticStorage & operator=(const volatile StaticStorage &s)
Assignment operator.
KOKKOS_INLINE_FUNCTION void init(const_pointer v, const ordinal_type &sz=0)
Initialize values to an array of values.
const value_type * const_pointer
KOKKOS_INLINE_FUNCTION StaticStorage(const ordinal_type &sz=1, const value_type &x=value_type(0.0))
Constructor.
KOKKOS_INLINE_FUNCTION StaticStorage(const StaticStorage &s)
Copy constructor.
StaticStorage< ord_t, val_t, Num, dev_t > type
volatile value_type & volatile_reference
KOKKOS_INLINE_FUNCTION void shallowReset(pointer v, const ordinal_type &sz, const ordinal_type &stride, bool owned) volatile
Reset storage to given array, size, and stride.
KOKKOS_INLINE_FUNCTION StaticStorage & operator=(const StaticStorage &s)
Assignment operator.
KOKKOS_INLINE_FUNCTION const_volatile_pointer coeff() const volatile
Get coefficients.
const volatile value_type & const_volatile_reference
static const bool supports_reset
KOKKOS_INLINE_FUNCTION volatile_reference getCoeff() volatile
Stokhos::StaticArrayTraits< value_type, execution_space > ss
KOKKOS_INLINE_FUNCTION StaticStorage(const volatile StaticStorage &s)
Copy constructor.
KOKKOS_INLINE_FUNCTION volatile StaticStorage & operator=(const StaticStorage &s) volatile
Assignment operator.
KOKKOS_INLINE_FUNCTION void resize(const ordinal_type &sz)
Resize to new size (values are preserved)
KOKKOS_INLINE_FUNCTION reference getCoeff()
KOKKOS_INLINE_FUNCTION void shallowReset(pointer v, const ordinal_type &sz, const ordinal_type &stride, bool owned)
Reset storage to given array, size, and stride.
Turn StaticStorage into a meta-function class usable with mpl::apply.
KOKKOS_INLINE_FUNCTION void init(const_reference v)
Initialize values to a constant value.
KOKKOS_INLINE_FUNCTION volatile_pointer coeff() volatile
Get coefficients.
volatile value_type * volatile_pointer
KOKKOS_INLINE_FUNCTION pointer coeff()
Get coefficients.
const volatile value_type * const_volatile_pointer
Statically allocated storage class.
KOKKOS_INLINE_FUNCTION const_pointer coeff() const
Get coefficients.
#define STOKHOS_STORAGE_HELPER_STRINGNAME_STATIC(__storagename__)
KOKKOS_INLINE_FUNCTION void resize(const ordinal_type &sz) volatile
Resize to new size (values are preserved)