UMPIRE
Umpire: resource management and provision
umpire::Allocator Class Reference

Provides a unified interface to allocate and free data. More...

#include </home/docs/checkouts/readthedocs.org/user_builds/umpire/checkouts/develop/src/umpire/Allocator.hpp>

Inheritance diagram for umpire::Allocator:

Public Member Functions

void * allocate (std::size_t bytes)
 Allocate bytes of memory. More...
 
void * allocate (std::size_t bytes, camp::resources::Resource const &r)
 
void * allocate (const std::string &name, std::size_t bytes)
 
void deallocate (void *ptr)
 Free the memory at ptr. More...
 
void deallocate (void *ptr, camp::resources::Resource const &r)
 
void release ()
 Release any and all unused memory held by this Allocator. More...
 
std::size_t getSize (void *ptr) const
 Return number of bytes allocated for allocation. More...
 
std::size_t getHighWatermark () const noexcept
 Return the memory high watermark for this Allocator. More...
 
std::size_t getCurrentSize () const noexcept
 Return the current size of this Allocator. More...
 
std::size_t getActualSize () const noexcept
 Return the actual size of this Allocator. More...
 
std::size_t getAllocationCount () const noexcept
 Return the number of active allocations. More...
 
const std::string & getName () const noexcept
 Get the name of this Allocator. More...
 
int getId () const noexcept
 Get the integer ID of this Allocator. More...
 
strategy::AllocationStrategygetParent () const noexcept
 
strategy::AllocationStrategygetAllocationStrategy () noexcept
 Get the AllocationStrategy object used by this Allocator. More...
 
Platform getPlatform () noexcept
 Get the Platform object appropriate for this Allocator. More...
 
bool isTracked () const noexcept
 
const std::string & getStrategyName () const noexcept
 
 Allocator ()=default
 

Friends

class ResourceManager
 
class ::AllocatorTest
 
class umpire::op::HostReallocateOperation
 
class umpire::op::GenericReallocateOperation
 
std::ostream & operator<< (std::ostream &, const Allocator &)
 

Detailed Description

Provides a unified interface to allocate and free data.

An Allocator encapsulates all the details of how and where allocations will be made, and can also be used to introspect the memory resource. Allocator objects do not return typed allocations, so the pointer returned from the allocate method must be cast to the relevant type.

See also
TypedAllocator

Constructor & Destructor Documentation

◆ Allocator()

umpire::Allocator::Allocator ( )
default

Member Function Documentation

◆ allocate() [1/3]

void * umpire::Allocator::allocate ( std::size_t  bytes)
inline

Allocate bytes of memory.

The memory will be allocated as determined by the AllocationStrategy used by this Allocator. Note that this method does not guarantee new memory pages being requested from the underlying memory system, as the associated AllocationStrategy could have already allocated sufficient memory, or re-use existing allocations that were not returned to the system.

Parameters
bytesNumber of bytes to allocate (>= 0)
Returns
Pointer to start of the allocation.

Referenced by umpire::malloc(), umpire::ResourceManager::move(), and umpire_allocator_allocate().

◆ allocate() [2/3]

void * umpire::Allocator::allocate ( std::size_t  bytes,
camp::resources::Resource const &  r 
)
inline

◆ allocate() [3/3]

void * umpire::Allocator::allocate ( const std::string &  name,
std::size_t  bytes 
)
inline

◆ deallocate() [1/2]

void umpire::Allocator::deallocate ( void *  ptr)
inline

Free the memory at ptr.

This method will throw an umpire::runtime_error if ptr was not allocated using this Allocator. If the value of the pointer is set to nullptr, this behavior is allowed, but it will be ignored. If you need to deallocate memory allocated by an unknown object, use the ResourceManager::deallocate method.

Parameters
ptrPointer to free (If nullptr, it will be ignored.)

Referenced by umpire::DeviceAllocator::destroy(), and umpire_allocator_deallocate().

◆ deallocate() [2/2]

void umpire::Allocator::deallocate ( void *  ptr,
camp::resources::Resource const &  r 
)
inline

◆ release()

void umpire::Allocator::release ( )

◆ getSize()

std::size_t umpire::Allocator::getSize ( void *  ptr) const

Return number of bytes allocated for allocation.

Parameters
ptrPointer to allocation in question
Returns
number of bytes allocated for ptr

References umpire::util::message::Debug, umpire::ResourceManager::getInstance(), umpire::ResourceManager::getSize(), and UMPIRE_LOG.

Referenced by umpire_allocator_get_size().

◆ getHighWatermark()

std::size_t umpire::Allocator::getHighWatermark ( ) const
noexcept

Return the memory high watermark for this Allocator.

This is the largest amount of memory allocated by this Allocator. Note that this may be larger than the largest value returned by getCurrentSize.

Returns
Memory high watermark.

References umpire::strategy::AllocationStrategy::getHighWatermark().

Referenced by umpire_allocator_get_high_watermark().

◆ getCurrentSize()

std::size_t umpire::Allocator::getCurrentSize ( ) const
noexcept

Return the current size of this Allocator.

This is sum of the sizes of all the tracked allocations. Note that this doesn't ever have to be equal to getHighWatermark.

Returns
current size of Allocator.

References umpire::strategy::AllocationStrategy::getCurrentSize().

Referenced by umpire_allocator_get_current_size().

◆ getActualSize()

std::size_t umpire::Allocator::getActualSize ( ) const
noexcept

Return the actual size of this Allocator.

For non-pool allocators, this will be the same as getCurrentSize().

For pools, this is the total amount of memory allocated for blocks managed by the pool.

Returns
actual size of Allocator.

References umpire::strategy::AllocationStrategy::getActualSize().

Referenced by umpire::get_total_bytes_allocated(), and umpire_allocator_get_actual_size().

◆ getAllocationCount()

std::size_t umpire::Allocator::getAllocationCount ( ) const
noexcept

Return the number of active allocations.

References umpire::strategy::AllocationStrategy::getAllocationCount().

Referenced by umpire_allocator_get_allocation_count().

◆ getName()

const std::string & umpire::Allocator::getName ( ) const
noexcept

◆ getId()

int umpire::Allocator::getId ( ) const
noexcept

Get the integer ID of this Allocator.

Allocators are uniquely identified, and the ID of the Allocator can be used to retrieve the same Allocator from the ResourceManager at a later time.

See also
ResourceManager::getAllocator
Returns
integer id of Allocator.

References umpire::strategy::AllocationStrategy::getId().

Referenced by umpire::ResourceManager::removeAlias(), and umpire_allocator_get_id().

◆ getParent()

strategy::AllocationStrategy * umpire::Allocator::getParent ( ) const
noexcept

◆ getAllocationStrategy()

◆ getPlatform()

Platform umpire::Allocator::getPlatform ( )
noexcept

◆ isTracked()

bool umpire::Allocator::isTracked ( ) const
noexcept

◆ getStrategyName()

const std::string & umpire::Allocator::getStrategyName ( ) const
noexcept

Friends And Related Function Documentation

◆ ResourceManager

friend class ResourceManager
friend

◆ ::AllocatorTest

friend class ::AllocatorTest
friend

◆ umpire::op::HostReallocateOperation

◆ umpire::op::GenericReallocateOperation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const Allocator allocator 
)
friend