Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
Stokhos_StaticStorage.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_STORAGE_HPP
43#define STOKHOS_STATIC_STORAGE_HPP
44
46
47#include "Kokkos_Macros.hpp"
48
49#include "Sacado_Traits.hpp"
51#include <sstream>
52
53namespace Stokhos {
54
56 template <typename ordinal_t, typename value_t, int Num, typename device_t>
58 public:
59
60 static const bool is_static = false;
61 static const int static_size = 0;
62 static const bool supports_reset = false;
63
64 typedef ordinal_t ordinal_type;
65 typedef value_t value_type;
66 typedef device_t execution_space;
68 typedef volatile value_type& volatile_reference;
70 typedef const volatile value_type& const_volatile_reference;
72 typedef volatile value_type* volatile_pointer;
73 typedef const value_type* const_pointer;
74 typedef const volatile value_type* const_volatile_pointer;
76
78 template <typename ord_t, typename val_t = value_t , typename dev_t = device_t >
79 struct apply {
80 typedef StaticStorage<ord_t,val_t,Num,dev_t> type;
81 };
82
84 KOKKOS_INLINE_FUNCTION
86 const value_type& x = value_type(0.0)) : sz_(sz) {
87 ss::fill(coeff_, sz_, x);
88 }
89
91 KOKKOS_INLINE_FUNCTION
92 StaticStorage(const ordinal_type& sz, const value_type* x) : sz_(sz) {
93 ss::copy(x, coeff_, sz);
94 }
95
97 KOKKOS_INLINE_FUNCTION
98 StaticStorage(const ordinal_type& sz, pointer v, bool owned) {}
99
101 KOKKOS_INLINE_FUNCTION
103 ss::copy(s.coeff_, coeff_, sz_);
104 }
105
107 KOKKOS_INLINE_FUNCTION
108 StaticStorage(const volatile StaticStorage& s) : sz_(s.sz_) {
109 ss::copy(s.coeff_, coeff_, sz_);
110 }
111
113 KOKKOS_INLINE_FUNCTION
115
117 KOKKOS_INLINE_FUNCTION
119 sz_ = s.sz_;
120 ss::copy(s.coeff_, coeff_, sz_);
121 return *this;
122 }
123
125 KOKKOS_INLINE_FUNCTION
127 sz_ = s.sz_;
128 ss::copy(s.coeff_, coeff_, sz_);
129 return *this;
130 }
131
133 KOKKOS_INLINE_FUNCTION
134 volatile StaticStorage& operator=(const StaticStorage& s) volatile {
135 sz_ = s.sz_;
136 ss::copy(s.coeff_, coeff_, sz_);
137 return *this;
138 }
139
141 KOKKOS_INLINE_FUNCTION
142 volatile StaticStorage& operator=(const volatile StaticStorage& s) volatile {
143 sz_ = s.sz_;
144 ss::copy(s.coeff_, coeff_, sz_);
145 return *this;
146 }
147
149 KOKKOS_INLINE_FUNCTION
151 ss::fill(coeff_, sz_, v);
152 }
153
155 KOKKOS_INLINE_FUNCTION
156 void init(const_reference v) volatile {
157 ss::fill(coeff_, sz_, v);
158 }
159
161 KOKKOS_INLINE_FUNCTION
162 void init(const_pointer v, const ordinal_type& sz = 0) {
163 if (sz == 0)
164 ss::copy(v, coeff_, sz_);
165 else
166 ss::copy(v, coeff_, sz);
167 }
168
170 KOKKOS_INLINE_FUNCTION
171 void init(const_pointer v, const ordinal_type& sz = 0) volatile {
172 if (sz == 0)
173 ss::copy(v, coeff_, sz_);
174 else
175 ss::copy(v, coeff_, sz);
176 }
177
179 KOKKOS_INLINE_FUNCTION
180 void load(pointer v) {
181 ss::copy(v, coeff_, sz_);
182 }
183
185 KOKKOS_INLINE_FUNCTION
186 void load(pointer v) volatile {
187 ss::copy(v, coeff_, sz_);
188 }
189
191 KOKKOS_INLINE_FUNCTION
192 void resize(const ordinal_type& sz) {
193 if (sz > sz_)
194 ss::fill(coeff_+sz_, sz-sz_, value_type(0.0));
195 sz_ = sz;
196 }
197
199 KOKKOS_INLINE_FUNCTION
200 void resize(const ordinal_type& sz) volatile {
201 if (sz > sz_)
202 ss::fill(coeff_+sz_, sz-sz_, value_type(0.0));
203 sz_ = sz;
204 }
205
207 KOKKOS_INLINE_FUNCTION
209 const ordinal_type& stride, bool owned) {}
210
212 KOKKOS_INLINE_FUNCTION
214 const ordinal_type& stride, bool owned) volatile {}
215
217 KOKKOS_INLINE_FUNCTION
218 ordinal_type size() const { return sz_; }
219
221 KOKKOS_INLINE_FUNCTION
222 ordinal_type size() const volatile { return sz_; }
223
225 KOKKOS_INLINE_FUNCTION
227 return coeff_[i];
228 }
229
231 KOKKOS_INLINE_FUNCTION
233 return coeff_[i];
234 }
235
237 KOKKOS_INLINE_FUNCTION
238 reference operator[] (const ordinal_type& i) { return coeff_[i]; }
239
241 KOKKOS_INLINE_FUNCTION
243 return coeff_[i];
244 }
245
246 template <int i>
247 KOKKOS_INLINE_FUNCTION
248 reference getCoeff() { return coeff_[i]; }
249
250 template <int i>
251 KOKKOS_INLINE_FUNCTION
252 volatile_reference getCoeff() volatile { return coeff_[i]; }
253
254 template <int i>
255 KOKKOS_INLINE_FUNCTION
256 const_volatile_reference getCoeff() const volatile { return coeff_[i]; }
257
258 template <int i>
259 KOKKOS_INLINE_FUNCTION
260 const_reference getCoeff() const { return coeff_[i]; }
261
263 KOKKOS_INLINE_FUNCTION
264 const_volatile_pointer coeff() const volatile { return coeff_; }
265
267 KOKKOS_INLINE_FUNCTION
268 const_pointer coeff() const { return coeff_; }
269
271 KOKKOS_INLINE_FUNCTION
272 volatile_pointer coeff() volatile { return coeff_; }
273
275 KOKKOS_INLINE_FUNCTION
276 pointer coeff() { return coeff_; }
277
278 private:
279
282
285
286 };
287
288}
289
292
293#endif // STOKHOS_STATIC_STORAGE_HPP
#define STOKHOS_STORAGE_HELPER_STRINGNAME_STATIC(__storagename__)
Statically allocated storage class.
KOKKOS_INLINE_FUNCTION volatile_reference getCoeff() volatile
KOKKOS_INLINE_FUNCTION reference getCoeff()
KOKKOS_INLINE_FUNCTION const_reference getCoeff() const
KOKKOS_INLINE_FUNCTION ordinal_type size() const
Return size.
KOKKOS_INLINE_FUNCTION void init(const_reference v)
Initialize values to a constant value.
KOKKOS_INLINE_FUNCTION const_volatile_reference getCoeff() const volatile
KOKKOS_INLINE_FUNCTION void resize(const ordinal_type &sz)
Resize to new size (values are preserved)
value_type coeff_[Num]
Coefficient values.
const volatile value_type & const_volatile_reference
Stokhos::StaticArrayTraits< value_type, execution_space > ss
KOKKOS_INLINE_FUNCTION const_volatile_pointer coeff() const volatile
Get coefficients.
const value_type & const_reference
ordinal_type sz_
Size of array used.
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.
const volatile value_type * const_volatile_pointer
KOKKOS_INLINE_FUNCTION StaticStorage(const ordinal_type &sz, const value_type *x)
Constructor from array.
KOKKOS_INLINE_FUNCTION void init(const_pointer v, const ordinal_type &sz=0)
Initialize values to an array of values.
KOKKOS_INLINE_FUNCTION StaticStorage & operator=(const StaticStorage &s)
Assignment operator.
volatile value_type * volatile_pointer
KOKKOS_INLINE_FUNCTION volatile StaticStorage & operator=(const volatile StaticStorage &s) volatile
Assignment operator.
KOKKOS_INLINE_FUNCTION StaticStorage(const ordinal_type &sz, pointer v, bool owned)
Constructor for creating a view (not allowed)
KOKKOS_INLINE_FUNCTION ordinal_type size() const volatile
Return size.
KOKKOS_INLINE_FUNCTION pointer coeff()
Get coefficients.
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.
KOKKOS_INLINE_FUNCTION const_pointer coeff() const
Get coefficients.
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) volatile
Resize to new size (values are preserved)
KOKKOS_INLINE_FUNCTION volatile_pointer coeff() volatile
Get coefficients.
KOKKOS_INLINE_FUNCTION StaticStorage(const ordinal_type &sz=1, const value_type &x=value_type(0.0))
Constructor.
KOKKOS_INLINE_FUNCTION StaticStorage & operator=(const volatile StaticStorage &s)
Assignment operator.
volatile value_type & volatile_reference
KOKKOS_INLINE_FUNCTION StaticStorage(const StaticStorage &s)
Copy constructor.
KOKKOS_INLINE_FUNCTION void load(pointer v) volatile
Load values to an array of values.
KOKKOS_INLINE_FUNCTION ~StaticStorage()
Destructor.
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 load(pointer v)
Load values to an array of values.
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.
Top-level namespace for Stokhos classes and functions.
Static array allocation class.
Turn StaticStorage into a meta-function class usable with mpl::apply.
StaticStorage< ord_t, val_t, Num, dev_t > type