Skip to main content

qualia_core_db/inference/runtime/prepared/
decode_plan.rs

1use super::PreparedPlanState;
2use crate::inference::runtime::receipt::ExecutionCounters;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum PreparedBackend {
6    Wgpu,
7    Cuda,
8    Metal,
9    Cpu,
10}
11
12#[derive(Debug)]
13pub enum DecodeStepError {
14    NotReady(PreparedPlanState),
15    InvalidInput,
16    BackendFailure,
17}
18
19#[derive(Debug)]
20pub struct DecodeStepInput<'a> {
21    pub token_position: u32,
22    pub token_id: u32,
23    pub hidden: &'a mut [f32],
24    pub kv_page_table: &'a [u32],
25}
26
27#[derive(Debug, Clone, Copy, Default, PartialEq)]
28pub struct DecodeStepOutput {
29    pub token_id: u32,
30    pub score: f32,
31}
32
33/// Tier-1 execution contract for an already prepared model/backend pair.
34pub trait PreparedDecodePlan {
35    fn backend(&self) -> PreparedBackend;
36    fn state(&self) -> PreparedPlanState;
37    fn counters(&self) -> ExecutionCounters;
38
39    /// Execute one autoregressive step.
40    ///
41    /// Implementations must not allocate, compile, discover tensors, upload immutable data, or
42    /// select another backend. A failure is returned to the owner, which records any explicit
43    /// fallback outside this call.
44    fn run_decode_step(
45        &mut self,
46        input: DecodeStepInput<'_>,
47        output: &mut DecodeStepOutput,
48    ) -> Result<(), DecodeStepError>;
49}