entrenar/efficiency/device/
gpu.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7pub struct GpuInfo {
8 pub name: String,
10 pub vram_bytes: u64,
12 pub compute_capability: Option<(u32, u32)>,
14 pub index: u32,
16}
17
18impl GpuInfo {
19 pub fn new(name: impl Into<String>, vram_bytes: u64) -> Self {
21 Self { name: name.into(), vram_bytes, compute_capability: None, index: 0 }
22 }
23
24 pub fn with_compute_capability(mut self, major: u32, minor: u32) -> Self {
26 self.compute_capability = Some((major, minor));
27 self
28 }
29
30 pub fn with_index(mut self, index: u32) -> Self {
32 self.index = index;
33 self
34 }
35
36 pub fn supports_compute_capability(&self, major: u32, minor: u32) -> bool {
38 self.compute_capability.is_some_and(|(m, n)| m > major || (m == major && n >= minor))
39 }
40
41 pub fn vram_gb(&self) -> f64 {
43 self.vram_bytes as f64 / (1024.0 * 1024.0 * 1024.0)
44 }
45}