Skip to main content

cubecl_runtime/device/
cuda.rs

1use cubecl_common::device::{Device, DeviceId};
2
3/// A device of the CUDA runtime, named by its index.
4#[derive(new, Clone, PartialEq, Eq, Default, Hash)]
5pub struct CudaDevice {
6    /// The index of the GPU among the ones CUDA reports.
7    pub index: usize,
8}
9
10impl core::fmt::Debug for CudaDevice {
11    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
12        write!(f, "Cuda({})", self.index)
13    }
14}
15
16impl Device for CudaDevice {
17    fn from_id(device_id: DeviceId) -> Self {
18        Self {
19            index: device_id.index_id as usize,
20        }
21    }
22
23    fn to_id(&self) -> DeviceId {
24        DeviceId {
25            type_id: 0,
26            index_id: super::index_id(self.index),
27        }
28    }
29}