ferrotorch_core/
device.rs1#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
6pub enum Device {
7 Cpu,
9 Cuda(usize),
11}
12
13impl Device {
14 #[inline]
16 pub fn is_cpu(&self) -> bool {
17 matches!(self, Device::Cpu)
18 }
19
20 #[inline]
22 pub fn is_cuda(&self) -> bool {
23 matches!(self, Device::Cuda(_))
24 }
25}
26
27impl core::fmt::Display for Device {
28 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
29 match self {
30 Device::Cpu => write!(f, "cpu"),
31 Device::Cuda(id) => write!(f, "cuda:{id}"),
32 }
33 }
34}
35
36impl Default for Device {
37 fn default() -> Self {
38 Device::Cpu
39 }
40}