mod cpu;
mod types;
pub use cpu::*;
pub use types::*;
use crate::GpuError;
pub trait ComputeDevice: Send + Sync {
fn device_id(&self) -> DeviceId;
fn device_name(&self) -> &str;
fn device_type(&self) -> DeviceType;
fn compute_utilization(&self) -> Result<f64, GpuError>;
fn compute_clock_mhz(&self) -> Result<u32, GpuError>;
fn compute_temperature_c(&self) -> Result<f64, GpuError>;
fn compute_power_watts(&self) -> Result<f64, GpuError>;
fn compute_power_limit_watts(&self) -> Result<f64, GpuError>;
fn memory_used_bytes(&self) -> Result<u64, GpuError>;
fn memory_total_bytes(&self) -> Result<u64, GpuError>;
fn memory_bandwidth_gbps(&self) -> Result<f64, GpuError>;
fn compute_unit_count(&self) -> u32;
fn active_compute_units(&self) -> Result<u32, GpuError>;
fn pcie_tx_bytes_per_sec(&self) -> Result<u64, GpuError>;
fn pcie_rx_bytes_per_sec(&self) -> Result<u64, GpuError>;
fn pcie_generation(&self) -> u8;
fn pcie_width(&self) -> u8;
fn refresh(&mut self) -> Result<(), GpuError>;
fn memory_usage_percent(&self) -> Result<f64, GpuError> {
let used = self.memory_used_bytes()?;
let total = self.memory_total_bytes()?;
if total == 0 {
return Ok(0.0);
}
Ok((used as f64 / total as f64) * 100.0)
}
fn memory_available_bytes(&self) -> Result<u64, GpuError> {
let used = self.memory_used_bytes()?;
let total = self.memory_total_bytes()?;
Ok(total.saturating_sub(used))
}
fn memory_used_mb(&self) -> Result<u64, GpuError> {
Ok(self.memory_used_bytes()? / (1024 * 1024))
}
fn memory_total_mb(&self) -> Result<u64, GpuError> {
Ok(self.memory_total_bytes()? / (1024 * 1024))
}
fn memory_total_gb(&self) -> Result<f64, GpuError> {
Ok(self.memory_total_bytes()? as f64 / (1024.0 * 1024.0 * 1024.0))
}
fn power_usage_percent(&self) -> Result<f64, GpuError> {
let current = self.compute_power_watts()?;
let limit = self.compute_power_limit_watts()?;
if limit == 0.0 {
return Ok(0.0);
}
Ok((current / limit) * 100.0)
}
fn is_thermal_throttling(&self) -> Result<bool, GpuError> {
let temp = self.compute_temperature_c()?;
Ok(temp > 80.0)
}
fn is_power_throttling(&self) -> Result<bool, GpuError> {
let percent = self.power_usage_percent()?;
Ok(percent > 95.0)
}
}
#[cfg(test)]
mod tests_core;
#[cfg(test)]
mod tests_coverage;
#[cfg(test)]
mod tests_error_propagation;