use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub enum Priority {
Background = 0,
Low = 1,
Normal = 2,
High = 3,
Critical = 4,
}
impl Default for Priority {
fn default() -> Self {
Self::Normal
}
}
impl Priority {
pub fn can_preempt(self, other: Self) -> bool {
self as u8 > other as u8 + 1
}
pub fn quality_multiplier(self) -> f32 {
match self {
Self::Background => 0.6,
Self::Low => 0.8,
Self::Normal => 1.0,
Self::High => 1.1,
Self::Critical => 1.2,
}
}
pub fn timeout_multiplier(self) -> f32 {
match self {
Self::Background => 0.5,
Self::Low => 0.75,
Self::Normal => 1.0,
Self::High => 1.5,
Self::Critical => 2.0,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum WorkloadType {
LlmInference,
ImageGeneration,
VideoGeneration,
}
impl WorkloadType {
pub fn min_quality(self) -> f32 {
match self {
Self::LlmInference => 0.4, Self::ImageGeneration => 0.3, Self::VideoGeneration => 0.25, }
}
pub fn target_quality(self) -> f32 {
match self {
Self::LlmInference => 1.0,
Self::ImageGeneration => 1.0,
Self::VideoGeneration => 1.0,
}
}
pub fn typical_memory_mb(self) -> u64 {
match self {
Self::LlmInference => 8 * 1024, Self::ImageGeneration => 6 * 1024, Self::VideoGeneration => 12 * 1024, }
}
pub fn is_streaming(self) -> bool {
match self {
Self::LlmInference => true, Self::ImageGeneration => false, Self::VideoGeneration => true, }
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_priority_ordering() {
assert!(Priority::Critical > Priority::High);
assert!(Priority::High > Priority::Normal);
assert!(Priority::Normal > Priority::Low);
assert!(Priority::Low > Priority::Background);
}
#[test]
fn test_preemption() {
assert!(Priority::Critical.can_preempt(Priority::Normal));
assert!(Priority::Critical.can_preempt(Priority::Low));
assert!(!Priority::High.can_preempt(Priority::Normal));
assert!(!Priority::Normal.can_preempt(Priority::Normal));
}
#[test]
fn test_quality_multipliers() {
assert!(Priority::Critical.quality_multiplier() > Priority::Normal.quality_multiplier());
assert!(Priority::Normal.quality_multiplier() > Priority::Background.quality_multiplier());
}
#[test]
fn test_workload_min_quality() {
assert!(
WorkloadType::LlmInference.min_quality() > WorkloadType::VideoGeneration.min_quality()
);
}
}