gpu-probe 0.1.0

Cross-platform GPU memory (VRAM) detection with no vendor SDKs — uses NVML, Linux DRM sysfs (AMD/Intel), and macOS system_profiler/sysctl.
Documentation
  • Coverage
  • 81.48%
    22 out of 27 items documented4 out of 10 items with examples
  • Size
  • Source code size: 73.76 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 766.53 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • jorge-menjivar/gpu-probe
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • jorge-menjivar

gpu-probe

crates.io docs.rs coverage

Cross-platform GPU memory (VRAM) detection for Rust — no vendor SDKs, nothing to install beyond your GPU driver.

Vendor Linux Windows macOS Backend
NVIDIA NVML · system_profiler
AMD DRM sysfs · system_profiler
Intel DRM sysfs · system_profiler
Apple system_profiler + sysctl

Intel Macs only — discrete and integrated GPUs are read from system_profiler.

Best-effort: you get an empty list on unsupported platforms, never an error.

Note: So far this crate has only been tested on NVIDIA hardware. The AMD, Intel, and Apple paths are implemented but not yet verified on real devices — if something doesn't work, please open an issue. Help from the community confirming detection on AMD/Intel/Apple GPUs is very much appreciated.

Install

[dependencies]
gpu-probe = "0.1"

NVIDIA support pulls in nvml-wrapper. For AMD/Apple-only builds, drop it:

gpu-probe = { version = "0.1", default-features = false }

Usage

for gpu in gpu_probe::detect() {
    println!("{gpu}");
    // NVIDIA GeForce RTX 3090 (NVIDIA): 24.0 GiB total, 9.8 GiB free
}

detect() returns Vec<GpuInfo>:

pub struct GpuInfo {
    pub name: String,
    pub vendor: Vendor,            // Nvidia | Amd | Intel | Apple | Unknown
    pub total_bytes: u64,
    pub free_bytes: Option<u64>,
    pub used_bytes: Option<u64>,
}

Check whether a model fits, or pick the emptiest GPU:

let need = 16 * 1024 * 1024 * 1024; // 16 GiB

let fits = gpu_probe::detect()
    .iter()
    .any(|g| g.free_bytes.unwrap_or(g.total_bytes) >= need);

let emptiest = gpu_probe::detect()
    .into_iter()
    .max_by_key(|g| g.free_bytes.unwrap_or(g.total_bytes));

Or run the bundled example: cargo run --example detect.

CUDA host properties

Compute capability and CUDA driver version describe the host and its driver rather than any one GPU, so they're returned separately — handy for selecting a prebuilt artifact that matches the machine:

use gpu_probe::ComputeCapability;

if let Some(cuda) = gpu_probe::cuda_host() {
    println!("{} / CUDA {}", cuda.compute_capability, cuda.driver_version);
    // 8.6 / CUDA 13.3

    if cuda.compute_capability >= ComputeCapability::new(8, 0) {
        // pick an Ampere-or-newer build
    }
}

Both are major/minor pairs ordered major-first, so comparing against a minimum requirement works directly. None means NVML is unavailable — no NVIDIA driver, no device, the nvidia feature disabled, or a driver reporting unusable values.

Notes

  • total_bytes is dedicated VRAM on discrete GPUs. On integrated/unified GPUs (Intel iGPUs, AMD APUs, Apple Silicon) it's the shared system-memory ceiling, and free_bytes / used_bytes are usually None.
  • NVIDIA detection reads NVML from the installed driver at runtime — the CUDA toolkit is not required.
  • NVML is initialized once per process and intentionally never shut down. Cycling nvmlInit/nvmlShutdown leaks a file descriptor each time, so detect() is safe to poll on a timer: descriptor use is flat, and each call still returns live memory values.

License

Apache-2.0