Public Member Functions | Friends | List of all members
rapidsmpf::detail::RmmResourceAdaptorImpl< PrimaryMR, FallbackMR > Class Template Reference

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
 
RmmResourceAdaptorImploperator= (RmmResourceAdaptorImpl const &)=delete
 
RmmResourceAdaptorImploperator= (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.
 

Detailed Description

template<cuda::mr::resource_with< cuda::mr::device_accessible > PrimaryMR, cuda::mr::resource_with< cuda::mr::device_accessible > FallbackMR = cuda::mr::any_resource<cuda::mr::device_accessible>>
class rapidsmpf::detail::RmmResourceAdaptorImpl< PrimaryMR, FallbackMR >

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.

Template Parameters
PrimaryMRThe 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.
FallbackMRThe 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.

Constructor & Destructor Documentation

◆ RmmResourceAdaptorImpl() [1/2]

template<cuda::mr::resource_with< cuda::mr::device_accessible > PrimaryMR, cuda::mr::resource_with< cuda::mr::device_accessible > FallbackMR = cuda::mr::any_resource<cuda::mr::device_accessible>>
rapidsmpf::detail::RmmResourceAdaptorImpl< PrimaryMR, FallbackMR >::RmmResourceAdaptorImpl ( PrimaryMR  primary_mr,
std::optional< FallbackMR >  fallback_mr = std::nullopt 
)
inline

Construct with a primary and optional fallback memory resource.

Parameters
primary_mrThe primary memory resource (moved in).
fallback_mrOptional fallback memory resource.

Definition at line 64 of file rmm_resource_adaptor_impl.hpp.

◆ RmmResourceAdaptorImpl() [2/2]

template<cuda::mr::resource_with< cuda::mr::device_accessible > PrimaryMR, cuda::mr::resource_with< cuda::mr::device_accessible > FallbackMR = cuda::mr::any_resource<cuda::mr::device_accessible>>
template<typename... Args>
rapidsmpf::detail::RmmResourceAdaptorImpl< PrimaryMR, FallbackMR >::RmmResourceAdaptorImpl ( std::in_place_t  ,
Args &&...  args 
)
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.

Parameters
argsArguments forwarded to the PrimaryMR constructor.

Definition at line 82 of file rmm_resource_adaptor_impl.hpp.

Member Function Documentation

◆ allocate()

template<cuda::mr::resource_with< cuda::mr::device_accessible > PrimaryMR, cuda::mr::resource_with< cuda::mr::device_accessible > FallbackMR = cuda::mr::any_resource<cuda::mr::device_accessible>>
void* rapidsmpf::detail::RmmResourceAdaptorImpl< PrimaryMR, FallbackMR >::allocate ( cuda::stream_ref  stream,
std::size_t  bytes,
std::size_t  alignment = rmm::CUDA_ALLOCATION_ALIGNMENT 
)
inline

Allocate memory asynchronously on the given stream.

Parameters
streamThe CUDA stream for the allocation.
bytesNumber of bytes to allocate.
alignmentAlignment requirement.
Returns
Pointer to the allocated memory.

Definition at line 163 of file rmm_resource_adaptor_impl.hpp.

◆ allocate_sync()

template<cuda::mr::resource_with< cuda::mr::device_accessible > PrimaryMR, cuda::mr::resource_with< cuda::mr::device_accessible > FallbackMR = cuda::mr::any_resource<cuda::mr::device_accessible>>
void* rapidsmpf::detail::RmmResourceAdaptorImpl< PrimaryMR, FallbackMR >::allocate_sync ( std::size_t  bytes,
std::size_t  alignment = rmm::CUDA_ALLOCATION_ALIGNMENT 
)
inline

Allocate memory synchronously.

Parameters
bytesNumber of bytes to allocate.
alignmentAlignment requirement.
Returns
Pointer to the allocated memory.

Definition at line 252 of file rmm_resource_adaptor_impl.hpp.

◆ begin_scoped_memory_record()

template<cuda::mr::resource_with< cuda::mr::device_accessible > PrimaryMR, cuda::mr::resource_with< cuda::mr::device_accessible > FallbackMR = cuda::mr::any_resource<cuda::mr::device_accessible>>
void rapidsmpf::detail::RmmResourceAdaptorImpl< PrimaryMR, FallbackMR >::begin_scoped_memory_record ( )
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().

See also
end_scoped_memory_record()

Definition at line 133 of file rmm_resource_adaptor_impl.hpp.

◆ current_allocated()

template<cuda::mr::resource_with< cuda::mr::device_accessible > PrimaryMR, cuda::mr::resource_with< cuda::mr::device_accessible > FallbackMR = cuda::mr::any_resource<cuda::mr::device_accessible>>
std::int64_t rapidsmpf::detail::RmmResourceAdaptorImpl< PrimaryMR, FallbackMR >::current_allocated ( ) const
inlinenoexcept

Get the total current allocated memory from both primary and fallback.

Returns
Total number of currently allocated bytes.

Definition at line 127 of file rmm_resource_adaptor_impl.hpp.

◆ deallocate()

template<cuda::mr::resource_with< cuda::mr::device_accessible > PrimaryMR, cuda::mr::resource_with< cuda::mr::device_accessible > FallbackMR = cuda::mr::any_resource<cuda::mr::device_accessible>>
void rapidsmpf::detail::RmmResourceAdaptorImpl< PrimaryMR, FallbackMR >::deallocate ( cuda::stream_ref  stream,
void *  ptr,
std::size_t  bytes,
std::size_t  alignment = rmm::CUDA_ALLOCATION_ALIGNMENT 
)
inlinenoexcept

Deallocate memory asynchronously on the given stream.

Parameters
streamThe CUDA stream for the deallocation.
ptrPointer to the memory to deallocate.
bytesNumber of bytes to deallocate.
alignmentAlignment of the original allocation.

Definition at line 211 of file rmm_resource_adaptor_impl.hpp.

◆ deallocate_sync()

template<cuda::mr::resource_with< cuda::mr::device_accessible > PrimaryMR, cuda::mr::resource_with< cuda::mr::device_accessible > FallbackMR = cuda::mr::any_resource<cuda::mr::device_accessible>>
void rapidsmpf::detail::RmmResourceAdaptorImpl< PrimaryMR, FallbackMR >::deallocate_sync ( void *  ptr,
std::size_t  bytes,
std::size_t  alignment = rmm::CUDA_ALLOCATION_ALIGNMENT 
)
inlinenoexcept

Deallocate memory synchronously.

Parameters
ptrPointer to the memory to deallocate.
bytesNumber of bytes to deallocate.
alignmentAlignment of the original allocation.

Definition at line 267 of file rmm_resource_adaptor_impl.hpp.

◆ end_scoped_memory_record()

template<cuda::mr::resource_with< cuda::mr::device_accessible > PrimaryMR, cuda::mr::resource_with< cuda::mr::device_accessible > FallbackMR = cuda::mr::any_resource<cuda::mr::device_accessible>>
ScopedMemoryRecord rapidsmpf::detail::RmmResourceAdaptorImpl< PrimaryMR, FallbackMR >::end_scoped_memory_record ( )
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.

Returns
The scope that was just ended.
Exceptions
std::out_of_rangeif called without a matching begin_scoped_memory_record().
See also
begin_scoped_memory_record()

Definition at line 139 of file rmm_resource_adaptor_impl.hpp.

◆ get_fallback_resource()

template<cuda::mr::resource_with< cuda::mr::device_accessible > PrimaryMR, cuda::mr::resource_with< cuda::mr::device_accessible > FallbackMR = cuda::mr::any_resource<cuda::mr::device_accessible>>
std::optional<FallbackMR> const& rapidsmpf::detail::RmmResourceAdaptorImpl< PrimaryMR, FallbackMR >::get_fallback_resource ( ) const
inlinenoexcept

Returns a const reference to the optional fallback resource.

Returns
Const reference to the optional fallback resource, or std::nullopt if no fallback is configured.

Definition at line 116 of file rmm_resource_adaptor_impl.hpp.

◆ get_main_record()

template<cuda::mr::resource_with< cuda::mr::device_accessible > PrimaryMR, cuda::mr::resource_with< cuda::mr::device_accessible > FallbackMR = cuda::mr::any_resource<cuda::mr::device_accessible>>
ScopedMemoryRecord rapidsmpf::detail::RmmResourceAdaptorImpl< PrimaryMR, FallbackMR >::get_main_record ( ) const
inline

Returns a copy of the main memory record.

The main record tracks memory statistics for the lifetime of the resource.

Returns
A copy of the current main memory record.

Definition at line 121 of file rmm_resource_adaptor_impl.hpp.

◆ get_upstream_resource()

template<cuda::mr::resource_with< cuda::mr::device_accessible > PrimaryMR, cuda::mr::resource_with< cuda::mr::device_accessible > FallbackMR = cuda::mr::any_resource<cuda::mr::device_accessible>>
PrimaryMR const& rapidsmpf::detail::RmmResourceAdaptorImpl< PrimaryMR, FallbackMR >::get_upstream_resource ( ) const
inlinenoexcept

Returns a reference to the primary upstream resource.

Returns
Reference to the primary resource.

Definition at line 106 of file rmm_resource_adaptor_impl.hpp.

◆ operator==()

template<cuda::mr::resource_with< cuda::mr::device_accessible > PrimaryMR, cuda::mr::resource_with< cuda::mr::device_accessible > FallbackMR = cuda::mr::any_resource<cuda::mr::device_accessible>>
bool rapidsmpf::detail::RmmResourceAdaptorImpl< PrimaryMR, FallbackMR >::operator== ( RmmResourceAdaptorImpl< PrimaryMR, FallbackMR > const &  other) const
inlinenoexcept

Equality comparison.

Parameters
otherThe other impl to compare.
Returns
True if the two instances are the same.

Definition at line 98 of file rmm_resource_adaptor_impl.hpp.


The documentation for this class was generated from the following file: