6#ifndef HIP_UNDERLYING_ALLOCATORS_HPP
7#define HIP_UNDERLYING_ALLOCATORS_HPP
9#include <hip/hip_runtime.h>
14namespace memory_recycling {
31 hipHostMalloc(
reinterpret_cast<void **
>(&data), n *
sizeof(T));
32 if (error != hipSuccess) {
35 "hip_pinned_allocator failed due to hipMallocHost failure : ") +
36 std::string(hipGetErrorString(error));
37 throw std::runtime_error(msg);
42 hipError_t error = hipHostFree(p);
43 if (error != hipSuccess) {
46 "hip_pinned_allocator failed due to hipFreeHost failure : ") +
47 std::string(hipGetErrorString(error));
48 throw std::runtime_error(msg);
52template <
class T,
class U>
57template <
class T,
class U>
71 hipError_t error = hipMalloc(&data, n *
sizeof(T));
72 if (error != hipSuccess) {
75 "hip_device_allocator failed due to hipMalloc failure : ") +
76 std::string(hipGetErrorString(error));
77 throw std::runtime_error(msg);
82 hipError_t error = hipFree(p);
83 if (error != hipSuccess) {
86 "hip_device_allocator failed due to hipFree failure : ") +
87 std::string(hipGetErrorString(error));
88 throw std::runtime_error(msg);
92template <
class T,
class U>
97template <
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
Underlying allocator for HIP device memory.
Definition hip_underlying_allocators.hpp:64
void deallocate(T *p, std::size_t n)
Definition hip_underlying_allocators.hpp:81
hip_device_allocator() noexcept=default
T value_type
Definition hip_underlying_allocators.hpp:65
T * allocate(std::size_t n)
Definition hip_underlying_allocators.hpp:69
Underlying host allocator for HIP pinned memory.
Definition hip_underlying_allocators.hpp:17
T value_type
Definition hip_underlying_allocators.hpp:18
void deallocate(T *p, std::size_t n)
Definition hip_underlying_allocators.hpp:41
T * allocate(std::size_t n)
Definition hip_underlying_allocators.hpp:22
hip_pinned_allocator() noexcept=default