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 //
4 // Stokhos Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef STOKHOS_STATIC_FIXED_STORAGE_HPP
43 #define STOKHOS_STATIC_FIXED_STORAGE_HPP
44 
46 #include "Stokhos_MemoryTraits.hpp"
47 
48 #include "Kokkos_Core_fwd.hpp"
49 #include "Kokkos_Cuda.hpp"
50 
51 #include "Sacado_Traits.hpp"
52 #include "Stokhos_KokkosTraits.hpp"
53 #include <sstream>
54 
55 namespace Stokhos {
56 
58  template <typename ordinal_t, typename value_t, int Num, typename device_t>
60  public:
61 
62  static const bool is_static = true ;
63  static const int static_size = Num;
64  static const bool supports_reset = false;
65 
66  typedef ordinal_t ordinal_type;
67  typedef value_t value_type;
69  typedef typename device_t::memory_space memory_space;
71  typedef volatile value_type& volatile_reference;
72  typedef const value_type& const_reference;
73  typedef const volatile value_type& const_volatile_reference;
74  typedef value_type* pointer;
75  typedef volatile value_type* volatile_pointer;
76  typedef const value_type* const_pointer;
77  typedef const volatile value_type* const_volatile_pointer;
79 
81 
83  template <typename ord_t, typename val_t = value_t , typename dev_t = device_t >
84  struct apply {
86  };
87 
88  template <int N>
89  struct apply_N {
91  };
92 
94  KOKKOS_DEFAULTED_FUNCTION
95  StaticFixedStorage() = default;
96 
98  KOKKOS_INLINE_FUNCTION
100  const value_type& x = value_type(0.0)) {
101  ss::fill(coeff_, Num, x);
102  }
103 
105  KOKKOS_INLINE_FUNCTION
107  ss::copy(x, coeff_, sz);
108  }
109 
111  KOKKOS_INLINE_FUNCTION
112  StaticFixedStorage(const ordinal_type& sz, pointer v, bool owned) {}
113 
115  KOKKOS_DEFAULTED_FUNCTION
116  StaticFixedStorage(const StaticFixedStorage& s) = default;
117 
119  KOKKOS_INLINE_FUNCTION
121  ss::copy(s.coeff_, coeff_, Num);
122  }
123 
125  KOKKOS_DEFAULTED_FUNCTION
126  ~StaticFixedStorage() = default;
127 
129  KOKKOS_DEFAULTED_FUNCTION
130  StaticFixedStorage& operator=(const StaticFixedStorage& s) = default;
131 
133  KOKKOS_INLINE_FUNCTION
135  ss::copy(s.coeff_, coeff_, Num);
136  return *this;
137  }
138 
140  KOKKOS_INLINE_FUNCTION
141  /*volatile*/ StaticFixedStorage&
142  operator=(const StaticFixedStorage& s) volatile {
143  ss::copy(s.coeff_, coeff_, Num);
144  return const_cast<StaticFixedStorage&>(*this);
145  }
146 
148  KOKKOS_INLINE_FUNCTION
149  /*volatile*/ StaticFixedStorage&
150  operator=(const volatile StaticFixedStorage& s) volatile {
151  ss::copy(s.coeff_, coeff_, Num);
152  return const_cast<StaticFixedStorage&>(*this);
153  }
154 
156  KOKKOS_INLINE_FUNCTION
158  ss::fill(coeff_, Num, v);
159  }
160 
162  KOKKOS_INLINE_FUNCTION
163  void init(const_reference v) volatile {
164  ss::fill(coeff_, Num, v);
165  }
166 
168  KOKKOS_INLINE_FUNCTION
169  void init(const_pointer v, const ordinal_type& sz = 0) {
170  if (sz == 0)
171  ss::copy(v, coeff_, Num);
172  else
173  ss::copy(v, coeff_, sz);
174  }
175 
177  KOKKOS_INLINE_FUNCTION
178  void init(const_pointer v, const ordinal_type& sz = 0) volatile {
179  if (sz == 0)
180  ss::copy(v, coeff_, Num);
181  else
182  ss::copy(v, coeff_, sz);
183  }
184 
186  KOKKOS_INLINE_FUNCTION
187  void load(pointer v) {
188  ss::copy(v, coeff_, Num);
189  }
190 
192  KOKKOS_INLINE_FUNCTION
193  void load(pointer v) volatile {
194  ss::copy(v, coeff_, Num);
195  }
196 
198  KOKKOS_INLINE_FUNCTION
199  void resize(const ordinal_type& sz) {}
200 
202  KOKKOS_INLINE_FUNCTION
203  void resize(const ordinal_type& sz) volatile {}
204 
206  KOKKOS_INLINE_FUNCTION
207  void shallowReset(pointer v, const ordinal_type& sz,
208  const ordinal_type& stride, bool owned) {}
209 
211  KOKKOS_INLINE_FUNCTION
212  void shallowReset(pointer v, const ordinal_type& sz,
213  const ordinal_type& stride, bool owned) volatile {}
214 
216  KOKKOS_INLINE_FUNCTION
217  static ordinal_type size() { return Num; }
218 
220  KOKKOS_INLINE_FUNCTION
222  return coeff_[i];
223  }
224 
226  KOKKOS_INLINE_FUNCTION
228  return coeff_[i];
229  }
230 
232  KOKKOS_INLINE_FUNCTION
233  reference operator[] (const ordinal_type& i) { return coeff_[i]; }
234 
236  KOKKOS_INLINE_FUNCTION
238  return coeff_[i]; }
239 
240  template <int i>
241  KOKKOS_INLINE_FUNCTION
242  reference getCoeff() { return coeff_[i]; }
243 
244  template <int i>
245  KOKKOS_INLINE_FUNCTION
246  volatile_reference getCoeff() volatile { return coeff_[i]; }
247 
248  template <int i>
249  KOKKOS_INLINE_FUNCTION
250  const_volatile_reference getCoeff() const volatile { return coeff_[i]; }
251 
252  template <int i>
253  KOKKOS_INLINE_FUNCTION
254  const_reference getCoeff() const { return coeff_[i]; }
255 
257  KOKKOS_INLINE_FUNCTION
258  const_volatile_pointer coeff() const volatile { return coeff_; }
259 
261  KOKKOS_INLINE_FUNCTION
262  const_pointer coeff() const { return coeff_; }
263 
265  KOKKOS_INLINE_FUNCTION
266  volatile_pointer coeff() volatile { return coeff_; }
267 
269  KOKKOS_INLINE_FUNCTION
270  pointer coeff() { return coeff_; }
271 
272  private:
273 
275 #if STOKHOS_ALIGN_MEMORY && ( defined(__INTEL_COMPILER) )
276  value_type coeff_[Num] __attribute__((aligned(MemTraits::Alignment)));
277 #else
279 #endif
280 
281  };
282 
283 #if defined(KOKKOS_ENABLE_CUDA)
284 
286 
290  template <typename ordinal_t, typename value_t, int Num>
291  class StaticFixedStorage<ordinal_t,value_t,Num,Kokkos::Cuda> {
292  public:
293 
294  static const bool is_static = true ;
295  static const int static_size = Num;
296  static const bool supports_reset = false;
297 
298  typedef ordinal_t ordinal_type;
299  typedef value_t value_type;
300  typedef Kokkos::Cuda execution_space;
301  typedef value_type& reference;
302  typedef volatile value_type& volatile_reference;
303  typedef const value_type& const_reference;
304  typedef const volatile value_type& const_volatile_reference;
305  typedef value_type* pointer;
306  typedef volatile value_type* volatile_pointer;
307  typedef const value_type* const_pointer;
308  typedef const volatile value_type* const_volatile_pointer;
310 
311  typedef typename execution_space::memory_space memory_space;
313 
315  template <typename ord_t, typename val_t = value_t , typename dev_t = execution_space >
316  struct apply {
318  };
319 
320  template <int N>
321  struct apply_N {
322  typedef StaticFixedStorage<ordinal_type,value_type,N,execution_space> type;
323  };
324 
326  KOKKOS_DEFAULTED_FUNCTION
327  StaticFixedStorage() = default;
328 
330  KOKKOS_INLINE_FUNCTION
332  const value_type& x = value_type(0.0)) {
333  ss::fill(coeff_, Num, x);
334  }
335 
337  KOKKOS_INLINE_FUNCTION
338  StaticFixedStorage(const ordinal_type& sz, const value_type* x) {
339  ss::copy(x, coeff_, sz);
340  }
341 
343  KOKKOS_INLINE_FUNCTION
344  StaticFixedStorage(const ordinal_type& sz, pointer v, bool owned) {}
345 
347  KOKKOS_DEFAULTED_FUNCTION
348  StaticFixedStorage(const StaticFixedStorage& s) = default;
349 
351  KOKKOS_INLINE_FUNCTION
352  StaticFixedStorage(const volatile StaticFixedStorage& s) {
353  ss::copy(s.coeff_, coeff_, Num);
354  }
355 
357  KOKKOS_DEFAULTED_FUNCTION
358  ~StaticFixedStorage() = default;
359 
361  KOKKOS_DEFAULTED_FUNCTION
362  StaticFixedStorage& operator=(const StaticFixedStorage& s) = default;
363 
365  KOKKOS_INLINE_FUNCTION
366  StaticFixedStorage& operator=(const volatile StaticFixedStorage& s) {
367  ss::copy(s.coeff_, coeff_, Num);
368  return *this;
369  }
370 
372  KOKKOS_INLINE_FUNCTION
373  /*volatile*/ StaticFixedStorage&
374  operator=(const StaticFixedStorage& s) volatile {
375  ss::copy(s.coeff_, coeff_, Num);
376  return const_cast<StaticFixedStorage&>(*this);
377  }
378 
380  KOKKOS_INLINE_FUNCTION
381  /*volatile*/ StaticFixedStorage&
382  operator=(const volatile StaticFixedStorage& s) volatile {
383  ss::copy(s.coeff_, coeff_, Num);
384  return const_cast<StaticFixedStorage&>(*this);
385  }
386 
388  KOKKOS_INLINE_FUNCTION
389  void init(const_reference v) {
390  ss::fill(coeff_, Num, v);
391  }
392 
394  KOKKOS_INLINE_FUNCTION
395  void init(const_reference v) volatile {
396  ss::fill(coeff_, Num, v);
397  }
398 
400  KOKKOS_INLINE_FUNCTION
401  void init(const_pointer v, const ordinal_type& sz = 0) {
402  if (sz == 0)
403  ss::copy(v, coeff_, Num);
404  else
405  ss::copy(v, coeff_, sz);
406  }
407 
409  KOKKOS_INLINE_FUNCTION
410  void init(const_pointer v, const ordinal_type& sz = 0) volatile {
411  if (sz == 0)
412  ss::copy(v, coeff_, Num);
413  else
414  ss::copy(v, coeff_, sz);
415  }
416 
418  KOKKOS_INLINE_FUNCTION
419  void load(pointer v) {
420  ss::copy(v, coeff_, Num);
421  }
422 
424  KOKKOS_INLINE_FUNCTION
425  void load(pointer v) volatile {
426  ss::copy(v, coeff_, Num);
427  }
428 
430  KOKKOS_INLINE_FUNCTION
431  void resize(const ordinal_type& sz) {}
432 
434  KOKKOS_INLINE_FUNCTION
435  void resize(const ordinal_type& sz) volatile {}
436 
438  KOKKOS_INLINE_FUNCTION
439  void shallowReset(pointer v, const ordinal_type& sz,
440  const ordinal_type& stride, bool owned) {}
441 
443  KOKKOS_INLINE_FUNCTION
444  void shallowReset(pointer v, const ordinal_type& sz,
445  const ordinal_type& stride, bool owned) volatile {}
446 
448  KOKKOS_INLINE_FUNCTION
449  static ordinal_type size() { return Num; }
450 
452  KOKKOS_INLINE_FUNCTION
453  const_reference operator[] (const ordinal_type& i) const {
454  return coeff_[i];
455  }
456 
458  KOKKOS_INLINE_FUNCTION
459  const_volatile_reference operator[] (const ordinal_type& i) const volatile {
460  return coeff_[i];
461  }
462 
464  KOKKOS_INLINE_FUNCTION
465  reference operator[] (const ordinal_type& i) { return coeff_[i]; }
466 
468  KOKKOS_INLINE_FUNCTION
469  volatile_reference operator[] (const ordinal_type& i) volatile {
470  return coeff_[i]; }
471 
472  template <int i>
473  KOKKOS_INLINE_FUNCTION
474  reference getCoeff() { return coeff_[i]; }
475 
476  template <int i>
477  KOKKOS_INLINE_FUNCTION
478  volatile_reference getCoeff() volatile { return coeff_[i]; }
479 
480  template <int i>
481  KOKKOS_INLINE_FUNCTION
482  const_volatile_reference getCoeff() const volatile { return coeff_[i]; }
483 
484  template <int i>
485  KOKKOS_INLINE_FUNCTION
486  const_reference getCoeff() const { return coeff_[i]; }
487 
489  KOKKOS_INLINE_FUNCTION
490  const_volatile_pointer coeff() const volatile { return coeff_; }
491 
493  KOKKOS_INLINE_FUNCTION
494  const_pointer coeff() const { return coeff_; }
495 
497  KOKKOS_INLINE_FUNCTION
498  volatile_pointer coeff() volatile { return coeff_; }
499 
501  KOKKOS_INLINE_FUNCTION
502  pointer coeff() { return coeff_; }
503 
504  private:
505 
507  value_type coeff_[Num];
508 
509  };
510 
511 #endif
512 
513 }
514 
515 namespace Sacado {
516  template <typename ordinal_t, typename value_t, int Num, typename device_t>
517  struct StringName< Stokhos::StaticFixedStorage<ordinal_t,
518  value_t,
519  Num,
520  device_t> > {
521  static std::string eval() {
522  std::stringstream ss;
523  ss << "Stokhos::StaticFixedStorage<"
524  << StringName<ordinal_t>::eval() << ","
525  << StringName<value_t>::eval() << ","
526  << Num << ","
527  << StringName<device_t>::eval() << ">";
528  return ss.str();
529  }
530  };
531 }
532 
533 #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.
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.