10 #ifndef STOKHOS_DYN_ARRAY_TRAITS_HPP
11 #define STOKHOS_DYN_ARRAY_TRAITS_HPP
16 #include "Kokkos_Core_fwd.hpp"
26 static const bool value =
false;
30 #define STOKHOS_BUILTIN_SPECIALIZATION(t) \
31 template <> struct IsScalarType2< t > { \
32 static const bool value = true; \
40 #undef STOKHOS_BUILTIN_SPECIALIZATION
46 template <
typename T,
typename device_t,
47 bool isScalar = IsScalarType2<T>::value>
55 KOKKOS_INLINE_FUNCTION
56 void copy(
const volatile T* src,
volatile T* dest, std::size_t sz) {
58 for (std::size_t i=0; i<sz; ++i)
64 KOKKOS_INLINE_FUNCTION
65 void copy(
const volatile T* src, T* dest, std::size_t sz) {
67 for (std::size_t i=0; i<sz; ++i)
73 KOKKOS_INLINE_FUNCTION
74 void copy(
const T* src,
volatile T* dest, std::size_t sz) {
76 for (std::size_t i=0; i<sz; ++i)
82 KOKKOS_INLINE_FUNCTION
83 void copy(
const T* src, T* dest, std::size_t sz) {
85 for (std::size_t i=0; i<sz; ++i)
91 KOKKOS_INLINE_FUNCTION
92 void zero(T* dest, std::size_t sz) {
93 if (sz > 0) std::memset(dest,0,sz*
sizeof(T));
98 KOKKOS_INLINE_FUNCTION
99 void zero(
volatile T* dest, std::size_t sz) {
101 for (std::size_t i=0; i<sz; ++i)
107 KOKKOS_INLINE_FUNCTION
108 void fill(T* dest, std::size_t sz,
const T& v) {
110 for (std::size_t i=0; i<sz; ++i)
116 KOKKOS_INLINE_FUNCTION
117 void fill(
volatile T* dest, std::size_t sz,
const T& v) {
119 for (std::size_t i=0; i<sz; ++i)
125 KOKKOS_INLINE_FUNCTION
129 m =
static_cast<T*
>(
operator new(sz*
sizeof(T)));
131 for (std::size_t i=0; i<sz; ++i)
142 KOKKOS_INLINE_FUNCTION
146 m =
static_cast<T*
>(
operator new(sz*
sizeof(T)));
147 for (std::size_t i=0; i<sz; ++i)
158 KOKKOS_INLINE_FUNCTION
162 m =
static_cast<T*
>(
operator new(sz*
sizeof(T)));
163 for (std::size_t i=0; i<sz; ++i)
171 KOKKOS_INLINE_FUNCTION
173 if (sz > 0)
operator delete((
void*) m);
178 KOKKOS_INLINE_FUNCTION
180 if (sz > 0)
operator delete((
void*) m);
187 template <
typename T,
typename device_t>
195 KOKKOS_INLINE_FUNCTION
196 void fill(T* dest, std::size_t sz,
const T& v) {
197 for (std::size_t i=0; i<sz; ++i)
203 KOKKOS_INLINE_FUNCTION
204 void fill(
volatile T* dest, std::size_t sz,
const T& v) {
205 for (std::size_t i=0; i<sz; ++i)
211 KOKKOS_INLINE_FUNCTION
212 void copy(
const volatile T* src,
volatile T* dest, std::size_t sz) {
213 for (std::size_t i=0; i<sz; ++i)
214 *(dest++) = *(src++);
219 KOKKOS_INLINE_FUNCTION
220 void copy(
const volatile T* src, T* dest, std::size_t sz) {
221 for (std::size_t i=0; i<sz; ++i)
222 *(dest++) = *(src++);
227 KOKKOS_INLINE_FUNCTION
228 void copy(
const T* src,
volatile T* dest, std::size_t sz) {
229 for (std::size_t i=0; i<sz; ++i)
230 *(dest++) = *(src++);
235 KOKKOS_INLINE_FUNCTION
236 void copy(
const T* src, T* dest, std::size_t sz) {
237 for (std::size_t i=0; i<sz; ++i)
238 *(dest++) = *(src++);
243 KOKKOS_INLINE_FUNCTION
244 void zero(T* dest, std::size_t sz) {
245 for (std::size_t i=0; i<sz; ++i)
251 KOKKOS_INLINE_FUNCTION
252 void zero(
volatile T* dest, std::size_t sz) {
253 for (std::size_t i=0; i<sz; ++i)
259 KOKKOS_INLINE_FUNCTION
263 m =
static_cast<T*
>(
operator new(sz*
sizeof(T)));
265 for (std::size_t i=0; i<sz; ++i)
276 KOKKOS_INLINE_FUNCTION
280 m =
static_cast<T*
>(
operator new(sz*
sizeof(T)));
282 for (std::size_t i=0; i<sz; ++i)
283 new (p++) T(*(src++));
293 KOKKOS_INLINE_FUNCTION
297 m =
static_cast<T*
>(
operator new(sz*
sizeof(T)));
299 for (std::size_t i=0; i<sz; ++i)
300 new (p++) T(*(src++));
307 KOKKOS_INLINE_FUNCTION
310 for (T* b = m; b!=e; b++)
312 operator delete((
void*) m);
317 KOKKOS_INLINE_FUNCTION
320 for (T* b = m; b!=e; b++)
322 operator delete((
void*) m);
326 #if defined(KOKKOS_ENABLE_CUDA)
334 template <
typename T>
335 struct DynArrayTraits<T,Kokkos::Cuda,
true> {
342 KOKKOS_INLINE_FUNCTION
343 void copy(
const volatile T* src,
volatile T* dest, std::size_t sz) {
345 for (std::size_t i=0; i<sz; ++i)
346 *(dest++) = *(src++);
351 KOKKOS_INLINE_FUNCTION
352 void copy(
const volatile T* src, T* dest, std::size_t sz) {
354 for (std::size_t i=0; i<sz; ++i)
355 *(dest++) = *(src++);
360 KOKKOS_INLINE_FUNCTION
361 void copy(
const T* src,
volatile T* dest, std::size_t sz) {
363 for (std::size_t i=0; i<sz; ++i)
364 *(dest++) = *(src++);
369 KOKKOS_INLINE_FUNCTION
370 void copy(
const T* src, T* dest, std::size_t sz) {
372 for (std::size_t i=0; i<sz; ++i)
373 *(dest++) = *(src++);
378 KOKKOS_INLINE_FUNCTION
379 void zero(T* dest, std::size_t sz) {
380 if (sz > 0) std::memset(dest,0,sz*
sizeof(T));
385 KOKKOS_INLINE_FUNCTION
386 void zero(
volatile T* dest, std::size_t sz) {
388 for (std::size_t i=0; i<sz; ++i)
394 KOKKOS_INLINE_FUNCTION
395 void fill(T* dest, std::size_t sz,
const T& v) {
397 for (std::size_t i=0; i<sz; ++i)
403 KOKKOS_INLINE_FUNCTION
404 void fill(
volatile T* dest, std::size_t sz,
const T& v) {
406 for (std::size_t i=0; i<sz; ++i)
412 KOKKOS_INLINE_FUNCTION
416 #if defined( CUDA_VERSION ) && ( 6000 <= CUDA_VERSION ) && defined(KOKKOS_ENABLE_CUDA_UVM) && !defined( __CUDA_ARCH__ )
417 cudaMallocManaged( (
void**) &m, sz*
sizeof(T), cudaMemAttachGlobal );
419 m =
static_cast<T*
>(
operator new(sz*
sizeof(T)));
422 for (std::size_t i=0; i<sz; ++i)
433 KOKKOS_INLINE_FUNCTION
437 #if defined( CUDA_VERSION ) && ( 6000 <= CUDA_VERSION ) && defined(KOKKOS_ENABLE_CUDA_UVM) && !defined( __CUDA_ARCH__ )
438 cudaMallocManaged( (
void**) &m, sz*
sizeof(T), cudaMemAttachGlobal );
440 m =
static_cast<T*
>(
operator new(sz*
sizeof(T)));
442 for (std::size_t i=0; i<sz; ++i)
453 KOKKOS_INLINE_FUNCTION
454 T*
get_and_fill(
const volatile T* src, std::size_t sz) {
457 #if defined( CUDA_VERSION ) && ( 6000 <= CUDA_VERSION ) && defined(KOKKOS_ENABLE_CUDA_UVM) && !defined( __CUDA_ARCH__ )
458 cudaMallocManaged( (
void**) &m, sz*
sizeof(T), cudaMemAttachGlobal );
460 m =
static_cast<T*
>(
operator new(sz*
sizeof(T)));
462 for (std::size_t i=0; i<sz; ++i)
470 KOKKOS_INLINE_FUNCTION
472 #if defined( CUDA_VERSION ) && ( 6000 <= CUDA_VERSION ) && defined(KOKKOS_ENABLE_CUDA_UVM) && !defined( __CUDA_ARCH__ )
475 if (sz > 0)
operator delete((
void*) m);
481 KOKKOS_INLINE_FUNCTION
483 #if defined( CUDA_VERSION ) && ( 6000 <= CUDA_VERSION ) && defined(KOKKOS_ENABLE_CUDA_UVM) && !defined( __CUDA_ARCH__ )
486 if (sz > 0)
operator delete((
void*) m);
496 template <
typename T>
497 struct DynArrayTraits<T, Kokkos::Cuda, false> {
504 KOKKOS_INLINE_FUNCTION
505 void fill(T* dest, std::size_t sz,
const T& v) {
506 for (std::size_t i=0; i<sz; ++i)
512 KOKKOS_INLINE_FUNCTION
513 void fill(
volatile T* dest, std::size_t sz,
const T& v) {
514 for (std::size_t i=0; i<sz; ++i)
520 KOKKOS_INLINE_FUNCTION
521 void copy(
const volatile T* src,
volatile T* dest, std::size_t sz) {
522 for (std::size_t i=0; i<sz; ++i)
523 *(dest++) = *(src++);
528 KOKKOS_INLINE_FUNCTION
529 void copy(
const volatile T* src, T* dest, std::size_t sz) {
530 for (std::size_t i=0; i<sz; ++i)
531 *(dest++) = *(src++);
536 KOKKOS_INLINE_FUNCTION
537 void copy(
const T* src,
volatile T* dest, std::size_t sz) {
538 for (std::size_t i=0; i<sz; ++i)
539 *(dest++) = *(src++);
544 KOKKOS_INLINE_FUNCTION
545 void copy(
const T* src, T* dest, std::size_t sz) {
546 for (std::size_t i=0; i<sz; ++i)
547 *(dest++) = *(src++);
552 KOKKOS_INLINE_FUNCTION
553 void zero(T* dest, std::size_t sz) {
554 for (std::size_t i=0; i<sz; ++i)
560 KOKKOS_INLINE_FUNCTION
561 void zero(
volatile T* dest, std::size_t sz) {
562 for (std::size_t i=0; i<sz; ++i)
568 KOKKOS_INLINE_FUNCTION
572 #if defined( CUDA_VERSION ) && ( 6000 <= CUDA_VERSION ) && defined(KOKKOS_ENABLE_CUDA_UVM) && !defined( __CUDA_ARCH__ )
573 cudaMallocManaged( (
void**) &m, sz*
sizeof(T), cudaMemAttachGlobal );
575 m =
static_cast<T*
>(
operator new(sz*
sizeof(T)));
578 for (std::size_t i=0; i<sz; ++i)
589 KOKKOS_INLINE_FUNCTION
593 #if defined( CUDA_VERSION ) && ( 6000 <= CUDA_VERSION ) && defined(KOKKOS_ENABLE_CUDA_UVM) && !defined( __CUDA_ARCH__ )
594 cudaMallocManaged( (
void**) &m, sz*
sizeof(T), cudaMemAttachGlobal );
596 m =
static_cast<T*
>(
operator new(sz*
sizeof(T)));
599 for (std::size_t i=0; i<sz; ++i)
600 new (p++) T(*(src++));
610 KOKKOS_INLINE_FUNCTION
611 T*
get_and_fill(
const volatile T* src, std::size_t sz) {
614 #if defined( CUDA_VERSION ) && ( 6000 <= CUDA_VERSION ) && defined(KOKKOS_ENABLE_CUDA_UVM) && !defined( __CUDA_ARCH__ )
615 cudaMallocManaged( (
void**) &m, sz*
sizeof(T), cudaMemAttachGlobal );
617 m =
static_cast<T*
>(
operator new(sz*
sizeof(T)));
620 for (std::size_t i=0; i<sz; ++i)
621 new (p++) T(*(src++));
628 KOKKOS_INLINE_FUNCTION
631 for (T* b = m; b!=e; b++)
633 operator delete((
void*) m);
638 KOKKOS_INLINE_FUNCTION
641 for (T* b = m; b!=e; b++)
643 operator delete((
void*) m);
651 #endif // STOKHOS_DYN_ARRAY_TRAITS_HPP
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 T * get_and_fill(const T *src, std::size_t sz)
Get memory for new array of length sz and fill with entries from src.
static KOKKOS_INLINE_FUNCTION void destroy_and_release(T *m, std::size_t sz)
Destroy array elements and release memory.
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 T * get_and_fill(const volatile T *src, std::size_t sz)
Get memory for new array of length sz and fill with entries from src.
static KOKKOS_INLINE_FUNCTION void destroy_and_release(volatile T *m, std::size_t sz)
Destroy array elements and release memory.
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 T *src, volatile T *dest, std::size_t sz)
Copy array from src to dest of length sz.
Base template specification for IsScalarType.
static KOKKOS_INLINE_FUNCTION T * get_and_fill(std::size_t sz, const T &x=T(0.0))
Get memory for new array of length sz and fill with zeros.
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(T *dest, std::size_t sz, const 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 fill(T *dest, std::size_t sz, const T &v)
Fill array dest of length sz with value v.
static KOKKOS_INLINE_FUNCTION T * get_and_fill(std::size_t sz, const T &x=T(0.0))
Get memory for new array of length sz and fill with zeros.
#define STOKHOS_BUILTIN_SPECIALIZATION(t)
Specialization of above classes to built-in types.
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 T * get_and_fill(const volatile T *src, std::size_t sz)
Get memory for new array of length sz and fill with entries from src.
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 T *src, T *dest, std::size_t sz)
Copy array from src to dest of length sz.
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 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 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.
Dynamic array allocation class that is specialized for scalar i.e., fundamental or built-in types (fl...
static KOKKOS_INLINE_FUNCTION void destroy_and_release(volatile T *m, std::size_t sz)
Destroy array elements and release memory.
static KOKKOS_INLINE_FUNCTION T * get_and_fill(const T *src, std::size_t sz)
Get memory for new array of length sz and fill with entries from src.
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 destroy_and_release(T *m, std::size_t sz)
Destroy array elements and release memory.