Entropic 2.14.3
Local-first agentic inference engine
Loading...
Searching...
No Matches
batch_kv_util.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
29#pragma once
30
31#include <cstddef>
32#include <vector>
33
34namespace entropic {
35
42 std::vector<int> seq_ids;
43
50 bool clears_whole_cache = false;
51};
52
69inline BatchKvPlan plan_batch_kv(std::size_t n, int session_slots,
70 const std::vector<int>& temp_ids) {
73 plan.seq_ids.reserve(n);
74 const int floor_id = session_slots < 1 ? 1 : session_slots;
75 for (std::size_t i = 0; i < n && i < temp_ids.size(); ++i) {
76 // Defence in depth: a temp pool whose base was never raised past the
77 // session slots would otherwise hand back a session's sequence. The
78 // configure-time exclusion in session_pool_util.h makes that
79 // unreachable today; this makes it unreachable by construction.
80 plan.seq_ids.push_back(
81 temp_ids[i] < floor_id ? floor_id + static_cast<int>(i)
82 : temp_ids[i]);
83 }
84 return plan;
85}
86
101 int session_slots) {
102 if (plan.clears_whole_cache) { return true; }
103 bool disturbs = false;
104 for (int id : plan.seq_ids) {
105 if (id < session_slots) { disturbs = true; }
106 }
107 return disturbs;
108}
109
110} // namespace entropic
Activate model on GPU (WARM → ACTIVE).
@ optional
optional: every escape asks the host's path approver
bool plan_disturbs_sessions(const BatchKvPlan &plan, int session_slots)
Whether a plan can disturb any session's resident KV.
BatchKvPlan plan_batch_kv(std::size_t n, int session_slots, const std::vector< int > &temp_ids)
Plan the sequence ids a same-prefix batch may use.
Which sequences a batch will write, and what it may clear.
std::vector< int > seq_ids
Sequence ids the batch will write, one per request.
bool clears_whole_cache
Whether the batch may clear the WHOLE KV cache.