image.domain\self_evolve\optimize_exec.mbt
83.3% · 15 / 18 points · 92 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// # 优化执行 self_evolve/optimize_exec - 3
/// - 4
/// 图像处理库子模块 - 5
/// 图像处理库子模块 Image processing library submodule - 6
// 管道优化执行 — 应用 OptimizationSuggestion 到实际 IRPipeline - 7
// Optimize execution: apply suggestions to actual pipeline and verify - 8
// - 9
// Phase 5 v283: 将管道优化从"建议"推向"执行" — 实际应用优化 + 成本验证。 - 10
- 11
///| - 12
/// 优化执行结果。 - 13
/// 描述 Optimization execution result. - 14
#derive(Eq, @debug.Debug) - 15
pub(all) struct OptimizeExecResult { - 16
original_length : Int32 - 17
optimized_length : Int32 - 18
ops_reduced : Int32 - 19
original_cost : Int32 - 20
optimized_cost : Int32 - 21
cost_reduced : Int32 - 22
is_improved : Bool - 23
optimized_pipeline_desc : String - 24
} - 25
- 26
///| - 27
pub extend OptimizeExecResult with @debug.Debug::{to_repr} - 28
- 29
///| - 30
pub extend OptimizeExecResult with Eq::{not_equal, equal} - 31
- 32
///| - 33
/// 执行管道优化并返回结果(含成本变化)。 - 34
/// 执行 Execute pipeline optimization and return result with cost delta. - 35
pub fn exec_optimize(pipeline : @imgir.IRPipeline) -> OptimizeExecResult { - 36●
let report = optimize_all(pipeline) - 37●
let original_baseline = estimate_pipeline_cost(pipeline) - 38●
let optimized_baseline = estimate_pipeline_cost(report.optimized_pipeline) - 39
let ops_reduced = report.original_length - report.optimized_length - 40
let cost_reduced = original_baseline.total_cost - - 41
optimized_baseline.total_cost - 42
let is_improved = ops_reduced > 0 || cost_reduced > 0 - 43
{ - 44
original_length: report.original_length, - 45
optimized_length: report.optimized_length, - 46
ops_reduced, - 47
original_cost: original_baseline.total_cost, - 48
optimized_cost: optimized_baseline.total_cost, - 49
cost_reduced, - 50
is_improved, - 51●
optimized_pipeline_desc: @imgir.ir_describe(report.optimized_pipeline), - 52
} - 53
} - 54
- 55
///| - 56
/// 对全部 19 种算子执行优化。 - 57
/// 执行 Execute optimization on all 19 op variants. - 58
pub fn exec_optimize_all() -> Array[OptimizeExecResult] { - 59●
let results : Array[OptimizeExecResult] = [] - 60●
for op in all_ops() { - 61●
let pipe = @imgir.IRPipeline::new().add(op) - 62●
results.push(exec_optimize(pipe)) - 63
} - 64
results - 65
} - 66
- 67
///| - 68
/// 验证优化后管道不劣化(算子数不增加且成本不增加)。 - 69
/// 校验 Verify optimization does not degrade (ops and cost non-increasing). - 70
pub fn optimize_verified(pipeline : @imgir.IRPipeline) -> Bool { - 71●
let result = exec_optimize(pipeline) - 72
result.optimized_length <= result.original_length && - 73
result.optimized_cost <= result.original_cost - 74
} - 75
- 76
///| - 77
/// 优化是否显著(算子减少或成本降低)。 - 78
/// 描述 Whether optimization is significant. - 79
pub fn OptimizeExecResult::is_significant(self : OptimizeExecResult) -> Bool { - 80●
self.ops_reduced > 0 || self.cost_reduced > 0 - 81
} - 82
- 83
///| - 84
/// 优化效率(成本降低百分比,0-100)。 - 85
/// 描述 Optimization efficiency (cost reduction percentage, 0-100). - 86
pub fn OptimizeExecResult::efficiency_pct(self : OptimizeExecResult) -> Int32 { - 87○
if self.original_cost == 0 { - 88○
0 - 89
} else { - 90○
self.cost_reduced * 100 / self.original_cost - 91
} - 92
}