Public Member Functions | 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

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 *p, std::size_t bytes, std::size_t alignment=alignof(std::max_align_t))
 Deallocate memory pointed to by p. More...
 
bool is_equal (host_memory_resource const &other) const noexcept
 Compare this resource to another. 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

@return void* Pointer to the newly allocated memory

◆ deallocate()

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

Deallocate memory pointed to by p.

------------------------------------------------------------------------—*

p 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.

Exceptions
Nothing.
Parameters
pPointer 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 p.
alignmentAlignment of the allocation. This must be equal to the value of alignment that was passed to the allocate call that returned p.

@param stream Stream on which to perform deallocation

◆ 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 If the two resources are equivalent


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