20#ifndef CUDA_UNDERLYING_ALLOCATORS_HPP
21#define CUDA_UNDERLYING_ALLOCATORS_HPP
23#include <cuda_runtime.h>
40 cudaMallocHost(
reinterpret_cast<void **
>(&data), n *
sizeof(T));
41 if (error != cudaSuccess) {
44 "cuda_pinned_allocator failed due to cudaMallocHost failure : ") +
45 std::string(cudaGetErrorString(error));
46 throw std::runtime_error(msg);
51 cudaError_t error = cudaFreeHost(p);
52 if (error != cudaSuccess) {
55 "cuda_pinned_allocator failed due to cudaFreeHost failure : ") +
56 std::string(cudaGetErrorString(error));
57 throw std::runtime_error(msg);
62template <
class T,
class U>
67template <
class T,
class U>
81 cudaError_t error = cudaMalloc(&data, n *
sizeof(T));
82 if (error != cudaSuccess) {
85 "cuda_device_allocator failed due to cudaMalloc failure : ") +
86 std::string(cudaGetErrorString(error));
87 throw std::runtime_error(msg);
92 cudaError_t error = cudaFree(p);
93 if (error != cudaSuccess) {
96 "cuda_device_allocator failed due to cudaFree failure : ") +
97 std::string(cudaGetErrorString(error));
98 throw std::runtime_error(msg);
102template <
class T,
class U>
107template <
class T,
class U>
120 cudaError_t error = cudaMallocManaged(&data, n *
sizeof(T));
121 if (error != cudaSuccess) {
124 "cuda_managed_memory_allocator failed due to cudaMallocManaged failure : ") +
125 std::string(cudaGetErrorString(error));
126 throw std::runtime_error(msg);
131 cudaError_t error = cudaFree(p);
132 if (error != cudaSuccess) {
135 "cuda_managed_memory_allocator failed due to cudaFree failure : ") +
136 std::string(cudaGetErrorString(error));
137 throw std::runtime_error(msg);
141template <
class T,
class U>
146template <
class T,
class U>
Definition buffer_management.hpp:79
constexpr bool operator!=(recycle_allocator< T, Host_Allocator > const &, recycle_allocator< U, Host_Allocator > const &) noexcept
Definition buffer_management.hpp:855
constexpr bool operator==(recycle_allocator< T, Host_Allocator > const &, recycle_allocator< U, Host_Allocator > const &) noexcept
Definition buffer_management.hpp:846
CPPuddle namespace containing the memory recycling functionality.
Definition aligned_recycling_allocators.hpp:17
Underlying allocator for CUDA device memory.
Definition cuda_underlying_allocators.hpp:74
void deallocate(T *p, std::size_t n)
Definition cuda_underlying_allocators.hpp:91
cuda_device_allocator() noexcept=default
T value_type
Definition cuda_underlying_allocators.hpp:75
T * allocate(std::size_t n)
Definition cuda_underlying_allocators.hpp:79
Underlying allocator for CUDA managed memory.
Definition cuda_underlying_allocators.hpp:113
T value_type
Definition cuda_underlying_allocators.hpp:114
void deallocate(T *p, std::size_t n)
Definition cuda_underlying_allocators.hpp:130
cuda_managed_memory_allocator() noexcept=default
T * allocate(std::size_t n)
Definition cuda_underlying_allocators.hpp:118
Underlying host allocator for CUDA pinned memory.
Definition cuda_underlying_allocators.hpp:32
cuda_pinned_allocator() noexcept=default
T value_type
Definition cuda_underlying_allocators.hpp:33
T * allocate(std::size_t n)
Definition cuda_underlying_allocators.hpp:37
void deallocate(T *p, std::size_t n)
Definition cuda_underlying_allocators.hpp:50