6 #include <cuda_runtime.h> 17 if (n > std::size_t(-1) /
sizeof(T))
18 throw std::bad_alloc();
20 cudaError_t err = cudaHostAlloc(&p, n *
sizeof(T), cudaHostAllocMapped | cudaHostAllocPortable);
21 if (err != cudaSuccess)
23 throw std::bad_alloc();
27 void deallocate(T *p, std::size_t) noexcept { cudaFreeHost(p); }
29 template <
class T,
class U>
31 template <
class T,
class U>
bool operator!=(const CUDAZeroCopyAllocator< T > &, const CUDAZeroCopyAllocator< U > &)
Definition: cuda_zero_copy.hpp:32
T * allocate(std::size_t n)
Definition: cuda_zero_copy.hpp:15
T value_type
Definition: cuda_zero_copy.hpp:11
bool operator==(const CUDAZeroCopyAllocator< T > &, const CUDAZeroCopyAllocator< U > &)
Definition: cuda_zero_copy.hpp:30
CUDAZeroCopyAllocator()=default
Definition: cuda_zero_copy.hpp:9
void deallocate(T *p, std::size_t) noexcept
Definition: cuda_zero_copy.hpp:27
constexpr CUDAZeroCopyAllocator(const CUDAZeroCopyAllocator< U > &) noexcept
Definition: cuda_zero_copy.hpp:14