Skip to main content

spatialrust_core/
device.rs

1/// Device kind supported by SpatialRust execution.
2#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
3#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4pub enum DeviceKind {
5    /// Host CPU execution.
6    #[default]
7    Cpu,
8    /// Portable GPU execution via wgpu/WebGPU.
9    Wgpu,
10    /// NVIDIA CUDA execution.
11    Cuda,
12}
13
14/// Minimal device abstraction defined in core and extended by `spatialrust-gpu`.
15pub trait Device: core::fmt::Debug + Send + Sync + 'static {
16    /// Returns the kind of this device.
17    fn kind(&self) -> DeviceKind;
18}
19
20/// Default CPU device.
21#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
22#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
23pub struct CpuDevice;
24
25impl Device for CpuDevice {
26    fn kind(&self) -> DeviceKind {
27        DeviceKind::Cpu
28    }
29}