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