Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

GPU Backend

New in 2.4.34 GPU

Backend detection and selection for CUDA, Metal (Apple Silicon), ROCm and CPU. Auto-detection at runtime with zero configuration. / Détection et sélection du backend GPU/CPU — CUDA, Metal, ROCm détectés automatiquement.

✓ CUDA detected ✓ CPU always available
Backends 4 CPU · CUDA · Metal · ROCm
Detection Auto env-var + path probing
Config Zero no setup required
⚠️
EN — Current state: The default pip install seraplot wheel ships CPU-only and uses rayon multi-threading. Real GPU kernels are available through opt-in feature flags compiled from source: cargo build --features cuda, --features metal, --features rocm. The detection and selection API works in both builds.
FR — État actuel : La wheel par défaut pip install seraplot est CPU only avec multi-threading rayon. Les vrais kernels GPU sont disponibles via des feature flags opt-in compilés depuis les sources : cargo build --features cuda, --features metal, --features rocm. L'API de détection et sélection fonctionne dans les deux builds.
🔍
gpu_devices

List all detected devices with backend, name, memory and availability flag.

gpu_set_backend

Explicitly select a backend. Pass None for auto-selection (picks the first available non-CPU backend).

📍
gpu_active_backend

Returns the currently active backend name as a string.

🖥️
Detection logic

CUDA: CUDA_PATH / CUDA_HOME env vars. Metal: macOS target. ROCm: /opt/rocm path probe.

Quick start
import seraplot as sp

devices = sp.gpu_devices()
for d in devices:
    avail = "available" if d["available"] else "detected / unavailable"
    print(f"  [{d['backend']}] {d['name']}  {d['mem_mb']} MB  — {avail}")

active = sp.gpu_active_backend()
print(f"\nActive backend: {active}")

sp.gpu_set_backend("cpu")
print(f"Forced CPU: {sp.gpu_active_backend()}")

sp.gpu_set_backend(None)
print(f"Auto-select: {sp.gpu_active_backend()}")

API Reference

Functions
FunctionSignatureReturns
gpu_devices()list[dict]
gpu_set_backend(backend: str | None)str — active backend
gpu_active_backend()str
Device record schema
FieldTypeDescription
backendstr"cpu", "cuda", "metal", "rocm"
namestrHuman-readable device name
mem_mbintDevice memory in MB (0 for CPU)
availableboolTrue if the device can be used for computation
Backend string values for gpu_set_backend
ValuePlatformDetection method
"cpu"AllAlways available
"cuda"NVIDIA GPUCUDA_PATH or CUDA_HOME env var set
"metal"Apple Silicon / macOScfg!(target_os = "macos") at compile time
"rocm"AMD GPU / Linux/opt/rocm directory exists
NoneAuto-select: first non-CPU available backend
ℹ️
Setting a backend does not automatically enable GPU kernels in the current version. It records your preference so that when kernel dispatch ships in 2.5.x, your code is already correct and ready.

Référence API

Fonctions
FonctionSignatureRetourne
gpu_devices()list[dict]
gpu_set_backend(backend: str | None)str — backend actif
gpu_active_backend()str
Schéma d'un device
ChampTypeDescription
backendstr"cpu", "cuda", "metal", "rocm"
namestrNom lisible du périphérique
mem_mbintMémoire du périphérique en Mo (0 pour CPU)
availableboolTrue si le périphérique peut être utilisé
Valeurs de backend pour gpu_set_backend
ValeurPlateformeMéthode de détection
"cpu"ToutesToujours disponible
"cuda"GPU NVIDIAVariable d'env CUDA_PATH ou CUDA_HOME
"metal"Apple Silicon / macOScfg!(target_os = "macos") à la compilation
"rocm"GPU AMD / LinuxDossier /opt/rocm présent
NoneAuto : premier backend non-CPU disponible
ℹ️
Dans la version actuelle, définir un backend ne déclenche pas encore les kernels GPU. Cela enregistre votre préférence : quand le dispatch de kernels arrivera en 2.5.x, votre code sera déjà correct et prêt.