QMCPACK
CUDAManagedAllocator< T > Struct Template Reference

allocator for CUDA unified memory More...

+ Collaboration diagram for CUDAManagedAllocator< T >:

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

 CUDAManagedAllocator ()=default
 
template<class U >
 CUDAManagedAllocator (const CUDAManagedAllocator< U > &)
 
T * allocate (std::size_t n)
 
void deallocate (T *p, std::size_t)
 

Detailed Description

template<typename T>
struct qmcplusplus::CUDAManagedAllocator< T >

allocator for CUDA unified memory

Template Parameters
Tdata type

Definition at line 41 of file CUDAallocator.hpp.


Class Documentation

◆ qmcplusplus::CUDAManagedAllocator::rebind

struct qmcplusplus::CUDAManagedAllocator::rebind

template<typename T>
template<class U>
struct qmcplusplus::CUDAManagedAllocator< T >::rebind< U >

Definition at line 54 of file CUDAallocator.hpp.

+ Collaboration diagram for CUDAManagedAllocator< T >::rebind< U >:
Class Members
typedef CUDAManagedAllocator< U > other

Member Typedef Documentation

◆ const_pointer

using const_pointer = const T*

Definition at line 46 of file CUDAallocator.hpp.

◆ pointer

using pointer = T*

Definition at line 45 of file CUDAallocator.hpp.

◆ size_type

using size_type = size_t

Definition at line 44 of file CUDAallocator.hpp.

◆ value_type

using value_type = T

Definition at line 43 of file CUDAallocator.hpp.

Constructor & Destructor Documentation

◆ CUDAManagedAllocator() [1/2]

CUDAManagedAllocator ( )
default

◆ CUDAManagedAllocator() [2/2]

CUDAManagedAllocator ( const CUDAManagedAllocator< U > &  )
inline

Definition at line 50 of file CUDAallocator.hpp.

51  {}

Member Function Documentation

◆ allocate()

T* allocate ( std::size_t  n)
inline

Definition at line 59 of file CUDAallocator.hpp.

References qmcplusplus::cudaErrorCheck(), cudaMallocManaged, and qmcplusplus::n.

60  {
61  void* pt;
62  cudaErrorCheck(cudaMallocManaged(&pt, n * sizeof(T)), "Allocation failed in CUDAManagedAllocator!");
63  if ((size_t(pt)) & (QMC_SIMD_ALIGNMENT - 1))
64  throw std::runtime_error("Unaligned memory allocated in CUDAManagedAllocator");
65  return static_cast<T*>(pt);
66  }
cudaErrorCheck(cudaMemcpyAsync(dev_lu.data(), lu.data(), sizeof(decltype(lu)::value_type) *lu.size(), cudaMemcpyHostToDevice, hstream), "cudaMemcpyAsync failed copying log_values to device")
#define cudaMallocManaged
Definition: cuda2hip.h:130

◆ deallocate()

void deallocate ( T *  p,
std::size_t   
)
inline

Definition at line 67 of file CUDAallocator.hpp.

References qmcplusplus::cudaErrorCheck(), and cudaFree.

67 { cudaErrorCheck(cudaFree(p), "Deallocation failed in CUDAManagedAllocator!"); }
cudaErrorCheck(cudaMemcpyAsync(dev_lu.data(), lu.data(), sizeof(decltype(lu)::value_type) *lu.size(), cudaMemcpyHostToDevice, hstream), "cudaMemcpyAsync failed copying log_values to device")
#define cudaFree
Definition: cuda2hip.h:99

The documentation for this struct was generated from the following file: