use cubecl_common::device::{Device, DeviceId};
#[derive(Clone, Debug, Hash, PartialEq, Eq, Default)]
pub enum WgpuDevice {
DiscreteGpu(usize),
IntegratedGpu(usize),
VirtualGpu(usize),
Cpu,
#[default]
DefaultDevice,
#[deprecated]
BestAvailable,
Existing(u32),
}
impl Device for WgpuDevice {
fn from_id(device_id: DeviceId) -> Self {
match device_id.type_id {
0 => Self::DiscreteGpu(device_id.index_id as usize),
1 => Self::IntegratedGpu(device_id.index_id as usize),
2 => Self::VirtualGpu(device_id.index_id as usize),
3 => Self::Cpu,
4 => Self::DefaultDevice,
5 => Self::Existing(device_id.index_id as u32),
_ => Self::DefaultDevice,
}
}
fn to_id(&self) -> DeviceId {
#[allow(deprecated)]
match self {
Self::DiscreteGpu(index) => DeviceId::new(0, *index as u16),
Self::IntegratedGpu(index) => DeviceId::new(1, *index as u16),
Self::VirtualGpu(index) => DeviceId::new(2, *index as u16),
Self::Cpu => DeviceId::new(3, 0),
Self::BestAvailable | WgpuDevice::DefaultDevice => DeviceId::new(4, 0),
Self::Existing(id) => DeviceId::new(5, *id as u16),
}
}
}