UMPIRE
Umpire: resource management and provision
umpire::strategy::ResourceAwarePool Class Reference

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

Inheritance diagram for umpire::strategy::ResourceAwarePool:

Classes

struct  Chunk
 

Public Types

using Pointer = void *
 

Public Member Functions

 ResourceAwarePool (const std::string &name, int id, Allocator allocator, const std::size_t first_minimum_pool_allocation_size=s_default_first_block_size, const std::size_t next_minimum_pool_allocation_size=s_default_next_block_size, const std::size_t alignment=s_default_alignment, PoolCoalesceHeuristic< ResourceAwarePool > should_coalesce=percent_releasable_hwm(100)) noexcept
 Construct a new ResourceAwarePool. More...
 
 ~ResourceAwarePool ()
 
 ResourceAwarePool (const ResourceAwarePool &)=delete
 
void * allocate (std::size_t bytes) override
 If this method is called, it will log a warning message and call allocate with the default Host resource. (Need to call allocate with a Camp resource instead). More...
 
void * allocate_resource (std::size_t bytes, camp::resources::Resource r) override
 Allocate memory with the ResourceAwarePool. More...
 
void deallocate_resource (void *ptr, camp::resources::Resource r, std::size_t size) override
 Deallocate memory with the ResourceAwarePool. More...
 
void deallocate (void *ptr, std::size_t size) override
 Deallocate function will call private getResource function to get the resource associated with the pointer and then call deallocate_resource above. More...
 
void release () override
 Release function will first check to see if there are any finished pending chunks and then release both the finished pending chunks and the free chunks. It will only wait for a pending chunk to finish if we are destructing the pool. More...
 
std::size_t getActualSize () const noexcept override
 Get the current amount of memory allocated by this allocator. More...
 
std::size_t getReleasableSize () const noexcept
 
std::size_t getActualHighwaterMark () const noexcept
 
std::size_t getAlignedSize () const noexcept
 Returns the current size of the pool, rounded up to alignment. More...
 
std::size_t getAlignedHighwaterMark () const noexcept
 
Platform getPlatform () noexcept override
 Get the platform associated with this AllocationStrategy. More...
 
MemoryResourceTraits getTraits () const noexcept override
 
bool tracksMemoryUse () const noexcept override
 
std::size_t getBlocksInPool () const noexcept
 Return the number of memory blocks – both leased to application and internal free memory – that the pool holds. More...
 
std::size_t getLargestAvailableBlock () noexcept
 Get the largest allocatable number of bytes from pool before the pool will grow. More...
 
std::size_t getReleasableBlocks () const noexcept
 
std::size_t getTotalBlocks () const noexcept
 
void coalesce () noexcept
 
void do_coalesce (std::size_t suggested_size) noexcept
 
void * allocate_internal (std::size_t bytes)
 
void * allocate_named_internal (const std::string &name, std::size_t bytes)
 
void deallocate_internal (void *ptr, std::size_t size=0)
 
virtual std::size_t getCurrentSize () const noexcept
 Get current (total) size of the allocated memory. More...
 
virtual std::size_t getHighWatermark () const noexcept
 Get the high watermark of the total allocated size. More...
 
virtual std::size_t getAllocationCount () const noexcept
 Get the total number of active allocations by this allocator. More...
 
const std::string & getName () noexcept
 Get the name of this AllocationStrategy. More...
 
const std::string & getStrategyName () const noexcept
 
int getId () noexcept
 Get the id of this AllocationStrategy. More...
 
virtual AllocationStrategygetParent () const noexcept
 Traces where the allocator came from. More...
 
bool isTracked () const noexcept
 

Static Public Member Functions

static PoolCoalesceHeuristic< ResourceAwarePoolpercent_releasable (int percentage)
 Coalescing Heuristic functions for Percent-Releasable and Blocks-Releasable. Both have the option to reallocate to High Watermark instead of actual size of the pool (actual size is currently the default). More...
 
static PoolCoalesceHeuristic< ResourceAwarePoolpercent_releasable_hwm (int percentage)
 
static PoolCoalesceHeuristic< ResourceAwarePoolblocks_releasable (std::size_t nblocks)
 
static PoolCoalesceHeuristic< ResourceAwarePoolblocks_releasable_hwm (std::size_t nblocks)
 

Public Attributes

std::size_t m_current_size {0}
 
std::size_t m_high_watermark {0}
 
std::size_t m_allocation_count {0}
 

Static Public Attributes

static constexpr std::size_t s_default_first_block_size {512 * 1024 * 1024}
 
static constexpr std::size_t s_default_next_block_size {1 * 1024 * 1024}
 
static constexpr std::size_t s_default_alignment {16}
 

Protected Member Functions

Resource getResource (void *ptr) const
 Get the camp resource associated with a ptr. This function is meant for internal use within the class and for testing. More...
 
std::size_t getNumPending () const noexcept
 Get the number of Pending chunks in the pool. This function is meant for testing. More...
 
void setTracking (bool) noexcept
 

Protected Attributes

std::string m_name
 
std::string m_strategy_name
 
int m_id
 
bool m_tracked {true}
 
AllocationStrategym_parent
 

Friends

camp::resources::Resource umpire::get_resource (Allocator a, void *ptr)
 
std::size_t umpire::get_num_pending (Allocator a)
 

Member Typedef Documentation

◆ Pointer

Constructor & Destructor Documentation

◆ ResourceAwarePool() [1/2]

umpire::strategy::ResourceAwarePool::ResourceAwarePool ( const std::string &  name,
int  id,
Allocator  allocator,
const std::size_t  first_minimum_pool_allocation_size = s_default_first_block_size,
const std::size_t  next_minimum_pool_allocation_size = s_default_next_block_size,
const std::size_t  alignment = s_default_alignment,
PoolCoalesceHeuristic< ResourceAwarePool should_coalesce = percent_releasable_hwm(100) 
)
noexcept

Construct a new ResourceAwarePool.

Parameters
nameName of this instance of the ResourceAwarePool
idUnique identifier for this instance
allocatorAllocation resource that pool uses
first_minimum_pool_allocation_sizeSize the pool initially allocates
next_minimum_pool_allocation_sizeThe minimum size of all future allocations
alignmentNumber of bytes with which to align allocation sizes (power-of-2)
should_coalesceHeuristic for when to perform coalesce operation

◆ ~ResourceAwarePool()

umpire::strategy::ResourceAwarePool::~ResourceAwarePool ( )

◆ ResourceAwarePool() [2/2]

umpire::strategy::ResourceAwarePool::ResourceAwarePool ( const ResourceAwarePool )
delete

Member Function Documentation

◆ percent_releasable()

PoolCoalesceHeuristic< ResourceAwarePool > umpire::strategy::ResourceAwarePool::percent_releasable ( int  percentage)
static

Coalescing Heuristic functions for Percent-Releasable and Blocks-Releasable. Both have the option to reallocate to High Watermark instead of actual size of the pool (actual size is currently the default).

References UMPIRE_ERROR, and UMPIRE_UNUSED_ARG.

◆ percent_releasable_hwm()

PoolCoalesceHeuristic< ResourceAwarePool > umpire::strategy::ResourceAwarePool::percent_releasable_hwm ( int  percentage)
static

References UMPIRE_ERROR, and UMPIRE_UNUSED_ARG.

◆ blocks_releasable()

PoolCoalesceHeuristic< ResourceAwarePool > umpire::strategy::ResourceAwarePool::blocks_releasable ( std::size_t  nblocks)
static

◆ blocks_releasable_hwm()

PoolCoalesceHeuristic< ResourceAwarePool > umpire::strategy::ResourceAwarePool::blocks_releasable_hwm ( std::size_t  nblocks)
static

◆ allocate()

void * umpire::strategy::ResourceAwarePool::allocate ( std::size_t  bytes)
overridevirtual

If this method is called, it will log a warning message and call allocate with the default Host resource. (Need to call allocate with a Camp resource instead).

Implements umpire::strategy::AllocationStrategy.

References allocate_resource(), umpire::resource::Host, UMPIRE_LOG, and umpire::util::message::Warning.

◆ allocate_resource()

◆ deallocate_resource()

void umpire::strategy::ResourceAwarePool::deallocate_resource ( void *  ptr,
camp::resources::Resource  r,
std::size_t  size 
)
overridevirtual

Deallocate memory with the ResourceAwarePool.

Parameters
ptrA pointer to the memory allocation
rThe Camp resource that owns the memory
bytesThe size in bytes for the allocation

Reimplemented from umpire::strategy::AllocationStrategy.

References umpire::util::message::Debug, do_coalesce(), UMPIRE_ERROR, and UMPIRE_LOG.

Referenced by deallocate().

◆ deallocate()

void umpire::strategy::ResourceAwarePool::deallocate ( void *  ptr,
std::size_t  size 
)
overridevirtual

Deallocate function will call private getResource function to get the resource associated with the pointer and then call deallocate_resource above.

Implements umpire::strategy::AllocationStrategy.

References deallocate_resource(), getResource(), UMPIRE_LOG, and umpire::util::message::Warning.

◆ release()

void umpire::strategy::ResourceAwarePool::release ( )
overridevirtual

Release function will first check to see if there are any finished pending chunks and then release both the finished pending chunks and the free chunks. It will only wait for a pending chunk to finish if we are destructing the pool.

Reimplemented from umpire::strategy::AllocationStrategy.

References umpire::strategy::mixins::AlignedAllocation::aligned_deallocate(), umpire::util::FixedMallocPool::deallocate(), umpire::util::message::Debug, umpire::util::message::Error, umpire_mod::get_backtrace(), umpire::util::message::Info, and UMPIRE_LOG.

Referenced by allocate_resource(), and ~ResourceAwarePool().

◆ getActualSize()

std::size_t umpire::strategy::ResourceAwarePool::getActualSize ( ) const
overridevirtualnoexcept

Get the current amount of memory allocated by this allocator.

Note that this can be larger than getCurrentSize(), particularly if the AllocationStrategy implements some kind of pooling.

Returns
The total size of all the memory this object has allocated.

Reimplemented from umpire::strategy::AllocationStrategy.

◆ getReleasableSize()

std::size_t umpire::strategy::ResourceAwarePool::getReleasableSize ( ) const
noexcept

◆ getActualHighwaterMark()

std::size_t umpire::strategy::ResourceAwarePool::getActualHighwaterMark ( ) const
noexcept

◆ getAlignedSize()

std::size_t umpire::strategy::ResourceAwarePool::getAlignedSize ( ) const
noexcept

Returns the current size of the pool, rounded up to alignment.

◆ getAlignedHighwaterMark()

std::size_t umpire::strategy::ResourceAwarePool::getAlignedHighwaterMark ( ) const
noexcept

◆ getPlatform()

Platform umpire::strategy::ResourceAwarePool::getPlatform ( )
overridevirtualnoexcept

Get the platform associated with this AllocationStrategy.

The Platform distinguishes the appropriate place to execute operations on memory allocated by this AllocationStrategy.

Returns
The platform associated with this AllocationStrategy.

Implements umpire::strategy::AllocationStrategy.

References umpire::strategy::AllocationStrategy::getPlatform(), and umpire::strategy::mixins::AlignedAllocation::m_allocator.

◆ getTraits()

MemoryResourceTraits umpire::strategy::ResourceAwarePool::getTraits ( ) const
overridevirtualnoexcept

◆ tracksMemoryUse()

bool umpire::strategy::ResourceAwarePool::tracksMemoryUse ( ) const
overridevirtualnoexcept

◆ getBlocksInPool()

std::size_t umpire::strategy::ResourceAwarePool::getBlocksInPool ( ) const
noexcept

Return the number of memory blocks – both leased to application and internal free memory – that the pool holds.

◆ getLargestAvailableBlock()

std::size_t umpire::strategy::ResourceAwarePool::getLargestAvailableBlock ( )
noexcept

Get the largest allocatable number of bytes from pool before the pool will grow.

return The largest number of bytes that may be allocated without causing pool growth

◆ getReleasableBlocks()

std::size_t umpire::strategy::ResourceAwarePool::getReleasableBlocks ( ) const
noexcept

◆ getTotalBlocks()

std::size_t umpire::strategy::ResourceAwarePool::getTotalBlocks ( ) const
noexcept

◆ coalesce()

◆ do_coalesce()

void umpire::strategy::ResourceAwarePool::do_coalesce ( std::size_t  suggested_size)
noexcept

◆ getResource()

camp::resources::Resource umpire::strategy::ResourceAwarePool::getResource ( void *  ptr) const
protected

Get the camp resource associated with a ptr. This function is meant for internal use within the class and for testing.

Parameters
ptrThe pointer to data allocated with a ResourceAwarePool

References umpire::util::message::Debug, umpire::util::message::Error, UMPIRE_LOG, and umpire::util::message::Warning.

Referenced by deallocate().

◆ getNumPending()

std::size_t umpire::strategy::ResourceAwarePool::getNumPending ( ) const
protectednoexcept

Get the number of Pending chunks in the pool. This function is meant for testing.

◆ allocate_internal()

◆ allocate_named_internal()

void * umpire::strategy::AllocationStrategy::allocate_named_internal ( const std::string &  name,
std::size_t  bytes 
)
inherited

◆ deallocate_internal()

◆ getCurrentSize()

std::size_t umpire::strategy::AllocationStrategy::getCurrentSize ( ) const
virtualnoexceptinherited

◆ getHighWatermark()

std::size_t umpire::strategy::AllocationStrategy::getHighWatermark ( ) const
virtualnoexceptinherited

Get the high watermark of the total allocated size.

This is equivalent to the highest observed value of getCurrentSize.

Returns
High watermark allocation size.

Reimplemented in umpire::strategy::FixedPool, umpire::strategy::MonotonicAllocationStrategy, umpire::resource::SyclDeviceMemoryResource< _allocator >, umpire::resource::NullMemoryResource, umpire::resource::NoOpMemoryResource, and umpire::resource::FileMemoryResource.

References umpire::strategy::AllocationStrategy::m_high_watermark.

Referenced by umpire::Allocator::getHighWatermark().

◆ getAllocationCount()

std::size_t umpire::strategy::AllocationStrategy::getAllocationCount ( ) const
virtualnoexceptinherited

Get the total number of active allocations by this allocator.

Returns
The total number of active allocations this object has allocated.

References umpire::strategy::AllocationStrategy::m_allocation_count.

Referenced by umpire::Allocator::getAllocationCount().

◆ getName()

◆ getStrategyName()

const std::string & umpire::strategy::AllocationStrategy::getStrategyName ( ) const
noexceptinherited

◆ getId()

int umpire::strategy::AllocationStrategy::getId ( )
noexceptinherited

◆ getParent()

AllocationStrategy * umpire::strategy::AllocationStrategy::getParent ( ) const
virtualnoexceptinherited

Traces where the allocator came from.

Returns
Pointer to the parent AllocationStrategy.

References umpire::strategy::AllocationStrategy::m_parent.

Referenced by umpire::ResourceManager::destroyAllocator(), umpire::Allocator::getParent(), and umpire::is_accessible().

◆ isTracked()

bool umpire::strategy::AllocationStrategy::isTracked ( ) const
noexceptinherited

◆ setTracking()

void umpire::strategy::AllocationStrategy::setTracking ( bool  tracking)
protectednoexceptinherited

Friends And Related Function Documentation

◆ umpire::get_resource

◆ umpire::get_num_pending

std::size_t umpire::get_num_pending ( Allocator  a)
friend

Member Data Documentation

◆ s_default_first_block_size

constexpr std::size_t umpire::strategy::ResourceAwarePool::s_default_first_block_size {512 * 1024 * 1024}
staticconstexpr

◆ s_default_next_block_size

constexpr std::size_t umpire::strategy::ResourceAwarePool::s_default_next_block_size {1 * 1024 * 1024}
staticconstexpr

◆ s_default_alignment

constexpr std::size_t umpire::strategy::ResourceAwarePool::s_default_alignment {16}
staticconstexpr

◆ m_current_size

◆ m_high_watermark

◆ m_allocation_count

◆ m_name

std::string umpire::strategy::AllocationStrategy::m_name
protectedinherited

◆ m_strategy_name

std::string umpire::strategy::AllocationStrategy::m_strategy_name
protectedinherited

◆ m_id

int umpire::strategy::AllocationStrategy::m_id
protectedinherited

◆ m_tracked

bool umpire::strategy::AllocationStrategy::m_tracked {true}
protectedinherited

◆ m_parent

AllocationStrategy* umpire::strategy::AllocationStrategy::m_parent
protectedinherited