Skip to main content

Hardware API

The hardware module detects system specifications including CPU, RAM, GPU hardware, and inference backends.

Core Types

SystemSpecs

The main struct containing all detected hardware information:
Key Fields:
  • total_ram_gb - Total system RAM in gigabytes
  • available_ram_gb - Currently available RAM (for model loading)
  • total_cpu_cores - Number of logical CPU cores
  • cpu_name - CPU model name string
  • has_gpu - Whether any GPU was detected
  • gpu_vram_gb - VRAM of primary GPU (per-card, not total)
  • total_gpu_vram_gb - Total VRAM across all same-model GPUs (for multi-GPU inference)
  • gpu_name - Primary GPU model name
  • gpu_count - Number of same-model GPUs (for multi-GPU setups)
  • unified_memory - Whether GPU and CPU share memory pool (Apple Silicon, AMD APUs)
  • backend - Primary inference backend for the system
  • gpus - All detected GPUs (may span multiple vendors)

GpuBackend

The acceleration backend for inference:
Methods:
Returns human-readable label (“CUDA”, “Metal”, etc.).

GpuInfo

Information about a single detected GPU:

Functions

SystemSpecs::detect()

Detects system hardware specifications:
Returns: Complete system specifications Example:

SystemSpecs::with_gpu_memory_override()

Override detected GPU VRAM (useful when detection fails):
Parameters:
  • vram_gb - VRAM amount in gigabytes
Returns: Updated SystemSpecs Example:

SystemSpecs::display()

Prints formatted system specifications:
Example Output:

parse_memory_size()

Parses human-readable memory sizes:
Parameters:
  • s - Size string (“32G”, “32GB”, “32000M”, etc.)
Returns: Size in gigabytes, or None if invalid Example:

gpu_memory_bandwidth_gbps()

Get memory bandwidth for known GPU models:
Parameters:
  • name - GPU model name
Returns: Memory bandwidth in GB/s, or None if unknown Example:
This is used for accurate token/s estimation based on memory bandwidth limits.

is_running_in_wsl()

Detects whether running in WSL (Windows Subsystem for Linux):
Returns: true if running in WSL, false otherwise Example:

GPU Detection Details

The hardware detection system uses platform-specific methods:

NVIDIA GPUs

  1. nvidia-smi - Primary method via --query-gpu=memory.total,name
  2. sysfs - Fallback for containerized environments (/sys/class/drm/card*/device)
  3. Unified Memory Detection - Detects NVIDIA Grace Blackwell via addressing_mode field

AMD GPUs

  1. rocm-smi - For systems with ROCm installed
  2. sysfs - For systems without ROCm (/sys/class/drm/card*/device)
  3. Unified APUs - Detects Ryzen AI MAX and AI 9/7/5 series with shared memory

Apple Silicon

  • system_profiler SPDisplaysDataType - Detects M1/M2/M3/M4 series
  • Unified memory: Reports total system RAM as VRAM (same memory pool)

Intel GPUs

  • sysfs - Detects Arc GPUs via vendor ID 0x8086
  • lspci - Fallback identification

Windows

  • PowerShell - Get-CimInstance Win32_VideoController
  • wmic - Fallback for older Windows versions

Multi-GPU Systems

For same-model multi-GPU setups:
The total_gpu_vram_gb field is used for fit scoring since llama.cpp and vLLM support tensor splitting across multiple GPUs.

Platform-Specific Notes

macOS

On newer macOS versions (Tahoe+), available_ram_gb uses vm_stat as a fallback when sysinfo fails.

Linux Containers

In containerized environments (Docker, Podman, Toolbx), GPU detection falls back to sysfs and uses flatpak-spawn --host lspci when needed.

WSL

WSL environments are detected via WSL_INTEROP environment variable or /proc/version contents.