image.domain\self_evolve\perf_cost.mbt
97.4% · 38 / 39 points · 114 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/perf_cost - 3
/// - 4
/// 图像处理库子模块 - 5
/// 图像处理库子模块 Image processing library submodule - 6
// 算子静态成本估算 — 基于复杂度模型 - 7
// Op static cost estimation: based on complexity model - 8
- 9
///| - 10
/// 估算单个算子的静态成本。 - 11
/// 描述 Estimate static cost of a single op. - 12
pub fn estimate_op_cost(op : @imgir.IROp) -> OpCost { - 13●
let tag = op.tag() - 14●
match op { - 15
@imgir.FlipH => - 16●
{ op_tag: tag, time_complexity: "O(n)", estimated_cost: 10, } - 17
@imgir.FlipV => - 18●
{ op_tag: tag, time_complexity: "O(n)", estimated_cost: 10, } - 19
@imgir.Rotate90 => - 20●
{ op_tag: tag, time_complexity: "O(n)", estimated_cost: 10, } - 21
@imgir.ToGray => - 22●
{ op_tag: tag, time_complexity: "O(n)", estimated_cost: 15, } - 23
@imgir.Brightness(_) => - 24●
{ op_tag: tag, time_complexity: "O(n)", estimated_cost: 5, } - 25
@imgir.Resize(_, _) => - 26●
{ op_tag: tag, time_complexity: "O(n)", estimated_cost: 30, } - 27
@imgir.Crop(_, _, _, _) => - 28●
{ op_tag: tag, time_complexity: "O(n)", estimated_cost: 8, } - 29
@imgir.GaussianBlur(_, _) => - 30●
{ op_tag: tag, time_complexity: "O(n*r^2)", estimated_cost: 50, } - 31
@imgir.BoxBlur(_) => - 32●
{ op_tag: tag, time_complexity: "O(n*r)", estimated_cost: 40, } - 33
@imgir.Sharpen(_) => - 34●
{ op_tag: tag, time_complexity: "O(n)", estimated_cost: 20, } - 35
@imgir.ToScalarField => - 36●
{ op_tag: tag, time_complexity: "O(n)", estimated_cost: 12, } - 37
@imgir.ScalarFieldToImage => - 38●
{ op_tag: tag, time_complexity: "O(n)", estimated_cost: 12, } - 39
@imgir.FieldGradient => - 40●
{ op_tag: tag, time_complexity: "O(n)", estimated_cost: 25, } - 41
@imgir.FieldLaplacian => - 42●
{ op_tag: tag, time_complexity: "O(n)", estimated_cost: 25, } - 43
@imgir.FieldIntegrate => - 44●
{ op_tag: tag, time_complexity: "O(n)", estimated_cost: 18, } - 45
@imgir.FieldClamp(_, _) => - 46●
{ op_tag: tag, time_complexity: "O(n)", estimated_cost: 10, } - 47
@imgir.FieldMask(_) => - 48●
{ op_tag: tag, time_complexity: "O(n)", estimated_cost: 10, } - 49
@imgir.STSnapshot(_) => - 50●
{ op_tag: tag, time_complexity: "O(n)", estimated_cost: 35, } - 51
@imgir.STInterpolate(_) => - 52●
{ op_tag: tag, time_complexity: "O(n)", estimated_cost: 35, } - 53
@imgir.IROp::.. => - 54○
{ op_tag: tag, time_complexity: "O(n)", estimated_cost: 20, } - 55
} - 56
} - 57
- 58
///| - 59
/// 估算管道总成本。 - 60
/// 描述 Estimate total cost of a pipeline. - 61
pub fn estimate_pipeline_cost(pipeline : @imgir.IRPipeline) -> PerfBaseline { - 62●
let ops = pipeline.ops - 63
let op_costs : Array[OpCost] = [] - 64
let mut total = 0 - 65
for op in ops { - 66●
let cost = estimate_op_cost(op) - 67●
op_costs.push(cost) - 68
total = total + cost.estimated_cost - 69
} - 70
{ - 71●
pipeline_desc: @imgir.ir_describe(pipeline), - 72
total_cost: total, - 73●
op_count: ops.length(), - 74
op_costs, - 75
} - 76
} - 77
- 78
///| - 79
/// 检测优化前后是否性能回归。 - 80
/// 检查 Check for performance regression between original and optimized. - 81
pub fn check_regression( - 82
original : PerfBaseline, - 83
optimized : PerfBaseline, - 84
) -> PerfRegression { - 85●
let delta = optimized.total_cost - original.total_cost - 86
{ - 87
original_cost: original.total_cost, - 88
optimized_cost: optimized.total_cost, - 89
delta, - 90
is_regression: delta > 0, - 91
} - 92
} - 93
- 94
///| - 95
/// 对管道执行优化并检测性能回归。 - 96
/// 描述 Optimize pipeline and check for performance regression. - 97
pub fn perf_optimize_check(pipeline : @imgir.IRPipeline) -> PerfRegression { - 98●
let original = estimate_pipeline_cost(pipeline) - 99●
let optimized_pipe = optimize_pipeline(pipeline) - 100●
let optimized = estimate_pipeline_cost(optimized_pipe) - 101●
check_regression(original, optimized) - 102
} - 103
- 104
///| - 105
/// 比较两个管道的成本。 - 106
/// 比较 Compare cost of two pipelines. - 107
pub fn compare_pipelines( - 108
pipe1 : @imgir.IRPipeline, - 109
pipe2 : @imgir.IRPipeline, - 110
) -> PerfRegression { - 111●
let baseline1 = estimate_pipeline_cost(pipe1) - 112●
let baseline2 = estimate_pipeline_cost(pipe2) - 113●
check_regression(baseline1, baseline2) - 114
}