oxmera_core/device.rs
1//! Device handles.
2
3/// Where a tensor's storage lives and where its work runs.
4///
5/// This is a *handle*, not a backend: it names a place. The backend
6/// registry resolves a handle to an implementation; this crate must never
7/// know how.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
9#[non_exhaustive]
10pub enum Device {
11 /// The multi-threaded CPU backend — always available.
12 Cpu,
13 /// An Apple-Silicon GPU via Metal, by device index.
14 Metal {
15 /// Zero-based device index. Registration adds device 0 only; a
16 /// higher index resolves to `BackendUnavailable`
17 /// (see `docs/LIMITATIONS.md`).
18 index: usize,
19 },
20 /// An NVIDIA GPU, by device index — served by `oxmera-cuda` once a
21 /// driver and device are registered (`oxmera_runtime::init`).
22 Cuda {
23 /// Zero-based device index. Registration adds device 0 only; a
24 /// higher index resolves to `BackendUnavailable`
25 /// (see `docs/LIMITATIONS.md`).
26 index: usize,
27 },
28}
29
30impl Device {
31 /// A short stable name for the device kind (`"cpu"`, `"metal"`,
32 /// `"cuda"`), used in error messages and `oxmera doctor` output.
33 pub fn kind_name(self) -> &'static str {
34 match self {
35 Device::Cpu => "cpu",
36 Device::Metal { .. } => "metal",
37 Device::Cuda { .. } => "cuda",
38 }
39 }
40}