14 #ifndef QMCPLUSPLUS_DUAL_ALLOCATOR_H 15 #define QMCPLUSPLUS_DUAL_ALLOCATOR_H 18 #include <type_traits> 24 #if defined(ENABLE_CUDA) 26 #elif defined(ENABLE_SYCL) 47 template<
typename T,
class DeviceAllocator,
class HostAllocator = std::allocator<T>>
51 using Size =
typename HostAllocator::size_type;
52 using Pointer =
typename HostAllocator::pointer;
61 template<
class U,
class V>
65 template<
class U,
class V>
73 static_assert(std::is_same<T, Value>::value,
"DualAllocator and HostAllocator data types must agree!");
75 throw std::runtime_error(
"DualAllocator does not support device reallocation");
76 Value* host_ptr = std::allocator_traits<HostAllocator>::allocate(
allocator_,
n);
86 std::allocator_traits<HostAllocator>::deallocate(
allocator_, pt,
n);
107 template<
typename T,
class DeviceAllocator,
class HostAllocator>
147 T* to_ptr = device_ptr + to;
148 T* from_ptr = device_ptr + from;
static constexpr bool is_dual_space
DualAllocator(const DualAllocator< U, V > &)
Generalizes the DualMemorySpace allocator This provides a limited alternative to OMPallocator for tes...
helper functions for EinsplineSetBuilder
static void deviceSideCopyN(DualAlloc &alloc, size_t to, size_t n, size_t from)
DeviceAllocator device_allocator_
static void fill_n(T *ptr, size_t n, const T &value)
static void updateFrom(DualAlloc &alloc, T *host_ptr, size_t n, size_t offset=0)
update from the device, assumes you are copying starting with the device_ptr to the implicit host_ptr...
static void attachReference(const DualAlloc &from, DualAlloc &to, std::ptrdiff_t ptr_offset)
this file provides three C++ memory allocators using CUDA specific memory allocation functions...
const DeviceAllocator & get_device_allocator() const
DualAllocator(const DualAllocator &)
static void updateTo(DualAlloc &alloc, T *host_ptr, size_t n, size_t offset=0)
update to the device, assumes you are copying starting with the implicit host_ptr.
typename HostAllocator::pointer Pointer
void attachReference(const DualAllocator &from, std::ptrdiff_t ptr_offset)
static constexpr bool is_host_accessible
DeviceAllocator & get_device_allocator()
template class analogous to std::allocator_traits.
const T * get_device_ptr() const
size_t getDualDeviceMemAllocated()
typename HostAllocator::const_pointer ConstPointer
std::atomic< size_t > dual_device_mem_allocated
this file provides three C++ memory allocators using SYCL specific memory allocation functions...
typename HostAllocator::size_type Size
void deallocate(Value *pt, std::size_t n)
DualAllocator & operator=(const DualAllocator &)
typename HostAllocator::value_type Value
Value * allocate(std::size_t n)
static void fill_n(value_type *ptr, size_t n, const value_type &value)
QMCTraits::FullPrecRealType value_type