18 #include <rmm/detail/export.hpp>
26 namespace RMM_NAMESPACE {
44 template <
typename Resource,
typename UpstreamTuple, std::size_t... Indices,
typename... Args>
46 std::index_sequence<Indices...>,
49 return std::make_unique<Resource>(std::get<Indices>(upstreams).get()...,
50 std::forward<Args>(args)...);
65 template <
typename Resource,
typename... Upstreams,
typename... Args>
66 auto make_resource(std::tuple<std::shared_ptr<Upstreams>...>
const& upstreams, Args&&... args)
68 return make_resource_impl<Resource>(
69 upstreams, std::index_sequence_for<Upstreams...>{}, std::forward<Args>(args)...);
106 template <
typename Resource,
typename... Upstreams>
110 std::tuple<std::shared_ptr<Upstreams>...>;
145 template <
typename... Args>
147 : upstreams_{std::move(upstreams)},
148 wrapped_{detail::make_resource<Resource>(upstreams_, std::forward<Args>(args)...)}
155 [[nodiscard]] Resource
const&
wrapped() const noexcept {
return *wrapped_; }
160 [[nodiscard]] Resource&
wrapped() noexcept {
return *wrapped_; }
175 return wrapped().allocate(bytes, stream);
187 void do_deallocate(
void* ptr, std::size_t bytes,
cuda_stream_view stream)
override
189 wrapped().deallocate(ptr, bytes, stream);
201 [[nodiscard]]
bool do_is_equal(device_memory_resource
const& other)
const noexcept
override
203 if (
this == &other) {
return true; }
204 auto casted =
dynamic_cast<owning_wrapper<Resource, Upstreams...
> const*>(&other);
205 if (
nullptr != casted) {
return wrapped().is_equal(casted->wrapped()); }
206 return wrapped().is_equal(other);
209 upstream_tuple upstreams_;
210 std::unique_ptr<Resource> wrapped_;
245 template <
template <
typename...>
class Resource,
typename... Upstreams,
typename... Args>
248 return std::make_shared<
owning_wrapper<Resource<Upstreams...>, Upstreams...>>(
249 std::move(upstreams), std::forward<Args>(args)...);
267 template <
template <
typename>
class Resource,
typename Upstream,
typename... Args>
270 return make_owning_wrapper<Resource>(std::make_tuple(std::move(upstream)),
271 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:94
Resource adaptor that maintains the lifetime of upstream resources.
Definition: owning_wrapper.hpp:107
Resource const & wrapped() const noexcept
A constant reference to the wrapped resource.
Definition: owning_wrapper.hpp:155
std::tuple< std::shared_ptr< Upstreams >... > upstream_tuple
Tuple of upstream memory resources.
Definition: owning_wrapper.hpp:110
Resource & wrapped() noexcept
A reference to the wrapped resource.
Definition: owning_wrapper.hpp:160
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:146
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:268
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:66
auto make_resource_impl(UpstreamTuple const &upstreams, std::index_sequence< Indices... >, Args &&... args)
Converts a tuple into a parameter pack.
Definition: owning_wrapper.hpp:45