Public Member Functions | Friends | List of all members
rapidsmpf::HostMemoryResource Class Reference

Host memory resource using standard CPU allocation. More...

#include <host_memory_resource.hpp>

Inheritance diagram for rapidsmpf::HostMemoryResource:
rapidsmpf::PinnedMemoryResource

Public Member Functions

 HostMemoryResource ()=default
 Default constructor.
 
virtual ~HostMemoryResource ()=default
 Virtual destructor to allow polymorphic use.
 
 HostMemoryResource (HostMemoryResource const &)=default
 Copyable.
 
 HostMemoryResource (HostMemoryResource &&)=default
 Movable.
 
HostMemoryResourceoperator= (HostMemoryResource const &)=default
 Copy assignment. More...
 
HostMemoryResourceoperator= (HostMemoryResource &&)=default
 Move assignment. More...
 
void * allocate_sync (std::size_t, std::size_t)
 Synchronously allocates host memory is disabled. More...
 
void deallocate_sync (void *, std::size_t, std::size_t)
 Synchronously deallocates host memory is disabled. More...
 
virtual void * allocate (rmm::cuda_stream_view stream, std::size_t size, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT)
 Allocates host memory associated with a CUDA stream. More...
 
virtual void deallocate (rmm::cuda_stream_view stream, void *ptr, std::size_t size, std::size_t alignment=rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept
 Deallocates host memory associated with a CUDA stream. More...
 
virtual bool is_equal ([[maybe_unused]] HostMemoryResource const &other) const noexcept
 Compares this resource to another resource. More...
 
bool operator== (HostMemoryResource const &other) const noexcept
 Compares this resource to another resource. More...
 
bool operator!= (HostMemoryResource const &other) const noexcept
 Compares this resource to another resource. More...
 

Friends

void get_property (HostMemoryResource const &, cuda::mr::host_accessible) noexcept
 Enables the cuda::mr::host_accessible property. More...
 

Detailed Description

Host memory resource using standard CPU allocation.

This resource allocates pageable host memory using the new and delete operators. It is intended for use with cuda::mr::resource and related facilities, and advertises the cuda::mr::host_accessible property.

For sufficiently large allocations (>4 MiB), this resource also issues a best-effort request to enable Transparent Huge Pages (THP) on the allocated region. THP can improve device-host memory transfer performance for large buffers. The hint is applied via madvise(MADV_HUGEPAGE) and may be ignored by the kernel depending on system configuration or resource availability.

Definition at line 32 of file host_memory_resource.hpp.

Member Function Documentation

◆ allocate()

virtual void* rapidsmpf::HostMemoryResource::allocate ( rmm::cuda_stream_view  stream,
std::size_t  size,
std::size_t  alignment = rmm::CUDA_ALLOCATION_ALIGNMENT 
)
virtual

Allocates host memory associated with a CUDA stream.

Derived classes may override this to provide custom host allocation strategies.

Parameters
streamCUDA stream associated with the allocation.
sizeNumber of bytes to at least allocate.
alignmentRequired alignment.
Returns
Pointer to the allocated memory.
Exceptions
std::bad_allocIf the allocation fails.
std::invalid_argumentIf alignment is not a valid alignment.

Reimplemented in rapidsmpf::PinnedMemoryResource.

◆ allocate_sync()

void* rapidsmpf::HostMemoryResource::allocate_sync ( std::size_t  ,
std::size_t   
)
inline

Synchronously allocates host memory is disabled.

Always use stream-ordered allocators in RapidsMPF.

Returns
N/A.
Exceptions
std::invalid_argumentAlways.

Definition at line 60 of file host_memory_resource.hpp.

◆ deallocate()

virtual void rapidsmpf::HostMemoryResource::deallocate ( rmm::cuda_stream_view  stream,
void *  ptr,
std::size_t  size,
std::size_t  alignment = rmm::CUDA_ALLOCATION_ALIGNMENT 
)
virtualnoexcept

Deallocates host memory associated with a CUDA stream.

The default implementation synchronizes stream before deallocating the memory with the delete operator. This ensures that any in-flight CUDA operations using the memory complete before it is freed.

Derived classes may override this to provide custom host deallocation strategies.

Parameters
streamCUDA stream associated with operations that used ptr.
ptrPointer to the memory to deallocate. May be nullptr.
sizeNumber of bytes previously allocated at ptr.
alignmentAlignment originally used for the allocation.

Reimplemented in rapidsmpf::PinnedMemoryResource.

◆ deallocate_sync()

void rapidsmpf::HostMemoryResource::deallocate_sync ( void *  ,
std::size_t  ,
std::size_t   
)
inline

Synchronously deallocates host memory is disabled.

Exceptions
std::invalid_argumentAlways.

Definition at line 72 of file host_memory_resource.hpp.

◆ is_equal()

virtual bool rapidsmpf::HostMemoryResource::is_equal ( [[maybe_unused] ] HostMemoryResource const &  other) const
inlinevirtualnoexcept

Compares this resource to another resource.

Two resources are considered equal if memory allocated by one may be deallocated by the other. The default implementation compares object identity.

The base class is stateless, and all instances behave identically. Any instance can deallocate memory allocated by any other instance of this base class, so the comparison always returns true.

Derived classes that use different allocation or deallocation strategies must override this function. Such classes should return true only when the other resource is compatible with their allocation and free methods.

Parameters
otherThe resource to compare with.
Returns
true because all instances of this base class are considered equal.

Definition at line 136 of file host_memory_resource.hpp.

◆ operator!=()

bool rapidsmpf::HostMemoryResource::operator!= ( HostMemoryResource const &  other) const
inlinenoexcept

Compares this resource to another resource.

Two resources are considered equal if memory allocated by one may be deallocated by the other. The default implementation compares object identity.

The base class is stateless, and all instances behave identically. Any instance can deallocate memory allocated by any other instance of this base class, so the comparison always returns true.

Derived classes that use different allocation or deallocation strategies must override this function. Such classes should return true only when the other resource is compatible with their allocation and free methods.

Parameters
otherThe resource to compare with.
Returns
true because all instances of this base class are considered equal.

Definition at line 148 of file host_memory_resource.hpp.

◆ operator=() [1/2]

HostMemoryResource& rapidsmpf::HostMemoryResource::operator= ( HostMemoryResource &&  )
default

Move assignment.

Returns
Reference to this object after assignment.

◆ operator=() [2/2]

HostMemoryResource& rapidsmpf::HostMemoryResource::operator= ( HostMemoryResource const &  )
default

Copy assignment.

Returns
Reference to this object after assignment.

◆ operator==()

bool rapidsmpf::HostMemoryResource::operator== ( HostMemoryResource const &  other) const
inlinenoexcept

Compares this resource to another resource.

Two resources are considered equal if memory allocated by one may be deallocated by the other. The default implementation compares object identity.

The base class is stateless, and all instances behave identically. Any instance can deallocate memory allocated by any other instance of this base class, so the comparison always returns true.

Derived classes that use different allocation or deallocation strategies must override this function. Such classes should return true only when the other resource is compatible with their allocation and free methods.

Parameters
otherThe resource to compare with.
Returns
true because all instances of this base class are considered equal.

Definition at line 143 of file host_memory_resource.hpp.

Friends And Related Function Documentation

◆ get_property

void get_property ( HostMemoryResource const &  ,
cuda::mr::host_accessible   
)
friend

Enables the cuda::mr::host_accessible property.

This property declares that a HostMemoryResource provides host accessible memory

Definition at line 157 of file host_memory_resource.hpp.


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