7 #include <rmm/detail/export.hpp>
13 namespace RMM_NAMESPACE {
31 template <
typename Resource,
typename UpstreamTuple, std::size_t... Indices,
typename... Args>
33 std::index_sequence<Indices...>,
36 return std::make_unique<Resource>(std::get<Indices>(upstreams).get()...,
37 std::forward<Args>(args)...);
52 template <
typename Resource,
typename... Upstreams,
typename... Args>
53 auto make_resource(std::tuple<std::shared_ptr<Upstreams>...>
const& upstreams, Args&&... args)
55 return make_resource_impl<Resource>(
56 upstreams, std::index_sequence_for<Upstreams...>{}, std::forward<Args>(args)...);
93 template <
typename Resource,
typename... Upstreams>
97 std::tuple<std::shared_ptr<Upstreams>...>;
132 template <
typename... Args>
134 : upstreams_{std::move(upstreams)},
135 wrapped_{detail::make_resource<Resource>(upstreams_, std::forward<Args>(args)...)}
142 [[nodiscard]] Resource
const&
wrapped() const noexcept {
return *wrapped_; }
147 [[nodiscard]] Resource&
wrapped() noexcept {
return *wrapped_; }
162 return wrapped().allocate(stream, bytes);
174 void do_deallocate(
void* ptr, std::size_t bytes,
cuda_stream_view stream) noexcept
override
176 wrapped().deallocate(stream, ptr, bytes);
188 [[nodiscard]]
bool do_is_equal(device_memory_resource
const& other)
const noexcept
override
190 if (
this == &other) {
return true; }
191 auto casted =
dynamic_cast<owning_wrapper<Resource, Upstreams...
> const*>(&other);
192 if (
nullptr != casted) {
return wrapped().is_equal(casted->wrapped()); }
193 return wrapped().is_equal(other);
196 upstream_tuple upstreams_;
197 std::unique_ptr<Resource> wrapped_;
232 template <
template <
typename...>
class Resource,
typename... Upstreams,
typename... Args>
235 return std::make_shared<
owning_wrapper<Resource<Upstreams...>, Upstreams...>>(
236 std::move(upstreams), std::forward<Args>(args)...);
254 template <
template <
typename>
class Resource,
typename Upstream,
typename... Args>
257 return make_owning_wrapper<Resource>(std::make_tuple(std::move(upstream)),
258 std::forward<Args>(args)...);
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
Resource adaptor that maintains the lifetime of upstream resources.
Definition: owning_wrapper.hpp:94
Resource const & wrapped() const noexcept
A constant reference to the wrapped resource.
Definition: owning_wrapper.hpp:142
std::tuple< std::shared_ptr< Upstreams >... > upstream_tuple
Tuple of upstream memory resources.
Definition: owning_wrapper.hpp:97
Resource & wrapped() noexcept
A reference to the wrapped resource.
Definition: owning_wrapper.hpp:147
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:133
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:255
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:53
auto make_resource_impl(UpstreamTuple const &upstreams, std::index_sequence< Indices... >, Args &&... args)
Converts a tuple into a parameter pack.
Definition: owning_wrapper.hpp:32