Skip to main content

lift_predict/
budget.rs

1use crate::roofline::RooflineResult;
2use lift_sim::analysis::AnalysisReport;
3use lift_sim::cost::Budget;
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct BudgetCheck {
8    pub passed: bool,
9    pub violations: Vec<String>,
10}
11
12pub fn check_budget(
13    report: &AnalysisReport,
14    prediction: &RooflineResult,
15    budget: &Budget,
16) -> BudgetCheck {
17    let mut violations = Vec::new();
18
19    if let Err(e) = budget.check_flops(report.total_flops) {
20        violations.push(e);
21    }
22    if let Err(e) = budget.check_memory(report.peak_memory_bytes) {
23        violations.push(e);
24    }
25    if let Some(max_time) = budget.max_time_ms {
26        if prediction.predicted_time_ms > max_time {
27            violations.push(format!(
28                "Time budget exceeded: {:.2}ms > {:.2}ms",
29                prediction.predicted_time_ms, max_time
30            ));
31        }
32    }
33
34    BudgetCheck {
35        passed: violations.is_empty(),
36        violations,
37    }
38}