42 #ifndef STOKHOS_DYN_ARRAY_TRAITS_HPP
43 #define STOKHOS_DYN_ARRAY_TRAITS_HPP
48 #include "Kokkos_Core_fwd.hpp"
58 static const bool value =
false;
62 #define STOKHOS_BUILTIN_SPECIALIZATION(t) \
63 template <> struct IsScalarType2< t > { \
64 static const bool value = true; \
72 #undef STOKHOS_BUILTIN_SPECIALIZATION
78 template <
typename T,
typename device_t,
79 bool isScalar = IsScalarType2<T>::value>
87 KOKKOS_INLINE_FUNCTION
88 void copy(
const volatile T* src,
volatile T* dest, std::size_t sz) {
90 for (std::size_t i=0; i<sz; ++i)
96 KOKKOS_INLINE_FUNCTION
97 void copy(
const volatile T* src, T* dest, std::size_t sz) {
99 for (std::size_t i=0; i<sz; ++i)
100 *(dest++) = *(src++);
105 KOKKOS_INLINE_FUNCTION
106 void copy(
const T* src,
volatile T* dest, std::size_t sz) {
108 for (std::size_t i=0; i<sz; ++i)
109 *(dest++) = *(src++);
114 KOKKOS_INLINE_FUNCTION
115 void copy(
const T* src, T* dest, std::size_t sz) {
117 for (std::size_t i=0; i<sz; ++i)
118 *(dest++) = *(src++);
123 KOKKOS_INLINE_FUNCTION
124 void zero(T* dest, std::size_t sz) {
125 if (sz > 0) std::memset(dest,0,sz*
sizeof(T));
130 KOKKOS_INLINE_FUNCTION
131 void zero(
volatile T* dest, std::size_t sz) {
133 for (std::size_t i=0; i<sz; ++i)
139 KOKKOS_INLINE_FUNCTION
140 void fill(T* dest, std::size_t sz,
const T& v) {
142 for (std::size_t i=0; i<sz; ++i)
148 KOKKOS_INLINE_FUNCTION
149 void fill(
volatile T* dest, std::size_t sz,
const T& v) {
151 for (std::size_t i=0; i<sz; ++i)
157 KOKKOS_INLINE_FUNCTION
161 m =
static_cast<T*
>(
operator new(sz*
sizeof(T)));
163 for (std::size_t i=0; i<sz; ++i)
174 KOKKOS_INLINE_FUNCTION
178 m =
static_cast<T*
>(
operator new(sz*
sizeof(T)));
179 for (std::size_t i=0; i<sz; ++i)
190 KOKKOS_INLINE_FUNCTION
194 m =
static_cast<T*
>(
operator new(sz*
sizeof(T)));
195 for (std::size_t i=0; i<sz; ++i)
203 KOKKOS_INLINE_FUNCTION
205 if (sz > 0)
operator delete((
void*) m);
210 KOKKOS_INLINE_FUNCTION
212 if (sz > 0)
operator delete((
void*) m);
219 template <
typename T,
typename device_t>
227 KOKKOS_INLINE_FUNCTION
228 void fill(T* dest, std::size_t sz,
const T& v) {
229 for (std::size_t i=0; i<sz; ++i)
235 KOKKOS_INLINE_FUNCTION
236 void fill(
volatile T* dest, std::size_t sz,
const T& v) {
237 for (std::size_t i=0; i<sz; ++i)
243 KOKKOS_INLINE_FUNCTION
244 void copy(
const volatile T* src,
volatile T* dest, std::size_t sz) {
245 for (std::size_t i=0; i<sz; ++i)
246 *(dest++) = *(src++);
251 KOKKOS_INLINE_FUNCTION
252 void copy(
const volatile T* src, T* dest, std::size_t sz) {
253 for (std::size_t i=0; i<sz; ++i)
254 *(dest++) = *(src++);
259 KOKKOS_INLINE_FUNCTION
260 void copy(
const T* src,
volatile T* dest, std::size_t sz) {
261 for (std::size_t i=0; i<sz; ++i)
262 *(dest++) = *(src++);
267 KOKKOS_INLINE_FUNCTION
268 void copy(
const T* src, T* dest, std::size_t sz) {
269 for (std::size_t i=0; i<sz; ++i)
270 *(dest++) = *(src++);
275 KOKKOS_INLINE_FUNCTION
276 void zero(T* dest, std::size_t sz) {
277 for (std::size_t i=0; i<sz; ++i)
283 KOKKOS_INLINE_FUNCTION
284 void zero(
volatile T* dest, std::size_t sz) {
285 for (std::size_t i=0; i<sz; ++i)
291 KOKKOS_INLINE_FUNCTION
295 m =
static_cast<T*
>(
operator new(sz*
sizeof(T)));
297 for (std::size_t i=0; i<sz; ++i)
308 KOKKOS_INLINE_FUNCTION
312 m =
static_cast<T*
>(
operator new(sz*
sizeof(T)));
314 for (std::size_t i=0; i<sz; ++i)
315 new (p++) T(*(src++));
325 KOKKOS_INLINE_FUNCTION
329 m =
static_cast<T*
>(
operator new(sz*
sizeof(T)));
331 for (std::size_t i=0; i<sz; ++i)
332 new (p++) T(*(src++));
339 KOKKOS_INLINE_FUNCTION
342 for (T* b = m; b!=e; b++)
344 operator delete((
void*) m);
349 KOKKOS_INLINE_FUNCTION
352 for (T* b = m; b!=e; b++)
354 operator delete((
void*) m);
358 #if defined(KOKKOS_ENABLE_CUDA)
366 template <
typename T>
367 struct DynArrayTraits<T,Kokkos::Cuda,
true> {
374 KOKKOS_INLINE_FUNCTION
375 void copy(
const volatile T* src,
volatile T* dest, std::size_t sz) {
377 for (std::size_t i=0; i<sz; ++i)
378 *(dest++) = *(src++);
383 KOKKOS_INLINE_FUNCTION
384 void copy(
const volatile T* src, T* dest, std::size_t sz) {
386 for (std::size_t i=0; i<sz; ++i)
387 *(dest++) = *(src++);
392 KOKKOS_INLINE_FUNCTION
393 void copy(
const T* src,
volatile T* dest, std::size_t sz) {
395 for (std::size_t i=0; i<sz; ++i)
396 *(dest++) = *(src++);
401 KOKKOS_INLINE_FUNCTION
402 void copy(
const T* src, T* dest, std::size_t sz) {
404 for (std::size_t i=0; i<sz; ++i)
405 *(dest++) = *(src++);
410 KOKKOS_INLINE_FUNCTION
411 void zero(T* dest, std::size_t sz) {
412 if (sz > 0) std::memset(dest,0,sz*
sizeof(T));
417 KOKKOS_INLINE_FUNCTION
418 void zero(
volatile T* dest, std::size_t sz) {
420 for (std::size_t i=0; i<sz; ++i)
426 KOKKOS_INLINE_FUNCTION
427 void fill(T* dest, std::size_t sz,
const T& v) {
429 for (std::size_t i=0; i<sz; ++i)
435 KOKKOS_INLINE_FUNCTION
436 void fill(
volatile T* dest, std::size_t sz,
const T& v) {
438 for (std::size_t i=0; i<sz; ++i)
444 KOKKOS_INLINE_FUNCTION
448 #if defined( CUDA_VERSION ) && ( 6000 <= CUDA_VERSION ) && defined(KOKKOS_ENABLE_CUDA_UVM) && !defined( __CUDA_ARCH__ )
449 cudaMallocManaged( (
void**) &m, sz*
sizeof(T), cudaMemAttachGlobal );
451 m =
static_cast<T*
>(
operator new(sz*
sizeof(T)));
454 for (std::size_t i=0; i<sz; ++i)
465 KOKKOS_INLINE_FUNCTION
469 #if defined( CUDA_VERSION ) && ( 6000 <= CUDA_VERSION ) && defined(KOKKOS_ENABLE_CUDA_UVM) && !defined( __CUDA_ARCH__ )
470 cudaMallocManaged( (
void**) &m, sz*
sizeof(T), cudaMemAttachGlobal );
472 m =
static_cast<T*
>(
operator new(sz*
sizeof(T)));
474 for (std::size_t i=0; i<sz; ++i)
485 KOKKOS_INLINE_FUNCTION
486 T*
get_and_fill(
const volatile T* src, std::size_t sz) {
489 #if defined( CUDA_VERSION ) && ( 6000 <= CUDA_VERSION ) && defined(KOKKOS_ENABLE_CUDA_UVM) && !defined( __CUDA_ARCH__ )
490 cudaMallocManaged( (
void**) &m, sz*
sizeof(T), cudaMemAttachGlobal );
492 m =
static_cast<T*
>(
operator new(sz*
sizeof(T)));
494 for (std::size_t i=0; i<sz; ++i)
502 KOKKOS_INLINE_FUNCTION
504 #if defined( CUDA_VERSION ) && ( 6000 <= CUDA_VERSION ) && defined(KOKKOS_ENABLE_CUDA_UVM) && !defined( __CUDA_ARCH__ )
507 if (sz > 0)
operator delete((
void*) m);
513 KOKKOS_INLINE_FUNCTION
515 #if defined( CUDA_VERSION ) && ( 6000 <= CUDA_VERSION ) && defined(KOKKOS_ENABLE_CUDA_UVM) && !defined( __CUDA_ARCH__ )
518 if (sz > 0)
operator delete((
void*) m);
528 template <
typename T>
529 struct DynArrayTraits<T, Kokkos::Cuda, false> {
536 KOKKOS_INLINE_FUNCTION
537 void fill(T* dest, std::size_t sz,
const T& v) {
538 for (std::size_t i=0; i<sz; ++i)
544 KOKKOS_INLINE_FUNCTION
545 void fill(
volatile T* dest, std::size_t sz,
const T& v) {
546 for (std::size_t i=0; i<sz; ++i)
552 KOKKOS_INLINE_FUNCTION
553 void copy(
const volatile T* src,
volatile T* dest, std::size_t sz) {
554 for (std::size_t i=0; i<sz; ++i)
555 *(dest++) = *(src++);
560 KOKKOS_INLINE_FUNCTION
561 void copy(
const volatile T* src, T* dest, std::size_t sz) {
562 for (std::size_t i=0; i<sz; ++i)
563 *(dest++) = *(src++);
568 KOKKOS_INLINE_FUNCTION
569 void copy(
const T* src,
volatile T* dest, std::size_t sz) {
570 for (std::size_t i=0; i<sz; ++i)
571 *(dest++) = *(src++);
576 KOKKOS_INLINE_FUNCTION
577 void copy(
const T* src, T* dest, std::size_t sz) {
578 for (std::size_t i=0; i<sz; ++i)
579 *(dest++) = *(src++);
584 KOKKOS_INLINE_FUNCTION
585 void zero(T* dest, std::size_t sz) {
586 for (std::size_t i=0; i<sz; ++i)
592 KOKKOS_INLINE_FUNCTION
593 void zero(
volatile T* dest, std::size_t sz) {
594 for (std::size_t i=0; i<sz; ++i)
600 KOKKOS_INLINE_FUNCTION
604 #if defined( CUDA_VERSION ) && ( 6000 <= CUDA_VERSION ) && defined(KOKKOS_ENABLE_CUDA_UVM) && !defined( __CUDA_ARCH__ )
605 cudaMallocManaged( (
void**) &m, sz*
sizeof(T), cudaMemAttachGlobal );
607 m =
static_cast<T*
>(
operator new(sz*
sizeof(T)));
610 for (std::size_t i=0; i<sz; ++i)
621 KOKKOS_INLINE_FUNCTION
625 #if defined( CUDA_VERSION ) && ( 6000 <= CUDA_VERSION ) && defined(KOKKOS_ENABLE_CUDA_UVM) && !defined( __CUDA_ARCH__ )
626 cudaMallocManaged( (
void**) &m, sz*
sizeof(T), cudaMemAttachGlobal );
628 m =
static_cast<T*
>(
operator new(sz*
sizeof(T)));
631 for (std::size_t i=0; i<sz; ++i)
632 new (p++) T(*(src++));
642 KOKKOS_INLINE_FUNCTION
643 T*
get_and_fill(
const volatile T* src, std::size_t sz) {
646 #if defined( CUDA_VERSION ) && ( 6000 <= CUDA_VERSION ) && defined(KOKKOS_ENABLE_CUDA_UVM) && !defined( __CUDA_ARCH__ )
647 cudaMallocManaged( (
void**) &m, sz*
sizeof(T), cudaMemAttachGlobal );
649 m =
static_cast<T*
>(
operator new(sz*
sizeof(T)));
652 for (std::size_t i=0; i<sz; ++i)
653 new (p++) T(*(src++));
660 KOKKOS_INLINE_FUNCTION
663 for (T* b = m; b!=e; b++)
665 operator delete((
void*) m);
670 KOKKOS_INLINE_FUNCTION
673 for (T* b = m; b!=e; b++)
675 operator delete((
void*) m);
683 #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.