Public Member Functions | Friends | List of all members
rmm::mr::host_memory_resource Class Referenceabstract

Base class for host memory allocation. More...

#include <host_memory_resource.hpp>

Inheritance diagram for rmm::mr::host_memory_resource:
Inheritance graph
[legend]

Public Member Functions

 host_memory_resource (host_memory_resource const &)=default
 Default copy constructor.
 
 host_memory_resource (host_memory_resource &&) noexcept=default
 Default move constructor.
 
host_memory_resourceoperator= (host_memory_resource const &)=default
 Default copy assignment operator. More...
 
host_memory_resourceoperator= (host_memory_resource &&) noexcept=default
 Default move assignment operator. More...
 
void * allocate (std::size_t bytes, std::size_t alignment=alignof(std::max_align_t))
 Allocates memory on the host of size at least bytes bytes. More...
 
void deallocate (void *ptr, std::size_t bytes, std::size_t alignment=alignof(std::max_align_t))
 Deallocate memory pointed to by ptr. More...
 
bool is_equal (host_memory_resource const &other) const noexcept
 Compare this resource to another. More...
 
bool operator== (host_memory_resource const &other) const noexcept
 Comparison operator with another device_memory_resource. More...
 
bool operator!= (host_memory_resource const &other) const noexcept
 Comparison operator with another device_memory_resource. More...
 

Friends

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

Detailed Description

Base class for host memory allocation.

This is based on std::pmr::memory_resource: https://en.cppreference.com/w/cpp/memory/memory_resource

When C++17 is available for use in RMM, rmm::host_memory_resource should inherit from std::pmr::memory_resource.

This class serves as the interface that all host memory resource implementations must satisfy.

There are two private, pure virtual functions that all derived classes must implement: do_allocate and do_deallocate. Optionally, derived classes may also override is_equal. By default, is_equal simply performs an identity comparison.

The public, non-virtual functions allocate, deallocate, and is_equal simply call the private virtual functions. The reason for this is to allow implementing shared, default behavior in the base class. For example, the base class' allocate function may log every allocation, no matter what derived class implementation is used.

Member Function Documentation

◆ allocate()

void* rmm::mr::host_memory_resource::allocate ( std::size_t  bytes,
std::size_t  alignment = alignof(std::max_align_t) 
)
inline

Allocates memory on the host of size at least bytes bytes.

The returned storage is aligned to the specified alignment if supported, and to alignof(std::max_align_t) otherwise.

Exceptions
std::bad_allocWhen the requested bytes and alignment cannot be allocated.
Parameters
bytesThe size of the allocation
alignmentAlignment of the allocation
Returns
void* Pointer to the newly allocated memory

◆ deallocate()

void rmm::mr::host_memory_resource::deallocate ( void *  ptr,
std::size_t  bytes,
std::size_t  alignment = alignof(std::max_align_t) 
)
inline

Deallocate memory pointed to by ptr.

ptr must have been returned by a prior call to allocate(bytes,alignment) on a host_memory_resource that compares equal to *this, and the storage it points to must not yet have been deallocated, otherwise behavior is undefined.

Parameters
ptrPointer to be deallocated
bytesThe size in bytes of the allocation. This must be equal to the value of bytes that was passed to the allocate call that returned ptr.
alignmentAlignment of the allocation. This must be equal to the value of alignment that was passed to the allocate call that returned ptr.

◆ is_equal()

bool rmm::mr::host_memory_resource::is_equal ( host_memory_resource const &  other) const
inlinenoexcept

Compare this resource to another.

Two host_memory_resources compare equal if and only if memory allocated from one host_memory_resource can be deallocated from the other and vice versa.

By default, simply checks if *this and other refer to the same object, i.e., does not check if they are two objects of the same class.

Parameters
otherThe other resource to compare to
Returns
true if the two resources are equivalent

◆ operator!=()

bool rmm::mr::host_memory_resource::operator!= ( host_memory_resource const &  other) const
inlinenoexcept

Comparison operator with another device_memory_resource.

Parameters
otherThe other resource to compare to
Returns
false If the two resources are equivalent
true If the two resources are not equivalent

◆ operator=() [1/2]

host_memory_resource& rmm::mr::host_memory_resource::operator= ( host_memory_resource &&  )
defaultnoexcept

Default move assignment operator.

Returns
host_memory_resource& Reference to the assigned object

◆ operator=() [2/2]

host_memory_resource& rmm::mr::host_memory_resource::operator= ( host_memory_resource const &  )
default

Default copy assignment operator.

Returns
host_memory_resource& Reference to the assigned object

◆ operator==()

bool rmm::mr::host_memory_resource::operator== ( host_memory_resource const &  other) const
inlinenoexcept

Comparison operator with another device_memory_resource.

Parameters
otherThe other resource to compare to
Returns
true If the two resources are equivalent
false If the two resources are not equivalent

Friends And Related Function Documentation

◆ get_property

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

Enables the cuda::mr::host_accessible property.

This property declares that a host_memory_resource provides host accessible memory


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