grafos_dsp/
placement.rs

1//! Placement hints for DSP pipeline stages.
2
3use grafos_stream::placement::NodeConstraint;
4
5/// Where a DSP stage should execute.
6#[derive(Debug, Clone)]
7pub enum StagePlacement {
8    /// Execute on CPU with an optional node constraint.
9    Cpu(NodeConstraint),
10    /// Execute on GPU with an optional node constraint.
11    Gpu(NodeConstraint),
12}
13
14impl Default for StagePlacement {
15    fn default() -> Self {
16        StagePlacement::Cpu(NodeConstraint::Any)
17    }
18}
19
20#[cfg(test)]
21mod tests {
22    use super::*;
23
24    #[test]
25    fn default_is_cpu_any() {
26        let placement = StagePlacement::default();
27        assert!(matches!(
28            placement,
29            StagePlacement::Cpu(NodeConstraint::Any)
30        ));
31    }
32
33    #[test]
34    fn cpu_with_constraint() {
35        let placement = StagePlacement::Cpu(NodeConstraint::HasGpu);
36        assert!(matches!(
37            placement,
38            StagePlacement::Cpu(NodeConstraint::HasGpu)
39        ));
40    }
41
42    #[test]
43    fn gpu_with_any() {
44        let placement = StagePlacement::Gpu(NodeConstraint::Any);
45        assert!(matches!(
46            placement,
47            StagePlacement::Gpu(NodeConstraint::Any)
48        ));
49    }
50
51    #[test]
52    fn gpu_with_memory_constraint() {
53        let placement = StagePlacement::Gpu(NodeConstraint::HasMemory(1024));
54        assert!(matches!(
55            placement,
56            StagePlacement::Gpu(NodeConstraint::HasMemory(1024))
57        ));
58    }
59
60    #[test]
61    fn clone() {
62        let placement = StagePlacement::Gpu(NodeConstraint::HasGpu);
63        let cloned = placement.clone();
64        assert!(matches!(
65            cloned,
66            StagePlacement::Gpu(NodeConstraint::HasGpu)
67        ));
68    }
69
70    #[test]
71    fn debug_format() {
72        let placement = StagePlacement::Cpu(NodeConstraint::Any);
73        let debug = format!("{:?}", placement);
74        assert!(debug.contains("Cpu"));
75    }
76}