Skip to main content

all_smi/
lib.rs

1// Copyright 2025 Lablup Inc. and Jeongkyu Shin
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! # all-smi
16//!
17//! A cross-platform library for monitoring GPU, NPU, CPU, and memory hardware.
18//!
19//! `all-smi` provides a unified API for querying hardware metrics across multiple
20//! platforms and device types including NVIDIA GPUs, AMD GPUs, Apple Silicon,
21//! Intel Gaudi NPUs, Google TPUs, Tenstorrent, Rebellions, and Furiosa NPUs.
22//!
23//! ## Quick Start
24//!
25//! ```rust,no_run
26//! use all_smi::{AllSmi, Result};
27//!
28//! fn main() -> Result<()> {
29//!     // Initialize with auto-detection
30//!     let smi = AllSmi::new()?;
31//!
32//!     // Get all GPU/NPU information
33//!     for gpu in smi.get_gpu_info() {
34//!         println!("{}: {}% utilization, {:.1}W",
35//!             gpu.name, gpu.utilization, gpu.power_consumption);
36//!     }
37//!
38//!     // Get CPU information
39//!     for cpu in smi.get_cpu_info() {
40//!         println!("{}: {:.1}% utilization", cpu.cpu_model, cpu.utilization);
41//!     }
42//!
43//!     // Get memory information
44//!     for mem in smi.get_memory_info() {
45//!         println!("Memory: {:.1}% used", mem.utilization);
46//!     }
47//!
48//!     Ok(())
49//! }
50//! ```
51//!
52//! ## Using the Prelude
53//!
54//! For convenience, you can import all common types with the prelude:
55//!
56//! ```rust,no_run
57//! use all_smi::prelude::*;
58//!
59//! fn main() -> Result<()> {
60//!     let smi = AllSmi::new()?;
61//!     let gpus: Vec<GpuInfo> = smi.get_gpu_info();
62//!     println!("Found {} GPU(s)", gpus.len());
63//!     Ok(())
64//! }
65//! ```
66//!
67//! ## Platform Support
68//!
69//! | Platform | GPUs | NPUs | CPU | Memory |
70//! |----------|------|------|-----|--------|
71//! | Linux | NVIDIA, AMD | Gaudi, TPU, Tenstorrent, Rebellions, Furiosa | Yes | Yes |
72//! | macOS | Apple Silicon | - | Yes | Yes |
73//! | Windows | NVIDIA, AMD | - | Yes | Yes |
74//!
75//! ## Features
76//!
77//! - **GPU Monitoring**: Utilization, memory, temperature, power, frequency
78//! - **NPU Monitoring**: Intel Gaudi, Google TPU, Tenstorrent, Rebellions, Furiosa
79//! - **CPU Monitoring**: Utilization, frequency, temperature, P/E cores (Apple Silicon)
80//! - **Memory Monitoring**: System RAM, swap, buffers, cache
81//! - **Process Monitoring**: GPU processes with memory usage
82//! - **Chassis Monitoring**: Total power, thermal pressure, fan speeds
83
84// =============================================================================
85// Public Library API
86// =============================================================================
87
88/// High-level client API for hardware monitoring.
89pub mod client;
90
91/// Unified error types for the library.
92pub mod error;
93
94/// Prelude module for convenient imports.
95pub mod prelude;
96
97// Re-export main types at crate root for convenience
98pub use client::{AllSmi, AllSmiConfig, DeviceType};
99pub use error::{Error, Result};
100
101// =============================================================================
102// Internal Modules (also exported for advanced usage and testing)
103// =============================================================================
104
105/// Device readers and types for GPU, CPU, memory monitoring.
106pub mod device;
107
108/// Parsing utilities and macros.
109#[macro_use]
110pub mod parsing;
111
112/// Application state management.
113pub mod app_state;
114
115/// Command-line interface definitions.
116pub mod cli;
117
118/// Network client for remote monitoring.
119pub mod network;
120
121/// Storage monitoring.
122pub mod storage;
123
124/// Common traits for collectors and exporters.
125pub mod traits;
126
127/// Terminal UI components.
128pub mod ui;
129
130/// Utility functions.
131pub mod utils;
132
133/// Configuration module.
134pub mod common {
135    /// Configuration management.
136    pub mod config;
137}