GPU Backend
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
FR — État actuel : La wheel par défaut
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
| Function | Signature | Returns |
|---|---|---|
gpu_devices | () | list[dict] |
gpu_set_backend | (backend: str | None) | str — active backend |
gpu_active_backend | () | str |
Device record schema
| Field | Type | Description |
|---|---|---|
backend | str | "cpu", "cuda", "metal", "rocm" |
name | str | Human-readable device name |
mem_mb | int | Device memory in MB (0 for CPU) |
available | bool | True if the device can be used for computation |
Backend string values for gpu_set_backend
| Value | Platform | Detection method |
|---|---|---|
"cpu" | All | Always available |
"cuda" | NVIDIA GPU | CUDA_PATH or CUDA_HOME env var set |
"metal" | Apple Silicon / macOS | cfg!(target_os = "macos") at compile time |
"rocm" | AMD GPU / Linux | /opt/rocm directory exists |
None | — | Auto-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
| Fonction | Signature | Retourne |
|---|---|---|
gpu_devices | () | list[dict] |
gpu_set_backend | (backend: str | None) | str — backend actif |
gpu_active_backend | () | str |
Schéma d'un device
| Champ | Type | Description |
|---|---|---|
backend | str | "cpu", "cuda", "metal", "rocm" |
name | str | Nom lisible du périphérique |
mem_mb | int | Mémoire du périphérique en Mo (0 pour CPU) |
available | bool | True si le périphérique peut être utilisé |
Valeurs de backend pour gpu_set_backend
| Valeur | Plateforme | Méthode de détection |
|---|---|---|
"cpu" | Toutes | Toujours disponible |
"cuda" | GPU NVIDIA | Variable d'env CUDA_PATH ou CUDA_HOME |
"metal" | Apple Silicon / macOS | cfg!(target_os = "macos") à la compilation |
"rocm" | GPU AMD / Linux | Dossier /opt/rocm présent |
None | — | Auto : 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.