image.domain\self_evolve\propagation.mbt

70.5% · 31 / 44 points · 147 lines

Background color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.

  1. 1///|
  2. 2/// # 传播 self_evolve/propagation
  3. 3///
  4. 4/// 图像处理库子模块
  5. 5/// 图像处理库子模块 Image processing library submodule
  6. 6// 跨算子退化传播 — 分析 pipeline 中退化如何在算子间传播
  7. 7// Cross-op degradation propagation: analyze how degradations propagate across pipeline
  8. 8//
  9. 9// Phase 7 v291: 将根因分析从"单算子"推向"跨算子传播链" — 退化如何在管道中传播。
  10. 10
  11. 11///|
  12. 12/// 单个退化传播步骤。
  13. 13/// 描述 Single degradation propagation step.
  14. 14#derive(Eq, @debug.Debug)
  15. 15pub(all) struct PropagationStep {
  16. 16 from_op_tag : String
  17. 17 to_op_tag : String
  18. 18 degradation_kind : DegradationKind
  19. 19 propagation_desc : String
  20. 20}
  21. 21
  22. 22///|
  23. 23pub extend PropagationStep with @debug.Debug::{to_repr}
  24. 24
  25. 25///|
  26. 26pub extend PropagationStep with Eq::{not_equal, equal}
  27. 27
  28. 28///|
  29. 29/// 退化传播报告。
  30. 30/// 描述 Degradation propagation report.
  31. 31#derive(Eq, @debug.Debug)
  32. 32pub(all) struct PropagationReport {
  33. 33 steps : Array[PropagationStep]
  34. 34 total_propagations : Int32
  35. 35 chain_length : Int32
  36. 36 summary : String
  37. 37}
  38. 38
  39. 39///|
  40. 40pub extend PropagationReport with @debug.Debug::{to_repr}
  41. 41
  42. 42///|
  43. 43pub extend PropagationReport with Eq::{not_equal, equal}
  44. 44
  45. 45///|
  46. 46/// 分析管道中退化传播链。
  47. 47/// 描述 Analyze degradation propagation chain in a pipeline.
  48. 48pub fn analyze_propagation(pipeline : @imgir.IRPipeline) -> PropagationReport {
  49. 49● let steps : Array[PropagationStep] = []
  50. 50 let ops = pipeline.ops
  51. 51● let n = ops.length()
  52. 52 for i in 0..<n {
  53. 53● let degs = detect_degradation(ops[i])
  54. 54● if degs.length() > 0 && i + 1 < n {
  55. 55● let from_tag = ops[i].tag()
  56. 56● let to_tag = ops[i + 1].tag()
  57. 57 for d in degs {
  58. 58● let desc = match d.kind {
  59. 59 DivisionByZero =>
  60. 60● "除零退化从 " + from_tag + " 传播至 " + to_tag
  61. 61 SingularMatrix =>
  62. 62○ "奇异矩阵从 " + from_tag + " 传播至 " + to_tag
  63. 63 FieldDiscontinuity =>
  64. 64● "场间断从 " + from_tag + " 传播至 " + to_tag
  65. 65○ Overflow => "溢出从 " + from_tag + " 传播至 " + to_tag
  66. 66○ NaNValue => "NaN 从 " + from_tag + " 传播至 " + to_tag
  67. 67○ InfValue => "Inf 从 " + from_tag + " 传播至 " + to_tag
  68. 68 }
  69. 69● steps.push({
  70. 70 from_op_tag: from_tag,
  71. 71 to_op_tag: to_tag,
  72. 72 degradation_kind: d.kind,
  73. 73 propagation_desc: desc,
  74. 74 })
  75. 75 }
  76. 76 }
  77. 77 }
  78. 78● let total = steps.length()
  79. 79● let chain_length = if total > 0 { n } else { 0 }
  80. 80 let summary = "传播分析: " +
  81. 81● total.to_string() +
  82. 82 " 处退化传播, 链长 " +
  83. 83● chain_length.to_string() +
  84. 84 "(管道 " +
  85. 85● @imgir.ir_describe(pipeline) +
  86. 86 ")"
  87. 87 { steps, total_propagations: total, chain_length, summary, }
  88. 88}
  89. 89
  90. 90///|
  91. 91/// 对全部 19 种算子的相邻组合分析传播。
  92. 92/// 描述 Analyze propagation for all adjacent op combinations.
  93. 93pub fn analyze_propagation_all() -> PropagationReport {
  94. 94● let ops = all_ops()
  95. 95 let steps : Array[PropagationStep] = []
  96. 96● let n = ops.length()
  97. 97 for i in 0..<(n - 1) {
  98. 98● let from_tag = ops[i].tag()
  99. 99● let to_tag = ops[i + 1].tag()
  100. 100● let degs = detect_degradation(ops[i])
  101. 101 for d in degs {
  102. 102○ let desc = match d.kind {
  103. 103○ DivisionByZero => "除零退化从 " + from_tag + " 传播至 " + to_tag
  104. 104○ SingularMatrix => "奇异矩阵从 " + from_tag + " 传播至 " + to_tag
  105. 105 FieldDiscontinuity =>
  106. 106○ "场间断从 " + from_tag + " 传播至 " + to_tag
  107. 107○ Overflow => "溢出从 " + from_tag + " 传播至 " + to_tag
  108. 108○ NaNValue => "NaN 从 " + from_tag + " 传播至 " + to_tag
  109. 109○ InfValue => "Inf 从 " + from_tag + " 传播至 " + to_tag
  110. 110 }
  111. 111○ steps.push({
  112. 112 from_op_tag: from_tag,
  113. 113 to_op_tag: to_tag,
  114. 114 degradation_kind: d.kind,
  115. 115 propagation_desc: desc,
  116. 116 })
  117. 117 }
  118. 118 }
  119. 119● let total = steps.length()
  120. 120 let summary = "全算子传播分析: " +
  121. 121● total.to_string() +
  122. 122 " 处退化传播"
  123. 123 { steps, total_propagations: total, chain_length: n, summary, }
  124. 124}
  125. 125
  126. 126///|
  127. 127/// 管道是否有传播风险。
  128. 128/// 描述 Whether pipeline has propagation risk.
  129. 129pub fn has_propagation_risk(pipeline : @imgir.IRPipeline) -> Bool {
  130. 130● analyze_propagation(pipeline).total_propagations > 0
  131. 131}
  132. 132
  133. 133///|
  134. 134/// 获取管道的传播链。
  135. 135/// 获取 Get propagation chain of a pipeline.
  136. 136pub fn propagation_chain(
  137. 137 pipeline : @imgir.IRPipeline,
  138. 138) -> Array[PropagationStep] {
  139. 139● analyze_propagation(pipeline).steps
  140. 140}
  141. 141
  142. 142///|
  143. 143/// 传播报告是否无风险。
  144. 144/// 描述 Whether propagation report has no risk.
  145. 145pub fn PropagationReport::is_safe(self : PropagationReport) -> Bool {
  146. 146● self.total_propagations == 0
  147. 147}