Implementation class for RmmResourceAdaptor. More...
#include <rmm_resource_adaptor_impl.hpp>
Public Member Functions | |
| RmmResourceAdaptorImpl (PrimaryMR primary_mr, std::optional< FallbackMR > fallback_mr=std::nullopt) | |
| Construct with a primary and optional fallback memory resource. More... | |
| template<typename... Args> | |
| RmmResourceAdaptorImpl (std::in_place_t, Args &&... args) | |
| Construct the primary resource in-place from forwarded arguments. More... | |
| RmmResourceAdaptorImpl (RmmResourceAdaptorImpl const &)=delete | |
| RmmResourceAdaptorImpl (RmmResourceAdaptorImpl &&)=delete | |
| RmmResourceAdaptorImpl & | operator= (RmmResourceAdaptorImpl const &)=delete |
| RmmResourceAdaptorImpl & | operator= (RmmResourceAdaptorImpl &&)=delete |
| bool | operator== (RmmResourceAdaptorImpl const &other) const noexcept |
| Equality comparison. More... | |
| PrimaryMR const & | get_upstream_resource () const noexcept |
| Returns a reference to the primary upstream resource. More... | |
| std::optional< FallbackMR > const & | get_fallback_resource () const noexcept |
| Returns a const reference to the optional fallback resource. More... | |
| ScopedMemoryRecord | get_main_record () const |
| Returns a copy of the main memory record. More... | |
| std::int64_t | current_allocated () const noexcept |
| Get the total current allocated memory from both primary and fallback. More... | |
| void | begin_scoped_memory_record () |
| Begin recording a new scoped memory usage record for the current thread. More... | |
| ScopedMemoryRecord | end_scoped_memory_record () |
| End the current scoped memory record and return it. More... | |
| void * | allocate (cuda::stream_ref stream, std::size_t bytes, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT) |
| Allocate memory asynchronously on the given stream. More... | |
| void | deallocate (cuda::stream_ref stream, void *ptr, std::size_t bytes, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept |
| Deallocate memory asynchronously on the given stream. More... | |
| void * | allocate_sync (std::size_t bytes, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT) |
| Allocate memory synchronously. More... | |
| void | deallocate_sync (void *ptr, std::size_t bytes, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept |
| Deallocate memory synchronously. More... | |
Friends | |
| void | get_property (RmmResourceAdaptorImpl const &, cuda::mr::device_accessible) noexcept |
| Tag this resource as device-accessible for the CCCL concept. | |
Implementation class for RmmResourceAdaptor.
Holds all mutable state for memory tracking and fallback allocation. This class satisfies the CCCL cuda::mr::resource concept and is held by RmmResourceAdaptor via cuda::mr::shared_resource for reference-counted ownership.
| PrimaryMR | The type of the primary memory resource. Use a concrete resource type (e.g. cuda::pinned_memory_pool) to store the resource directly inside the shared control block, avoiding an extra heap allocation. |
| FallbackMR | The type of the optional fallback memory resource, used when the primary resource throws rmm::out_of_memory. Defaults to cuda::mr::any_resource<cuda::mr::device_accessible> for type-erased use. |
Definition at line 52 of file rmm_resource_adaptor_impl.hpp.
|
inline |
Construct with a primary and optional fallback memory resource.
| primary_mr | The primary memory resource (moved in). |
| fallback_mr | Optional fallback memory resource. |
Definition at line 64 of file rmm_resource_adaptor_impl.hpp.
|
inlineexplicit |
Construct the primary resource in-place from forwarded arguments.
Use this overload when the primary resource type is non-movable (e.g. cuda::pinned_memory_pool). The resource is constructed directly inside the shared-ownership control block, avoiding an extra heap allocation.
| args | Arguments forwarded to the PrimaryMR constructor. |
Definition at line 82 of file rmm_resource_adaptor_impl.hpp.
|
inline |
Allocate memory asynchronously on the given stream.
| stream | The CUDA stream for the allocation. |
| bytes | Number of bytes to allocate. |
| alignment | Alignment requirement. |
Definition at line 163 of file rmm_resource_adaptor_impl.hpp.
|
inline |
Allocate memory synchronously.
| bytes | Number of bytes to allocate. |
| alignment | Alignment requirement. |
Definition at line 252 of file rmm_resource_adaptor_impl.hpp.
|
inline |
Begin recording a new scoped memory usage record for the current thread.
This method pushes a new empty ScopedMemoryRecord onto the thread-local record stack, allowing for nested memory tracking scopes.
Must be paired with a matching call to end_scoped_memory_record().
Definition at line 133 of file rmm_resource_adaptor_impl.hpp.
|
inlinenoexcept |
Get the total current allocated memory from both primary and fallback.
Definition at line 127 of file rmm_resource_adaptor_impl.hpp.
|
inlinenoexcept |
Deallocate memory asynchronously on the given stream.
| stream | The CUDA stream for the deallocation. |
| ptr | Pointer to the memory to deallocate. |
| bytes | Number of bytes to deallocate. |
| alignment | Alignment of the original allocation. |
Definition at line 211 of file rmm_resource_adaptor_impl.hpp.
|
inlinenoexcept |
Deallocate memory synchronously.
| ptr | Pointer to the memory to deallocate. |
| bytes | Number of bytes to deallocate. |
| alignment | Alignment of the original allocation. |
Definition at line 267 of file rmm_resource_adaptor_impl.hpp.
|
inline |
End the current scoped memory record and return it.
Pops the top ScopedMemoryRecord from the thread-local stack and returns it. If this scope was nested within another (i.e. if begin_scoped_memory_record() was called multiple times in a row), the returned scope is automatically added as a subscope to the next scope remaining on the stack.
This allows nesting of scoped memory tracking, where each scope can contain one or more subscopes. When analyzing or reporting memory statistics, the memory usage of each scope can be calculated inclusive of its subscopes. This behavior mimics standard hierarchical memory profilers, where the total memory attributed to a scope includes all allocations made within it, plus those made in its nested regions.
| std::out_of_range | if called without a matching begin_scoped_memory_record(). |
Definition at line 139 of file rmm_resource_adaptor_impl.hpp.
|
inlinenoexcept |
Returns a const reference to the optional fallback resource.
std::nullopt if no fallback is configured. Definition at line 116 of file rmm_resource_adaptor_impl.hpp.
|
inline |
Returns a copy of the main memory record.
The main record tracks memory statistics for the lifetime of the resource.
Definition at line 121 of file rmm_resource_adaptor_impl.hpp.
|
inlinenoexcept |
Returns a reference to the primary upstream resource.
Definition at line 106 of file rmm_resource_adaptor_impl.hpp.
|
inlinenoexcept |
Equality comparison.
| other | The other impl to compare. |
Definition at line 98 of file rmm_resource_adaptor_impl.hpp.