RMM
23.12
RAPIDS Memory Manager
|
Resource adaptor that maintains the lifetime of upstream resources. More...
#include <owning_wrapper.hpp>
Public Types | |
using | upstream_tuple = std::tuple< std::shared_ptr< Upstreams >... > |
Tuple of upstream memory resources. | |
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 |
A constant reference to the wrapped resource. More... | |
Resource & | wrapped () noexcept |
A reference to the wrapped resource. More... | |
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 |
true if the wrapped resource supports get_mem_info, false otherwise More... | |
Public Member Functions inherited from rmm::mr::device_memory_resource | |
device_memory_resource (device_memory_resource const &)=default | |
Default copy constructor. | |
device_memory_resource (device_memory_resource &&) noexcept=default | |
Default move constructor. | |
device_memory_resource & | operator= (device_memory_resource const &)=default |
Default copy assignment operator. More... | |
device_memory_resource & | operator= (device_memory_resource &&) noexcept=default |
Default move assignment operator. More... | |
void * | allocate (std::size_t bytes, cuda_stream_view stream=cuda_stream_view{}) |
Allocates memory of size at least bytes . More... | |
void | deallocate (void *ptr, 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... | |
void * | allocate (std::size_t bytes, std::size_t alignment) |
Allocates memory of size at least bytes . More... | |
void | deallocate (void *ptr, std::size_t bytes, std::size_t alignment) |
Deallocate memory pointed to by p . More... | |
void * | allocate_async (std::size_t bytes, std::size_t alignment, cuda_stream_view stream) |
Allocates memory of size at least bytes . More... | |
void * | allocate_async (std::size_t bytes, cuda_stream_view stream) |
Allocates memory of size at least bytes . More... | |
void | deallocate_async (void *ptr, std::size_t bytes, std::size_t alignment, cuda_stream_view stream) |
Deallocate memory pointed to by p . More... | |
void | deallocate_async (void *ptr, std::size_t bytes, cuda_stream_view stream) |
Deallocate memory pointed to by p . More... | |
bool | operator== (device_memory_resource const &other) const noexcept |
Comparison operator with another device_memory_resource. More... | |
bool | operator!= (device_memory_resource const &other) const noexcept |
Comparison operator with another device_memory_resource. 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... | |
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:
Resource | Type of the wrapped resource |
Upstreams | Template parameter pack of the types of the upstream resources used by Resource |
|
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:
Args | Template parameter pack to forward to the wrapped resource's constructor |
upstreams | Tuple of std::shared_ptr s to the upstreams used by the wrapped resource, in the same order as expected by Resource s constructor. |
args | Function parameter pack of arguments to forward to the wrapped resource's constructor |
|
inlineoverridevirtualnoexcept |
true if the wrapped resource supports get_mem_info, false otherwise
Implements rmm::mr::device_memory_resource.
|
inlineoverridevirtualnoexcept |
Query whether the resource supports use of non-null CUDA streams for allocation/deallocation.
Implements rmm::mr::device_memory_resource.
|
inlinenoexcept |
A constant reference to the wrapped resource.
|
inlinenoexcept |
A reference to the wrapped resource.