use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ServerBaseline {
pub name: &'static str,
pub peak_tok_per_sec: u32,
pub p95_latency_ms: u32,
pub sm_utilization: u8,
pub memory_overhead: u8,
pub gpu: &'static str,
}
pub const VLLM_BASELINE: ServerBaseline = ServerBaseline {
name: "vLLM",
peak_tok_per_sec: 412,
p95_latency_ms: 1715,
sm_utilization: 99,
memory_overhead: 42,
gpu: "A10",
};
pub const TGI_BASELINE: ServerBaseline = ServerBaseline {
name: "TGI",
peak_tok_per_sec: 408,
p95_latency_ms: 1704,
sm_utilization: 98,
memory_overhead: 44,
gpu: "A10",
};
pub const TRITON_BASELINE: ServerBaseline = ServerBaseline {
name: "Triton",
peak_tok_per_sec: 385,
p95_latency_ms: 2007,
sm_utilization: 97,
memory_overhead: 45,
gpu: "A10",
};
pub const INDUSTRY_BASELINES: [ServerBaseline; 3] = [VLLM_BASELINE, TGI_BASELINE, TRITON_BASELINE];
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GpuClass {
A10,
A100,
H100,
Rtx4090,
Rtx3090,
Unknown,
}
struct GpuSpec {
label: &'static str,
throughput: (u32, u32),
vram_gb: u32,
}
const fn gpu_spec(class: &GpuClass) -> GpuSpec {
match class {
GpuClass::A10 => GpuSpec {
label: "A10 (24GB)",
throughput: (350, 450),
vram_gb: 24,
},
GpuClass::A100 => GpuSpec {
label: "A100 (40/80GB)",
throughput: (800, 1200),
vram_gb: 80, },
GpuClass::H100 => GpuSpec {
label: "H100 (80GB)",
throughput: (1800, 2400),
vram_gb: 80,
},
GpuClass::Rtx4090 => GpuSpec {
label: "RTX 4090 (24GB)",
throughput: (300, 400),
vram_gb: 24,
},
GpuClass::Rtx3090 => GpuSpec {
label: "RTX 3090 (24GB)",
throughput: (200, 300),
vram_gb: 24,
},
GpuClass::Unknown => GpuSpec {
label: "Unknown GPU",
throughput: (100, 500), vram_gb: 8,
},
}
}
impl GpuClass {
pub fn expected_throughput(&self) -> (u32, u32) {
gpu_spec(self).throughput
}
pub fn vram_gb(&self) -> u32 {
gpu_spec(self).vram_gb
}
pub fn from_name(name: &str) -> Self {
let name_lower = name.to_lowercase();
if name_lower.contains("h100") {
GpuClass::H100
} else if name_lower.contains("a100") {
GpuClass::A100
} else if name_lower.contains("a10") && !name_lower.contains("a100") {
GpuClass::A10
} else if name_lower.contains("4090") {
GpuClass::Rtx4090
} else if name_lower.contains("3090") {
GpuClass::Rtx3090
} else {
GpuClass::Unknown
}
}
}
impl fmt::Display for GpuClass {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", gpu_spec(self).label)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum ThroughputGrade {
F,
D,
C,
B,
A,
}
struct GradeSpec {
threshold: f64,
label: &'static str,
description: &'static str,
}
const GRADE_SPECS: [(ThroughputGrade, GradeSpec); 5] = [
(
ThroughputGrade::A,
GradeSpec {
threshold: 100.0,
label: "A",
description: "Excellent - meets or exceeds baseline",
},
),
(
ThroughputGrade::B,
GradeSpec {
threshold: 80.0,
label: "B",
description: "Good - 80%+ of baseline",
},
),
(
ThroughputGrade::C,
GradeSpec {
threshold: 60.0,
label: "C",
description: "Fair - 60%+ of baseline",
},
),
(
ThroughputGrade::D,
GradeSpec {
threshold: 40.0,
label: "D",
description: "Poor - 40%+ of baseline",
},
),
(
ThroughputGrade::F,
GradeSpec {
threshold: 0.0,
label: "F",
description: "Failing - below 40% of baseline",
},
),
];
fn grade_spec(grade: &ThroughputGrade) -> &'static GradeSpec {
&GRADE_SPECS
.iter()
.find(|(g, _)| g == grade)
.expect("all variants present in GRADE_SPECS")
.1
}
impl ThroughputGrade {
pub fn from_percentage(percentage: f64) -> Self {
GRADE_SPECS
.iter()
.find(|(_, spec)| percentage >= spec.threshold)
.map(|(grade, _)| *grade)
.unwrap_or(ThroughputGrade::F)
}
pub fn threshold(&self) -> f64 {
grade_spec(self).threshold
}
}
impl fmt::Display for ThroughputGrade {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let spec = grade_spec(self);
write!(f, "{} ({})", spec.label, spec.description)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SmHealth {
Saturated,
Optimal,
Moderate,
Critical,
}
struct SmHealthSpec {
min_util: u8,
exclusive: bool,
label: &'static str,
}
const SM_HEALTH_SPECS: [(SmHealth, SmHealthSpec); 4] = [
(
SmHealth::Saturated,
SmHealthSpec {
min_util: 95,
exclusive: true,
label: "SATURATED (>95%)",
},
),
(
SmHealth::Optimal,
SmHealthSpec {
min_util: 80,
exclusive: false,
label: "OPTIMAL (80-95%)",
},
),
(
SmHealth::Moderate,
SmHealthSpec {
min_util: 50,
exclusive: false,
label: "MODERATE (50-80%)",
},
),
(
SmHealth::Critical,
SmHealthSpec {
min_util: 0,
exclusive: false,
label: "CRITICAL (<50%)",
},
),
];
fn sm_health_spec(health: &SmHealth) -> &'static SmHealthSpec {
&SM_HEALTH_SPECS
.iter()
.find(|(h, _)| h == health)
.expect("all variants present in SM_HEALTH_SPECS")
.1
}
impl SmHealth {
pub fn from_utilization(sm_util: u8) -> Self {
SM_HEALTH_SPECS
.iter()
.find(|(_, spec)| {
if spec.exclusive {
sm_util > spec.min_util
} else {
sm_util >= spec.min_util
}
})
.map(|(health, _)| *health)
.unwrap_or(SmHealth::Critical)
}
pub fn is_acceptable(&self) -> bool {
matches!(self, SmHealth::Optimal | SmHealth::Saturated)
}
}
impl fmt::Display for SmHealth {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", sm_health_spec(self).label)
}
}
#[derive(Debug, Clone)]
pub struct SingleComparison {
pub baseline: ServerBaseline,
pub percentage: f64,
pub delta_tok_per_sec: i32,
}