How llmfit Detects System CPU, RAM, and GPU Hardware: A Deep Dive into the Detection Logic

llmfit gathers comprehensive system hardware information through the SystemSpecs::detect() constructor in [llmfit-core/src/hardware.rs](https://github.com/AlexsJones/llmfit/blob/main/llmfit-core/src/hardware.rs), using a layered detection strategy that combines the sysinfo crate for CPU/RAM with vendor-specific CLI tools and sysfs parsing for multi-platform GPU discovery.

The hardware detection engine in the AlexsJones/llmfit repository implements exhaustive cross-platform discovery to support Linux, Windows, and macOS environments. This system enables intelligent model selection by accurately cataloging available compute resources, including edge cases like unified memory architectures and multi-GPU configurations.

CPU and RAM Detection (Cross-Platform)

llmfit relies on the sysinfo crate for reliable cross-platform system information gathering. This approach ensures consistent behavior across operating systems without requiring platform-specific Kernel APIs.

Using the sysinfo Crate

In [hardware.rs](https://github.com/AlexsJones/llmfit/blob/main/llmfit-core/src/hardware.rs) lines 73-76, the detection routine initializes a System object and refreshes all system information:

let mut sys = System::new_all();
sys.refresh_all();

From this populated system object, llmfit extracts:

  • Total RAM: Retrieved via sys.total_memory() and converted to GB (lines 77-80)
  • CPU Core Count: Determined by sys.cpus().len() (line 88)
  • CPU Name: Resolved through Self::detect_cpu_name(&sys) (line 89)

Handling Edge Cases in Memory Reporting

When the OS reports zero available RAM—a common occurrence in certain containerized environments—the detector falls back to a custom helper method available_ram_fallback (lines 80-86). This ensures accurate memory profiling even when standard system calls return unreliable data.

GPU Detection Architecture

The GPU detection logic centers on detect_all_gpus(total_ram_gb, &cpu_name) (line 99), which aggregates results from multiple vendor-specific probes. This method merges datasets from NVIDIA, AMD, Intel, and platform-specific backends before sorting the final inventory.

NVIDIA GPU Detection (nvidia-smi and sysfs)

For NVIDIA hardware, llmfit implements a dual-path strategy:

  1. Primary Path: Executes nvidia-smi queries with extended addressing mode support (lines 326-359). If the addressing mode is unavailable, it falls back to classic memory.total,name queries (lines 340-354). Results parse through parse_nvidia_smi_extended (lines 58-74) or parse_nvidia_smi_list (lines 46-59).

  2. Sysfs Fallback: When nvidia-smi is absent—as in minimal container environments—the detector scans /sys/class/drm entries via detect_nvidia_gpu_sysfs_info (lines 505-565).

AMD GPU Detection (ROCm and sysfs)

AMD hardware detection follows a similar tiered approach:

  • Preferred Path: Uses rocm-smi --showmeminfo vram combined with --showproductname (lines 887-913 in detect_amd_gpu_rocm_info). The parser handles both block and tabular outputs through parse_rocm_vram_bytes and parse_rocm_product_names (lines 627-664).

  • Sysfs Scanner: If ROCm utilities are unavailable, detect_amd_gpu_sysfs_info (lines 636-673) reads from /sys/class/drm to enumerate AMD GPUs.

Intel GPU Detection

Intel GPUs are detected via lspci output parsing on Linux and Windows systems (lines 724-749 in detect_intel_gpus). This method identifies Intel integrated and discrete graphics hardware by examining PCI device listings.

Apple Silicon and Unified Memory

For Apple Silicon devices, detect_apple_gpu (lines 445-452) recognizes the unified memory architecture by treating system RAM as VRAM and setting unified_memory = true. This distinction is critical for memory allocation strategies on M1/M2/M3 processors.

Windows WMI and Registry Fallbacks

On Windows platforms, llmfit queries WMI via PowerShell (lines 1010-1022 in detect_gpu_windows_info) with fallback to wmic commands. The system can correct VRAM values using registry entries through apply_registry_vram (lines 1455-1555), addressing common misreporting issues in Windows GPU drivers.

macOS Metal Support

For Metal-compatible GPUs on macOS, detect_macos_metal_gpus (lines 334-343) parses system_profiler output to identify Radeon and other discrete GPUs alongside Apple Silicon.

Vulkan and Additional Backends

The detection framework includes supplementary paths such as detect_vulkan_gpu_info for Vulkan-compatible devices and Ascend NPU detection (lines 620-624), ensuring broad hardware compatibility.

Aggregating and Ranking GPU Results

After collection, llmfit applies intelligent filtering and sorting logic:

  • Discrete vs. Integrated: Discrete GPUs are preferred over integrated graphics (lines 677-686), with the exception of macOS where iGPUs remain visible due to Apple's unified architecture.
  • VRAM Sorting: The final list sorts by VRAM descending (lines 80-85), ensuring the primary GPU has the most available memory.
  • Primary Selection: Lines 106-110 set has_gpu, gpu_vram_gb, gpu_name, and unified_memory flags based on the top-ranked device.
  • Backend Inference: When no GPU is detected, GpuBackend defaults to CPU-only variants (CpuArm or CpuX86) as shown in lines 123-129.

The total_gpu_vram_gb field aggregates VRAM across all detected GPUs (lines 112-119), supporting multi-GPU training scenarios.

Practical Usage Example

Access the hardware detection module through the public API exported in [llmfit-core/src/lib.rs](https://github.com/AlexsJones/llmfit/blob/main/llmfit-core/src/lib.rs):

use llmfit_core::hardware::SystemSpecs;

// Detect the host's hardware.
let specs = SystemSpecs::detect();

// Inspect CPU info.
println!("CPU: {} ({} cores)", specs.cpu_name, specs.total_cpu_cores);

// Inspect RAM.
println!("Total RAM: {:.1} GB, Available: {:.1} GB", specs.total_ram_gb, specs.available_ram_gb);

// List detected GPUs.
if specs.has_gpu {
    for gpu in &specs.gpus {
        println!(
            "GPU: {} – {:.1} GB VRAM (backend: {}, unified: {})",
            gpu.name,
            gpu.vram_gb.unwrap_or(0.0),
            gpu.backend.label(),
            gpu.unified_memory
        );
    }
} else {
    println!("No GPU detected – falling back to CPU-only inference.");
}

Summary

Frequently Asked Questions

How does llmfit handle systems without NVIDIA drivers installed?

When nvidia-smi is not present, llmfit falls back to detect_nvidia_gpu_sysfs_info (lines 505-565), which reads /sys/class/drm entries to identify NVIDIA hardware directly from the kernel's device system. This ensures GPU detection in minimal container environments or systems with driver-only installations lacking the NVIDIA management tools.

Does llmfit support unified memory configurations like Apple Silicon?

Yes, detect_apple_gpu (lines 445-452) specifically handles Apple Silicon by reading system RAM as VRAM and setting unified_memory = true. Additionally, [hwprofile.rs](https://github.com/AlexsJones/llmfit/blob/main/llmfit-core/src/hwprofile.rs) manages AMD APU unified memory adjustments, ensuring accurate memory profiling across architectures where CPU and GPU share physical RAM.

What happens if multiple GPUs from different vendors are present?

The detect_all_gpus method aggregates GPUs from all available backends—NVIDIA, AMD, Intel, Vulkan, and platform-specific sources—then merges them into a single inventory. Discrete GPUs are preferred over integrated ones (lines 677-686), and the final list sorts by VRAM descending so the most capable GPU receives primary status, enabling intelligent model placement in heterogeneous environments.

Can I use the hardware detection module separately from the main llmfit application?

Absolutely. The SystemSpecs struct and its detect() method are publicly exported in [llmfit-core/src/lib.rs](https://github.com/AlexsJones/llmfit/blob/main/llmfit-core/src/lib.rs), allowing you to import llmfit_core::hardware::SystemSpecs in any Rust project to gather system specifications without invoking the full llmfit inference pipeline.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →