Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
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
52
53namespace Stokhos {
54
58 template <typename T, typename device,
59 bool isScalar = Sacado::IsScalarType<T>::value>
61
65 template <typename T, typename D>
66 struct StaticArrayTraits<T, D, false> {
67
68 typedef T value_type;
69 typedef D execution_space;
70
72 static
73 KOKKOS_INLINE_FUNCTION
74 void copy(const volatile T* src, volatile T* dest, std::size_t sz) {
75 for (std::size_t i=0; i<sz; ++i)
76 *(dest++) = *(src++);
77 }
78
80 static
81 KOKKOS_INLINE_FUNCTION
82 void copy(const volatile T* src, T* dest, std::size_t sz) {
83 for (std::size_t i=0; i<sz; ++i)
84 *(dest++) = *(src++);
85 }
86
88 static
89 KOKKOS_INLINE_FUNCTION
90 void copy(const T* src, volatile T* dest, std::size_t sz) {
91 for (std::size_t i=0; i<sz; ++i)
92 *(dest++) = *(src++);
93 }
94
96 static
97 KOKKOS_INLINE_FUNCTION
98 void copy(const T* src, T* dest, std::size_t sz) {
99 for (std::size_t i=0; i<sz; ++i)
100 *(dest++) = *(src++);
101 }
102
104 static
105 KOKKOS_INLINE_FUNCTION
106 void zero(T* dest, std::size_t sz) {
107 for (std::size_t i=0; i<sz; ++i)
108 *(dest++) = T(0.);
109 }
110
112 static
113 KOKKOS_INLINE_FUNCTION
114 void zero(volatile T* dest, std::size_t sz) {
115 for (std::size_t i=0; i<sz; ++i)
116 *(dest++) = T(0.);
117 }
118
120 static
121 KOKKOS_INLINE_FUNCTION
122 void fill(T* dest, std::size_t sz, const T& v) {
123 for (std::size_t i=0; i<sz; ++i)
124 *(dest++) = v;
125 }
126
128 static
129 KOKKOS_INLINE_FUNCTION
130 void fill(volatile T* dest, std::size_t sz, const T& v) {
131 for (std::size_t i=0; i<sz; ++i)
132 *(dest++) = v;
133 }
134
135 };
136
141 template <typename T, typename D>
143
144 typedef T value_type;
146
148 static
149 KOKKOS_INLINE_FUNCTION
150 void copy(const volatile T* src, volatile T* dest, std::size_t sz) {
151 // if (sz > 0)
152 // std::memcpy(const_cast<const T*>(dest),const_cast<T*>(src),sz*sizeof(T));
153#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
154#pragma ivdep
155#endif
156#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
157#pragma vector aligned
158#endif
159#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
160#pragma unroll
161#endif
162 for (std::size_t i=0; i<sz; ++i)
163 *(dest++) = *(src++);
164 }
165
167 static
168 KOKKOS_INLINE_FUNCTION
169 void copy(const volatile T* src, T* dest, std::size_t sz) {
170 // if (sz > 0)
171 // std::memcpy(dest,const_cast<const T*>(src),sz*sizeof(T));
172#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
173#pragma ivdep
174#endif
175#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
176#pragma vector aligned
177#endif
178#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
179#pragma unroll
180#endif
181 for (std::size_t i=0; i<sz; ++i)
182 *(dest++) = *(src++);
183 }
184
186 static
187 KOKKOS_INLINE_FUNCTION
188 void copy(const T* src, volatile T* dest, std::size_t sz) {
189 // if (sz > 0)
190 // std::memcpy(const_cast<T*>(dest),src,sz*sizeof(T));
191#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
192#pragma ivdep
193#endif
194#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
195#pragma vector aligned
196#endif
197#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
198#pragma unroll
199#endif
200 for (std::size_t i=0; i<sz; ++i)
201 *(dest++) = *(src++);
202 }
203
205 static
206 KOKKOS_INLINE_FUNCTION
207 void copy(const T* src, T* dest, std::size_t sz) {
208 //if (sz > 0) std::memcpy(dest,src,sz*sizeof(T));
209#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
210#pragma ivdep
211#endif
212#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
213#pragma vector aligned
214#endif
215#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
216#pragma unroll
217#endif
218 for (std::size_t i=0; i<sz; ++i)
219 *(dest++) = *(src++);
220 }
221
223 static
224 KOKKOS_INLINE_FUNCTION
225 void zero(T* dest, std::size_t sz) {
226 // if (sz > 0) std::memset(dest,0,sz*sizeof(T));
227#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
228#pragma ivdep
229#endif
230#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
231#pragma vector aligned
232#endif
233#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
234#pragma unroll
235#endif
236 for (std::size_t i=0; i<sz; ++i)
237 *(dest++) = T(0.);
238 }
239
241 static
242 KOKKOS_INLINE_FUNCTION
243 void zero(volatile T* dest, std::size_t sz) {
244 // if (sz > 0) std::memset(const_cast<T*>(dest),0,sz*sizeof(T));
245#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
246#pragma ivdep
247#endif
248#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
249#pragma vector aligned
250#endif
251#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
252#pragma unroll
253#endif
254 for (std::size_t i=0; i<sz; ++i)
255 *(dest++) = T(0.);
256 }
257
259 static
260 KOKKOS_INLINE_FUNCTION
261 void fill(T* dest, std::size_t sz, T v) {
262 //std::memset(dest,v,sz*sizeof(T)); // memset doesn't work if v != 0?
263#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
264#pragma ivdep
265#endif
266#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
267#pragma vector aligned
268#endif
269#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
270#pragma unroll
271#endif
272 for (std::size_t i=0; i<sz; ++i)
273 *(dest++) = v;
274 }
275
277 static
278 KOKKOS_INLINE_FUNCTION
279 void fill(volatile T* dest, std::size_t sz, T v) {
280 //std::memset(dest,v,sz*sizeof(T)); // memset doesn't work if v != 0?
281#ifdef STOKHOS_HAVE_PRAGMA_IVDEP
282#pragma ivdep
283#endif
284#ifdef STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
285#pragma vector aligned
286#endif
287#ifdef STOKHOS_HAVE_PRAGMA_UNROLL
288#pragma unroll
289#endif
290 for (std::size_t i=0; i<sz; ++i)
291 *(dest++) = v;
292 }
293
294 };
295
296} // namespace Stokhos
297
298#endif // STOKHOS_STATIC_ARRAY_TRAITS_HPP
Kokkos::DefaultExecutionSpace device
Top-level namespace for Stokhos classes and functions.
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 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, T *dest, std::size_t sz)
Copy array from src to dest of length sz.
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 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(T *dest, std::size_t sz)
Zero out array 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 zero(volatile T *dest, std::size_t sz)
Zero out array 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 fill(volatile T *dest, std::size_t sz, T v)
Fill array dest of length sz with value v.
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 T *src, volatile T *dest, std::size_t sz)
Copy array from src to 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 copy(const volatile 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 fill(T *dest, std::size_t sz, T v)
Fill array dest of length sz with value v.
Static array allocation class.