6 #ifndef CUDA_UNDERLYING_ALLOCATORS_HPP
7 #define CUDA_UNDERLYING_ALLOCATORS_HPP
9 #include <cuda_runtime.h>
14 namespace memory_recycling {
25 cudaMallocHost(
reinterpret_cast<void **
>(&data), n *
sizeof(T));
26 if (error != cudaSuccess) {
29 "cuda_pinned_allocator failed due to cudaMallocHost failure : ") +
30 std::string(cudaGetErrorString(error));
31 throw std::runtime_error(msg);
36 cudaError_t error = cudaFreeHost(p);
37 if (error != cudaSuccess) {
40 "cuda_pinned_allocator failed due to cudaFreeHost failure : ") +
41 std::string(cudaGetErrorString(error));
42 throw std::runtime_error(msg);
47 template <
class T,
class U>
52 template <
class T,
class U>
66 cudaError_t error = cudaMalloc(&data, n *
sizeof(T));
67 if (error != cudaSuccess) {
70 "cuda_device_allocator failed due to cudaMalloc failure : ") +
71 std::string(cudaGetErrorString(error));
72 throw std::runtime_error(msg);
77 cudaError_t error = cudaFree(p);
78 if (error != cudaSuccess) {
81 "cuda_device_allocator failed due to cudaFree failure : ") +
82 std::string(cudaGetErrorString(error));
83 throw std::runtime_error(msg);
87 template <
class T,
class U>
92 template <
class T,
class U>
constexpr bool operator!=(recycle_allocator< T, Host_Allocator > const &, recycle_allocator< U, Host_Allocator > const &) noexcept
Definition: buffer_management.hpp:830
constexpr bool operator==(recycle_allocator< T, Host_Allocator > const &, recycle_allocator< U, Host_Allocator > const &) noexcept
Definition: buffer_management.hpp:821
Definition: config.hpp:31
Underlying allocator for CUDA device memory.
Definition: cuda_underlying_allocators.hpp:59
void deallocate(T *p, std::size_t n)
Definition: cuda_underlying_allocators.hpp:76
cuda_device_allocator() noexcept=default
T value_type
Definition: cuda_underlying_allocators.hpp:60
T * allocate(std::size_t n)
Definition: cuda_underlying_allocators.hpp:64
Underlying host allocator for CUDA pinned memory.
Definition: cuda_underlying_allocators.hpp:17
cuda_pinned_allocator() noexcept=default
T * allocate(std::size_t n)
Definition: cuda_underlying_allocators.hpp:22
T value_type
Definition: cuda_underlying_allocators.hpp:18
void deallocate(T *p, std::size_t n)
Definition: cuda_underlying_allocators.hpp:35