#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum DeviceType {
Cpu = 1,
Cuda = 2,
CudaHost = 3,
OpenCl = 4,
Vulkan = 7,
Metal = 8,
Vpi = 9,
Rocm = 10,
RocmHost = 11,
ExtDev = 12,
CudaManaged = 13,
OneApi = 14,
WebGpu = 15,
Hexagon = 16,
Maia = 17,
}
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct Device {
pub device_type: DeviceType,
pub device_id: i32,
}
impl From<(DeviceType, i32)> for Device {
fn from(value: (DeviceType, i32)) -> Self {
Self {
device_type: value.0,
device_id: value.1,
}
}
}
impl Default for DeviceType {
fn default() -> Self {
Self::Cpu
}
}
impl Default for Device {
fn default() -> Self {
Self {
device_type: DeviceType::Cpu,
device_id: 0,
}
}
}
impl Device {
pub const CPU: Self = Self {
device_type: DeviceType::Cpu,
device_id: 0,
};
pub fn cuda(index: usize) -> Self {
Self {
device_type: DeviceType::Cuda,
device_id: index as i32,
}
}
}