entrenar/efficiency/platform/
server.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7pub struct ServerEfficiency {
8 pub throughput_samples_per_sec: f64,
10 pub gpu_utilization_percent: f64,
12 pub memory_bandwidth_gbps: f64,
14}
15
16impl ServerEfficiency {
17 pub fn new(
19 throughput_samples_per_sec: f64,
20 gpu_utilization_percent: f64,
21 memory_bandwidth_gbps: f64,
22 ) -> Self {
23 Self {
24 throughput_samples_per_sec,
25 gpu_utilization_percent: gpu_utilization_percent.clamp(0.0, 100.0),
26 memory_bandwidth_gbps,
27 }
28 }
29
30 pub fn is_gpu_efficient(&self) -> bool {
32 self.gpu_utilization_percent >= 70.0
33 }
34
35 pub fn is_gpu_underutilized(&self) -> bool {
37 self.gpu_utilization_percent < 50.0
38 }
39
40 pub fn throughput_efficiency(&self) -> f64 {
42 if self.gpu_utilization_percent > 0.0 {
43 self.throughput_samples_per_sec / self.gpu_utilization_percent
44 } else {
45 0.0
46 }
47 }
48
49 pub fn estimated_max_throughput(&self) -> f64 {
51 if self.gpu_utilization_percent > 0.0 {
52 self.throughput_samples_per_sec * (100.0 / self.gpu_utilization_percent)
53 } else {
54 0.0
55 }
56 }
57
58 pub fn memory_bound(&self, expected_bandwidth_gbps: f64) -> bool {
60 self.memory_bandwidth_gbps > expected_bandwidth_gbps * 0.9
61 }
62}
63
64impl Default for ServerEfficiency {
65 fn default() -> Self {
66 Self {
67 throughput_samples_per_sec: 0.0,
68 gpu_utilization_percent: 0.0,
69 memory_bandwidth_gbps: 0.0,
70 }
71 }
72}