18 #include <rmm/detail/aligned.hpp>
22 #include <cuda_runtime_api.h>
43 template <
typename Upstream>
57 : upstream_mr_{[upstream_resource]() {
58 RMM_EXPECTS(
nullptr != upstream_resource,
"Unexpected null upstream pointer.");
59 return upstream_resource;
77 int8_t min_size_exponent,
78 int8_t max_size_exponent)
79 : upstream_mr_{[upstream_resource]() {
80 RMM_EXPECTS(
nullptr != upstream_resource,
"Unexpected null upstream pointer.");
81 return upstream_resource;
84 for (
auto i = min_size_exponent; i <= max_size_exponent; i++) {
121 [[nodiscard]] Upstream*
get_upstream() const noexcept {
return upstream_mr_; }
142 rmm::detail::align_up(allocation_size, rmm::detail::CUDA_ALLOCATION_ALIGNMENT);
144 if (
nullptr != bin_resource) {
145 resource_bins_.insert({allocation_size, bin_resource});
146 }
else if (resource_bins_.count(allocation_size) == 0) {
148 owned_bin_resources_.push_back(
150 resource_bins_.insert({allocation_size, owned_bin_resources_.back().get()});
165 auto iter = resource_bins_.lower_bound(bytes);
166 return (iter != resource_bins_.cend()) ? iter->second
181 if (bytes <= 0) {
return nullptr; }
182 return get_resource(bytes)->
allocate(bytes, stream);
195 void do_deallocate(
void* ptr, std::size_t bytes, cuda_stream_view stream)
override
197 auto res = get_resource(bytes);
198 if (res !=
nullptr) { res->deallocate(ptr, bytes, stream); }
209 [[nodiscard]] std::pair<std::size_t, std::size_t> do_get_mem_info(
210 [[maybe_unused]] cuda_stream_view stream)
const override
212 return std::make_pair(0, 0);
215 Upstream* upstream_mr_;
217 std::vector<std::unique_ptr<fixed_size_memory_resource<Upstream>>> owned_bin_resources_;
219 std::map<std::size_t, device_memory_resource*> resource_bins_;
Strongly-typed non-owning wrapper for CUDA streams with default constructor.
Definition: cuda_stream_view.hpp:41
Allocates memory from upstream resources associated with bin sizes.
Definition: binning_memory_resource.hpp:44
binning_memory_resource(Upstream *upstream_resource)
Construct a new binning memory resource object.
Definition: binning_memory_resource.hpp:56
void add_bin(std::size_t allocation_size, device_memory_resource *bin_resource=nullptr)
Add a bin allocator to this resource.
Definition: binning_memory_resource.hpp:139
bool supports_get_mem_info() const noexcept override
Query whether the resource supports the get_mem_info API.
Definition: binning_memory_resource.hpp:114
~binning_memory_resource() override=default
Destroy the binning_memory_resource and free all memory allocated from the upstream resource.
Upstream * get_upstream() const noexcept
Get the upstream memory_resource object.
Definition: binning_memory_resource.hpp:121
binning_memory_resource(Upstream *upstream_resource, int8_t min_size_exponent, int8_t max_size_exponent)
Construct a new binning memory resource object with a range of initial bins.
Definition: binning_memory_resource.hpp:76
bool supports_streams() const noexcept override
Query whether the resource supports use of non-null streams for allocation/deallocation.
Definition: binning_memory_resource.hpp:107
Base class for all libcudf device memory allocation.
Definition: device_memory_resource.hpp:89
void * allocate(std::size_t bytes, cuda_stream_view stream=cuda_stream_view{})
Allocates memory of size at least bytes.
Definition: device_memory_resource.hpp:116
A device_memory_resource which allocates memory blocks of a single fixed size.
Definition: fixed_size_memory_resource.hpp:53