Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_StaticFixedStorage.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_FIXED_STORAGE_HPP
11 #define STOKHOS_STATIC_FIXED_STORAGE_HPP
12 
14 #include "Stokhos_MemoryTraits.hpp"
15 
16 // We are hooking into Kokkos Core internals here
17 // Need to define this macro since we include non-public headers
18 #ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
19 #define KOKKOS_IMPL_PUBLIC_INCLUDE
20 #define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
21 #endif
22 #include "Kokkos_Core_fwd.hpp"
23 #include "Cuda/Kokkos_Cuda.hpp"
24 #ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
25 #undef KOKKOS_IMPL_PUBLIC_INCLUDE
26 #undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
27 #endif
28 
29 #include "Sacado_Traits.hpp"
30 #include "Stokhos_KokkosTraits.hpp"
31 #include <sstream>
32 
33 namespace Stokhos {
34 
36  template <typename ordinal_t, typename value_t, int Num, typename device_t>
38  public:
39 
40  static const bool is_static = true ;
41  static const int static_size = Num;
42  static const bool supports_reset = false;
43 
44  typedef ordinal_t ordinal_type;
45  typedef value_t value_type;
47  typedef typename device_t::memory_space memory_space;
49  typedef volatile value_type& volatile_reference;
50  typedef const value_type& const_reference;
51  typedef const volatile value_type& const_volatile_reference;
52  typedef value_type* pointer;
53  typedef volatile value_type* volatile_pointer;
54  typedef const value_type* const_pointer;
55  typedef const volatile value_type* const_volatile_pointer;
57 
59 
61  template <typename ord_t, typename val_t = value_t , typename dev_t = device_t >
62  struct apply {
64  };
65 
66  template <int N>
67  struct apply_N {
69  };
70 
72  KOKKOS_DEFAULTED_FUNCTION
73  StaticFixedStorage() = default;
74 
76  KOKKOS_INLINE_FUNCTION
78  const value_type& x = value_type(0.0)) {
79  ss::fill(coeff_, Num, x);
80  }
81 
83  KOKKOS_INLINE_FUNCTION
85  ss::copy(x, coeff_, sz);
86  }
87 
89  KOKKOS_INLINE_FUNCTION
90  StaticFixedStorage(const ordinal_type& sz, pointer v, bool owned) {}
91 
93  KOKKOS_DEFAULTED_FUNCTION
94  StaticFixedStorage(const StaticFixedStorage& s) = default;
95 
97  KOKKOS_INLINE_FUNCTION
99  ss::copy(s.coeff_, coeff_, Num);
100  }
101 
103  KOKKOS_DEFAULTED_FUNCTION
104  ~StaticFixedStorage() = default;
105 
107  KOKKOS_DEFAULTED_FUNCTION
108  StaticFixedStorage& operator=(const StaticFixedStorage& s) = default;
109 
111  KOKKOS_INLINE_FUNCTION
113  ss::copy(s.coeff_, coeff_, Num);
114  return *this;
115  }
116 
118  KOKKOS_INLINE_FUNCTION
119  /*volatile*/ StaticFixedStorage&
120  operator=(const StaticFixedStorage& s) volatile {
121  ss::copy(s.coeff_, coeff_, Num);
122  return const_cast<StaticFixedStorage&>(*this);
123  }
124 
126  KOKKOS_INLINE_FUNCTION
127  /*volatile*/ StaticFixedStorage&
128  operator=(const volatile StaticFixedStorage& s) volatile {
129  ss::copy(s.coeff_, coeff_, Num);
130  return const_cast<StaticFixedStorage&>(*this);
131  }
132 
134  KOKKOS_INLINE_FUNCTION
136  ss::fill(coeff_, Num, v);
137  }
138 
140  KOKKOS_INLINE_FUNCTION
141  void init(const_reference v) volatile {
142  ss::fill(coeff_, Num, v);
143  }
144 
146  KOKKOS_INLINE_FUNCTION
147  void init(const_pointer v, const ordinal_type& sz = 0) {
148  if (sz == 0)
149  ss::copy(v, coeff_, Num);
150  else
151  ss::copy(v, coeff_, sz);
152  }
153 
155  KOKKOS_INLINE_FUNCTION
156  void init(const_pointer v, const ordinal_type& sz = 0) volatile {
157  if (sz == 0)
158  ss::copy(v, coeff_, Num);
159  else
160  ss::copy(v, coeff_, sz);
161  }
162 
164  KOKKOS_INLINE_FUNCTION
165  void load(pointer v) {
166  ss::copy(v, coeff_, Num);
167  }
168 
170  KOKKOS_INLINE_FUNCTION
171  void load(pointer v) volatile {
172  ss::copy(v, coeff_, Num);
173  }
174 
176  KOKKOS_INLINE_FUNCTION
177  void resize(const ordinal_type& sz) {}
178 
180  KOKKOS_INLINE_FUNCTION
181  void resize(const ordinal_type& sz) volatile {}
182 
184  KOKKOS_INLINE_FUNCTION
185  void shallowReset(pointer v, const ordinal_type& sz,
186  const ordinal_type& stride, bool owned) {}
187 
189  KOKKOS_INLINE_FUNCTION
190  void shallowReset(pointer v, const ordinal_type& sz,
191  const ordinal_type& stride, bool owned) volatile {}
192 
194  KOKKOS_INLINE_FUNCTION
195  static ordinal_type size() { return Num; }
196 
198  KOKKOS_INLINE_FUNCTION
200  return coeff_[i];
201  }
202 
204  KOKKOS_INLINE_FUNCTION
206  return coeff_[i];
207  }
208 
210  KOKKOS_INLINE_FUNCTION
211  reference operator[] (const ordinal_type& i) { return coeff_[i]; }
212 
214  KOKKOS_INLINE_FUNCTION
216  return coeff_[i]; }
217 
218  template <int i>
219  KOKKOS_INLINE_FUNCTION
220  reference getCoeff() { return coeff_[i]; }
221 
222  template <int i>
223  KOKKOS_INLINE_FUNCTION
224  volatile_reference getCoeff() volatile { return coeff_[i]; }
225 
226  template <int i>
227  KOKKOS_INLINE_FUNCTION
228  const_volatile_reference getCoeff() const volatile { return coeff_[i]; }
229 
230  template <int i>
231  KOKKOS_INLINE_FUNCTION
232  const_reference getCoeff() const { return coeff_[i]; }
233 
235  KOKKOS_INLINE_FUNCTION
236  const_volatile_pointer coeff() const volatile { return coeff_; }
237 
239  KOKKOS_INLINE_FUNCTION
240  const_pointer coeff() const { return coeff_; }
241 
243  KOKKOS_INLINE_FUNCTION
244  volatile_pointer coeff() volatile { return coeff_; }
245 
247  KOKKOS_INLINE_FUNCTION
248  pointer coeff() { return coeff_; }
249 
250  private:
251 
253 #if STOKHOS_ALIGN_MEMORY && ( defined(__INTEL_COMPILER) )
254  value_type coeff_[Num] __attribute__((aligned(MemTraits::Alignment)));
255 #else
257 #endif
258 
259  };
260 
261 #if defined(KOKKOS_ENABLE_CUDA)
262 
264 
268  template <typename ordinal_t, typename value_t, int Num>
269  class StaticFixedStorage<ordinal_t,value_t,Num,Kokkos::Cuda> {
270  public:
271 
272  static const bool is_static = true ;
273  static const int static_size = Num;
274  static const bool supports_reset = false;
275 
276  typedef ordinal_t ordinal_type;
277  typedef value_t value_type;
278  typedef Kokkos::Cuda execution_space;
279  typedef value_type& reference;
280  typedef volatile value_type& volatile_reference;
281  typedef const value_type& const_reference;
282  typedef const volatile value_type& const_volatile_reference;
283  typedef value_type* pointer;
284  typedef volatile value_type* volatile_pointer;
285  typedef const value_type* const_pointer;
286  typedef const volatile value_type* const_volatile_pointer;
288 
289  typedef typename execution_space::memory_space memory_space;
291 
293  template <typename ord_t, typename val_t = value_t , typename dev_t = execution_space >
294  struct apply {
296  };
297 
298  template <int N>
299  struct apply_N {
300  typedef StaticFixedStorage<ordinal_type,value_type,N,execution_space> type;
301  };
302 
304  KOKKOS_DEFAULTED_FUNCTION
305  StaticFixedStorage() = default;
306 
308  KOKKOS_INLINE_FUNCTION
310  const value_type& x = value_type(0.0)) {
311  ss::fill(coeff_, Num, x);
312  }
313 
315  KOKKOS_INLINE_FUNCTION
316  StaticFixedStorage(const ordinal_type& sz, const value_type* x) {
317  ss::copy(x, coeff_, sz);
318  }
319 
321  KOKKOS_INLINE_FUNCTION
322  StaticFixedStorage(const ordinal_type& sz, pointer v, bool owned) {}
323 
325  KOKKOS_DEFAULTED_FUNCTION
326  StaticFixedStorage(const StaticFixedStorage& s) = default;
327 
329  KOKKOS_INLINE_FUNCTION
330  StaticFixedStorage(const volatile StaticFixedStorage& s) {
331  ss::copy(s.coeff_, coeff_, Num);
332  }
333 
335  KOKKOS_DEFAULTED_FUNCTION
336  ~StaticFixedStorage() = default;
337 
339  KOKKOS_DEFAULTED_FUNCTION
340  StaticFixedStorage& operator=(const StaticFixedStorage& s) = default;
341 
343  KOKKOS_INLINE_FUNCTION
344  StaticFixedStorage& operator=(const volatile StaticFixedStorage& s) {
345  ss::copy(s.coeff_, coeff_, Num);
346  return *this;
347  }
348 
350  KOKKOS_INLINE_FUNCTION
351  /*volatile*/ StaticFixedStorage&
352  operator=(const StaticFixedStorage& s) volatile {
353  ss::copy(s.coeff_, coeff_, Num);
354  return const_cast<StaticFixedStorage&>(*this);
355  }
356 
358  KOKKOS_INLINE_FUNCTION
359  /*volatile*/ StaticFixedStorage&
360  operator=(const volatile StaticFixedStorage& s) volatile {
361  ss::copy(s.coeff_, coeff_, Num);
362  return const_cast<StaticFixedStorage&>(*this);
363  }
364 
366  KOKKOS_INLINE_FUNCTION
367  void init(const_reference v) {
368  ss::fill(coeff_, Num, v);
369  }
370 
372  KOKKOS_INLINE_FUNCTION
373  void init(const_reference v) volatile {
374  ss::fill(coeff_, Num, v);
375  }
376 
378  KOKKOS_INLINE_FUNCTION
379  void init(const_pointer v, const ordinal_type& sz = 0) {
380  if (sz == 0)
381  ss::copy(v, coeff_, Num);
382  else
383  ss::copy(v, coeff_, sz);
384  }
385 
387  KOKKOS_INLINE_FUNCTION
388  void init(const_pointer v, const ordinal_type& sz = 0) volatile {
389  if (sz == 0)
390  ss::copy(v, coeff_, Num);
391  else
392  ss::copy(v, coeff_, sz);
393  }
394 
396  KOKKOS_INLINE_FUNCTION
397  void load(pointer v) {
398  ss::copy(v, coeff_, Num);
399  }
400 
402  KOKKOS_INLINE_FUNCTION
403  void load(pointer v) volatile {
404  ss::copy(v, coeff_, Num);
405  }
406 
408  KOKKOS_INLINE_FUNCTION
409  void resize(const ordinal_type& sz) {}
410 
412  KOKKOS_INLINE_FUNCTION
413  void resize(const ordinal_type& sz) volatile {}
414 
416  KOKKOS_INLINE_FUNCTION
417  void shallowReset(pointer v, const ordinal_type& sz,
418  const ordinal_type& stride, bool owned) {}
419 
421  KOKKOS_INLINE_FUNCTION
422  void shallowReset(pointer v, const ordinal_type& sz,
423  const ordinal_type& stride, bool owned) volatile {}
424 
426  KOKKOS_INLINE_FUNCTION
427  static ordinal_type size() { return Num; }
428 
430  KOKKOS_INLINE_FUNCTION
431  const_reference operator[] (const ordinal_type& i) const {
432  return coeff_[i];
433  }
434 
436  KOKKOS_INLINE_FUNCTION
437  const_volatile_reference operator[] (const ordinal_type& i) const volatile {
438  return coeff_[i];
439  }
440 
442  KOKKOS_INLINE_FUNCTION
443  reference operator[] (const ordinal_type& i) { return coeff_[i]; }
444 
446  KOKKOS_INLINE_FUNCTION
447  volatile_reference operator[] (const ordinal_type& i) volatile {
448  return coeff_[i]; }
449 
450  template <int i>
451  KOKKOS_INLINE_FUNCTION
452  reference getCoeff() { return coeff_[i]; }
453 
454  template <int i>
455  KOKKOS_INLINE_FUNCTION
456  volatile_reference getCoeff() volatile { return coeff_[i]; }
457 
458  template <int i>
459  KOKKOS_INLINE_FUNCTION
460  const_volatile_reference getCoeff() const volatile { return coeff_[i]; }
461 
462  template <int i>
463  KOKKOS_INLINE_FUNCTION
464  const_reference getCoeff() const { return coeff_[i]; }
465 
467  KOKKOS_INLINE_FUNCTION
468  const_volatile_pointer coeff() const volatile { return coeff_; }
469 
471  KOKKOS_INLINE_FUNCTION
472  const_pointer coeff() const { return coeff_; }
473 
475  KOKKOS_INLINE_FUNCTION
476  volatile_pointer coeff() volatile { return coeff_; }
477 
479  KOKKOS_INLINE_FUNCTION
480  pointer coeff() { return coeff_; }
481 
482  private:
483 
485  value_type coeff_[Num];
486 
487  };
488 
489 #endif
490 
491 }
492 
495 
496 #endif // STOKHOS_STATIC_FIXED_STORAGE_HPP
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 reference getCoeff()
KOKKOS_INLINE_FUNCTION const_reference operator[](const ordinal_type &i) const
Coefficient access (avoid if possible)
KOKKOS_INLINE_FUNCTION void init(const_reference v) volatile
Initialize values to a constant value.
Statically allocated storage class.
KOKKOS_DEFAULTED_FUNCTION StaticFixedStorage()=default
Constructor.
Kokkos::DefaultExecutionSpace execution_space
KOKKOS_INLINE_FUNCTION StaticFixedStorage(const ordinal_type &sz, const value_type &x=value_type(0.0))
Constructor.
Stokhos::StaticArrayTraits< value_type, execution_space > ss
const volatile value_type & const_volatile_reference
Static array allocation class.
KOKKOS_INLINE_FUNCTION void load(pointer v)
Load values to an array of values.
KOKKOS_INLINE_FUNCTION void load(pointer v) volatile
Load 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)
const volatile value_type * const_volatile_pointer
KOKKOS_INLINE_FUNCTION const_pointer coeff() const
Get coefficients.
Stokhos::MemoryTraits< memory_space > MemTraits
KOKKOS_INLINE_FUNCTION void init(const_pointer v, const ordinal_type &sz=0)
Initialize values to an array of values.
KOKKOS_INLINE_FUNCTION const_reference getCoeff() const
KOKKOS_INLINE_FUNCTION void resize(const ordinal_type &sz)
Resize to new size (values are preserved)
Turn StaticFixedStorage into a meta-function class usable with mpl::apply.
KOKKOS_INLINE_FUNCTION void init(const_pointer v, const ordinal_type &sz=0) volatile
Initialize values to an array of values.
KOKKOS_INLINE_FUNCTION void resize(const ordinal_type &sz) volatile
Resize to new size (values are preserved)
KOKKOS_INLINE_FUNCTION StaticFixedStorage(const ordinal_type &sz, pointer v, bool owned)
Constructor for creating a view (not allowed)
StaticFixedStorage< ordinal_type, value_type, N, device_t > type
Traits class encapsulting memory alignment.
KOKKOS_INLINE_FUNCTION StaticFixedStorage & operator=(const volatile StaticFixedStorage &s) volatile
Assignment operator.
KOKKOS_INLINE_FUNCTION StaticFixedStorage(const ordinal_type &sz, const value_type *x)
Constructor from array.
device_t::execution_space execution_space
KOKKOS_INLINE_FUNCTION StaticFixedStorage & operator=(const StaticFixedStorage &s) volatile
Assignment operator.
KOKKOS_INLINE_FUNCTION pointer coeff()
Get coefficients.
static const unsigned Alignment
Bytes to which memory allocations are aligned.
static KOKKOS_INLINE_FUNCTION ordinal_type size()
Return size.
KOKKOS_INLINE_FUNCTION const_volatile_reference getCoeff() const volatile
KOKKOS_INLINE_FUNCTION volatile_reference getCoeff() volatile
KOKKOS_INLINE_FUNCTION const_volatile_pointer coeff() const volatile
Get coefficients.
KOKKOS_INLINE_FUNCTION void init(const_reference v)
Initialize values to a constant value.
StaticFixedStorage< ord_t, val_t, Num, dev_t > type
KOKKOS_DEFAULTED_FUNCTION StaticFixedStorage & operator=(const StaticFixedStorage &s)=default
Assignment operator.
KOKKOS_INLINE_FUNCTION StaticFixedStorage & operator=(const volatile StaticFixedStorage &s)
Assignment operator.
KOKKOS_INLINE_FUNCTION StaticFixedStorage(const volatile StaticFixedStorage &s)
Copy constructor.
value_type coeff_[Num]
Coefficient values.
KOKKOS_INLINE_FUNCTION volatile_pointer coeff() volatile
Get coefficients.
#define STOKHOS_STORAGE_HELPER_STRINGNAME_STATIC(__storagename__)
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.
KOKKOS_DEFAULTED_FUNCTION ~StaticFixedStorage()=default
Destructor.