Skip to main content

spatialrust_core/
execution.rs

1use crate::DeviceKind;
2
3/// Execution policy for spatial algorithms.
4#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
5pub enum ExecutionPolicy {
6    /// Single-threaded CPU execution.
7    #[default]
8    CpuSingle,
9    /// Parallel CPU execution.
10    CpuParallel,
11    /// GPU execution on a device of the given kind.
12    Gpu(DeviceKind),
13    /// Automatic selection based on runtime heuristics.
14    Auto,
15}
16
17impl ExecutionPolicy {
18    /// Returns the device kind targeted by this policy when known.
19    #[must_use]
20    pub fn device_kind(&self) -> Option<DeviceKind> {
21        match self {
22            Self::CpuSingle | Self::CpuParallel => Some(DeviceKind::Cpu),
23            Self::Gpu(kind) => Some(*kind),
24            Self::Auto => None,
25        }
26    }
27}