Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
Stokhos_StaticArrayTraits.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_ARRAY_TRAITS_HPP
43 #define STOKHOS_STATIC_ARRAY_TRAITS_HPP
44 
45 #include <cstring>
46 
47 #include "Sacado_Traits.hpp"
48 
49 #include "Kokkos_Macros.hpp"
50 
51 namespace Stokhos {
52 
56  template <typename T, typename device,
57  bool isScalar = Sacado::IsScalarType<T>::value>
58  struct StaticArrayTraits {};
59 
63  template <typename T, typename D>
64  struct StaticArrayTraits<T, D, false> {
65 
66  typedef T value_type;
67  typedef D execution_space;
68 
70  static
71  KOKKOS_INLINE_FUNCTION
72  void copy(const volatile T* src, volatile T* dest, std::size_t sz) {
73  for (std::size_t i=0; i<sz; ++i)
74  *(dest++) = *(src++);
75  }
76 
78  static
79  KOKKOS_INLINE_FUNCTION
80  void copy(const volatile T* src, T* dest, std::size_t sz) {
81  for (std::size_t i=0; i<sz; ++i)
82  *(dest++) = *(src++);
83  }
84 
86  static
87  KOKKOS_INLINE_FUNCTION
88  void copy(const T* src, volatile T* dest, std::size_t sz) {
89  for (std::size_t i=0; i<sz; ++i)
90  *(dest++) = *(src++);
91  }
92 
94  static
95  KOKKOS_INLINE_FUNCTION
96  void copy(const T* src, T* dest, std::size_t sz) {
97  for (std::size_t i=0; i<sz; ++i)
98  *(dest++) = *(src++);
99  }
100 
102  static
103  KOKKOS_INLINE_FUNCTION
104  void zero(T* dest, std::size_t sz) {
105  for (std::size_t i=0; i<sz; ++i)
106  *(dest++) = T(0.);
107  }
108 
110  static
111  KOKKOS_INLINE_FUNCTION
112  void zero(volatile T* dest, std::size_t sz) {
113  for (std::size_t i=0; i<sz; ++i)
114  *(dest++) = T(0.);
115  }
116 
118  static
119  KOKKOS_INLINE_FUNCTION
120  void fill(T* dest, std::size_t sz, const T& v) {
121  for (std::size_t i=0; i<sz; ++i)
122  *(dest++) = v;
123  }
124 
126  static
127  KOKKOS_INLINE_FUNCTION
128  void fill(volatile T* dest, std::size_t sz, const T& v) {
129  for (std::size_t i=0; i<sz; ++i)
130  *(dest++) = v;
131  }
132 
133  };
134 
139  template <typename T, typename D>
140  struct StaticArrayTraits<T,D,true> {
141 
142  typedef T value_type;
143  typedef D execution_space;
144 
146  static
147  KOKKOS_INLINE_FUNCTION
148  void copy(const volatile T* src, volatile T* dest, std::size_t sz) {
149  // if (sz > 0)
150  // std::memcpy(const_cast<const T*>(dest),const_cast<T*>(src),sz*sizeof(T));
151  for (std::size_t i=0; i<sz; ++i)
152  *(dest++) = *(src++);
153  }
154 
156  static
157  KOKKOS_INLINE_FUNCTION
158  void copy(const volatile T* src, T* dest, std::size_t sz) {
159  // if (sz > 0)
160  // std::memcpy(dest,const_cast<const T*>(src),sz*sizeof(T));
161  for (std::size_t i=0; i<sz; ++i)
162  *(dest++) = *(src++);
163  }
164 
166  static
167  KOKKOS_INLINE_FUNCTION
168  void copy(const T* src, volatile T* dest, std::size_t sz) {
169  // if (sz > 0)
170  // std::memcpy(const_cast<T*>(dest),src,sz*sizeof(T));
171  for (std::size_t i=0; i<sz; ++i)
172  *(dest++) = *(src++);
173  }
174 
176  static
177  KOKKOS_INLINE_FUNCTION
178  void copy(const T* src, T* dest, std::size_t sz) {
179  if (sz > 0) std::memcpy(dest,src,sz*sizeof(T));
180  }
181 
183  static
184  KOKKOS_INLINE_FUNCTION
185  void zero(T* dest, std::size_t sz) {
186  if (sz > 0) std::memset(dest,0,sz*sizeof(T));
187  }
188 
190  static
191  KOKKOS_INLINE_FUNCTION
192  void zero(volatile T* dest, std::size_t sz) {
193  // if (sz > 0) std::memset(const_cast<T*>(dest),0,sz*sizeof(T));
194  for (std::size_t i=0; i<sz; ++i)
195  *(dest++) = T(0.);
196  }
197 
199  static
200  KOKKOS_INLINE_FUNCTION
201  void fill(T* dest, std::size_t sz, T v) {
202  //std::memset(dest,v,sz*sizeof(T)); // memset doesn't work if v != 0?
203  for (std::size_t i=0; i<sz; ++i)
204  *(dest++) = v;
205  }
206 
208  static
209  KOKKOS_INLINE_FUNCTION
210  void fill(volatile T* dest, std::size_t sz, T v) {
211  //std::memset(dest,v,sz*sizeof(T)); // memset doesn't work if v != 0?
212  for (std::size_t i=0; i<sz; ++i)
213  *(dest++) = v;
214  }
215 
216  };
217 
218 } // namespace Stokhos
219 
220 #endif // STOKHOS_STATIC_ARRAY_TRAITS_HPP
static KOKKOS_INLINE_FUNCTION void copy(const T *src, T *dest, std::size_t sz)
Copy array from src to dest of length sz.
static KOKKOS_INLINE_FUNCTION void zero(volatile T *dest, std::size_t sz)
Zero out array dest of length sz.
static KOKKOS_INLINE_FUNCTION void copy(const volatile T *src, T *dest, std::size_t sz)
Copy array from src to dest of length sz.
Static array allocation class.
static KOKKOS_INLINE_FUNCTION void fill(T *dest, std::size_t sz, const T &v)
Fill array dest of length sz with value v.
static KOKKOS_INLINE_FUNCTION void copy(const T *src, volatile T *dest, std::size_t sz)
Copy array from src to dest of length sz.
static KOKKOS_INLINE_FUNCTION void copy(const T *src, volatile T *dest, std::size_t sz)
Copy array from src to dest of length sz.
static KOKKOS_INLINE_FUNCTION void copy(const volatile T *src, volatile T *dest, std::size_t sz)
Copy array from src to dest of length sz.
static KOKKOS_INLINE_FUNCTION void copy(const volatile T *src, T *dest, std::size_t sz)
Copy array from src to dest of length sz.
Top-level namespace for Stokhos classes and functions.
static KOKKOS_INLINE_FUNCTION void copy(const T *src, T *dest, std::size_t sz)
Copy array from src to dest of length sz.
static KOKKOS_INLINE_FUNCTION void copy(const volatile T *src, volatile T *dest, std::size_t sz)
Copy array from src to dest of length sz.
static KOKKOS_INLINE_FUNCTION void zero(volatile T *dest, std::size_t sz)
Zero out array dest of length sz.
Kokkos::DefaultExecutionSpace device
static KOKKOS_INLINE_FUNCTION void fill(volatile T *dest, std::size_t sz, const T &v)
Fill array dest of length sz with value v.
static KOKKOS_INLINE_FUNCTION void fill(T *dest, std::size_t sz, T v)
Fill array dest of length sz with value v.
static KOKKOS_INLINE_FUNCTION void zero(T *dest, std::size_t sz)
Zero out array dest of length sz.
static KOKKOS_INLINE_FUNCTION void zero(T *dest, std::size_t sz)
Zero out array dest of length sz.
static KOKKOS_INLINE_FUNCTION void fill(volatile T *dest, std::size_t sz, T v)
Fill array dest of length sz with value v.