20 #include <rmm/detail/export.hpp>
28 namespace RMM_NAMESPACE {
76 void* do_allocate(std::size_t bytes, [[maybe_unused]]
cuda_stream_view stream)
override
81 auto const allocatable = free > headroom_ ? free - headroom_ : 0UL;
82 auto const gpu_portion =
84 auto const cpu_portion = bytes - gpu_portion;
86 if (gpu_portion != 0) {
87 #if defined(CUDART_VERSION) && CUDART_VERSION >= 13000
90 cudaMemAdvise(pointer, gpu_portion, cudaMemAdviseSetPreferredLocation, location));
92 RMM_CUDA_TRY(cudaMemAdvise(pointer,
94 cudaMemAdviseSetPreferredLocation,
98 if (cpu_portion != 0) {
99 #if defined(CUDART_VERSION) && CUDART_VERSION >= 13000
100 cudaMemLocation location{cudaMemLocationTypeHost, 0};
101 RMM_CUDA_TRY(cudaMemAdvise(
static_cast<char*
>(pointer) + gpu_portion,
103 cudaMemAdviseSetPreferredLocation,
106 RMM_CUDA_TRY(cudaMemAdvise(
static_cast<char*
>(pointer) + gpu_portion,
108 cudaMemAdviseSetPreferredLocation,
125 void do_deallocate(
void* ptr,
126 [[maybe_unused]] std::size_t bytes,
127 [[maybe_unused]] cuda_stream_view stream)
override
139 [[nodiscard]]
bool do_is_equal(device_memory_resource
const& other)
const noexcept
override
141 if (
this == &other) {
return true; }
142 auto cast =
dynamic_cast<sam_headroom_memory_resource const*
>(&other);
143 if (cast ==
nullptr) {
return false; }
144 return headroom_ == cast->headroom_;
148 system_memory_resource system_mr_;
150 std::size_t headroom_;
Strongly-typed non-owning wrapper for CUDA streams with default constructor.
Definition: cuda_stream_view.hpp:39
Base class for all librmm device memory allocation.
Definition: device_memory_resource.hpp:92
void * allocate_async(std::size_t bytes, std::size_t alignment, cuda_stream_view stream)
Allocates memory of size at least bytes.
Definition: device_memory_resource.hpp:215
Resource that uses system memory resource to allocate memory with a headroom.
Definition: sam_headroom_memory_resource.hpp:48
sam_headroom_memory_resource(std::size_t headroom)
Construct a headroom memory resource.
Definition: sam_headroom_memory_resource.hpp:55
std::pair< std::size_t, std::size_t > available_device_memory()
Returns the available and total device memory in bytes for the current device.
cuda_device_id get_current_cuda_device()
Returns a cuda_device_id for the current device.
static constexpr std::size_t CUDA_ALLOCATION_ALIGNMENT
Default alignment used for CUDA memory allocation.
Definition: aligned.hpp:43
std::size_t align_down(std::size_t value, std::size_t alignment) noexcept
Align down to the nearest multiple of specified power of 2.
constexpr value_type value() const noexcept
The wrapped integer value.
Definition: cuda_device.hpp:54