Skip to main content

cubecl_runtime/
description.rs

1//! Identity and properties of a device, as its driver reports before anything runs on it.
2
3use alloc::string::String;
4use cubecl_ir::PhysicalDevice;
5
6/// Identity and properties of a device, as its driver reports before anything runs on it:
7/// enough to list the machine's devices, show them to a user and pick one.
8#[derive(Debug, Clone, PartialEq, Eq)]
9#[non_exhaustive]
10pub struct DeviceDescription {
11    /// The name the device reports, e.g. `NVIDIA GeForce RTX 5070 Laptop GPU`.
12    pub name: String,
13    /// The kind of device.
14    pub kind: DeviceKind,
15    /// The memory the device can use, in bytes. The card's own memory for a GPU, the machine's RAM
16    /// for the CPU runtime, and on Metal the working set the device recommends staying under.
17    /// `None` where the runtime's API does not say.
18    pub max_memory: Option<u64>,
19    /// The card the device runs on. `None` for a device that is not a card: a CPU or a software
20    /// rasterizer.
21    pub physical: Option<PhysicalDevice>,
22    /// The architecture the runtime compiles for: the NVPTX target on CUDA, the
23    /// `gcnArchName` on HIP, the LLVM CPU name on the CPU runtime.
24    /// `None` on Metal and wgpu.
25    pub architecture: Option<String>,
26    /// The driver's version, in each API's own terms, so two runtimes on one card can disagree:
27    /// on CUDA the CUDA version the driver supports (`13.0`), on HIP the HIP version
28    /// (`7.1.25424`), on wgpu the driver's name and release (`NVIDIA 580.82.09`). `None` on Metal
29    /// and the CPU runtime.
30    pub driver_version: Option<String>,
31}
32
33impl DeviceDescription {
34    /// A device named `name`, of `kind`.
35    pub fn new(name: impl Into<String>, kind: DeviceKind) -> Self {
36        Self {
37            name: name.into(),
38            kind,
39            max_memory: None,
40            physical: None,
41            architecture: None,
42            driver_version: None,
43        }
44    }
45}
46
47/// What sort of device a [`DeviceDescription`] describes.
48#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
49#[non_exhaustive]
50pub enum DeviceKind {
51    /// A GPU with memory of its own.
52    Discrete,
53    /// A GPU sharing the host's memory: an APU, Apple silicon, an Intel iGPU.
54    Integrated,
55    /// A GPU a hypervisor hands to a virtual machine.
56    Virtual,
57    /// The host's processors, or a software rasterizer running on them.
58    Cpu,
59    /// Whatever the driver calls none of the above.
60    Other,
61}