10 #ifndef STOKHOS_MEMORY_TRAITS_HPP
11 #define STOKHOS_MEMORY_TRAITS_HPP
15 #include "Kokkos_Core_fwd.hpp"
18 #define STOKHOS_ALIGN_MEMORY 1
28 #if defined(__INTEL_COMPILER) && ! defined(__CUDA_ARCH__)
29 #define STOKHOS_HAVE_PRAGMA_IVDEP
33 #if 0 && ( defined(__INTEL_COMPILER) || defined(__CUDA_ARCH__) )
34 #define STOKHOS_HAVE_PRAGMA_UNROLL
39 #if defined(STOKHOS_ALIGN_MEMORY) && defined(STOKHOS_ASSUME_ALIGNED) && defined(__INTEL_COMPILER) && ! defined(__CUDA_ARCH__)
40 #define STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
46 template <
typename MemorySpace>
53 KOKKOS_INLINE_FUNCTION
54 static void*
alloc(
const size_t size) {
return operator new(size); }
57 KOKKOS_INLINE_FUNCTION
58 static void free(
void *ptr) {
operator delete(ptr); }
66 #if STOKHOS_ALIGN_MEMORY
69 #elif defined(__AVX__)
71 #elif defined(__SSE2__)
89 KOKKOS_INLINE_FUNCTION
90 static void*
alloc(
const size_t size) {
93 #if STOKHOS_ALIGN_MEMORY
95 const size_t total_size = size + mask +
sizeof(std::ptrdiff_t);
96 char *ptr_alloc =
reinterpret_cast<char*
>(std::malloc(total_size));
97 char *ptr_storage = ptr_alloc +
sizeof(std::ptrdiff_t);
98 char *ptr_body =
reinterpret_cast<char*
>(
99 (
reinterpret_cast<size_t>(ptr_storage) + mask ) & ~mask );
100 char *ptr_header = ptr_body -
sizeof(std::ptrdiff_t);
101 const std::ptrdiff_t offset = ptr_body - ptr_alloc;
102 *
reinterpret_cast<std::ptrdiff_t*
>(ptr_header) = offset;
103 ptr =
reinterpret_cast<void*
>(ptr_body);
105 ptr =
operator new(size);
112 KOKKOS_INLINE_FUNCTION
115 #if STOKHOS_ALIGN_MEMORY
116 void *ptr_header =
reinterpret_cast<char*
>(ptr) -
sizeof(std::ptrdiff_t);
117 const std::ptrdiff_t offset = *
reinterpret_cast<std::ptrdiff_t*
>(ptr_header);
118 void *ptr_alloc =
reinterpret_cast<char*
>(ptr) - offset;
119 std::free(ptr_alloc);
121 operator delete(ptr);
128 template <
typename T>
159 if (ptr == 0)
throw std::bad_alloc();
160 return reinterpret_cast<pointer>(ptr);
171 template <
typename T>
200 if (ptr == 0)
throw std::bad_alloc();
201 return reinterpret_cast<pointer>(ptr);
211 template <
typename T,
typename U>
216 template <
typename T,
typename U>
223 #endif // STOKHOS_MEMORY_TRAITS_HPP
static KOKKOS_INLINE_FUNCTION void free(void *ptr)
Free memory allocated by alloc()
An aligned STL allocator.
const_pointer address(const_reference x) const
pointer address(reference x) const
Specialization of MemoryTraits for host memory spaces.
pointer allocate(size_type n, const void *=0)
const_pointer address(const_reference x) const
bool operator==(const aligned_allocator< T > &, const aligned_allocator< U > &)
static KOKKOS_INLINE_FUNCTION void * alloc(const size_t size)
Allocate aligned memory of given size.
static KOKKOS_INLINE_FUNCTION void free(void *ptr)
Free memory allocated by alloc()
const T & const_reference
const T & const_reference
Stokhos::MemoryTraits< Kokkos::HostSpace > Traits
Traits class encapsulting memory alignment.
void deallocate(pointer p, size_type)
pointer allocate(size_type n, const void *=0)
size_type max_size() const
aligned_allocator< U > other
static const unsigned Alignment
Bytes to which memory allocations are aligned.
void deallocate(pointer p, size_type)
std::ptrdiff_t difference_type
aligned_allocator< U > other
void construct(pointer p, const_reference val)
void construct(pointer p, const_reference val)
Stokhos::MemoryTraits< Kokkos::HostSpace > Traits
static KOKKOS_INLINE_FUNCTION void * alloc(const size_t size)
Allocate aligned memory.
size_type max_size() const
aligned_allocator(const aligned_allocator< U > &)
static const unsigned Alignment
Bytes to which memory allocations are aligned.
std::ptrdiff_t difference_type
aligned_allocator(const aligned_allocator< U > &)
bool operator!=(const aligned_allocator< T > &, const aligned_allocator< U > &)