42 template <
typename Resource,
typename UpstreamTuple, std::size_t... Indices,
typename... Args>
44 std::index_sequence<Indices...>,
47 return std::make_unique<Resource>(std::get<Indices>(upstreams).get()...,
48 std::forward<Args>(args)...);
63 template <
typename Resource,
typename... Upstreams,
typename... Args>
64 auto make_resource(std::tuple<std::shared_ptr<Upstreams>...>
const& upstreams, Args&&... args)
66 return make_resource_impl<Resource>(
67 upstreams, std::index_sequence_for<Upstreams...>{}, std::forward<Args>(args)...);
104 template <
typename Resource,
typename... Upstreams>
108 std::tuple<std::shared_ptr<Upstreams>...>;
143 template <
typename... Args>
145 : upstreams_{std::move(upstreams)},
146 wrapped_{detail::make_resource<Resource>(upstreams_, std::forward<Args>(args)...)}
153 [[nodiscard]] Resource
const&
wrapped() const noexcept {
return *wrapped_; }
158 [[nodiscard]] Resource&
wrapped() noexcept {
return *wrapped_; }
165 return wrapped().supports_streams();
173 return wrapped().supports_get_mem_info();
189 return wrapped().allocate(bytes, stream);
201 void do_deallocate(
void* ptr, std::size_t bytes,
cuda_stream_view stream)
override
203 wrapped().deallocate(ptr, bytes, stream);
215 [[nodiscard]]
bool do_is_equal(device_memory_resource
const& other)
const noexcept
override
217 if (
this == &other) {
return true; }
218 auto casted =
dynamic_cast<owning_wrapper<Resource, Upstreams...
> const*>(&other);
219 if (
nullptr != casted) {
return wrapped().is_equal(casted->wrapped()); }
220 return wrapped().is_equal(other);
231 [[nodiscard]] std::pair<std::size_t, std::size_t> do_get_mem_info(
232 cuda_stream_view stream)
const override
234 return wrapped().get_mem_info(stream);
238 std::unique_ptr<Resource> wrapped_;
273 template <
template <
typename...>
class Resource,
typename... Upstreams,
typename... Args>
276 return std::make_shared<
owning_wrapper<Resource<Upstreams...>, Upstreams...>>(
277 std::move(upstreams), std::forward<Args>(args)...);
295 template <
template <
typename>
class Resource,
typename Upstream,
typename... Args>
298 return make_owning_wrapper<Resource>(std::make_tuple(std::move(upstream)),
299 std::forward<Args>(args)...);
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
Resource adaptor that maintains the lifetime of upstream resources.
Definition: owning_wrapper.hpp:105
Resource const & wrapped() const noexcept
A constant reference to the wrapped resource.
Definition: owning_wrapper.hpp:153
std::tuple< std::shared_ptr< Upstreams >... > upstream_tuple
Tuple of upstream memory resources.
Definition: owning_wrapper.hpp:108
bool supports_streams() const noexcept override
Query whether the resource supports use of non-null CUDA streams for allocation/deallocation.
Definition: owning_wrapper.hpp:163
bool supports_get_mem_info() const noexcept override
true if the wrapped resource supports get_mem_info, false otherwise
Definition: owning_wrapper.hpp:171
Resource & wrapped() noexcept
A reference to the wrapped resource.
Definition: owning_wrapper.hpp:158
owning_wrapper(upstream_tuple upstreams, Args &&... args)
Constructs the wrapped resource using the provided upstreams and any additional arguments forwarded t...
Definition: owning_wrapper.hpp:144
auto make_owning_wrapper(std::shared_ptr< Upstream > upstream, Args &&... args)
Additional convenience factory for owning_wrapper when Resource has only a single upstream resource.
Definition: owning_wrapper.hpp:296
auto make_resource(std::tuple< std::shared_ptr< Upstreams >... > const &upstreams, Args &&... args)
Create a std::unique_ptr to a Resource with the given upstreams and arguments.
Definition: owning_wrapper.hpp:64
auto make_resource_impl(UpstreamTuple const &upstreams, std::index_sequence< Indices... >, Args &&... args)
Converts a tuple into a parameter pack.
Definition: owning_wrapper.hpp:43