pub mod async_device;
pub mod no_device;
pub mod request;
pub mod spill;
pub mod sync_device;
pub mod telemetry;
#[cfg(test)]
mod tests;
use metrale_gpu_runtime::gpu::DevicePtr;
use metrale_model_engine::traits::{Model, SequenceState};
pub use async_device::AsyncDeviceIo;
#[cfg(test)]
pub use metrale_scheduler::TracingDeviceIo;
pub use metrale_scheduler::{
ClockIo, DecodeCtxCommit, DecodeRows, DeviceError, DeviceIo, EffectOutcome, Label, Readback,
SpillIo, SystemClock, WaitPolicy,
};
pub use no_device::NoDeviceIo;
pub use request::{Arrivals, FinishFrame, RequestIo, TokioRequestIo};
pub use spill::FileSpill;
pub use sync_device::SyncDeviceIo;
pub use telemetry::{SysTelemetry, TelemetryIo};
use crate::scheduler::{LoraAck, LoraCommand};
pub type StepPlan<'a> = metrale_scheduler::StepPlan<'a>;
pub type StepOutcome = metrale_scheduler::StepOutcome<DevicePtr>;
pub type StepResult = metrale_scheduler::StepResult<DevicePtr>;
pub type Effect<'a> = metrale_scheduler::Effect<'a, SequenceState, DevicePtr>;
pub type DynDevice = dyn DeviceIo<
Seq = SequenceState,
Ptr = DevicePtr,
Model = dyn Model + 'static,
LoraCmd = LoraCommand,
LoraAck = LoraAck,
>;
impl Label for LoraCommand {
fn label(&self) -> String {
match self {
LoraCommand::Rotate(name) => format!("Rotate({name})"),
LoraCommand::LoadIntoSlot { name, slot, .. } => format!("LoadIntoSlot({name}, {slot})"),
LoraCommand::Promote { name, .. } => format!("Promote({name})"),
LoraCommand::PromoteDisk { name, .. } => format!("PromoteDisk({name})"),
}
}
}
pub struct SchedIo {
pub dev: Box<DynDevice>,
pub clock: Box<dyn ClockIo>,
pub tel: std::sync::Arc<dyn TelemetryIo>,
pub req: std::sync::Arc<dyn RequestIo>,
pub spill: Option<Box<dyn SpillIo>>,
}
impl SchedIo {
pub fn serving(
dev: Box<DynDevice>,
telemetry: &'static metrale_telemetry::Telemetry,
snapshot: std::sync::Arc<metrale_speculative::snapshot::SnapshotCell>,
req: std::sync::Arc<dyn RequestIo>,
spill: Option<Box<dyn SpillIo>>,
) -> Self {
Self {
dev,
clock: Box::new(SystemClock),
tel: std::sync::Arc::new(SysTelemetry::from_env(telemetry, snapshot)),
req,
spill,
}
}
pub fn for_test() -> Self {
Self::for_test_with_device(Box::new(NoDeviceIo))
}
pub fn for_test_with(model: std::sync::Arc<dyn Model>) -> Self {
Self::for_test_with_device(Box::new(SyncDeviceIo::new(model)))
}
fn for_test_with_device(dev: Box<DynDevice>) -> Self {
Self {
dev,
clock: Box::new(SystemClock),
tel: std::sync::Arc::new(SysTelemetry::quiet(std::sync::Arc::new(
metrale_speculative::snapshot::SnapshotCell::default(),
))),
req: std::sync::Arc::new(TokioRequestIo::closed()),
spill: None,
}
}
}