Skip to main content

sightloom_host/
device.rs

1//! Device preference for host inference (CPU / GPU / auto).
2
3use serde::{Deserialize, Serialize};
4
5/// Where the host prefers to run a model.
6///
7/// Step 1 only records intent. Real ONNX/CUDA selection lands behind `onnx`
8/// (or a host-private runtime crate) in a later step.
9#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
10#[serde(rename_all = "snake_case")]
11pub enum DevicePreference {
12    /// Let the runtime choose.
13    #[default]
14    Auto,
15    /// Force CPU.
16    Cpu,
17    /// Prefer discrete / integrated GPU when available.
18    Gpu,
19    /// Explicit device index (runtime-defined).
20    DeviceIndex(u32),
21}
22
23impl DevicePreference {
24    /// Human-readable label for logs / metrics.
25    #[must_use]
26    pub const fn as_str(self) -> &'static str {
27        match self {
28            Self::Auto => "auto",
29            Self::Cpu => "cpu",
30            Self::Gpu => "gpu",
31            Self::DeviceIndex(_) => "device_index",
32        }
33    }
34}