Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_Fad_ViewStorage.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 SACADO_FAD_VIEWSTORAGE_HPP
31 #define SACADO_FAD_VIEWSTORAGE_HPP
32 
33 #include "Sacado_ConfigDefs.h"
34 
35 #ifdef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
36 
38 
39 namespace Sacado {
40  namespace Fad {
41 
42  template <typename T, unsigned static_length, unsigned static_stride,
43  typename U>
44  using ViewStorage = Exp::ViewStorage<T,static_length,static_stride,U>;
45 
46  }
47 }
48 
49 #else
50 
51 #include "Sacado_Traits.hpp"
54 
55 namespace Sacado {
56 
57  namespace Fad {
58 
59 #ifndef SACADO_FAD_DERIV_LOOP
60 #if defined(SACADO_VIEW_CUDA_HIERARCHICAL_DFAD) && !defined(SACADO_DISABLE_CUDA_IN_KOKKOS) && defined(__CUDA_ARCH__)
61 #define SACADO_FAD_DERIV_LOOP(I,SZ) for (int I=threadIdx.x; I<SZ; I+=blockDim.x)
62 #else
63 #define SACADO_FAD_DERIV_LOOP(I,SZ) for (int I=0; I<SZ; ++I)
64 #endif
65 #endif
66 
72  template <typename T, unsigned static_length, unsigned static_stride, typename U>
73  class ViewStorage {
74 
75  private:
76 
77  // Enumerated flag so logic is evaluated at compile-time
78  enum { stride_one = 1 == static_stride };
79 
80  public:
81 
82  typedef T value_type;
83 
85  template <typename S>
88  sz_(0), stride_(0), val_(0), dx_(0) {}
89 
92  ViewStorage(const int sz, const T & x, const DerivInit zero_out = InitDerivArray) :
93  sz_(0), stride_(0), val_(0), dx_(0) {}
94 
97  ViewStorage(T* v, const int arg_size = 0, const int arg_stride = 0) :
98  sz_(arg_size), stride_(arg_stride), val_(v+sz_.value*stride_.value), dx_(v) {}
99 
102  ViewStorage(T* arg_dx, T* arg_val, const int arg_size = 0,
103  const int arg_stride = 0) :
104  sz_(arg_size), stride_(arg_stride), val_(arg_val), dx_(arg_dx) {}
105 
109  sz_(x.sz_), stride_(x.stride_), val_(x.val_), dx_(x.dx_) {}
110 
114 
118  if (this != &x) {
119  *val_ = *x.val_;
120  if (stride_one)
121  //for (int i=0; i<sz_.value; ++i)
123  dx_[i] = x.dx_[i];
124  else
125  //for (int i=0; i<sz_.value; ++i)
127  dx_[i*stride_.value] = x.dx_[i*x.stride_.value];
128  }
129  return *this;
130  }
131 
134  int size() const { return sz_.value;}
135 
138  int length() const { return sz_.value; }
139 
141 
147  void resize(int sz) {
149  }
150 
152 
158  void resizeAndZero(int /* sz */) {}
159 
162  void expand(int sz) {}
163 
166  void zero() {
168  }
169 
172  const T& val() const { return *val_; }
173 
176  T& val() { return *val_; }
177 
180  const T* dx() const { return dx_;}
181 
184  T dx(int i) const {
185  return unsigned(sz_.value) > 0 ? dx_[ unsigned(stride_one) == 1 ? i : i * stride_.value ] : T(0.);
186  }
187 
190  T& fastAccessDx(int i) {
191  return dx_[ unsigned(stride_one) == 1 ? i : i * stride_.value ];
192  }
193 
196  const T& fastAccessDx(int i) const {
197  return dx_[ unsigned(stride_one) == 1 ? i : i * stride_.value ];
198  }
199 
200  protected:
201 
204 
207 
209  T *val_;
210 
212  T *dx_;
213 
214  }; // class ViewStorage
215 
216  } // namespace Fad
217 
218 } // namespace Sacado
219 
220 #endif // SACADO_NEW_FAD_DESIGN_IS_DEFAULT
221 
222 #endif // SACADO_FAD_VIEWSTORAGE_HPP
KOKKOS_INLINE_FUNCTION void resizeAndZero(int)
Resize the derivative array to sz.
KOKKOS_INLINE_FUNCTION void resize(int sz)
Resize the derivative array to sz.
KOKKOS_INLINE_FUNCTION T dx(int i) const
Returns derivative component i with bounds checking.
KOKKOS_INLINE_FUNCTION int length() const
Returns array length.
const mpl::integral_nonzero_constant< int, static_length > sz_
Derivative array size.
#define SACADO_ENABLE_VALUE_CTOR_DECL
static KOKKOS_INLINE_FUNCTION void strided_zero(T *dest, int stride, int sz)
Zero out array dest of length sz.
KOKKOS_INLINE_FUNCTION ViewStorage(T *arg_dx, T *arg_val, const int arg_size=0, const int arg_stride=0)
Constructor.
#define SACADO_FAD_DERIV_LOOP(I, SZ)
KOKKOS_INLINE_FUNCTION void zero()
Zero out derivative array.
KOKKOS_INLINE_FUNCTION ViewStorage(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Default constructor (needed to satisfy interface)
KOKKOS_INLINE_FUNCTION const T * dx() const
Returns derivative array.
KOKKOS_INLINE_FUNCTION ViewStorage(T *v, const int arg_size=0, const int arg_stride=0)
Constructor.
#define KOKKOS_INLINE_FUNCTION
#define T
Definition: Sacado_rad.hpp:573
KOKKOS_INLINE_FUNCTION T & fastAccessDx(int i)
Returns derivative component i without bounds checking.
KOKKOS_INLINE_FUNCTION ~ViewStorage()
Destructor.
KOKKOS_INLINE_FUNCTION void expand(int sz)
Expand derivative array to size sz.
const mpl::integral_nonzero_constant< int, static_stride > stride_
Derivative array stride.
KOKKOS_INLINE_FUNCTION T & val()
Returns value.
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors...
KOKKOS_INLINE_FUNCTION const T & val() const
Returns value.
KOKKOS_INLINE_FUNCTION ViewStorage(const ViewStorage &x)
Copy constructor.
Initialize the derivative array.
Derivative array storage class that is a view into a contiguous memory allocation. It does not provide proper value semantics and thus should not be used in a general-purpose scalar type.
KOKKOS_INLINE_FUNCTION int size() const
Returns number of derivative components.
KOKKOS_INLINE_FUNCTION const T & fastAccessDx(int i) const
Returns derivative component i without bounds checking.
KOKKOS_INLINE_FUNCTION ViewStorage(const int sz, const T &x, const DerivInit zero_out=InitDerivArray)
Constructor with size sz (needed to satisfy interface)
KOKKOS_INLINE_FUNCTION ViewStorage & operator=(const ViewStorage &x)
Assignment.