Expand description
CUDA-first device selection with environment variable overrides.
This module provides unified device selection logic across all rust-ai crates. The philosophy is CUDA-first: GPU is always preferred, and CPU fallback triggers a warning to alert users they’re not getting optimal performance.
§Environment Variables
RUST_AI_FORCE_CPU- Set to1ortrueto force CPU executionRUST_AI_CUDA_DEVICE- Set to device ordinal (e.g.,0,1) to select GPU
Legacy variables are also supported for backwards compatibility:
AXOLOTL_FORCE_CPU,VSA_OPTIM_FORCE_CPUAXOLOTL_CUDA_DEVICE,VSA_OPTIM_CUDA_DEVICE
§Example
use rust_ai_core::{get_device, DeviceConfig};
// Default: CUDA device 0 with auto-fallback
let device = get_device(&DeviceConfig::default())?;
// Explicit GPU selection
let config = DeviceConfig::new().with_cuda_device(1);
let device = get_device(&config)?;
// Force CPU (for testing)
let config = DeviceConfig::new().with_force_cpu(true);
let device = get_device(&config)?;Structs§
- Device
Config - Configuration for device selection.
Functions§
- get_
device - Get a device according to configuration, preferring CUDA.
- warn_
if_ cpu - Emit a one-time warning if running on CPU.