cherenkov/qwen4_exp/gpu/activity/
layers.rs1use super::reads::{ReadSources, ReadStats};
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize)]
7pub struct PredictionStats {
8 pub target_batches: u64,
9 pub predicted_selected: u64,
10 pub predicted_unused: u64,
11 pub selected_unpredicted: u64,
12 pub predicted_resident: u64,
13 pub needed_prefetch_ready: u64,
14 pub needed_prefetch_late: u64,
15}
16
17impl PredictionStats {
18 pub fn add(&mut self, other: Self) {
19 self.target_batches += other.target_batches;
20 self.predicted_selected += other.predicted_selected;
21 self.predicted_unused += other.predicted_unused;
22 self.selected_unpredicted += other.selected_unpredicted;
23 self.predicted_resident += other.predicted_resident;
24 self.needed_prefetch_ready += other.needed_prefetch_ready;
25 self.needed_prefetch_late += other.needed_prefetch_late;
26 }
27}
28
29#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize)]
30pub struct PhaseStats {
31 pub service_windows: u64,
32 pub service_wall_seconds: f64,
33 pub service_cpu_seconds: f64,
34 pub prefetch_wait_seconds: f64,
35 pub demand_wait_seconds: f64,
36 pub gpu_windows: u64,
37 pub invalid_gpu_windows: u64,
38 pub router_to_resident_seconds: f64,
39 pub resident_seconds: f64,
40 pub resident_to_fetched_seconds: f64,
41 pub fetched_stage_seconds: f64,
42 pub cpu_observation_delay_seconds: f64,
43 pub cpu_prepare_seconds: f64,
44 pub cpu_after_resident_release_seconds: f64,
45}
46
47impl PhaseStats {
48 pub fn add(&mut self, other: Self) {
49 self.service_windows += other.service_windows;
50 self.service_wall_seconds += other.service_wall_seconds;
51 self.service_cpu_seconds += other.service_cpu_seconds;
52 self.prefetch_wait_seconds += other.prefetch_wait_seconds;
53 self.demand_wait_seconds += other.demand_wait_seconds;
54 self.gpu_windows += other.gpu_windows;
55 self.invalid_gpu_windows += other.invalid_gpu_windows;
56 self.router_to_resident_seconds += other.router_to_resident_seconds;
57 self.resident_seconds += other.resident_seconds;
58 self.resident_to_fetched_seconds += other.resident_to_fetched_seconds;
59 self.fetched_stage_seconds += other.fetched_stage_seconds;
60 self.cpu_observation_delay_seconds += other.cpu_observation_delay_seconds;
61 self.cpu_prepare_seconds += other.cpu_prepare_seconds;
62 self.cpu_after_resident_release_seconds += other.cpu_after_resident_release_seconds;
63 }
64}
65
66#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize)]
67pub struct QuantStats {
68 pub bits: u8,
69 pub selected_rows: u64,
70 pub selected_experts: u64,
71 pub eligible_weak_misses: u64,
72 pub cut_experts: u64,
73 pub cut_batches: u64,
74 pub reads: ReadSources,
75}
76
77impl QuantStats {
78 fn add(&mut self, other: Self) {
79 self.selected_rows += other.selected_rows;
80 self.selected_experts += other.selected_experts;
81 self.eligible_weak_misses += other.eligible_weak_misses;
82 self.cut_experts += other.cut_experts;
83 self.cut_batches += other.cut_batches;
84
85 self.reads.add(other.reads);
86 }
87}
88
89#[derive(Debug, Clone, Serialize, Deserialize)]
90pub struct LayerStats {
91 pub prediction: PredictionStats,
92 pub phases: PhaseStats,
93 pub quant: [QuantStats; 3],
94}
95
96impl Default for LayerStats {
97 fn default() -> Self {
98 Self {
99 prediction: PredictionStats::default(),
100 phases: PhaseStats::default(),
101 quant: [4, 3, 2].map(|bits| QuantStats {
102 bits,
103 ..QuantStats::default()
104 }),
105 }
106 }
107}
108
109impl LayerStats {
110 pub fn add(&mut self, other: &Self) {
111 self.prediction.add(other.prediction);
112 self.phases.add(other.phases);
113
114 for (a, &b) in self.quant.iter_mut().zip(&other.quant) {
115 a.add(b);
116 }
117 }
118
119 pub fn reads(&self) -> ReadStats {
120 let mut total = ReadStats::default();
121
122 for q in &self.quant {
123 total.add(q.reads.total());
124 }
125
126 total
127 }
128}