pulsatrix 1.1.0
Loading...
Searching...
No Matches
pulsatrix::CachingAllocator Class Reference

#include <caching_allocator.hpp>

Classes

struct  Stats
 

Public Types

using RawAlloc = std::function< void *(size_t bytes)>
 throws std::bad_alloc on failure
 
using RawFree = std::function< void(void *ptr)>
 
using Synchronize = std::function< void()>
 waits until queued device work is done
 

Public Member Functions

 CachingAllocator (RawAlloc raw_alloc, RawFree raw_free, Synchronize synchronize, size_t budget_bytes=0)
 
 ~CachingAllocator ()
 Synchronizes, then returns every block to the device, cached or still in use.
 
 CachingAllocator (const CachingAllocator &)=delete
 
CachingAllocator & operator= (const CachingAllocator &)=delete
 
void * allocate (size_t bytes)
 A block of at least bytes, reused from the cache when one of its size class is free.
 
void free (void *ptr) noexcept
 Returns a block to the cache. nullptr is ignored.
 
void empty_cache ()
 Synchronizes, then returns every cached block to the device.
 
void set_budget (size_t budget_bytes)
 Changes the budget (0: unlimited). Takes effect at the next allocation.
 
Stats stats () const
 

Static Public Member Functions

static size_t round_size (size_t bytes)
 The size class: 512-byte steps below 1 MiB, then steps of an eighth of the power of two below the size, so rounding wastes at most 12.5%.
 

Member Typedef Documentation

◆ RawAlloc

using pulsatrix::CachingAllocator::RawAlloc = std::function<void*(size_t bytes)>

throws std::bad_alloc on failure

◆ RawFree

using pulsatrix::CachingAllocator::RawFree = std::function<void(void* ptr)>

◆ Synchronize

using pulsatrix::CachingAllocator::Synchronize = std::function<void()>

waits until queued device work is done

Constructor & Destructor Documentation

◆ CachingAllocator() [1/2]

pulsatrix::CachingAllocator::CachingAllocator ( RawAlloc  raw_alloc,
RawFree  raw_free,
Synchronize  synchronize,
size_t  budget_bytes = 0 
)
Parameters
budget_bytesMost memory to hold, in use plus cached; 0 means no limit beyond what the device grants. A configured budget replaces asking the driver, which on APUs reports more memory than can actually be allocated.

◆ ~CachingAllocator()

pulsatrix::CachingAllocator::~CachingAllocator ( )

Synchronizes, then returns every block to the device, cached or still in use.

◆ CachingAllocator() [2/2]

pulsatrix::CachingAllocator::CachingAllocator ( const CachingAllocator &  )
delete

Member Function Documentation

◆ allocate()

void * pulsatrix::CachingAllocator::allocate ( size_t  bytes)

A block of at least bytes, reused from the cache when one of its size class is free.

Returns
nullptr for 0 bytes.
Exceptions
std::bad_allocif the request doesn't fit the budget even with the cache released, or the device refuses it twice, once more after the cache was released.

◆ empty_cache()

void pulsatrix::CachingAllocator::empty_cache ( )

Synchronizes, then returns every cached block to the device.

◆ free()

void pulsatrix::CachingAllocator::free ( void *  ptr)
noexcept

Returns a block to the cache. nullptr is ignored.

◆ operator=()

CachingAllocator & pulsatrix::CachingAllocator::operator= ( const CachingAllocator &  )
delete

◆ round_size()

static size_t pulsatrix::CachingAllocator::round_size ( size_t  bytes)
static

The size class: 512-byte steps below 1 MiB, then steps of an eighth of the power of two below the size, so rounding wastes at most 12.5%.

◆ set_budget()

void pulsatrix::CachingAllocator::set_budget ( size_t  budget_bytes)

Changes the budget (0: unlimited). Takes effect at the next allocation.

◆ stats()

Stats pulsatrix::CachingAllocator::stats ( ) const

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