18 #include <rmm/detail/error.hpp>
19 #include <rmm/mr/device/device_memory_resource.hpp>
42 using failure_callback_t = std::function<bool(std::size_t,
void*)>;
85 template <
typename Upstream,
typename ExceptionType = rmm::out_of_memory>
101 failure_callback_t callback,
103 : upstream_{upstream}, callback_{std::move(callback)}, callback_arg_{callback_arg}
105 RMM_EXPECTS(
nullptr != upstream,
"Unexpected null upstream resource pointer.");
113 failure_callback_resource_adaptor& operator=(failure_callback_resource_adaptor&&) noexcept =
131 return upstream_->supports_streams();
141 return upstream_->supports_get_mem_info();
162 ret = upstream_->allocate(bytes, stream);
165 if (!callback_(bytes, callback_arg_)) {
throw; }
180 void do_deallocate(
void* ptr, std::size_t bytes, cuda_stream_view stream)
override
182 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);
217 failure_callback_t callback_;