metrale_scheduler/
device.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! 2026-09-25: [`DeviceIo`], the model-facing router: the core launches
4//! [`StepPlan`]s and applies [`Effect`]s, and the router decides how they
5//! reach the device.
6//!
7//! Owner: scheduler.
8//! Invariants: none beyond the types.
9
10use crate::effect::{Effect, EffectOutcome};
11use crate::plan::{StepPlan, StepResult};
12use crate::types::{DeviceError, DeviceFacts, Ticket};
13
14pub trait DeviceIo: Send {
15    /// 2026-09-25: The per-sequence device bookkeeping the plans and effects mutate.
16    type Seq;
17    /// 2026-09-25: The device's logits handle.
18    type Ptr: Copy + Send;
19    /// 2026-09-25: The model behind this router, returned by [`Self::model`] for
20    /// calls that go around plans and effects.
21    type Model: ?Sized;
22    /// 2026-09-25: A LoRA control command and its acknowledgement.
23    type LoraCmd;
24    type LoraAck;
25
26    fn model(&self) -> &Self::Model;
27    /// 2026-09-25: The KV pool and SSM snapshot counters ([`DeviceFacts`]).
28    fn facts(&self) -> DeviceFacts;
29    /// 2026-09-25: How many steps may be in flight (1 = every step settles before the
30    /// next launches).
31    fn max_depth(&self) -> usize;
32    /// 2026-09-25: Start `plan` over `rows`; settle it with [`Self::await_result`].
33    fn launch(
34        &self,
35        plan: StepPlan<'_>,
36        rows: &mut [&mut Self::Seq],
37    ) -> Result<Ticket, DeviceError>;
38    fn await_result(&self, ticket: Ticket) -> Result<StepResult<Self::Ptr>, DeviceError>;
39    fn apply(&self, effect: Effect<'_, Self::Seq, Self::Ptr>)
40    -> Result<EffectOutcome, DeviceError>;
41    /// 2026-09-25: A LoRA control command, applied at quiescence (the model mutates its
42    /// adapter table, hence the exclusive borrow).
43    fn lora(&mut self, cmd: Self::LoraCmd) -> Result<Self::LoraAck, String>;
44    /// 2026-09-25: Release the model's device memory. Consumes the router.
45    fn teardown(self: Box<Self>) -> anyhow::Result<()>;
46}