liblloyal 1.0.0
Branched Inference for llama.cpp
Loading...
Searching...
No Matches
lloyal::kv::tenancy Namespace Reference

Classes

struct  State
 Tenancy state — tracks seq_id vacancy and leases. More...
 

Functions

State init (llama_context *ctx, llama_seq_id n_seq_max)
 Initialize tenancy with all seq_ids vacant.
 
llama_seq_id acquire (State &s)
 Acquire a seq_id from the vacant pool.
 
void release (State &s, llama_seq_id seq)
 Release a seq_id back to vacant — bookkeeping only, no KV calls.
 
void evict (State &s, llama_seq_id seq)
 Evict a seq_id — strip all KV tags then release.
 
void retain (State &s, llama_seq_id keep)
 Nuclear retain — keep one seq, rebuild vacancy from scratch.
 
void evict_all (State &s)
 Evict every leased seq_id.
 
size_t available (const State &s)
 Number of vacant seq_ids available for acquisition.
 

Function Documentation

◆ acquire()

llama_seq_id lloyal::kv::tenancy::acquire ( State s)
inline

Acquire a seq_id from the vacant pool.

Pops one seq_id from the LIFO stack and marks it as leased. The caller is responsible for eventually calling release() or evict() to return the lease.

Parameters
sTenancy state
Returns
Acquired seq_id, or NO_LEASE (-1) if the pool is exhausted
Examples
/home/runner/work/liblloyal/liblloyal/include/lloyal/branch.hpp, and /home/runner/work/liblloyal/liblloyal/include/lloyal/kv.hpp.

Definition at line 255 of file kv.hpp.

◆ available()

size_t lloyal::kv::tenancy::available ( const State s)
inline

Number of vacant seq_ids available for acquisition.

Parameters
sTenancy state
Returns
Count of seq_ids in the vacant pool
Examples
/home/runner/work/liblloyal/liblloyal/include/lloyal/branch.hpp, and /home/runner/work/liblloyal/liblloyal/include/lloyal/kv.hpp.

Definition at line 364 of file kv.hpp.

◆ evict()

void lloyal::kv::tenancy::evict ( State s,
llama_seq_id  seq 
)
inline

Evict a seq_id — strip all KV tags then release.

Used when the seq had actual KV residency (tokens were decoded into it). Calls remove_range() to strip all tags before returning the seq to the vacant pool, preserving the "vacant ⇒ clean" invariant.

Parameters
sTenancy state
seqSeq_id to evict (must be currently leased)
Precondition
seq is in range [0, n_seq_max) and is currently leased
Warning
Must be called while ctx is still alive (before llama_free). BranchStore::drain() ensures this ordering.
Examples
/home/runner/work/liblloyal/liblloyal/include/lloyal/branch.hpp, and /home/runner/work/liblloyal/liblloyal/include/lloyal/kv.hpp.

Definition at line 296 of file kv.hpp.

◆ evict_all()

void lloyal::kv::tenancy::evict_all ( State s)
inline

Evict every leased seq_id.

Iterates all seq_ids and evicts any that are currently leased. Used by BranchStore::drain() before context teardown.

Parameters
sTenancy state
Warning
Must be called while ctx is still alive.
Examples
/home/runner/work/liblloyal/liblloyal/include/lloyal/branch.hpp, and /home/runner/work/liblloyal/liblloyal/include/lloyal/kv.hpp.

Definition at line 350 of file kv.hpp.

◆ init()

State lloyal::kv::tenancy::init ( llama_context *  ctx,
llama_seq_id  n_seq_max 
)
inline

Initialize tenancy with all seq_ids vacant.

Fills the vacant stack in reverse order so that seq 0 is acquired first (LIFO pop from back). Safe for n_seq_max == 0 (produces empty state).

Parameters
ctxLlama context for KV operations
n_seq_maxTotal number of seq_ids (from llama_n_seq_max)
Returns
Initialized tenancy state with all seq_ids vacant
Examples
/home/runner/work/liblloyal/liblloyal/include/lloyal/branch.hpp, and /home/runner/work/liblloyal/liblloyal/include/lloyal/kv.hpp.

Definition at line 233 of file kv.hpp.

◆ release()

void lloyal::kv::tenancy::release ( State s,
llama_seq_id  seq 
)
inline

Release a seq_id back to vacant — bookkeeping only, no KV calls.

Used when a seq was acquired but never written to (e.g. slot allocation failure rollback). The seq must already be clean (no KV tags).

Parameters
sTenancy state
seqSeq_id to release (must be currently leased)
Precondition
seq is in range [0, n_seq_max) and is currently leased
Examples
/home/runner/work/liblloyal/liblloyal/include/lloyal/branch.hpp, and /home/runner/work/liblloyal/liblloyal/include/lloyal/kv.hpp.

Definition at line 274 of file kv.hpp.

◆ retain()

void lloyal::kv::tenancy::retain ( State s,
llama_seq_id  keep 
)
inline

Nuclear retain — keep one seq, rebuild vacancy from scratch.

Calls seq_keep() for a single KV pass that strips all tags except the keeper, then rebuilds the lease bitmap and vacant pool. O(n_seq_max).

Used by BranchStore::retainOnly() to promote a winner after search.

Parameters
sTenancy state
keepSeq_id to retain (must be currently leased)
Precondition
keep is in range [0, n_seq_max) and is currently leased
Note
In debug builds, verifies that seq_keep actually stripped all non-keep seqs (catches backend bugs via pos_max assertions).
Examples
/home/runner/work/liblloyal/liblloyal/include/lloyal/branch.hpp, and /home/runner/work/liblloyal/liblloyal/include/lloyal/kv.hpp.

Definition at line 319 of file kv.hpp.