Skip to main content

cbtop/grammar/
context.rs

1//! Execution context (Coordinates equivalent in Grammar of Graphics).
2
3/// CPU affinity specification
4#[derive(Debug, Clone, PartialEq)]
5pub struct CpuAffinity {
6    /// List of CPU cores to use
7    pub cores: Vec<usize>,
8}
9
10/// Execution context (analogous to Coordinates)
11#[derive(Debug, Clone, PartialEq)]
12pub enum ExecutionContext {
13    /// Local CPU execution
14    Cpu {
15        affinity: Option<CpuAffinity>,
16        numa_node: Option<usize>,
17    },
18    /// GPU execution
19    Gpu { device_id: u32, stream: Option<u32> },
20    /// Heterogeneous (multiple contexts)
21    Heterogeneous { contexts: Vec<ExecutionContext> },
22}
23
24impl Default for ExecutionContext {
25    fn default() -> Self {
26        ExecutionContext::Cpu {
27            affinity: None,
28            numa_node: None,
29        }
30    }
31}
32
33impl ExecutionContext {
34    /// Create CPU context
35    pub fn cpu() -> Self {
36        ExecutionContext::Cpu {
37            affinity: None,
38            numa_node: None,
39        }
40    }
41
42    /// Create GPU context
43    pub fn gpu(device_id: u32) -> Self {
44        ExecutionContext::Gpu {
45            device_id,
46            stream: None,
47        }
48    }
49}