rexlib 0.1.0
Device-agnostic array computing library for CryoEM and CryoET image processing, with a pluggable backend architecture
Loading...
Searching...
No Matches
Public Member Functions | List of all members
rexlib::program_cache Class Reference

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.
 

Detailed Description

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.

Thread safety
Individual calls to touch() and store() are atomic and may be issued concurrently from multiple threads. The compound touch-then-store sequence a builder performs on a miss is intentionally not atomic as a whole: because the cache stores functionally interchangeable resources, two threads racing on the same missing key may each build the resource and store it, with one replacing the other. This wastes a build but never corrupts the cache, and either stored value is equally valid.

Constructor & Destructor Documentation

◆ program_cache()

rexlib::program_cache::program_cache ( std::size_t  capacity)
explicitnoexcept

Construct a cache with the given capacity.

Parameters
capacityMaximum number of entries the cache may hold. Must be greater than zero.

Member Function Documentation

◆ get_capacity()

std::size_t rexlib::program_cache::get_capacity ( ) const
noexcept

Get the maximum number of entries this cache may hold.

Returns
std::size_t The capacity, in entries.

◆ store()

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.

Parameters
keyThe key under which the value is stored. The cache takes ownership. Must not be null.
valueThe value to store. Must not be null.
Exceptions
std::invalid_argumentWhen key or value is null.

◆ touch()

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.

Parameters
keyThe key to look up. Its dynamic type and value must match those of the key under which the entry was stored.
Returns
std::shared_ptr<void> The stored value, or nullptr if no entry is present.

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