cubecl_runtime/device/mod.rs
1//! The device type of each runtime, named without naming the runtime crate,
2//! and [which hardware](crate::device::HardwareIdentity) a device is.
3//!
4//! Each one is a value and nothing more: which GPU, which index, which kind of
5//! card. So they live here rather than in the runtime crates that act on them,
6//! which lets a caller hold one, and lets `cubecl` put a single enum over the
7//! devices, without depending on any runtime.
8
9mod cpu;
10mod cuda;
11mod hardware_identity;
12mod hip;
13mod metal;
14mod wgpu;
15
16pub use cpu::CpuDevice;
17pub use cuda::CudaDevice;
18pub use hardware_identity::HardwareIdentity;
19pub use hip::AmdDevice;
20pub use metal::MetalDevice;
21pub use wgpu::{WgpuBackend, WgpuDevice, WgpuDeviceKind};
22
23pub use cubecl_common::device::DeviceId;
24
25/// A device index as a [`DeviceId`] carries it.
26///
27/// Kept at the largest the id holds rather than wrapped: wrapped, an index
28/// past the end lands on a device that exists; kept, it names one no machine
29/// has, and naming it is refused.
30fn index_id(index: usize) -> u16 {
31 index.min(u16::MAX as usize) as u16
32}