Public Types | Public Member Functions | List of all members
rmm::mr::owning_wrapper< Resource, Upstreams > Class Template Reference

Resource adaptor that maintains the lifetime of upstream resources. More...

#include <owning_wrapper.hpp>

Inheritance diagram for rmm::mr::owning_wrapper< Resource, Upstreams >:
Inheritance graph
[legend]
Collaboration diagram for rmm::mr::owning_wrapper< Resource, Upstreams >:
Collaboration graph
[legend]

Public Types

using upstream_tuple = std::tuple< std::shared_ptr< Upstreams >... >
 

Public Member Functions

template<typename... Args>
 owning_wrapper (upstream_tuple upstreams, Args &&... args)
 Constructs the wrapped resource using the provided upstreams and any additional arguments forwarded to the wrapped resources constructor. More...
 
Resource const & wrapped () const noexcept
 Returns a constant reference to the wrapped resource.
 
Resource & wrapped () noexcept
 Returns reference to the wrapped resource.
 
bool supports_streams () const noexcept override
 Query whether the resource supports use of non-null CUDA streams for allocation/deallocation. More...
 
bool supports_get_mem_info () const noexcept override
 Query whether the resource supports the get_mem_info API. More...
 
- Public Member Functions inherited from rmm::mr::device_memory_resource
void * allocate (std::size_t bytes, cuda_stream_view stream=cuda_stream_view{})
 Allocates memory of size at least bytes. More...
 
void deallocate (void *p, std::size_t bytes, cuda_stream_view stream=cuda_stream_view{})
 Deallocate memory pointed to by p. More...
 
bool is_equal (device_memory_resource const &other) const noexcept
 Compare this resource to another. More...
 
std::pair< std::size_t, std::size_t > get_mem_info (cuda_stream_view stream) const
 Queries the amount of free and total memory for the resource. More...
 

Detailed Description

template<typename Resource, typename... Upstreams>
class rmm::mr::owning_wrapper< Resource, Upstreams >

Resource adaptor that maintains the lifetime of upstream resources.

Many device_memory_resource derived types allocate memory from another "upstream" resource. E.g., pool_memory_resource allocates its pool from an upstream resource. Typically, a resource does not own its upstream, and therefore it is the user's responsibility to maintain the lifetime of the upstream resource. This can be inconvenient and error prone, especially for resources with complex upstreams that may themselves also have an upstream.

owning_wrapper simplifies lifetime management of a resource, wrapped, by taking shared ownership of all upstream resources via a std::shared_ptr.

For convenience, it is recommended to use the make_owning_wrapper factory instead of constructing an owning_wrapper directly.

Example:

auto cuda = std::make_shared<rmm::mr::cuda_memory_resource>();
auto pool = rmm::mr::make_owning_wrapper<rmm::mr::pool_memory_resource>(cuda,initial_pool_size,
max_pool_size);
// The `cuda` resource will be kept alive for the lifetime of `pool` and automatically be
// destroyed after `pool` is destroyed
Template Parameters
ResourceType of the wrapped resource
UpstreamsTemplate parameter pack of the types of the upstream resources used by Resource

Constructor & Destructor Documentation

◆ owning_wrapper()

template<typename Resource , typename... Upstreams>
template<typename... Args>
rmm::mr::owning_wrapper< Resource, Upstreams >::owning_wrapper ( upstream_tuple  upstreams,
Args &&...  args 
)
inline

Constructs the wrapped resource using the provided upstreams and any additional arguments forwarded to the wrapped resources constructor.

Resource is required to have a constructor whose first argument(s) are raw pointers to its upstream resources in the same order as upstreams, followed by any additional arguments in the same order as args.

Example:

template <typename Upstream1, typename Upstream2>
class example_resource{
example_resource(Upstream1 * u1, Upstream2 * u2, int n, float f);
};
using example = example_resource<cuda,cuda>;
auto cuda_mr = std::make_shared<cuda>();
// Constructs an `example_resource` wrapped by an `owning_wrapper` taking shared ownership of
//`cuda_mr` and using it as both of `example_resource`s upstream resources. Forwards the
// arguments `42` and `3.14` to the additional `n` and `f` arguments of `example_resources`
// constructor.
wrapped_example w{std::make_tuple(cuda_mr,cuda_mr), 42, 3.14};
Template Parameters
ArgsTemplate parameter pack to forward to the wrapped resource's constructor
Parameters
upstreamsTuple of std::shared_ptrs to the upstreams used by the wrapped resource, in the same order as expected by Resources constructor.
argsFunction parameter pack of arguments to forward to the wrapped resource's constructor

Member Function Documentation

◆ supports_get_mem_info()

template<typename Resource , typename... Upstreams>
bool rmm::mr::owning_wrapper< Resource, Upstreams >::supports_get_mem_info ( ) const
inlineoverridevirtualnoexcept

Query whether the resource supports the get_mem_info API.

Returns
true if the upstream resource supports get_mem_info, false otherwise.

Implements rmm::mr::device_memory_resource.

◆ supports_streams()

template<typename Resource , typename... Upstreams>
bool rmm::mr::owning_wrapper< Resource, Upstreams >::supports_streams ( ) const
inlineoverridevirtualnoexcept

Query whether the resource supports use of non-null CUDA streams for allocation/deallocation.

Returns
bool true if the resource supports non-null CUDA streams.

Implements rmm::mr::device_memory_resource.


The documentation for this class was generated from the following file:
rmm::mr::owning_wrapper
Resource adaptor that maintains the lifetime of upstream resources.
Definition: owning_wrapper.hpp:72
rmm::mr::cuda_memory_resource
device_memory_resource derived class that uses cudaMalloc/Free for allocation/deallocation.
Definition: cuda_memory_resource.hpp:29