use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct GpuInfo {
pub name: String,
pub vram_bytes: u64,
pub compute_capability: Option<(u32, u32)>,
pub index: u32,
}
impl GpuInfo {
pub fn new(name: impl Into<String>, vram_bytes: u64) -> Self {
Self { name: name.into(), vram_bytes, compute_capability: None, index: 0 }
}
pub fn with_compute_capability(mut self, major: u32, minor: u32) -> Self {
self.compute_capability = Some((major, minor));
self
}
pub fn with_index(mut self, index: u32) -> Self {
self.index = index;
self
}
pub fn supports_compute_capability(&self, major: u32, minor: u32) -> bool {
self.compute_capability.is_some_and(|(m, n)| m > major || (m == major && n >= minor))
}
pub fn vram_gb(&self) -> f64 {
self.vram_bytes as f64 / (1024.0 * 1024.0 * 1024.0)
}
}