18 #include <rmm/detail/error.hpp>
90 template <
typename Upstream,
typename ExceptionType = rmm::out_of_memory>
108 : upstream_{upstream}, callback_{std::move(callback)}, callback_arg_{callback_arg}
110 RMM_EXPECTS(
nullptr != upstream,
"Unexpected null upstream resource pointer.");
135 return upstream_->supports_streams();
145 return upstream_->supports_get_mem_info();
166 ret = upstream_->allocate(bytes, stream);
169 if (!callback_(bytes, callback_arg_)) {
throw; }
182 void do_deallocate(
void* ptr, std::size_t bytes, cuda_stream_view stream)
override
184 upstream_->deallocate(ptr, bytes, stream);
194 [[nodiscard]]
bool do_is_equal(device_memory_resource
const& other)
const noexcept
override
196 if (
this == &other) {
return true; }
197 auto cast =
dynamic_cast<failure_callback_resource_adaptor<Upstream> const*
>(&other);
198 return cast !=
nullptr ? upstream_->is_equal(*cast->get_upstream())
199 : upstream_->is_equal(other);
210 [[nodiscard]] std::pair<std::size_t, std::size_t> do_get_mem_info(
211 cuda_stream_view stream)
const override
213 return upstream_->get_mem_info(stream);
Strongly-typed non-owning wrapper for CUDA streams with default constructor.
Definition: cuda_stream_view.hpp:41
Base class for all libcudf device memory allocation.
Definition: device_memory_resource.hpp:89
A device memory resource that calls a callback function when allocations throw a specified exception ...
Definition: failure_callback_resource_adaptor.hpp:91
Upstream * get_upstream() const noexcept
Pointer to the upstream resource.
Definition: failure_callback_resource_adaptor.hpp:125
ExceptionType exception_type
The type of exception this object catches/throws.
Definition: failure_callback_resource_adaptor.hpp:93
failure_callback_resource_adaptor(Upstream *upstream, failure_callback_t callback, void *callback_arg)
Construct a new failure_callback_resource_adaptor using upstream to satisfy allocation requests.
Definition: failure_callback_resource_adaptor.hpp:105
bool supports_get_mem_info() const noexcept override
Query whether the resource supports the get_mem_info API.
Definition: failure_callback_resource_adaptor.hpp:143
failure_callback_resource_adaptor(failure_callback_resource_adaptor &&) noexcept=default
Default move constructor.
bool supports_streams() const noexcept override
Checks whether the upstream resource supports streams.
Definition: failure_callback_resource_adaptor.hpp:133
std::function< bool(std::size_t, void *)> failure_callback_t
Callback function type used by failure_callback_resource_adaptor.
Definition: failure_callback_resource_adaptor.hpp:47