Skip to main content

Module device

Module device 

Source
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 to 1 or true to force CPU execution
  • RUST_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_CPU
  • AXOLOTL_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§

DeviceConfig
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.