7 #include <rmm/detail/error.hpp>
8 #include <rmm/detail/export.hpp>
17 namespace RMM_NAMESPACE {
83 template <
typename Upstream,
typename ExceptionType = rmm::out_of_memory>
99 : upstream_{upstream}, callback_{std::move(callback)}, callback_arg_{callback_arg}
117 callback_{std::move(callback)},
118 callback_arg_{callback_arg}
157 ret = get_upstream_resource().
allocate(stream, bytes);
159 }
catch (exception_type
const& e) {
160 if (!callback_(bytes, callback_arg_)) {
throw; }
173 void do_deallocate(
void* ptr, std::size_t bytes, cuda_stream_view stream) noexcept
override
175 get_upstream_resource().deallocate(stream, ptr, bytes);
185 [[nodiscard]]
bool do_is_equal(device_memory_resource
const& other)
const noexcept
override
187 if (
this == &other) {
return true; }
188 auto cast =
dynamic_cast<failure_callback_resource_adaptor<Upstream> const*
>(&other);
189 if (cast ==
nullptr) {
return false; }
190 return get_upstream_resource() == cast->get_upstream_resource();
Strongly-typed non-owning wrapper for CUDA streams with default constructor.
Definition: cuda_stream_view.hpp:28
Base class for all librmm device memory allocation.
Definition: device_memory_resource.hpp:83
void * allocate(cuda_stream_view stream, std::size_t bytes, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT)
Allocates memory of size at least bytes on the specified stream.
Definition: device_memory_resource.hpp:322
A device memory resource that calls a callback function when allocations throw a specified exception ...
Definition: failure_callback_resource_adaptor.hpp:84
failure_callback_resource_adaptor(device_async_resource_ref 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:96
ExceptionType exception_type
The type of exception this object catches/throws.
Definition: failure_callback_resource_adaptor.hpp:86
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:113
failure_callback_resource_adaptor(failure_callback_resource_adaptor &&) noexcept=default
Default move constructor.
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:40
device_async_resource_ref to_device_async_resource_ref_checked(Resource *res)
Convert pointer to memory resource into device_async_resource_ref, checking for nullptr
Definition: resource_ref.hpp:72
detail::cccl_async_resource_ref< cuda::mr::resource_ref< cuda::mr::device_accessible > > device_async_resource_ref
Alias for a cuda::mr::async_resource_ref with the property cuda::mr::device_accessible.
Definition: resource_ref.hpp:32
Management of per-device device_memory_resources.