42#ifndef STOKHOS_MEMORY_TRAITS_HPP
43#define STOKHOS_MEMORY_TRAITS_HPP
47#include "Kokkos_Core_fwd.hpp"
50#define STOKHOS_ALIGN_MEMORY 1
60#if defined(__INTEL_COMPILER) && ! defined(__CUDA_ARCH__)
61#define STOKHOS_HAVE_PRAGMA_IVDEP
65#if 0 && ( defined(__INTEL_COMPILER) || defined(__CUDA_ARCH__) )
66#define STOKHOS_HAVE_PRAGMA_UNROLL
71#if defined(STOKHOS_ALIGN_MEMORY) && defined(STOKHOS_ASSUME_ALIGNED) && defined(__INTEL_COMPILER) && ! defined(__CUDA_ARCH__)
72#define STOKHOS_HAVE_PRAGMA_VECTOR_ALIGNED
78template <
typename MemorySpace>
85 KOKKOS_INLINE_FUNCTION
86 static void*
alloc(
const size_t size) {
return operator new(size); }
89 KOKKOS_INLINE_FUNCTION
90 static void free(
void *ptr) {
operator delete(ptr); }
98#if STOKHOS_ALIGN_MEMORY
101#elif defined(__AVX__)
103#elif defined(__SSE2__)
121 KOKKOS_INLINE_FUNCTION
122 static void*
alloc(
const size_t size) {
125#if STOKHOS_ALIGN_MEMORY
127 const size_t total_size = size + mask +
sizeof(std::ptrdiff_t);
128 char *ptr_alloc =
reinterpret_cast<char*
>(std::malloc(total_size));
129 char *ptr_storage = ptr_alloc +
sizeof(std::ptrdiff_t);
130 char *ptr_body =
reinterpret_cast<char*
>(
131 (
reinterpret_cast<size_t>(ptr_storage) + mask ) & ~mask );
132 char *ptr_header = ptr_body -
sizeof(std::ptrdiff_t);
133 const std::ptrdiff_t offset = ptr_body - ptr_alloc;
134 *
reinterpret_cast<std::ptrdiff_t*
>(ptr_header) = offset;
135 ptr =
reinterpret_cast<void*
>(ptr_body);
137 ptr =
operator new(size);
144 KOKKOS_INLINE_FUNCTION
147#if STOKHOS_ALIGN_MEMORY
148 void *ptr_header =
reinterpret_cast<char*
>(ptr) -
sizeof(std::ptrdiff_t);
149 const std::ptrdiff_t offset = *
reinterpret_cast<std::ptrdiff_t*
>(ptr_header);
150 void *ptr_alloc =
reinterpret_cast<char*
>(ptr) - offset;
151 std::free(ptr_alloc);
153 operator delete(ptr);
174 template <
class U>
struct rebind {
typedef aligned_allocator<U>
other; };
191 if (ptr == 0)
throw std::bad_alloc();
192 return reinterpret_cast<pointer>(ptr);
217 template <
class U>
struct rebind {
typedef aligned_allocator<U>
other; };
232 if (ptr == 0)
throw std::bad_alloc();
233 return reinterpret_cast<pointer>(ptr);
243template <
typename T,
typename U>
245operator == (
const aligned_allocator<T>&,
const aligned_allocator<U>&)
248template <
typename T,
typename U>
250operator != (
const aligned_allocator<T>&,
const aligned_allocator<U>&)
const T & const_reference
void deallocate(pointer p, size_type)
void construct(pointer p, const_reference val)
aligned_allocator(const aligned_allocator< U > &)
const_pointer address(const_reference x) const
pointer allocate(size_type n, const void *=0)
size_type max_size() const
Stokhos::MemoryTraits< Kokkos::HostSpace > Traits
std::ptrdiff_t difference_type
An aligned STL allocator.
aligned_allocator(const aligned_allocator< U > &)
void construct(pointer p, const_reference val)
const T & const_reference
pointer address(reference x) const
const_pointer address(const_reference x) const
std::ptrdiff_t difference_type
Stokhos::MemoryTraits< Kokkos::HostSpace > Traits
size_type max_size() const
void deallocate(pointer p, size_type)
pointer allocate(size_type n, const void *=0)
Top-level namespace for Stokhos classes and functions.
bool operator!=(const aligned_allocator< T > &, const aligned_allocator< U > &)
bool operator==(const aligned_allocator< T > &, const aligned_allocator< U > &)
Specialization of MemoryTraits for host memory spaces.
static KOKKOS_INLINE_FUNCTION void * alloc(const size_t size)
Allocate aligned memory.
static const unsigned Alignment
Bytes to which memory allocations are aligned.
static KOKKOS_INLINE_FUNCTION void free(void *ptr)
Free memory allocated by alloc()
Traits class encapsulting memory alignment.
static KOKKOS_INLINE_FUNCTION void free(void *ptr)
Free memory allocated by alloc()
static const unsigned Alignment
Bytes to which memory allocations are aligned.
static KOKKOS_INLINE_FUNCTION void * alloc(const size_t size)
Allocate aligned memory of given size.
aligned_allocator< U > other
aligned_allocator< U > other