use crate::device::{
platform_detection::{
get_os_type, has_furiosa, has_gaudi, has_nvidia, has_rebellions, is_jetson,
},
readers::{furiosa, gaudi, nvidia, nvidia_jetson, rebellions},
traits::{CpuReader, GpuReader, MemoryReader},
};
#[cfg(target_os = "linux")]
use crate::device::platform_detection::{has_google_tpu, has_tenstorrent};
#[cfg(target_os = "linux")]
use crate::device::readers::{google_tpu, tenstorrent};
#[cfg(target_os = "macos")]
use crate::device::{cpu_macos, memory_macos, platform_detection::is_apple_silicon};
#[cfg(target_os = "macos")]
use crate::device::readers::apple_silicon_native;
#[cfg(target_os = "linux")]
use crate::device::{cpu_linux, memory_linux};
#[cfg(target_os = "windows")]
use crate::device::{cpu_windows, memory_windows};
#[cfg(target_os = "windows")]
use crate::device::readers::amd_windows;
#[cfg(target_os = "linux")]
use crate::device::readers::intel_gpu_linux;
#[cfg(target_os = "windows")]
use crate::device::readers::intel_gpu_windows;
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
use crate::device::platform_detection::has_amd;
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
use crate::device::readers::amd;
pub fn get_gpu_readers() -> Vec<Box<dyn GpuReader>> {
let mut readers: Vec<Box<dyn GpuReader>> = Vec::new();
if std::env::var("SKIP_GPU_DETECTION").is_ok() || std::env::var("NO_GPU").is_ok() {
eprintln!("GPU detection skipped (SKIP_GPU_DETECTION or NO_GPU environment variable set)");
return readers;
}
let os_type = get_os_type();
match os_type {
"linux" => {
if is_jetson() && has_nvidia() {
readers.push(Box::new(nvidia_jetson::NvidiaJetsonGpuReader::new()));
} else if has_nvidia() && !is_jetson() {
readers.push(Box::new(nvidia::NvidiaGpuReader::new()));
}
if has_furiosa() {
readers.push(Box::new(furiosa::FuriosaNpuReader::new()));
}
#[cfg(target_os = "linux")]
if has_tenstorrent() {
readers.push(Box::new(tenstorrent::TenstorrentReader::new()));
}
if has_rebellions() {
readers.push(Box::new(rebellions::RebellionsNpuReader::new()));
}
if has_gaudi() {
readers.push(Box::new(gaudi::GaudiNpuReader::new()));
}
#[cfg(target_os = "linux")]
if has_google_tpu() {
readers.push(Box::new(google_tpu::GoogleTpuReader::new()));
}
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
if has_amd() {
match amd::AmdGpuReader::try_new() {
Ok(reader) => readers.push(Box::new(reader)),
Err(error) => eprintln!("AMD backend unavailable: {error}"),
}
}
#[cfg(target_os = "linux")]
if crate::device::has_intel_gpu() {
readers.push(Box::new(intel_gpu_linux::IntelGpuReader::new()));
}
}
"macos" => {
#[cfg(target_os = "macos")]
if is_apple_silicon() {
readers.push(Box::new(
apple_silicon_native::AppleSiliconNativeGpuReader::new(),
));
}
}
"windows" => {
#[cfg(target_os = "windows")]
{
if has_nvidia() {
readers.push(Box::new(nvidia::NvidiaGpuReader::new()));
}
if amd_windows::has_amd_gpu_windows() {
readers.push(Box::new(amd_windows::AmdWindowsGpuReader::new()));
}
if intel_gpu_windows::has_intel_gpu_windows() {
readers.push(Box::new(intel_gpu_windows::IntelWindowsGpuReader::new()));
}
}
}
_ => println!("Unsupported OS type: {os_type}"),
}
readers
}
#[allow(unused_mut)]
pub fn get_cpu_readers() -> Vec<Box<dyn CpuReader>> {
let mut readers: Vec<Box<dyn CpuReader>> = Vec::new();
let os_type = get_os_type();
match os_type {
"linux" => {
#[cfg(target_os = "linux")]
readers.push(Box::new(cpu_linux::LinuxCpuReader::new()));
}
"macos" => {
#[cfg(target_os = "macos")]
readers.push(Box::new(cpu_macos::MacOsCpuReader::new()));
}
"windows" => {
#[cfg(target_os = "windows")]
readers.push(Box::new(cpu_windows::WindowsCpuReader::new()));
}
_ => println!("CPU monitoring not supported for OS type: {os_type}"),
}
readers
}
#[allow(unused_mut)]
pub fn get_memory_readers() -> Vec<Box<dyn MemoryReader>> {
let mut readers: Vec<Box<dyn MemoryReader>> = Vec::new();
let os_type = get_os_type();
match os_type {
"linux" => {
#[cfg(target_os = "linux")]
readers.push(Box::new(memory_linux::LinuxMemoryReader::new()));
}
"macos" => {
#[cfg(target_os = "macos")]
readers.push(Box::new(memory_macos::MacOsMemoryReader::new()));
}
"windows" => {
#[cfg(target_os = "windows")]
readers.push(Box::new(memory_windows::WindowsMemoryReader::new()));
}
_ => println!("Memory monitoring not supported for OS type: {os_type}"),
}
readers
}