Skip to main content

trueno/monitor/
compute_device.rs

1#![allow(missing_docs)]
2//! Unified Compute Device Abstraction (TRUENO-SPEC-020)
3
4/// Device identification
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6pub struct DeviceId(pub u32);
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum DeviceType {
10    Cpu,
11    NvidiaGpu,
12    AmdGpu,
13    IntelGpu,
14    AppleSilicon,
15    Hpu, // Hardware Processing Unit (e.g., Gaudi, TPU)
16}
17
18/// Unified compute device abstraction (TRUENO-SPEC-020)
19pub trait ComputeDevice: Send + Sync {
20    /// Device identification
21    fn device_id(&self) -> DeviceId;
22    fn device_name(&self) -> &str;
23    fn device_type(&self) -> DeviceType;
24
25    /// Compute metrics
26    fn compute_utilization(&self) -> anyhow::Result<f64>; // 0.0-100.0%
27    fn compute_clock_mhz(&self) -> anyhow::Result<u32>;
28    fn compute_temperature_c(&self) -> anyhow::Result<f64>;
29    fn compute_power_watts(&self) -> anyhow::Result<f64>;
30    fn compute_power_limit_watts(&self) -> anyhow::Result<f64>;
31
32    /// Memory metrics
33    fn memory_used_bytes(&self) -> anyhow::Result<u64>;
34    fn memory_total_bytes(&self) -> anyhow::Result<u64>;
35    fn memory_bandwidth_gbps(&self) -> anyhow::Result<f64>;
36
37    /// Streaming multiprocessor / Compute Unit metrics
38    fn sm_count(&self) -> u32;
39    fn active_sm_count(&self) -> anyhow::Result<u32>;
40
41    /// PCIe / Interconnect metrics
42    fn pcie_tx_bytes_per_sec(&self) -> anyhow::Result<u64>;
43    fn pcie_rx_bytes_per_sec(&self) -> anyhow::Result<u64>;
44    fn pcie_generation(&self) -> u8;
45    fn pcie_width(&self) -> u8;
46}