ops-tune-workbench-plugin 0.0.0-stage → 0.0.1-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/NOTICE.md +14 -0
  2. package/README.md +39 -2
  3. package/cordis.patch.yml +20 -0
  4. package/lib/client.js +4253 -0
  5. package/lib/host.js +2518 -0
  6. package/package.json +53 -4
  7. package/skills/tool-ops-tune/INSTALL.md +52 -0
  8. package/skills/tool-ops-tune/README.md +167 -0
  9. package/skills/tool-ops-tune/SKILL.md +93 -0
  10. package/skills/tool-ops-tune/agent/AGENTS.md +195 -0
  11. package/skills/tool-ops-tune/agent/agents/perf-implementer.md +68 -0
  12. package/skills/tool-ops-tune/agent/agents/perf-reviewer.md +86 -0
  13. package/skills/tool-ops-tune/agent/workflows/task-prompts.md +362 -0
  14. package/skills/tool-ops-tune/agent/workflows/troubleshooting.md +43 -0
  15. package/skills/tool-ops-tune/docs/figures/opstune-architecture.png +0 -0
  16. package/skills/tool-ops-tune/docs/figures/opstune-architecture.svg +253 -0
  17. package/skills/tool-ops-tune/docs/ops-tune-design.md +404 -0
  18. package/skills/tool-ops-tune/docs//347/224/250/344/276/213/346/236/204/345/273/272.md +714 -0
  19. package/skills/tool-ops-tune/docs//347/237/245/350/257/206/345/272/223/350/247/204/350/214/203.md +103 -0
  20. package/skills/tool-ops-tune/evals/evals.json +242 -0
  21. package/skills/tool-ops-tune/ops-collect/SKILL.md +146 -0
  22. package/skills/tool-ops-tune/ops-collect/references/tool-routing.md +86 -0
  23. package/skills/tool-ops-tune/ops-collect/scripts/collect_board.sh +444 -0
  24. package/skills/tool-ops-tune/ops-collect/scripts/collect_cases.py +368 -0
  25. package/skills/tool-ops-tune/ops-collect/scripts/collect_sim.sh +134 -0
  26. package/skills/tool-ops-tune/ops-collect/scripts/csv_to_db.py +314 -0
  27. package/skills/tool-ops-tune/ops-collect/scripts/db_bench.py +545 -0
  28. package/skills/tool-ops-tune/ops-collect/scripts/facts_bridge.py +1063 -0
  29. package/skills/tool-ops-tune/ops-collect/scripts/isolation_test.py +454 -0
  30. package/skills/tool-ops-tune/ops-collect/scripts/jsonl_to_cases.py +163 -0
  31. package/skills/tool-ops-tune/ops-family/SKILL.md +76 -0
  32. package/skills/tool-ops-tune/ops-family/references/broadcast/advanced_tiling.md +92 -0
  33. package/skills/tool-ops-tune/ops-family/references/broadcast/broadcast_design.md +160 -0
  34. package/skills/tool-ops-tune/ops-family/references/broadcast/code/broadcast_add_kernel.cpp +126 -0
  35. package/skills/tool-ops-tune/ops-family/references/broadcast/code/broadcast_add_tiling.cpp +144 -0
  36. package/skills/tool-ops-tune/ops-family/references/broadcast/code/broadcast_tiling_common.h +401 -0
  37. package/skills/tool-ops-tune/ops-family/references/broadcast/code/onedim_add_kernel.cpp +107 -0
  38. package/skills/tool-ops-tune/ops-family/references/broadcast/code/onedim_add_tiling.cpp +64 -0
  39. package/skills/tool-ops-tune/ops-family/references/broadcast/datacopypad_design.md +46 -0
  40. package/skills/tool-ops-tune/ops-family/references/broadcast/guide.md +14 -0
  41. package/skills/tool-ops-tune/ops-family/references/broadcast/nddma_design.md +53 -0
  42. package/skills/tool-ops-tune/ops-family/references/broadcast/onedim_design.md +114 -0
  43. package/skills/tool-ops-tune/ops-family/references/broadcast/ub_broadcast_design.md +67 -0
  44. package/skills/tool-ops-tune/ops-family/references/common/datacopy_optimization_design.md +351 -0
  45. package/skills/tool-ops-tune/ops-family/references/common/index.md +9 -0
  46. package/skills/tool-ops-tune/ops-family/references/common/tail_block_design.md +268 -0
  47. package/skills/tool-ops-tune/ops-family/references/common/timing_harness/index.md +38 -0
  48. package/skills/tool-ops-tune/ops-family/references/common/timing_harness/timing_harness_aclrt_event.cpp +199 -0
  49. package/skills/tool-ops-tune/ops-family/references/common/timing_harness/timing_harness_torch_event.py +130 -0
  50. package/skills/tool-ops-tune/ops-family/references/common/ub_resident_design.md +342 -0
  51. package/skills/tool-ops-tune/ops-family/references/conversion/guide.md +69 -0
  52. package/skills/tool-ops-tune/ops-family/references/conversion/index.md +4 -0
  53. package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_base.template +81 -0
  54. package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_big_dim.template +217 -0
  55. package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_cut_one_axis.template +336 -0
  56. package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_cut_two_axis.template +781 -0
  57. package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_n_last.template +340 -0
  58. package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_small_shape.template +321 -0
  59. package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_tensor_move.template +102 -0
  60. package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_transdata_5hd.template +480 -0
  61. package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_transdata_5hd_021axis.template +533 -0
  62. package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_with_gather.template +688 -0
  63. package/skills/tool-ops-tune/ops-family/references/conversion/templates/transpose_tiling_data.template +192 -0
  64. package/skills/tool-ops-tune/ops-family/references/conversion/transpose_big_dim.md +220 -0
  65. package/skills/tool-ops-tune/ops-family/references/conversion/transpose_cut_one_axis.md +175 -0
  66. package/skills/tool-ops-tune/ops-family/references/conversion/transpose_cut_two_axis.md +177 -0
  67. package/skills/tool-ops-tune/ops-family/references/conversion/transpose_fusion_design.md +398 -0
  68. package/skills/tool-ops-tune/ops-family/references/conversion/transpose_gather.md +191 -0
  69. package/skills/tool-ops-tune/ops-family/references/conversion/transpose_n_last.md +276 -0
  70. package/skills/tool-ops-tune/ops-family/references/conversion/transpose_small_shape.md +315 -0
  71. package/skills/tool-ops-tune/ops-family/references/conversion/transpose_tensor_move.md +203 -0
  72. package/skills/tool-ops-tune/ops-family/references/conversion/transpose_tiling_data.md +176 -0
  73. package/skills/tool-ops-tune/ops-family/references/conversion/transpose_vconv_021.md +206 -0
  74. package/skills/tool-ops-tune/ops-family/references/conversion/transpose_vconv_5hd.md +179 -0
  75. package/skills/tool-ops-tune/ops-family/references/elementwise/double_buffer_design.md +288 -0
  76. package/skills/tool-ops-tune/ops-family/references/elementwise/guide.md +46 -0
  77. package/skills/tool-ops-tune/ops-family/references/elementwise/index.md +10 -0
  78. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/CMakeLists.txt +131 -0
  79. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/README.md +55 -0
  80. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_extension/add_custom_torch.cpp +80 -0
  81. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_extension/ops.h +23 -0
  82. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_extension/register.cpp +30 -0
  83. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_host/add_custom.asc +149 -0
  84. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_host/data_utils.h +97 -0
  85. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_kernel/add_custom_kernel.asc +136 -0
  86. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_kernel/add_custom_tiling.h +31 -0
  87. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/run.sh +86 -0
  88. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/scripts/gen_data.py +70 -0
  89. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/scripts/golden.py +34 -0
  90. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/scripts/test_torch.py +99 -0
  91. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/scripts/verify_result.py +56 -0
  92. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/usage_guide.md +61 -0
  93. package/skills/tool-ops-tune/ops-family/references/elementwise/vector_efficiency_design.md +203 -0
  94. package/skills/tool-ops-tune/ops-family/references/fa/fa_mixed_kernel_design.md +174 -0
  95. package/skills/tool-ops-tune/ops-family/references/fa/fa_roofline_design.md +141 -0
  96. package/skills/tool-ops-tune/ops-family/references/fa/guide.md +87 -0
  97. package/skills/tool-ops-tune/ops-family/references/knowledge_gaps.json +56 -0
  98. package/skills/tool-ops-tune/ops-family/references/matmul/best-practices-guide.md +14 -0
  99. package/skills/tool-ops-tune/ops-family/references/matmul/fullload_design.md +344 -0
  100. package/skills/tool-ops-tune/ops-family/references/matmul/guide.md +52 -0
  101. package/skills/tool-ops-tune/ops-family/references/matmul/mte2_preload_design.md +320 -0
  102. package/skills/tool-ops-tune/ops-family/references/matmul/pingpong_design.md +254 -0
  103. package/skills/tool-ops-tune/ops-family/references/matmul/scale_coalescing_design.md +282 -0
  104. package/skills/tool-ops-tune/ops-family/references/matmul/streamk_design.md +374 -0
  105. package/skills/tool-ops-tune/ops-family/references/matmul/swat_design.md +423 -0
  106. package/skills/tool-ops-tune/ops-family/references/matmul/templates/matmul_basic_blaze.template +165 -0
  107. package/skills/tool-ops-tune/ops-family/references/matmul/templates/usage_guide.md +29 -0
  108. package/skills/tool-ops-tune/ops-family/references/mc2/best-practices-guide.md +43 -0
  109. package/skills/tool-ops-tune/ops-family/references/mc2/guide.md +42 -0
  110. package/skills/tool-ops-tune/ops-family/references/mc2/local_matmul_design.md +130 -0
  111. package/skills/tool-ops-tune/ops-family/references/mc2/pipeline_balancing_design.md +502 -0
  112. package/skills/tool-ops-tune/ops-family/references/reduce/guide.md +178 -0
  113. package/skills/tool-ops-tune/ops-family/references/reduce/templates/dav310/kernel_utils.template +75 -0
  114. package/skills/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_ar_full_load.template +429 -0
  115. package/skills/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_ar_recompute.template +485 -0
  116. package/skills/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_ar_small_r.template +348 -0
  117. package/skills/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_ara_full_load.template +574 -0
  118. package/skills/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_ara_online.template +324 -0
  119. package/skills/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_ara_recompute.template +436 -0
  120. package/skills/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_base.template +950 -0
  121. package/skills/tool-ops-tune/ops-family/references/reduce/templates/fused_attention_online_softmax_design.md +428 -0
  122. package/skills/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_ar_full_load.md +137 -0
  123. package/skills/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_ar_recompute.md +135 -0
  124. package/skills/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_ar_small_r.md +122 -0
  125. package/skills/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_ara_full_load.md +144 -0
  126. package/skills/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_ara_online.md +185 -0
  127. package/skills/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_ara_recompute.md +163 -0
  128. package/skills/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_tiling.template +460 -0
  129. package/skills/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_tiling_data.template +278 -0
  130. package/skills/tool-ops-tune/ops-family/references/reduce/templates/state_resident_design.md +337 -0
  131. package/skills/tool-ops-tune/ops-family/references/reduce/templates/usage_guide.md +253 -0
  132. package/skills/tool-ops-tune/ops-family/references/scalar/coding_principles.md +476 -0
  133. package/skills/tool-ops-tune/ops-family/references/scalar/conv_scalar.md +163 -0
  134. package/skills/tool-ops-tune/ops-family/references/scalar/guide.md +30 -0
  135. package/skills/tool-ops-tune/ops-family/references/simt/guide.md +91 -0
  136. package/skills/tool-ops-tune/ops-family/references/simt/optimization-guide.md +110 -0
  137. package/skills/tool-ops-tune/ops-family/references/sort/guide.md +83 -0
  138. package/skills/tool-ops-tune/ops-family/references/sort/radix_sort.md +354 -0
  139. package/skills/tool-ops-tune/ops-family/scripts/family_asset_audit.py +68 -0
  140. package/skills/tool-ops-tune/ops-family/scripts/tiling_candidates.py +419 -0
  141. package/skills/tool-ops-tune/ops-mechanism/SKILL.md +23 -0
  142. package/skills/tool-ops-tune/ops-mechanism/cases/ascendc/case_groupedmatmul_pipeline.md +23 -0
  143. package/skills/tool-ops-tune/ops-mechanism/cases/ascendc/case_triton_atomic_revert.md +19 -0
  144. package/skills/tool-ops-tune/ops-mechanism/cases/mc2/case_mc2_fusion.md +19 -0
  145. package/skills/tool-ops-tune/ops-mechanism/references/optimize/api-usage.md +70 -0
  146. package/skills/tool-ops-tune/ops-mechanism/references/optimize/ascendc-regbase-vf.md +45 -0
  147. package/skills/tool-ops-tune/ops-mechanism/references/optimize/ascendc-tiling.md +51 -0
  148. package/skills/tool-ops-tune/ops-mechanism/references/optimize/data-copy.md +67 -0
  149. package/skills/tool-ops-tune/ops-mechanism/references/optimize/index.md +45 -0
  150. package/skills/tool-ops-tune/ops-mechanism/references/optimize/mc2-balancing.md +77 -0
  151. package/skills/tool-ops-tune/ops-mechanism/references/optimize/mc2.md +103 -0
  152. package/skills/tool-ops-tune/ops-mechanism/references/optimize/memory-hierarchy.md +40 -0
  153. package/skills/tool-ops-tune/ops-mechanism/references/optimize/pipeline.md +95 -0
  154. package/skills/tool-ops-tune/ops-mechanism/scripts/case_backfill.py +170 -0
  155. package/skills/tool-ops-tune/ops-mechanism/scripts/log_gap.py +145 -0
  156. package/skills/tool-ops-tune/ops-mechanism/scripts/mc2_search.py +367 -0
  157. package/skills/tool-ops-tune/ops-report/SKILL.md +77 -0
  158. package/skills/tool-ops-tune/ops-verdict/evals/run_evals.py +837 -0
  159. package/skills/tool-ops-tune/ops-verdict/evals/smoke/install-hooks.sh +65 -0
  160. package/skills/tool-ops-tune/ops-verdict/evals/smoke/run_smoke.sh +405 -0
  161. package/skills/tool-ops-tune/ops-verdict/fixtures/core_tail_a5.csv +25 -0
  162. package/skills/tool-ops-tune/ops-verdict/fixtures/few_cores_a5.csv +5 -0
  163. package/skills/tool-ops-tune/ops-verdict/fixtures/mte2_bound_a2.csv +17 -0
  164. package/skills/tool-ops-tune/ops-verdict/fixtures/multi_kernel_mix_a5.csv +7 -0
  165. package/skills/tool-ops-tune/ops-verdict/fixtures/no_bound_a5.csv +9 -0
  166. package/skills/tool-ops-tune/ops-verdict/fixtures/serial_no_overlap_a2.csv +9 -0
  167. package/skills/tool-ops-tune/ops-verdict/fixtures/vec_bound_a5.csv +9 -0
  168. package/skills/tool-ops-tune/ops-verdict/references/io-contracts.md +94 -0
  169. package/skills/tool-ops-tune/ops-verdict/references/rule-schema.md +130 -0
  170. package/skills/tool-ops-tune/ops-verdict/references/scope-schema.md +61 -0
  171. package/skills/tool-ops-tune/ops-verdict/references/soc-spec.yaml +140 -0
  172. package/skills/tool-ops-tune/ops-verdict/rules/L0-instruction.yaml +67 -0
  173. package/skills/tool-ops-tune/ops-verdict/rules/L1-single-core.yaml +316 -0
  174. package/skills/tool-ops-tune/ops-verdict/rules/L2-inter-core.yaml +173 -0
  175. package/skills/tool-ops-tune/ops-verdict/rules/L3-inter-card.yaml +156 -0
  176. package/skills/tool-ops-tune/ops-verdict/scripts/batch_pipeline.py +444 -0
  177. package/skills/tool-ops-tune/ops-verdict/scripts/calibrate.py +249 -0
  178. package/skills/tool-ops-tune/ops-verdict/scripts/delta_compare.py +244 -0
  179. package/skills/tool-ops-tune/ops-verdict/scripts/render_html.py +274 -0
  180. package/skills/tool-ops-tune/ops-verdict/scripts/snapshot.py +200 -0
  181. package/skills/tool-ops-tune/ops-verdict/scripts/trace_bubble.py +331 -0
  182. package/skills/tool-ops-tune/ops-verdict/scripts/verdict.py +1072 -0
  183. package/skills/tool-ops-tune/scripts/diff_audit.py +281 -0
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env bash
2
+ # -----------------------------------------------------------------------------------------------------------
3
+ # Copyright (c) 2026 Huawei Technologies Co., Ltd.
4
+ # This program is free software, you can redistribute it and/or modify it under the terms and conditions of
5
+ # CANN Open Software License Agreement Version 2.0 (the "License").
6
+ # Please refer to the License for details. You may not use this file except in compliance with the License.
7
+ # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
8
+ # INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
9
+ # See LICENSE in the root of the software repository for the full text of the License.
10
+ # -----------------------------------------------------------------------------------------------------------
11
+ # install-hooks.sh — 把 evals + smoke 挂成 pre-push 门禁(本地侧;CI 侧见 .workflow/)
12
+ #
13
+ # 用法:bash ops-verdict/evals/smoke/install-hooks.sh(在 skills/tool-ops-tune/ 下执行)
14
+ set -euo pipefail
15
+ # 脚本所在套件目录(三级上溯 = skills/tool-ops-tune);git 仓库根与 git dir
16
+ # 一律以 git 命令解析(检视 #20 修复:直接把套件目录当仓库根会导致
17
+ # hooks 写到不存在的 skills/tool-ops-tune/.git/hooks/,set -e 下安装直接失败)
18
+ SUITE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
19
+ REPO_ROOT="$(git -C "$SUITE_ROOT" rev-parse --show-toplevel)" || {
20
+ echo "ERROR: 不在 git 仓库内($SUITE_ROOT)——pre-push 门禁需要 git hooks 目录" >&2
21
+ exit 1
22
+ }
23
+ GIT_DIR="$(git -C "$SUITE_ROOT" rev-parse --absolute-git-dir)"
24
+ HOOK="$GIT_DIR/hooks/pre-push"
25
+ mkdir -p "$GIT_DIR/hooks"
26
+
27
+ # 套件在仓内的真实路径(hook 以 git toplevel 为根解析;检视 #18 修复:
28
+ # 此前两套路径互相矛盾且都缺 tool-ops-tune 一级 → 每次 push 必被误拦)
29
+ SUITE_DIR="skills/tool-ops-tune"
30
+ cat > "$HOOK" <<HOOKEOF
31
+ #!/usr/bin/env bash
32
+ # OpsTune pre-push 门禁(install-hooks.sh 生成;检视 §7b)
33
+ set -uo pipefail
34
+ REPO_ROOT="\$(git rev-parse --show-toplevel)"
35
+ SUITE="\$REPO_ROOT/${SUITE_DIR}"
36
+ FAIL=0
37
+
38
+ EVALS_PY="\$SUITE/ops-verdict/evals/run_evals.py"
39
+ SMOKE_SH="\$SUITE/ops-verdict/evals/smoke/run_smoke.sh"
40
+ for f in "\$EVALS_PY" "\$SMOKE_SH"; do
41
+ if [ ! -f "\$f" ]; then
42
+ echo "[pre-push] ERROR: 门禁脚本缺失: \$f(套件未完整检出?)" >&2
43
+ exit 1
44
+ fi
45
+ done
46
+
47
+ echo "[pre-push] evals(判定回归 38 用例)…"
48
+ python3 "\$EVALS_PY" >/dev/null || {
49
+ echo "[pre-push] FAIL: evals 未全绿 —— 规则/阈值变更未过回归,禁止推送" >&2
50
+ FAIL=1
51
+ }
52
+
53
+ echo "[pre-push] smoke(离线干跑冒烟)…"
54
+ bash "\$SMOKE_SH" >/dev/null || {
55
+ echo "[pre-push] FAIL: smoke 冒烟未通过 —— 禁止推送" >&2
56
+ FAIL=1
57
+ }
58
+
59
+ if [[ \$FAIL -ne 0 ]]; then
60
+ exit 1
61
+ fi
62
+ echo "[pre-push] 门禁全绿,放行"
63
+ HOOKEOF
64
+ chmod +x "$HOOK"
65
+ echo "installed: $HOOK(pre-push 时自动跑 evals + smoke;跳过用 git push --no-verify)"
@@ -0,0 +1,405 @@
1
+ #!/usr/bin/env bash
2
+ # -----------------------------------------------------------------------------------------------------------
3
+ # Copyright (c) 2026 Huawei Technologies Co., Ltd.
4
+ # This program is free software, you can redistribute it and/or modify it under the terms and conditions of
5
+ # CANN Open Software License Agreement Version 2.0 (the "License").
6
+ # Please refer to the License for details. You may not use this file except in compliance with the License.
7
+ # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
8
+ # INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
9
+ # See LICENSE in the root of the software repository for the full text of the License.
10
+ # -----------------------------------------------------------------------------------------------------------
11
+ # run_smoke.sh — 离线干跑冒烟(检视 §7b / 整改批次 0)
12
+ #
13
+ # 目的:F1 类「bash -n 查不出、只有真跑才暴露」的 bug 在无 NPU 环境即暴露。
14
+ # 手段:msprof shim(按参数产出预置 CSV 目录的假可执行文件)+ 三模式
15
+ # collect_board.sh 干跑 + bash 语法检查 + isolation from-prof 干跑 +
16
+ # 规则包加载校验 + 族表资产断言。
17
+ #
18
+ # 用法:bash evals/smoke/run_smoke.sh (在仓库根执行)
19
+ # 退出码:0 全绿 / 1 有失败(CI 门禁语义,与 evals/run_evals.py 同级)。
20
+
21
+ set -uo pipefail
22
+ REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)" # skills/tool-ops-tune/
23
+ FAILURES=0
24
+
25
+ pass() { echo "[PASS] $1"; }
26
+ fail() { echo "[FAIL] $1"; FAILURES=$((FAILURES + 1)); }
27
+ check() { if [[ $? -eq 0 ]]; then pass "$1"; else fail "$1"; fi }
28
+
29
+ echo "=== smoke 1: bash 语法检查(collect_board.sh)==="
30
+ bash -n "$REPO_ROOT/ops-collect/scripts/collect_board.sh" 2>/dev/null
31
+ check "bash -n collect_board.sh"
32
+
33
+ echo "=== smoke 2: msprof shim 三模式干跑 ==="
34
+ SMOKE_TMP="$(mktemp -d)"
35
+ trap 'rm -rf "$SMOKE_TMP"' EXIT
36
+ SHIM_BIN="$SMOKE_TMP/bin"; mkdir -p "$SHIM_BIN"
37
+ SHIM_OUT="$SMOKE_TMP/shim_out"; mkdir -p "$SHIM_OUT"
38
+
39
+ # shim:解析 --output= 参数,产出预置 op_summary CSV(Task Duration + pipe 占比)
40
+ cat > "$SHIM_BIN/msprof" <<'SHIM'
41
+ #!/usr/bin/env bash
42
+ OUT=""
43
+ for a in "$@"; do
44
+ case "$a" in --output=*) OUT="${a#--output=}" ;; esac
45
+ done
46
+ mkdir -p "$OUT/mindstudio_profiler_output"
47
+ cat > "$OUT/mindstudio_profiler_output/op_summary_1.csv" <<'CSV'
48
+ Task Duration(us),aic_time(us),aiv_time(us),aiv_vec_ratio,aic_cube_ratio,aic_mte2_ratio,aic_mte1_ratio,aic_fixpipe_ratio,ai_scalar_ratio,aic_mte3_ratio,ai_icache_miss_rate
49
+ 100,0,100.5,0.32,0.00,0.55,0.02,0.01,0.22,0.03,0.9
50
+ 100,0,99.8,0.31,0.00,0.56,0.02,0.01,0.21,0.03,0.9
51
+ CSV
52
+ SHIM
53
+ chmod +x "$SHIM_BIN/msprof"
54
+
55
+ for MODE in standard quick mc2; do
56
+ OUT_DIR="$SMOKE_TMP/prof_$MODE"
57
+ if PATH="$SHIM_BIN:$PATH" bash "$REPO_ROOT/ops-collect/scripts/collect_board.sh" \
58
+ --exe /bin/true --mode "$MODE" --output "$OUT_DIR" >/dev/null 2>&1 \
59
+ && python3 -c "
60
+ import json, sys
61
+ m = json.load(open('$OUT_DIR/collection_manifest.json'))
62
+ assert m['mode'] == '$MODE'
63
+ assert m['blocks'] and all(b['status'] == 'ok' for b in m['blocks']), m['blocks']
64
+ " 2>/dev/null; then
65
+ pass "collect_board.sh --mode $MODE(shim 干跑 + manifest 全 ok)"
66
+ else
67
+ fail "collect_board.sh --mode $MODE"
68
+ fi
69
+ done
70
+
71
+ echo "=== smoke 3: isolation from-prof 干跑(R 值档位从规则 YAML 派生)==="
72
+ if [ ! -f "$REPO_ROOT/ops-collect/scripts/isolation_test.py" ]; then
73
+ echo "[SKIP] isolation_test.py 未交付(随多卡域 PR),smoke 3 暂跳过——交付后本段自动生效"
74
+ else
75
+ ISO_TMP="$SMOKE_TMP/iso"
76
+ mkdir -p "$ISO_TMP/comm/PROF_x/mindstudio_profiler_output" "$ISO_TMP/compute/PROF_y/mindstudio_profiler_output"
77
+ printf 'Task Duration(us),aic_mte2_ratio\n101,4\n102,4\n103,5\n104,5\n105,5\n106,5\n107,5\n108,5\n109,5\n110,5\n' \
78
+ > "$ISO_TMP/comm/PROF_x/mindstudio_profiler_output/op_summary_a.csv"
79
+ printf 'Task Duration(us),aic_mte2_ratio\n251,40\n252,40\n253,41\n254,41\n255,41\n256,41\n257,41\n258,41\n259,41\n260,41\n' \
80
+ > "$ISO_TMP/compute/PROF_y/mindstudio_profiler_output/op_summary_b.csv"
81
+ if python3 "$REPO_ROOT/ops-collect/scripts/isolation_test.py" \
82
+ --exe /bin/true --switch-mode from-prof \
83
+ --comm-prof "$ISO_TMP/comm" --compute-prof "$ISO_TMP/compute" --warmup 5 \
84
+ --output "$SMOKE_TMP/iso_result.json" >/dev/null 2>&1 \
85
+ && python3 -c "
86
+ import json
87
+ d = json.load(open('$SMOKE_TMP/iso_result.json'))
88
+ assert d['bound_hint'] == 'L3_MC2_STRONG_COMPUTE', d['bound_hint']
89
+ assert d['mte2_ratio_pure'] is not None
90
+ assert 'mte2_ratio_pure' in d['verdict_scalar']
91
+ " 2>/dev/null; then
92
+ pass "isolation_test from-prof(R≈2.4 → STRONG_COMPUTE + mte2_ratio_pure 产出)"
93
+ else
94
+ fail "isolation_test from-prof"
95
+ fi
96
+ fi
97
+
98
+ echo "=== smoke 4: 规则包加载校验(四包零误报)==="
99
+ if python3 "$REPO_ROOT/ops-verdict/scripts/verdict.py" \
100
+ --rules "$REPO_ROOT/ops-verdict/rules/L3-inter-card.yaml,$REPO_ROOT/ops-verdict/rules/L2-inter-core.yaml,$REPO_ROOT/ops-verdict/rules/L1-single-core.yaml,$REPO_ROOT/ops-verdict/rules/L0-instruction.yaml" \
101
+ --soc a5 --scalar t_comm_us=100,t_compute_us=250 \
102
+ -o "$SMOKE_TMP/v.json" >/dev/null 2>&1; then
103
+ pass "四规则包全瀑布加载校验通过(V1-V4 零误报)"
104
+ else
105
+ fail "四规则包全瀑布加载校验"
106
+ fi
107
+
108
+ echo "=== smoke 5: 防回归自证——顶层 local 注入必须被冒烟抓住 ==="
109
+ INJECT_TMP="$SMOKE_TMP/inject.sh"
110
+ cp "$REPO_ROOT/ops-collect/scripts/collect_board.sh" "$INJECT_TMP"
111
+ # 在 mc2 case 前注入一行顶层 local(复刻 F1 bug 形态)
112
+ python3 - "$INJECT_TMP" <<'PYEOF'
113
+ import sys
114
+ from pathlib import Path
115
+ p = Path(sys.argv[1])
116
+ t = p.read_text(encoding="utf-8")
117
+ t = t.replace(" mc2)\n run_msprof_mc2\n", " mc2)\n local injected=1\n run_msprof_mc2\n")
118
+ p.write_text(t, encoding="utf-8")
119
+ PYEOF
120
+ if bash "$INJECT_TMP" --exe /bin/true --mode mc2 --output "$SMOKE_TMP/prof_inject" >/dev/null 2>&1; then
121
+ fail "顶层 local 注入未被抓住(冒烟网失效)"
122
+ else
123
+ pass "顶层 local 注入 → mc2 模式退出非 0(F1 类 bug 冒烟可抓)"
124
+ fi
125
+
126
+ echo "=== smoke 6: 族表资产静态断言(防 SKILL.md 数据漂移)==="
127
+ if [ -f "$REPO_ROOT/ops-family/scripts/family_asset_audit.py" ]; then
128
+ python3 "$REPO_ROOT/ops-family/scripts/family_asset_audit.py" >/dev/null 2>&1
129
+ check "family_asset_audit.py(族表模板数与实测一致)"
130
+ else
131
+ echo "[SKIP] family_asset_audit.py 未交付(随算子族 PR),smoke 6 暂跳过——交付后本段自动生效"
132
+ fi
133
+
134
+ echo "=== smoke 7: facts_bridge 真实导出干跑(G2 标量生产者)==="
135
+ BRIDGE_TMP="$SMOKE_TMP/bridge"
136
+ mkdir -p "$BRIDGE_TMP/fixtures"
137
+ # 用 fixture 形态(本仓 6 个 fixtures 同款逐核明细 + 顶层 7 组导出)构造最小产物集
138
+ printf 'block_id,sub_block_id,aic_time(us),aiv_time(us),aiv_vec_ratio,aic_cube_ratio,aic_mte2_ratio,aic_mte1_ratio,aic_fixpipe_ratio,ai_scalar_ratio,aic_mte3_ratio,ai_icache_miss_rate,aiv_mte2_active_bw(GB/s)\n0,Vec0,0,100.5,0.32,0.00,0.55,0.02,0.01,0.22,0.03,1.2,1200.0\n1,Vec0,0,99.8,0.31,0.00,0.56,0.02,0.01,0.21,0.03,1.1,1240.0\n' > "$BRIDGE_TMP/fixtures/PipeUtilization.csv"
139
+ printf 'block_id,sub_block_id,aiv_total_hit_rate(%%)\n0,Vec0,96.1\n1,Vec0,95.7\n' > "$BRIDGE_TMP/fixtures/L2Cache.csv"
140
+ printf 'block_id,sub_block_id,aiv_vec_fp32_ratio\n0,Vec0,0.61\n1,Vec0,0.63\n' > "$BRIDGE_TMP/fixtures/ArithmeticUtilization.csv"
141
+ printf 'block_id,sub_block_id,aiv_vec_total_cflt_ratio\n0,Vec0,0.08\n1,Vec0,0.07\n' > "$BRIDGE_TMP/fixtures/ResourceConflictRatio.csv"
142
+ printf 'Op Name,Op Type,Task Duration(us),Block Dim\nop866214,vector,14.7,8\n' > "$BRIDGE_TMP/fixtures/OpBasicInfo.csv"
143
+ if python3 "$REPO_ROOT/ops-collect/scripts/facts_bridge.py" \
144
+ --manifest "$BRIDGE_TMP/fixtures" --soc a2 --output "$BRIDGE_TMP/scalars.json" >/dev/null 2>&1 \
145
+ && python3 -c "
146
+ import json, sys
147
+ d = json.load(open('$BRIDGE_TMP/scalars.json'))
148
+ s = d['scalars']
149
+ assert abs(s['l2_hit_rate'] - 95.9) < 0.01, s
150
+ assert abs(s['icache_miss_rate'] - 1.15) < 0.01, s
151
+ assert abs(s['vec_fp32_ratio'] - 62.0) < 0.01, s # 0~1 比例 ×100
152
+ assert abs(s['vec_total_cflt_ratio'] - 8.0) < 0.01, s # 0~1 比例 ×100(mean 0.075 → round 0.08 ×100)
153
+ assert abs(s['mte2_active_bw_pct_of_peak'] - 76.25) < 0.01, s # 1220/1600 GB/s
154
+ assert abs(s['task_duration_us'] - 14.7) < 0.01, s
155
+ assert s['block_dim'] == 8 and s['physical_cores'] == 24, s
156
+ assert d['missing'] == [], d['missing']
157
+ " 2>/dev/null; then
158
+ pass "facts_bridge 标量提取与峰值换算(7 标量 + 换算正确)"
159
+ else
160
+ fail "facts_bridge 标量提取"
161
+ fi
162
+
163
+
164
+
165
+ echo "=== smoke 8: timing 模式干跑(P0-2 计时 harness 归档)==="
166
+ TIMING_TMP="$SMOKE_TMP/timing"
167
+ mkdir -p "$TIMING_TMP"
168
+ cat > "$TIMING_TMP/fake_harness.sh" <<'HARNESS'
169
+ #!/usr/bin/env bash
170
+ echo '{"schema":"opstune.timing/1.0","kernel_avg_us":14.2,"warmup":5,"repeat":20}' > result.json
171
+ HARNESS
172
+ chmod +x "$TIMING_TMP/fake_harness.sh"
173
+ ( cd "$TIMING_TMP" && PATH="$SHIM_BIN:$PATH" bash "$REPO_ROOT/ops-collect/scripts/collect_board.sh" \
174
+ --exe "$TIMING_TMP/fake_harness.sh" --mode timing --output "$TIMING_TMP/prof" ) >/dev/null 2>&1
175
+ if python3 -c "
176
+ import json
177
+ m = json.load(open('$TIMING_TMP/prof/collection_manifest.json'))
178
+ assert m['mode'] == 'timing', m['mode']
179
+ assert m['blocks'][0]['name'] == 'timing_harness' and m['blocks'][0]['status'] == 'ok', m['blocks']
180
+ r = json.load(open('$TIMING_TMP/prof/result.json'))
181
+ assert r['kernel_avg_us'] == 14.2
182
+ " 2>/dev/null; then
183
+ pass "collect_board.sh --mode timing(harness result.json 归档 + manifest ok)"
184
+ else
185
+ fail "collect_board.sh --mode timing"
186
+ fi
187
+
188
+
189
+ echo "=== smoke 9: tiling_candidates 四族干跑(候选生成 + 容量校验)==="
190
+ if [ ! -f "$REPO_ROOT/ops-family/scripts/tiling_candidates.py" ]; then
191
+ echo "[SKIP] tiling_candidates.py 未交付(随算子族 PR),smoke 9 暂跳过——交付后本段自动生效"
192
+ else
193
+ TILING_TMP="$SMOKE_TMP/tiling"; mkdir -p "$TILING_TMP"
194
+ if python3 "$REPO_ROOT/ops-family/scripts/tiling_candidates.py" \
195
+ --family elementwise --shape 8448,4096 --dtype fp16 --soc a5 \
196
+ --output "$TILING_TMP/cand.json" >/dev/null 2>&1 \
197
+ && python3 "$REPO_ROOT/ops-family/scripts/tiling_candidates.py" \
198
+ --family reduction --shape 32,4096 --dtype fp16 --soc a5 --axis -1 \
199
+ --output "$TILING_TMP/red.json" >/dev/null 2>&1 \
200
+ && python3 -c "
201
+ import json
202
+ c = json.load(open('$TILING_TMP/cand.json'))
203
+ assert c['soc_caps']['core_num'] == 28 and c['soc_caps']['ub_kb'] == 248, c['soc_caps']
204
+ fc = next(x for x in c['candidates'] if x['variant'] == 'full-cores')
205
+ assert fc['block_dim'] == 28 and fc['aligned'], fc
206
+ assert fc['block_former'] % 512 == 0, fc # 多核 512 元素对齐
207
+ assert fc['capacity_kb'] <= 248, fc # 容量预算不超限
208
+ r = json.load(open('$TILING_TMP/red.json'))
209
+ assert r['pruned'] and r['pruned'][0]['variant'] == 'full-load', r # 整行驻留不可行被剪枝
210
+ assert r['candidates'][0]['block_dim'] == 28, r
211
+ " 2>/dev/null; then
212
+ pass "tiling_candidates(elementwise 满核对齐 + reduction full-load 剪枝记录)"
213
+ else
214
+ fail "tiling_candidates 四族干跑"
215
+ fi
216
+
217
+ fi
218
+
219
+
220
+ echo "=== smoke 10: collect_cases → batch 直连端到端(P0-1 A1 铁律一条命令)==="
221
+ P1_TMP="$SMOKE_TMP/p1"; mkdir -p "$P1_TMP/bin"
222
+ cat > "$P1_TMP/cases.csv" <<'CASES'
223
+ case_id,shape,dtype,ref_impl
224
+ c01,8448x4096,fp16,aclnnGelu
225
+ c02,4096x4096,fp16,aclnnGelu
226
+ c03,1024x1024,bf16,aclnnGelu
227
+ CASES
228
+ cat > "$P1_TMP/bin/msprof" <<'P1SHIM'
229
+ #!/usr/bin/env bash
230
+ OUT=""
231
+ for a in "$@"; do
232
+ case "$a" in --output=*) OUT="${a#--output=}" ;; esac
233
+ done
234
+ mkdir -p "$OUT/mindstudio_profiler_output"
235
+ printf 'Task Duration(us),aiv_vec_ratio,aic_mte2_ratio\n100.5,0.32,0.55\n101.2,0.31,0.56\n' \
236
+ > "$OUT/mindstudio_profiler_output/op_summary_1.csv"
237
+ P1SHIM
238
+ chmod +x "$P1_TMP/bin/msprof"
239
+ # scope.json(12 HARD 字段齐)
240
+ cat > "$P1_TMP/scope.json" <<'SCOPE'
241
+ {"schema":"opstune.scope/1.0","op":"gelu","soc":"a5","mode":"board","timing_method":"msprof_task_duration",
242
+ "baseline_kind":"system","cann_version":"8.3.0","device_id":"0","shape":"8448x4096","dtype":"fp16",
243
+ "format":"ND","warmup":5,"repeat":10}
244
+ SCOPE
245
+ ( cd "$P1_TMP" && PATH="$P1_TMP/bin:$PATH" python3 \
246
+ "$REPO_ROOT/ops-collect/scripts/collect_cases.py" \
247
+ --cases "$P1_TMP/cases.csv" --exe /bin/true --mode quick \
248
+ --output "$P1_TMP/collect_out" ) >/dev/null 2>&1
249
+ # 模拟标杆侧数据(system 行:80/82/40us)
250
+ printf 'c01,system,80.0,pass\nc02,system,82.0,pass\nc03,system,40.0,pass\n' \
251
+ >> "$P1_TMP/collect_out/perf_data.csv"
252
+ if python3 "$REPO_ROOT/ops-verdict/scripts/batch_pipeline.py" \
253
+ --from-collect "$P1_TMP/collect_out" --cases "$P1_TMP/cases.csv" \
254
+ --baseline-variant system --after-variants custom \
255
+ --scope "$P1_TMP/scope.json" --output-dir "$P1_TMP/matrix" >/dev/null 2>&1 \
256
+ && python3 -c "
257
+ import csv, json
258
+ rows = list(csv.DictReader(open('$P1_TMP/collect_out/perf_data.csv')))
259
+ assert len(rows) == 6, rows # 3 case × 2 variant(custom 采集 + system 追加)
260
+ assert {(r['case_id'], r['variant']) for r in rows if r['variant']=='custom'} == \
261
+ {('c01','custom'),('c02','custom'),('c03','custom')}
262
+ md = open('$P1_TMP/matrix/comparison_matrix.md').read()
263
+ assert 'geomean speedup' in md and 'c03' in md # 矩阵产出且逐 case 覆盖(A1)
264
+ assert '0.793x' in md or 'REVERT' in md # vs 标杆读数成立(100.85/80 → 劣化如实呈现)
265
+ s = json.load(open('$P1_TMP/collect_out/collect_summary.json'))
266
+ assert s['ok'] == 3 and s['failed_or_partial'] == [], s
267
+ " 2>/dev/null; then
268
+ pass "collect_cases → batch --from-collect(cases.csv 到对比矩阵零手工中间产物)"
269
+ else
270
+ fail "P0-1 直连端到端"
271
+ fi
272
+
273
+ echo "=== smoke 11: csv_to_db + facts_bridge DB 通道端到端(Roadmap #4)==="
274
+ DB_TMP="$SMOKE_TMP/db_channel"; mkdir -p "$DB_TMP/fixtures"
275
+ # fixture:npu-compute 解包形态(Section CSV 顶层平铺 + summary.jsonl)
276
+ printf 'block_id,sub_block_id,aic_time(us),aiv_time(us),aiv_vec_ratio,aiv_mte2_active_bw(GB/s)\n0,vector0,NA,100.5,0.32,1200.0\n1,vector0,NA,99.8,0.31,1240.0\n' > "$DB_TMP/fixtures/PipeUtilization.csv"
277
+ printf 'block_id,sub_block_id,aiv_read_hit_rate(%%)\n0,vector0,96.1\n1,vector0,95.7\n' > "$DB_TMP/fixtures/L2Cache.csv"
278
+ printf 'block_id,sub_block_id,aiv_vec_stu_cflt_ratio,aiv_vec_ldu_cflt_ratio,aiv_vec_sfu_cflt_ratio\n0,vector0,0.01,0.03,0.00\n1,vector0,0.01,0.05,0.00\n' > "$DB_TMP/fixtures/ResourceConflictRatio.csv"
279
+ printf 'block_id,sub_block_id,aiv_vec_vf_ratio\n0,vector0,0.61\n1,vector0,0.63\n' > "$DB_TMP/fixtures/ArithmeticUtilization.csv"
280
+ printf '{"category":"OpInfoSummary","Op Name":"vec_demo","Op Type":"vector","Task Duration(us)":51.7,"Block Dim":8}\n' > "$DB_TMP/fixtures/summary.jsonl"
281
+ if python3 "$REPO_ROOT/ops-collect/scripts/csv_to_db.py" \
282
+ --csv-dir "$DB_TMP/fixtures" --db "$DB_TMP/fixtures/summary.db" --quiet >/dev/null 2>&1 \
283
+ && ! python3 "$REPO_ROOT/ops-collect/scripts/csv_to_db.py" \
284
+ --csv-dir "$DB_TMP/fixtures" --db "$DB_TMP/fixtures/summary.db" --quiet >/dev/null 2>&1 \
285
+ && python3 -c "
286
+ import sqlite3
287
+ # 注入 PcSampling 行(DB 独有表——真源 DDL 同构,冒烟只验证消费链不验证采集)
288
+ db = sqlite3.connect('$DB_TMP/fixtures/summary.db')
289
+ db.execute('''CREATE TABLE PcSampling(address INTEGER NOT NULL PRIMARY KEY,
290
+ ibuf_empty INTEGER NOT NULL, nop_cycles INTEGER NOT NULL,
291
+ scoreboard_not_ready INTEGER NOT NULL, register_bank_conflict INTEGER NOT NULL,
292
+ resource_conflict INTEGER NOT NULL, warp_level_sync INTEGER NOT NULL,
293
+ divergence_stack_spill INTEGER NOT NULL, others INTEGER NOT NULL)''')
294
+ db.execute('INSERT INTO PcSampling VALUES(616,0,210,16320,0,0,0,0,0)')
295
+ db.commit(); db.close()
296
+ " 2>/dev/null \
297
+ && python3 "$REPO_ROOT/ops-collect/scripts/facts_bridge.py" \
298
+ --manifest "$DB_TMP/fixtures" --soc a5 --no-db \
299
+ --output "$DB_TMP/scalars_csv.json" >/dev/null 2>&1 \
300
+ && python3 "$REPO_ROOT/ops-collect/scripts/facts_bridge.py" \
301
+ --manifest "$DB_TMP/fixtures" --soc a5 \
302
+ --output "$DB_TMP/scalars_db.json" >/dev/null 2>&1 \
303
+ && python3 -c "
304
+ import json
305
+ d_csv = json.load(open('$DB_TMP/scalars_csv.json'))
306
+ d_db = json.load(open('$DB_TMP/scalars_db.json'))
307
+ assert d_csv['source_tool'] == 'npu-compute' and d_db['source_tool'] == 'npu-compute'
308
+ s_db = d_db['scalars']
309
+ # DB 通道产出(PcSampling/OpInfoSummary/列候选扩充三类新能力全断言):
310
+ assert abs(s_db['top_stall_pct'] - 98.73) < 0.01, s_db # PcSampling → L0 生产者
311
+ assert abs(s_db['task_duration_us'] - 51.7) < 0.01, s_db # Summary.jsonl OpInfoSummary
312
+ assert abs(s_db['block_dim'] - 8.0) < 0.01, s_db
313
+ assert abs(s_db['l2_hit_rate'] - 95.9) < 0.01, s_db # read_hit_rate 口径补位
314
+ assert abs(s_db['vec_total_cflt_ratio'] - 5.0) < 0.01, s_db # stu+ldu+sfu 分量和 ×100
315
+ assert d_db['pcsampling'] and d_db['pcsampling']['top_stall'] == 'scoreboard_not_ready'
316
+ # 双通道等价(同数据两格式,标量必须一致):
317
+ common = set(d_csv['scalars']) - {'top_stall_pct'} # top_stall 为 DB 独有
318
+ assert common == set(d_db['scalars']) - {'top_stall_pct'}, (d_csv['scalars'], d_db['scalars'])
319
+ for k in common:
320
+ assert abs(d_csv['scalars'][k] - d_db['scalars'][k]) < 0.02, (k, d_csv['scalars'][k], d_db['scalars'][k])
321
+ " 2>/dev/null; then
322
+ pass "csv_to_db 转换(覆盖保护:二次转换拒覆盖)+ facts_bridge DB 通道(top_stall/OpInfoSummary/双通道等价)"
323
+ else
324
+ fail "facts_bridge DB 通道端到端"
325
+ fi
326
+
327
+ echo "=== smoke 12: db_bench 等价性门禁(W1-W3 双通道数值一致)==="
328
+ if python3 "$REPO_ROOT/ops-collect/scripts/db_bench.py" \
329
+ --dir "$DB_TMP/fixtures" --repeat 3 \
330
+ -o "$DB_TMP/db_bench_report.json" >/dev/null 2>&1 \
331
+ && python3 -c "
332
+ import json
333
+ r = json.load(open('$DB_TMP/db_bench_report.json'))
334
+ assert r['schema'] == 'opstune.db-bench/1.0'
335
+ assert r['all_equivalent'] is True, r
336
+ for w in ('W1-facts-scalar-extract', 'W2-verdict-full-load', 'W3-analytical-batch'):
337
+ assert r['workloads'][w]['equivalent'] is True
338
+ assert r['workloads'][w]['csv_ms'] > 0 and r['workloads'][w]['db_ms'] > 0
339
+ # 不断言具体倍数(机器相关);W4 PcSampling 独有断言:
340
+ assert r['workloads']['W4-pcsampling-dist']['db_value'] is not None
341
+ " 2>/dev/null; then
342
+ pass "db_bench 等价性门禁(提速比如实呈现不作门禁)"
343
+ else
344
+ fail "db_bench 等价性"
345
+ fi
346
+
347
+ echo "=== smoke 13: collect_board --mode npu-compute shim 干跑(DB 格式采集编排)==="
348
+ NPC_TMP="$SMOKE_TMP/npc"; mkdir -p "$NPC_TMP/bin" "$NPC_TMP/fixtures/unpacked"
349
+ # fixture:解包形态目录(采集 shim 的 --import 复制源)
350
+ printf 'block_id,sub_block_id,aic_time(us),aiv_time(us),aiv_vec_ratio\n0,vector0,NA,100.5,0.32\n' > "$NPC_TMP/fixtures/unpacked/PipeUtilization.csv"
351
+ cp "$NPC_TMP/fixtures/unpacked/PipeUtilization.csv" "$NPC_TMP/fixtures/unpacked/L2Cache.csv"
352
+ # shim npu-compute:--list-sets/--list-sections 查询门禁 + --export 落 rep 副本 +
353
+ # --import 复制 fixture 目录并打印 unpacked= 路径(真实工具的终端契约)
354
+ cat > "$NPC_TMP/bin/npu-compute" <<'NPCSHIM'
355
+ #!/usr/bin/env bash
356
+ FIXTURE="$(dirname "$0")/../fixtures"
357
+ IMPORT=""; EXPORT=""
358
+ for ((i=1; i<=$#; i++)); do
359
+ arg="${!i}"
360
+ case "$arg" in
361
+ --list-sets) echo "basic: Pipeline PipeUtilization Memory MemoryL0 MemoryUB L2Cache ArithmeticUtilization"; echo "full: + ResourceConflictRatio"; exit 0 ;;
362
+ --list-sections) printf 'PipeUtilization\nMemory\nMemoryL0\nMemoryUB\nL2Cache\nPipeline\nArithmeticUtilization\nResourceConflictRatio\n'; exit 0 ;;
363
+ --import) n=$((i+1)); IMPORT="${!n}" ;;
364
+ --export) n=$((i+1)); EXPORT="${!n}" ;;
365
+ esac
366
+ done
367
+ if [[ -n "$IMPORT" ]]; then
368
+ DIR="$EXPORT/unpacked_1"; mkdir -p "$DIR"
369
+ cp -r "$FIXTURE/unpacked/." "$DIR/"
370
+ echo "npu-compute: unpacked= $DIR"; exit 0
371
+ fi
372
+ printf 'npu-rep-container-fixture' > "$EXPORT"
373
+ echo "npu-compute: report= $EXPORT"; exit 0
374
+ NPCSHIM
375
+ chmod +x "$NPC_TMP/bin/npu-compute"
376
+ if PATH="$NPC_TMP/bin:$PATH" bash "$REPO_ROOT/ops-collect/scripts/collect_board.sh" \
377
+ --exe /bin/true --mode npu-compute --sections PmSampling,BogusSection \
378
+ --output "$NPC_TMP/npc_out" >/dev/null 2>&1 \
379
+ && python3 -c "
380
+ import json
381
+ m = json.load(open('$NPC_TMP/npc_out/collection_manifest.json'))
382
+ assert m['mode'] == 'npu-compute'
383
+ b = m['blocks'][0]
384
+ assert b['name'] == 'npu-compute' and b['status'] == 'ok', m
385
+ assert 'unpacked=' in b['note'], b
386
+ # 产物断言(伪 Green 防护路径):解包目录主输入在位
387
+ # (note 含中文括号注记——用 (\S+) 在 ASCII 路径后截断)
388
+ import pathlib, re
389
+ unpacked = re.search(r'unpacked=(\S+)', b['note']).group(1)
390
+ unpacked = unpacked.rstrip('(无含')
391
+ assert (pathlib.Path(unpacked) / 'PipeUtilization.csv').exists(), unpacked
392
+ " 2>/dev/null; then
393
+ pass "collect_board --mode npu-compute(探测门禁 + manifest + 解包产物断言)"
394
+ else
395
+ fail "npu-compute 采集模式干跑"
396
+ fi
397
+
398
+ echo ""
399
+ if [[ $FAILURES -eq 0 ]]; then
400
+ echo "smoke: 全部通过"
401
+ exit 0
402
+ else
403
+ echo "smoke: $FAILURES 项失败 —— F1 类运行时 bug 防线失效,禁止合入"
404
+ exit 1
405
+ fi
@@ -0,0 +1,25 @@
1
+ block_id,sub_block_id,aic_time(us),aiv_time(us),aiv_vec_ratio,aic_cube_ratio,aic_mte2_ratio,aic_mte1_ratio,aic_fixpipe_ratio,ai_scalar_ratio,aic_mte3_ratio,ai_icache_miss_rate
2
+ 0,Vec0,0,96.3,0.32,0.00,0.28,0.02,0.01,0.22,0.03,0.9
3
+ 1,Vec0,0,184.7,0.61,0.00,0.55,0.04,0.02,0.15,0.05,1.1
4
+ 2,Vec0,0,91.8,0.30,0.00,0.26,0.02,0.01,0.21,0.03,0.9
5
+ 3,Vec0,0,182.4,0.60,0.00,0.54,0.04,0.02,0.14,0.05,1.0
6
+ 4,Vec0,0,95.1,0.31,0.00,0.27,0.02,0.01,0.22,0.03,0.9
7
+ 5,Vec0,0,186.2,0.62,0.00,0.56,0.04,0.02,0.15,0.05,1.1
8
+ 6,Vec0,0,93.6,0.31,0.00,0.27,0.02,0.01,0.22,0.03,0.9
9
+ 7,Vec0,0,185.5,0.61,0.00,0.55,0.04,0.02,0.15,0.05,1.0
10
+ 8,Vec0,0,92.7,0.30,0.00,0.26,0.02,0.01,0.21,0.03,0.9
11
+ 9,Vec0,0,184.9,0.61,0.00,0.55,0.04,0.02,0.15,0.05,1.1
12
+ 10,Vec0,0,94.2,0.31,0.00,0.27,0.02,0.01,0.22,0.03,0.9
13
+ 11,Vec0,0,186.8,0.62,0.00,0.56,0.04,0.02,0.15,0.05,1.1
14
+ 12,Vec0,0,93.1,0.30,0.00,0.26,0.02,0.01,0.21,0.03,0.9
15
+ 13,Vec0,0,185.8,0.61,0.00,0.55,0.04,0.02,0.15,0.05,1.0
16
+ 14,Vec0,0,94.9,0.31,0.00,0.27,0.02,0.01,0.22,0.03,0.9
17
+ 15,Vec0,0,187.3,0.63,0.00,0.56,0.04,0.02,0.15,0.05,1.1
18
+ 16,Vec0,0,92.4,0.30,0.00,0.26,0.02,0.01,0.21,0.03,0.9
19
+ 17,Vec0,0,183.6,0.60,0.00,0.54,0.04,0.02,0.14,0.05,1.0
20
+ 18,Vec0,0,94.6,0.31,0.00,0.27,0.02,0.01,0.22,0.03,0.9
21
+ 19,Vec0,0,185.2,0.61,0.00,0.55,0.04,0.02,0.15,0.05,1.1
22
+ 20,Vec0,0,93.4,0.30,0.00,0.27,0.02,0.01,0.21,0.03,0.9
23
+ 21,Vec0,0,186.5,0.62,0.00,0.56,0.04,0.02,0.15,0.05,1.1
24
+ 22,Vec0,0,92.9,0.30,0.00,0.26,0.02,0.01,0.21,0.03,0.9
25
+ 23,Vec0,0,184.1,0.61,0.00,0.55,0.04,0.02,0.15,0.05,1.0
@@ -0,0 +1,5 @@
1
+ block_id,sub_block_id,aic_time(us),aiv_time(us),aiv_vec_ratio,aic_cube_ratio,aic_mte2_ratio,aic_mte1_ratio,aic_fixpipe_ratio,ai_scalar_ratio,aic_mte3_ratio,ai_icache_miss_rate
2
+ 0,Vec0,0,100.0,0.30,0.00,0.26,0.02,0.01,0.21,0.03,0.9
3
+ 1,Vec0,0,100.0,0.30,0.00,0.26,0.02,0.01,0.21,0.03,0.9
4
+ 2,Vec0,0,100.0,0.30,0.00,0.26,0.02,0.01,0.21,0.03,0.9
5
+ 3,Vec0,0,100.0,0.30,0.00,0.26,0.02,0.01,0.21,0.03,0.9
@@ -0,0 +1,17 @@
1
+ block_id,sub_block_id,aic_time(us),aiv_time(us),aiv_vec_ratio,aic_cube_ratio,aic_mte2_ratio,aic_mte1_ratio,aic_fixpipe_ratio,ai_scalar_ratio,aic_mte3_ratio,ai_icache_miss_rate
2
+ 0,Vec0,0,482.1,0.52,0.00,0.78,0.05,0.03,0.12,0.02,1.2
3
+ 1,Vec0,0,479.8,0.53,0.00,0.77,0.05,0.03,0.11,0.02,1.1
4
+ 2,Vec0,0,481.0,0.51,0.00,0.79,0.05,0.03,0.12,0.02,1.3
5
+ 3,Vec0,0,480.5,0.52,0.00,0.78,0.05,0.03,0.11,0.02,1.2
6
+ 4,Vec0,0,483.2,0.53,0.00,0.77,0.05,0.03,0.12,0.02,1.2
7
+ 5,Vec0,0,478.9,0.51,0.00,0.78,0.05,0.03,0.11,0.02,1.1
8
+ 6,Vec0,0,481.7,0.52,0.00,0.78,0.05,0.03,0.12,0.02,1.2
9
+ 7,Vec0,0,480.2,0.52,0.00,0.77,0.05,0.03,0.11,0.02,1.2
10
+ 8,Vec0,0,479.4,0.51,0.00,0.78,0.05,0.03,0.12,0.02,1.1
11
+ 9,Vec0,0,482.8,0.52,0.00,0.78,0.05,0.03,0.11,0.02,1.2
12
+ 10,Vec0,0,480.9,0.53,0.00,0.77,0.05,0.03,0.12,0.02,1.2
13
+ 11,Vec0,0,481.3,0.51,0.00,0.79,0.05,0.03,0.11,0.02,1.1
14
+ 12,Vec0,0,478.6,0.52,0.00,0.78,0.05,0.03,0.12,0.02,1.2
15
+ 13,Vec0,0,480.7,0.52,0.00,0.77,0.05,0.03,0.11,0.02,1.2
16
+ 14,Vec0,0,481.5,0.51,0.00,0.78,0.05,0.03,0.12,0.02,1.1
17
+ 15,Vec0,0,479.9,0.52,0.00,0.78,0.05,0.03,0.11,0.02,1.2
@@ -0,0 +1,7 @@
1
+ Op Name,Op Type,Task Duration(us),block_id,sub_block_id,aic_time(us),aiv_time(us),aiv_vec_ratio,aic_cube_ratio,aic_mte2_ratio,aic_mte1_ratio,aic_fixpipe_ratio,ai_scalar_ratio,aic_mte3_ratio,ai_icache_miss_rate
2
+ gemu_mix,Vector,60,0,Vec0,0,48.2,0.78,0.00,0.31,0.05,0.03,0.11,0.02,1.1
3
+ gelu_mix,Vector,60,1,Vec0,0,47.9,0.77,0.00,0.30,0.05,0.03,0.10,0.02,1.0
4
+ matmul_mix,Matrix,210,0,Cube0,205.1,0,0.01,0.88,0.22,0.11,0.05,0.06,0.04,0.8
5
+ matmul_mix,Matrix,210,1,Cube0,204.3,0,0.01,0.87,0.22,0.10,0.05,0.06,0.04,0.9
6
+ matmul_mix,Matrix,210,2,Cube0,206.0,0,0.01,0.89,0.23,0.11,0.05,0.06,0.04,0.8
7
+ matmul_mix,Matrix,210,3,Cube0,205.4,0,0.01,0.86,0.22,0.10,0.04,0.06,0.04,0.8
@@ -0,0 +1,9 @@
1
+ block_id,sub_block_id,aic_time(us),aiv_time(us),aiv_vec_ratio,aic_cube_ratio,aic_mte2_ratio,aic_mte1_ratio,aic_fixpipe_ratio,ai_scalar_ratio,aic_mte3_ratio,ai_icache_miss_rate
2
+ 0,Vec0,0,100.0,0.55,0.05,0.05,0.02,0.01,0.05,0.05,0.9
3
+ 1,Vec0,0,99.5,0.54,0.05,0.05,0.02,0.01,0.05,0.05,0.9
4
+ 2,Vec0,0,100.2,0.55,0.05,0.05,0.02,0.01,0.05,0.05,0.9
5
+ 3,Vec0,0,99.8,0.54,0.05,0.05,0.02,0.01,0.05,0.05,0.9
6
+ 4,Vec0,0,100.1,0.55,0.05,0.05,0.02,0.01,0.05,0.05,0.9
7
+ 5,Vec0,0,99.9,0.54,0.05,0.05,0.02,0.01,0.05,0.05,0.9
8
+ 6,Vec0,0,100.0,0.55,0.05,0.05,0.02,0.01,0.05,0.05,0.9
9
+ 7,Vec0,0,100.3,0.54,0.05,0.05,0.02,0.01,0.05,0.05,0.9
@@ -0,0 +1,9 @@
1
+ block_id,sub_block_id,aic_time(us),aiv_time(us),aiv_vec_ratio,aic_cube_ratio,aic_mte2_ratio,aic_mte1_ratio,aic_fixpipe_ratio,ai_scalar_ratio,aic_mte3_ratio,ai_icache_miss_rate
2
+ 0,Cube0,612.4,0,0.01,0.44,0.42,0.18,0.02,0.06,0.01,0.8
3
+ 1,Cube0,609.8,0,0.01,0.45,0.41,0.18,0.02,0.06,0.01,0.8
4
+ 2,Cube0,611.2,0,0.01,0.44,0.42,0.17,0.02,0.06,0.01,0.9
5
+ 3,Cube0,608.9,0,0.01,0.43,0.43,0.18,0.02,0.06,0.01,0.8
6
+ 4,Cube0,610.5,0,0.01,0.44,0.42,0.18,0.02,0.06,0.01,0.8
7
+ 5,Cube0,613.1,0,0.01,0.44,0.41,0.17,0.02,0.06,0.01,0.9
8
+ 6,Cube0,609.2,0,0.01,0.44,0.42,0.18,0.02,0.06,0.01,0.8
9
+ 7,Cube0,611.8,0,0.01,0.45,0.41,0.18,0.02,0.06,0.01,0.8
@@ -0,0 +1,9 @@
1
+ block_id,sub_block_id,aic_time(us),aiv_time(us),aiv_vec_ratio,aic_cube_ratio,aic_mte2_ratio,aic_mte1_ratio,aic_fixpipe_ratio,ai_scalar_ratio,aic_mte3_ratio,ai_icache_miss_rate
2
+ 0,Vec0,0,320.5,0.82,0.00,0.05,0.02,0.01,0.10,0.02,1.0
3
+ 1,Vec0,0,319.8,0.83,0.00,0.05,0.02,0.01,0.10,0.02,1.0
4
+ 2,Vec0,0,321.0,0.82,0.00,0.05,0.02,0.01,0.10,0.02,1.0
5
+ 3,Vec0,0,320.2,0.83,0.00,0.05,0.02,0.01,0.10,0.02,1.0
6
+ 4,Vec0,0,320.8,0.82,0.00,0.05,0.02,0.01,0.10,0.02,1.0
7
+ 5,Vec0,0,319.5,0.83,0.00,0.05,0.02,0.01,0.10,0.02,1.0
8
+ 6,Vec0,0,320.6,0.82,0.00,0.05,0.02,0.01,0.10,0.02,1.0
9
+ 7,Vec0,0,320.9,0.83,0.00,0.05,0.02,0.01,0.10,0.02,1.0