![]() |
QMCPACK
|
allocator for CUDA device memory More...
Classes | |
struct | rebind |
Public Types | |
using | value_type = T |
using | size_type = size_t |
using | pointer = T * |
using | const_pointer = const T * |
Public Member Functions | |
CUDAAllocator ()=default | |
template<class U > | |
CUDAAllocator (const CUDAAllocator< U > &) | |
T * | allocate (std::size_t n) |
void | deallocate (T *p, std::size_t n) |
void | copyToDevice (T *device_ptr, T *host_ptr, size_t n) |
void | copyFromDevice (T *host_ptr, T *device_ptr, size_t n) |
void | copyDeviceToDevice (T *to_ptr, size_t n, T *from_ptr) |
Static Public Member Functions | |
template<class U , class... Args> | |
static void | construct (U *p, Args &&... args) |
Provide a construct for std::allocator_traits::contruct to call. More... | |
template<class U > | |
static void | destroy (U *p) |
Give std::allocator_traits something to call. More... | |
allocator for CUDA device memory
T | data type |
using this with something other than Ohmms containers? – use caution, write unit tests! – It's not tested beyond use in some unit tests using std::vector with constant size. CUDAAllocator appears to meet all the nonoptional requirements of a c++ Allocator.
Some of the default implementations in std::allocator_traits of optional Allocator requirements may cause runtime or compilation failures. They assume there is only one memory space and that the host has access to it.
Definition at line 95 of file CUDAallocator.hpp.
struct qmcplusplus::CUDAAllocator::rebind |
Definition at line 109 of file CUDAallocator.hpp.
Class Members | ||
---|---|---|
typedef CUDAAllocator< U > | other |
using const_pointer = const T* |
Definition at line 101 of file CUDAallocator.hpp.
using pointer = T* |
Definition at line 100 of file CUDAallocator.hpp.
using size_type = size_t |
Definition at line 99 of file CUDAallocator.hpp.
using value_type = T |
Definition at line 98 of file CUDAallocator.hpp.
|
default |
|
inline |
Definition at line 105 of file CUDAallocator.hpp.
|
inline |
Definition at line 114 of file CUDAallocator.hpp.
|
inlinestatic |
Provide a construct for std::allocator_traits::contruct to call.
Don't do anything on construct, pointer p is on the device!
For example std::vector calls this to default initialize each element. You'll segfault if std::allocator_traits::construct tries doing that at p.
The standard is a bit confusing on this point. Implementing this is an optional requirement of Allocator from C++11 on, its not slated to be removed.
Its deprecated for the std::allocator in c++17 and will be removed in c++20. But we are not implementing std::allocator.
STL containers only use Allocators through allocator_traits and std::allocator_traits handles the case where no construct method is present in the Allocator. But std::allocator_traits will call the Allocators construct method if present.
Definition at line 144 of file CUDAallocator.hpp.
|
inline |
Definition at line 167 of file CUDAallocator.hpp.
|
inline |
Definition at line 161 of file CUDAallocator.hpp.
|
inline |
Definition at line 155 of file CUDAallocator.hpp.
|
inline |
Definition at line 121 of file CUDAallocator.hpp.
|
inlinestatic |
Give std::allocator_traits something to call.
The default if this isn't present is to call p->~T() which we can't do on device memory.
Definition at line 152 of file CUDAallocator.hpp.