Skip to main content

get_device

Function get_device 

Source
pub fn get_device(config: &DeviceConfig) -> Result<Device>
Expand description

Get a device according to configuration, preferring CUDA.

This function implements the CUDA-first philosophy:

  1. If force_cpu is set, returns CPU device with warning
  2. Otherwise, attempts to get CUDA device at specified ordinal
  3. Falls back to CPU with warning if CUDA unavailable

§Arguments

  • config - Device configuration specifying preferences

§Returns

The selected Candle Device.

§Errors

Returns error only if device creation fails entirely (rare).

§Example

use rust_ai_core::{get_device, DeviceConfig};

let device = get_device(&DeviceConfig::from_env())?;
println!("Using device: {:?}", device);