#include <caching_allocator.hpp>
|
| 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
|
| |
|
| 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%.
|
| |
◆ RawAlloc
throws std::bad_alloc on failure
◆ RawFree
◆ Synchronize
waits until queued device work is done
◆ CachingAllocator() [1/2]
| pulsatrix::CachingAllocator::CachingAllocator |
( |
RawAlloc |
raw_alloc, |
|
|
RawFree |
raw_free, |
|
|
Synchronize |
synchronize, |
|
|
size_t |
budget_bytes = 0 |
|
) |
| |
- Parameters
-
| budget_bytes | Most 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]
◆ 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_alloc | if 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=()
◆ 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: