Skip to main content

cubecl_runtime/device/
mod.rs

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