|
rexlib 0.1.0
Device-agnostic array computing library for CryoEM and CryoET image processing, with a pluggable backend architecture
|
Bounded associative store for backend-private resources reused across operation program builds. More...
#include <rexlib/core/dispatch/program_cache.hpp>
Public Member Functions | |
| program_cache (std::size_t capacity) noexcept | |
| Construct a cache with the given capacity. | |
| program_cache (const program_cache &other)=delete | |
| program_cache (program_cache &&other)=delete | |
| program_cache & | operator= (const program_cache &other)=delete |
| program_cache & | operator= (program_cache &&other)=delete |
| std::size_t | get_capacity () const noexcept |
| Get the maximum number of entries this cache may hold. | |
| std::shared_ptr< void > | touch (const program_cache_key &key) |
| Look up a previously stored value and grant it amnesty. | |
| void | store (std::unique_ptr< const program_cache_key > key, std::shared_ptr< void > value) |
| Store a value under the given key, replacing any existing entry under a key of the same dynamic type and value. May evict another entry when the cache is at capacity. | |
Bounded associative store for backend-private resources reused across operation program builds.
The cache behaves as a typed key/value bag: each builder defines its own key type and stores its own backend-specific resources (FFT plans, compiled kernels, ...). Entries are partitioned by the static type of the key, so unrelated builders never collide even if their key layouts happen to coincide.
The cache holds at most a fixed number of entries set at construction; once that bound is reached, inserting a new entry evicts the oldest one. Eviction order is shared across all key types: a hot inner bucket may evict entries from a cold one.
|
explicitnoexcept |
Construct a cache with the given capacity.
| capacity | Maximum number of entries the cache may hold. Must be greater than zero. |
|
noexcept |
Get the maximum number of entries this cache may hold.
| void rexlib::program_cache::store | ( | std::unique_ptr< const program_cache_key > | key, |
| std::shared_ptr< void > | value | ||
| ) |
Store a value under the given key, replacing any existing entry under a key of the same dynamic type and value. May evict another entry when the cache is at capacity.
The newly stored or replaced entry is placed at the lowest eviction priority.
| key | The key under which the value is stored. The cache takes ownership. Must not be null. |
| value | The value to store. Must not be null. |
| std::invalid_argument | When key or value is null. |
| std::shared_ptr< void > rexlib::program_cache::touch | ( | const program_cache_key & | key | ) |
Look up a previously stored value and grant it amnesty.
Lookup is partitioned by the dynamic type of key, so entries stored under keys of a different dynamic type are never considered. On a hit, the entry is promoted to the lowest eviction priority, so recently touched entries are the last to be evicted.
| key | The key to look up. Its dynamic type and value must match those of the key under which the entry was stored. |