Skip to main content

cbtop/
config.rs

1//! Configuration for cbtop
2//!
3//! Handles CLI arguments and config file parsing.
4
5use std::path::PathBuf;
6
7/// cbtop configuration
8#[derive(Debug, Clone)]
9pub struct Config {
10    /// Refresh rate in milliseconds
11    pub refresh_ms: u64,
12    /// GPU device index
13    pub device_index: u32,
14    /// Compute backend
15    pub backend: ComputeBackend,
16    /// Load profile
17    pub load_profile: LoadProfile,
18    /// Workload type
19    pub workload: WorkloadType,
20    /// Problem size in elements
21    pub problem_size: usize,
22    /// Thread count for SIMD
23    pub threads: usize,
24    /// Enable deterministic mode for testing
25    pub deterministic: bool,
26    /// Show FPS statistics
27    pub show_fps: bool,
28    /// Config file path
29    pub config_path: Option<PathBuf>,
30}
31
32impl Default for Config {
33    fn default() -> Self {
34        Self {
35            refresh_ms: 100,
36            device_index: 0,
37            backend: ComputeBackend::All,
38            load_profile: LoadProfile::Idle,
39            workload: WorkloadType::Gemm,
40            problem_size: 1_048_576,
41            threads: num_cpus::get(),
42            deterministic: false,
43            show_fps: false,
44            config_path: None,
45        }
46    }
47}
48
49/// Compute backend selection
50#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, serde::Serialize, serde::Deserialize)]
51pub enum ComputeBackend {
52    /// CPU SIMD (SSE2/AVX2/AVX-512/NEON)
53    Simd,
54    /// Cross-platform GPU (Vulkan/Metal/DX12)
55    Wgpu,
56    /// Native NVIDIA CUDA
57    Cuda,
58    /// All backends simultaneously
59    #[default]
60    All,
61}
62
63/// Load profile intensity
64#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
65pub enum LoadProfile {
66    /// No load
67    #[default]
68    Idle,
69    /// 25% intensity
70    Light,
71    /// 50% intensity
72    Medium,
73    /// 75% intensity
74    Heavy,
75    /// 100% intensity
76    Stress,
77}
78
79impl LoadProfile {
80    /// Convert to intensity value (0.0 - 1.0)
81    pub fn intensity(&self) -> f64 {
82        match self {
83            Self::Idle => 0.0,
84            Self::Light => 0.25,
85            Self::Medium => 0.50,
86            Self::Heavy => 0.75,
87            Self::Stress => 1.0,
88        }
89    }
90}
91
92/// Workload type
93#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, serde::Serialize, serde::Deserialize)]
94pub enum WorkloadType {
95    /// Matrix multiplication
96    #[default]
97    Gemm,
98    /// 2D convolution
99    Conv2d,
100    /// Transformer attention
101    Attention,
102    /// Memory bandwidth stress
103    Bandwidth,
104    /// Element-wise operations
105    Elementwise,
106    /// Reduction operations
107    Reduction,
108    /// Cycle through all
109    All,
110}
111
112fn num_cpus() -> usize {
113    std::thread::available_parallelism()
114        .map(|n| n.get())
115        .unwrap_or(1)
116}
117
118mod num_cpus {
119    pub fn get() -> usize {
120        std::thread::available_parallelism()
121            .map(|n| n.get())
122            .unwrap_or(1)
123    }
124}