cubecl_wgpu/device.rs
1/// The device struct when using the `wgpu` backend.
2///
3/// Note that you need to provide the device index when using a GPU backend.
4///
5/// # Example
6///
7/// ```ignore
8/// use cubecl_wgpu::WgpuDevice;
9///
10/// let device_gpu_1 = WgpuDevice::DiscreteGpu(0); // First discrete GPU found.
11/// let device_gpu_2 = WgpuDevice::DiscreteGpu(1); // Second discrete GPU found.
12/// ```
13#[derive(Clone, Debug, Hash, PartialEq, Eq)]
14pub enum WgpuDevice {
15 /// Discrete GPU with the given index. The index is the index of the discrete GPU in the list
16 /// of all discrete GPUs found on the system.
17 DiscreteGpu(usize),
18
19 /// Integrated GPU with the given index. The index is the index of the integrated GPU in the
20 /// list of all integrated GPUs found on the system.
21 IntegratedGpu(usize),
22
23 /// Virtual GPU with the given index. The index is the index of the virtual GPU in the list of
24 /// all virtual GPUs found on the system.
25 VirtualGpu(usize),
26
27 /// CPU.
28 Cpu,
29
30 /// The best available device found with the current [graphics API](crate::GraphicsApi).
31 ///
32 /// This will prioritize GPUs wgpu recognizes as "high power". Additionally, you can override this using
33 /// the `CUBECL_WGPU_DEFAULT_DEVICE` environment variable. This variable is spelled as if i was a WgpuDevice,
34 /// so for example CUBECL_WGPU_DEFAULT_DEVICE=IntegratedGpu(1) or CUBECL_WGPU_DEFAULT_DEVICE=Cpu
35 DefaultDevice,
36
37 /// Deprecated, use [`DefaultDevice`](WgpuDevice::DefaultDevice).
38 #[deprecated]
39 BestAvailable,
40
41 /// Use an externally created, existing, wgpu setup. This is helpful when using CubeCL in conjunction
42 /// with some existing wgpu setup (eg. egui or bevy), as resources can be transferred in & out of CubeCL.
43 ///
44 /// # Notes
45 ///
46 /// This can be initialized with [`init_device`](crate::runtime::init_device).
47 Existing(u32),
48}
49
50impl Default for WgpuDevice {
51 fn default() -> Self {
52 Self::DefaultDevice
53 }
54}