cann-workbench 0.0.0-stage → 0.0.2-alpha
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.
- package/README.md +183 -2
- package/THIRD_PARTY_NOTICES.md +85 -0
- package/cordis.patch.yml +3 -0
- package/doctor/LICENSE +202 -0
- package/doctor/NOTICE +12 -0
- package/doctor/README.md +18 -0
- package/lib/client.js +94437 -0
- package/lib/index.d.ts +722 -0
- package/lib/index.js +33711 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +171 -4
- package/skills/asc-tools/tool-ops-tune/INSTALL.md +52 -0
- package/skills/asc-tools/tool-ops-tune/LICENSE +38 -0
- package/skills/asc-tools/tool-ops-tune/README.md +167 -0
- package/skills/asc-tools/tool-ops-tune/SKILL.md +93 -0
- package/skills/asc-tools/tool-ops-tune/agent/AGENTS.md +195 -0
- package/skills/asc-tools/tool-ops-tune/agent/agents/perf-implementer.md +68 -0
- package/skills/asc-tools/tool-ops-tune/agent/agents/perf-reviewer.md +86 -0
- package/skills/asc-tools/tool-ops-tune/agent/workflows/task-prompts.md +362 -0
- package/skills/asc-tools/tool-ops-tune/agent/workflows/troubleshooting.md +43 -0
- package/skills/asc-tools/tool-ops-tune/docs/figures/opstune-architecture.png +0 -0
- package/skills/asc-tools/tool-ops-tune/docs/figures/opstune-architecture.svg +253 -0
- package/skills/asc-tools/tool-ops-tune/docs/ops-tune-design.md +404 -0
- package/skills/asc-tools/tool-ops-tune/docs//347/224/250/344/276/213/346/236/204/345/273/272.md +730 -0
- package/skills/asc-tools/tool-ops-tune/docs//347/237/245/350/257/206/345/272/223/350/247/204/350/214/203.md +103 -0
- package/skills/asc-tools/tool-ops-tune/evals/evals.json +242 -0
- package/skills/asc-tools/tool-ops-tune/ops-collect/SKILL.md +146 -0
- package/skills/asc-tools/tool-ops-tune/ops-collect/references/tool-routing.md +86 -0
- package/skills/asc-tools/tool-ops-tune/ops-collect/scripts/collect_board.sh +458 -0
- package/skills/asc-tools/tool-ops-tune/ops-collect/scripts/collect_cases.py +368 -0
- package/skills/asc-tools/tool-ops-tune/ops-collect/scripts/collect_sim.sh +134 -0
- package/skills/asc-tools/tool-ops-tune/ops-collect/scripts/csv_to_db.py +314 -0
- package/skills/asc-tools/tool-ops-tune/ops-collect/scripts/db_bench.py +545 -0
- package/skills/asc-tools/tool-ops-tune/ops-collect/scripts/facts_bridge.py +1102 -0
- package/skills/asc-tools/tool-ops-tune/ops-collect/scripts/isolation_test.py +452 -0
- package/skills/asc-tools/tool-ops-tune/ops-collect/scripts/jsonl_to_cases.py +163 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/SKILL.md +76 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/broadcast/advanced_tiling.md +92 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/broadcast/broadcast_design.md +160 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/broadcast/code/broadcast_add_kernel.cpp +126 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/broadcast/code/broadcast_add_tiling.cpp +144 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/broadcast/code/broadcast_tiling_common.h +401 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/broadcast/code/onedim_add_kernel.cpp +107 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/broadcast/code/onedim_add_tiling.cpp +64 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/broadcast/datacopypad_design.md +46 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/broadcast/guide.md +14 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/broadcast/nddma_design.md +53 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/broadcast/onedim_design.md +114 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/broadcast/ub_broadcast_design.md +67 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/common/datacopy_optimization_design.md +351 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/common/index.md +9 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/common/tail_block_design.md +268 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/common/timing_harness/index.md +38 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/common/timing_harness/timing_harness_aclrt_event.cpp +199 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/common/timing_harness/timing_harness_torch_event.py +130 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/common/ub_resident_design.md +342 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/conversion/guide.md +69 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/conversion/index.md +4 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_base.template +81 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_big_dim.template +217 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_cut_one_axis.template +336 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_cut_two_axis.template +781 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_n_last.template +340 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_small_shape.template +321 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_tensor_move.template +102 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_transdata_5hd.template +480 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_transdata_5hd_021axis.template +533 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_with_gather.template +688 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/conversion/templates/transpose_tiling_data.template +192 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/conversion/transpose_big_dim.md +220 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/conversion/transpose_cut_one_axis.md +175 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/conversion/transpose_cut_two_axis.md +177 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/conversion/transpose_fusion_design.md +398 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/conversion/transpose_gather.md +191 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/conversion/transpose_n_last.md +276 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/conversion/transpose_small_shape.md +315 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/conversion/transpose_tensor_move.md +203 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/conversion/transpose_tiling_data.md +176 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/conversion/transpose_vconv_021.md +206 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/conversion/transpose_vconv_5hd.md +179 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/elementwise/double_buffer_design.md +288 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/elementwise/guide.md +46 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/elementwise/index.md +10 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/CMakeLists.txt +131 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/README.md +55 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_extension/add_custom_torch.cpp +80 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_extension/ops.h +23 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_extension/register.cpp +30 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_host/add_custom.asc +149 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_host/data_utils.h +97 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_kernel/add_custom_kernel.asc +136 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_kernel/add_custom_tiling.h +31 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/run.sh +87 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/scripts/gen_data.py +70 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/scripts/golden.py +34 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/scripts/test_torch.py +99 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/scripts/verify_result.py +56 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/elementwise/templates/usage_guide.md +61 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/elementwise/vector_efficiency_design.md +203 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/fa/fa_mixed_kernel_design.md +174 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/fa/fa_roofline_design.md +141 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/fa/guide.md +87 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/knowledge_gaps.json +56 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/matmul/best-practices-guide.md +14 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/matmul/fullload_design.md +344 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/matmul/guide.md +52 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/matmul/mte2_preload_design.md +320 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/matmul/pingpong_design.md +254 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/matmul/scale_coalescing_design.md +282 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/matmul/streamk_design.md +374 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/matmul/swat_design.md +423 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/matmul/templates/matmul_basic_blaze.template +165 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/matmul/templates/usage_guide.md +29 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/mc2/best-practices-guide.md +43 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/mc2/guide.md +42 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/mc2/local_matmul_design.md +130 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/mc2/pipeline_balancing_design.md +502 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/reduce/guide.md +178 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/reduce/templates/dav310/kernel_utils.template +75 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_ar_full_load.template +429 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_ar_recompute.template +485 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_ar_small_r.template +348 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_ara_full_load.template +574 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_ara_online.template +324 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_ara_recompute.template +436 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_base.template +950 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/reduce/templates/fused_attention_online_softmax_design.md +428 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_ar_full_load.md +137 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_ar_recompute.md +135 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_ar_small_r.md +122 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_ara_full_load.md +144 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_ara_online.md +185 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_ara_recompute.md +163 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_tiling.template +460 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_tiling_data.template +278 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/reduce/templates/state_resident_design.md +337 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/reduce/templates/usage_guide.md +253 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/scalar/coding_principles.md +476 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/scalar/conv_scalar.md +163 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/scalar/guide.md +30 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/simt/guide.md +91 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/simt/optimization-guide.md +110 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/sort/guide.md +83 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/references/sort/radix_sort.md +354 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/scripts/family_asset_audit.py +68 -0
- package/skills/asc-tools/tool-ops-tune/ops-family/scripts/tiling_candidates.py +419 -0
- package/skills/asc-tools/tool-ops-tune/ops-mechanism/SKILL.md +23 -0
- package/skills/asc-tools/tool-ops-tune/ops-mechanism/cases/ascendc/case_groupedmatmul_pipeline.md +23 -0
- package/skills/asc-tools/tool-ops-tune/ops-mechanism/cases/ascendc/case_triton_atomic_revert.md +19 -0
- package/skills/asc-tools/tool-ops-tune/ops-mechanism/cases/mc2/case_mc2_fusion.md +19 -0
- package/skills/asc-tools/tool-ops-tune/ops-mechanism/references/optimize/api-usage.md +70 -0
- package/skills/asc-tools/tool-ops-tune/ops-mechanism/references/optimize/ascendc-regbase-vf.md +45 -0
- package/skills/asc-tools/tool-ops-tune/ops-mechanism/references/optimize/ascendc-tiling.md +51 -0
- package/skills/asc-tools/tool-ops-tune/ops-mechanism/references/optimize/data-copy.md +67 -0
- package/skills/asc-tools/tool-ops-tune/ops-mechanism/references/optimize/index.md +45 -0
- package/skills/asc-tools/tool-ops-tune/ops-mechanism/references/optimize/mc2-balancing.md +77 -0
- package/skills/asc-tools/tool-ops-tune/ops-mechanism/references/optimize/mc2.md +103 -0
- package/skills/asc-tools/tool-ops-tune/ops-mechanism/references/optimize/memory-hierarchy.md +40 -0
- package/skills/asc-tools/tool-ops-tune/ops-mechanism/references/optimize/pipeline.md +95 -0
- package/skills/asc-tools/tool-ops-tune/ops-mechanism/scripts/case_backfill.py +170 -0
- package/skills/asc-tools/tool-ops-tune/ops-mechanism/scripts/log_gap.py +145 -0
- package/skills/asc-tools/tool-ops-tune/ops-mechanism/scripts/mc2_search.py +367 -0
- package/skills/asc-tools/tool-ops-tune/ops-report/SKILL.md +77 -0
- package/skills/asc-tools/tool-ops-tune/ops-verdict/evals/run_evals.py +963 -0
- package/skills/asc-tools/tool-ops-tune/ops-verdict/evals/smoke/install-hooks.sh +65 -0
- package/skills/asc-tools/tool-ops-tune/ops-verdict/evals/smoke/run_smoke.sh +535 -0
- package/skills/asc-tools/tool-ops-tune/ops-verdict/fixtures/core_tail_a5.csv +25 -0
- package/skills/asc-tools/tool-ops-tune/ops-verdict/fixtures/few_cores_a5.csv +5 -0
- package/skills/asc-tools/tool-ops-tune/ops-verdict/fixtures/mte2_bound_a2.csv +17 -0
- package/skills/asc-tools/tool-ops-tune/ops-verdict/fixtures/multi_kernel_mix_a5.csv +7 -0
- package/skills/asc-tools/tool-ops-tune/ops-verdict/fixtures/no_bound_a5.csv +9 -0
- package/skills/asc-tools/tool-ops-tune/ops-verdict/fixtures/serial_no_overlap_a2.csv +9 -0
- package/skills/asc-tools/tool-ops-tune/ops-verdict/fixtures/vec_bound_a5.csv +9 -0
- package/skills/asc-tools/tool-ops-tune/ops-verdict/references/io-contracts.md +94 -0
- package/skills/asc-tools/tool-ops-tune/ops-verdict/references/rule-schema.md +130 -0
- package/skills/asc-tools/tool-ops-tune/ops-verdict/references/scope-schema.md +61 -0
- package/skills/asc-tools/tool-ops-tune/ops-verdict/references/soc-spec.yaml +140 -0
- package/skills/asc-tools/tool-ops-tune/ops-verdict/rules/L0-instruction.yaml +67 -0
- package/skills/asc-tools/tool-ops-tune/ops-verdict/rules/L1-single-core.yaml +316 -0
- package/skills/asc-tools/tool-ops-tune/ops-verdict/rules/L2-inter-core.yaml +173 -0
- package/skills/asc-tools/tool-ops-tune/ops-verdict/rules/L3-inter-card.yaml +156 -0
- package/skills/asc-tools/tool-ops-tune/ops-verdict/scripts/batch_pipeline.py +466 -0
- package/skills/asc-tools/tool-ops-tune/ops-verdict/scripts/calibrate.py +249 -0
- package/skills/asc-tools/tool-ops-tune/ops-verdict/scripts/delta_compare.py +278 -0
- package/skills/asc-tools/tool-ops-tune/ops-verdict/scripts/render_html.py +304 -0
- package/skills/asc-tools/tool-ops-tune/ops-verdict/scripts/snapshot.py +200 -0
- package/skills/asc-tools/tool-ops-tune/ops-verdict/scripts/trace_bubble.py +331 -0
- package/skills/asc-tools/tool-ops-tune/ops-verdict/scripts/verdict.py +1094 -0
- package/skills/asc-tools/tool-ops-tune/scripts/diff_audit.py +281 -0
- package/skills/asc-tools/tool-precision-debug/LICENSE +38 -0
- package/skills/asc-tools/tool-precision-debug/README.md +190 -0
- package/skills/asc-tools/tool-precision-debug/scripts/install.sh +475 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/LICENSE +38 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/SKILL.md +136 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/evals/evals.json +932 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/diagnosis/baseline.md +69 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/diagnosis/checkpoint-design.md +82 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/diagnosis/dumptensor.md +83 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/diagnosis/hypothesis-experiment.md +114 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/diagnosis/index.md +20 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/diagnosis/localization.md +85 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/diagnosis/numerical-modeling.md +94 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/diagnosis/operator-modeling.md +116 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/diagnosis/progressive-error-analysis.md +86 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/diagnosis/reporting.md +140 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/diagnosis/reproducibility.md +121 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/diagnosis/semantic-bisection.md +72 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/diagnosis/sensitive-points.md +146 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/cases/fp16-promotion-boundary.md +46 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/cases/fused-rmsnorm-gelu-residual.md +162 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/cases/index.md +16 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/cases/integer-float-collision.md +44 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/cases/partial-statistics-merge.md +30 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/cases/softplus-v2-grad-family.md +156 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/cases/sync-dataflow-handshake.md +89 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/cases/tail-valid-region-state.md +30 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/cases/thnn-fused-gru-bias-reduction.md +73 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/index.md +34 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/mechanisms/accumulation-order.md +108 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/mechanisms/algorithm-parameter-contract.md +118 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/mechanisms/buffer-lifetime-alias.md +133 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/mechanisms/cast-rounding.md +76 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/mechanisms/complex-operator-boundary.md +48 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/mechanisms/data-movement-alignment.md +104 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/mechanisms/golden-host-contract.md +84 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/mechanisms/index-address-ownership.md +57 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/mechanisms/index.md +32 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/mechanisms/multicore-ownership.md +117 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/mechanisms/pipeline-sync-visibility.md +146 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/mechanisms/precision-mode-approximation.md +90 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/mechanisms/shape-boundary-contract.md +57 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/mechanisms/special-values.md +122 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/mechanisms/tiling-tail-state.md +146 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/operators/broadcast-transpose.md +64 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/operators/convolution.md +60 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/operators/dynamic-quant.md +47 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/operators/index.md +18 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/operators/matmul-mmad.md +131 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/operators/normalization.md +145 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/operators/reduction.md +167 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/operators/softplus-v2-grad.md +58 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/patterns/operators/sort-merge.md +65 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/tools/index.md +18 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/tools/kernel-debug-data.md +133 -0
- package/skills/asc-tools/tool-precision-debug/skills/tool-precision-debug/references/tools/msobjdump.md +150 -0
- package/skills/cann-doctor/SKILL.md +15 -0
- package/skills/catalog.json +79 -0
- package/skills/mattpocock/GLOSSARY.md +30 -0
- package/skills/mattpocock/LICENSE +21 -0
- package/skills/mattpocock/README.md +258 -0
- package/skills/mattpocock/SCOPE.md +35 -0
- package/skills/mattpocock/docs/agents/triage-labels.md +15 -0
- package/skills/mattpocock/docs/engineering/ask-matt.md +91 -0
- package/skills/mattpocock/docs/engineering/code-review.md +101 -0
- package/skills/mattpocock/docs/engineering/codebase-design.md +88 -0
- package/skills/mattpocock/docs/engineering/diagnosing-bugs.md +94 -0
- package/skills/mattpocock/docs/engineering/domain-modeling.md +86 -0
- package/skills/mattpocock/docs/engineering/grill-with-docs.md +82 -0
- package/skills/mattpocock/docs/engineering/implement-spec.md +86 -0
- package/skills/mattpocock/docs/engineering/implement.md +97 -0
- package/skills/mattpocock/docs/engineering/improve-codebase-architecture.md +113 -0
- package/skills/mattpocock/docs/engineering/pr.md +79 -0
- package/skills/mattpocock/docs/engineering/prototype.md +67 -0
- package/skills/mattpocock/docs/engineering/research.md +73 -0
- package/skills/mattpocock/docs/engineering/resolving-merge-conflicts.md +53 -0
- package/skills/mattpocock/docs/engineering/retro.md +81 -0
- package/skills/mattpocock/docs/engineering/setup-matt-pocock-skills.md +94 -0
- package/skills/mattpocock/docs/engineering/tdd.md +94 -0
- package/skills/mattpocock/docs/engineering/to-spec.md +81 -0
- package/skills/mattpocock/docs/engineering/to-tickets.md +99 -0
- package/skills/mattpocock/docs/engineering/triage.md +109 -0
- package/skills/mattpocock/docs/engineering/wayfinder.md +103 -0
- package/skills/mattpocock/docs/engineering/wizard.md +96 -0
- package/skills/mattpocock/docs/productivity/grill-me.md +76 -0
- package/skills/mattpocock/docs/productivity/grilling.md +87 -0
- package/skills/mattpocock/docs/productivity/handoff.md +76 -0
- package/skills/mattpocock/docs/productivity/teach.md +97 -0
- package/skills/mattpocock/docs/productivity/to-questionnaire.md +78 -0
- package/skills/mattpocock/docs/productivity/wait-what.md +36 -0
- package/skills/mattpocock/docs/productivity/writing-for-agents.md +70 -0
- package/skills/mattpocock/scripts/link-skills.sh +62 -0
- package/skills/mattpocock/scripts/list-skills.sh +7 -0
- package/skills/mattpocock/scripts/sync-plugin-version.mjs +41 -0
- package/skills/mattpocock/skills/deprecated/README.md +3 -0
- package/skills/mattpocock/skills/engineering/README.md +34 -0
- package/skills/mattpocock/skills/engineering/ask-matt/PHASE-BOUNDARIES.md +55 -0
- package/skills/mattpocock/skills/engineering/ask-matt/SKILL.md +97 -0
- package/skills/mattpocock/skills/engineering/ask-matt/agents/openai.yaml +5 -0
- package/skills/mattpocock/skills/engineering/code-review/SKILL.md +89 -0
- package/skills/mattpocock/skills/engineering/code-review/agents/openai.yaml +3 -0
- package/skills/mattpocock/skills/engineering/codebase-design/DEEPENING.md +37 -0
- package/skills/mattpocock/skills/engineering/codebase-design/DESIGN-IT-TWICE.md +44 -0
- package/skills/mattpocock/skills/engineering/codebase-design/SKILL.md +114 -0
- package/skills/mattpocock/skills/engineering/codebase-design/agents/openai.yaml +3 -0
- package/skills/mattpocock/skills/engineering/diagnosing-bugs/SKILL.md +138 -0
- package/skills/mattpocock/skills/engineering/diagnosing-bugs/agents/openai.yaml +3 -0
- package/skills/mattpocock/skills/engineering/diagnosing-bugs/scripts/hitl-loop.template.sh +44 -0
- package/skills/mattpocock/skills/engineering/domain-modeling/ADR-FORMAT.md +47 -0
- package/skills/mattpocock/skills/engineering/domain-modeling/GLOSSARY-FORMAT.md +60 -0
- package/skills/mattpocock/skills/engineering/domain-modeling/SKILL.md +74 -0
- package/skills/mattpocock/skills/engineering/domain-modeling/agents/openai.yaml +3 -0
- package/skills/mattpocock/skills/engineering/grill-with-docs/SKILL.md +7 -0
- package/skills/mattpocock/skills/engineering/grill-with-docs/agents/openai.yaml +5 -0
- package/skills/mattpocock/skills/engineering/implement/SKILL.md +17 -0
- package/skills/mattpocock/skills/engineering/implement/agents/openai.yaml +5 -0
- package/skills/mattpocock/skills/engineering/implement-spec/SKILL.md +42 -0
- package/skills/mattpocock/skills/engineering/implement-spec/agents/openai.yaml +5 -0
- package/skills/mattpocock/skills/engineering/improve-codebase-architecture/HTML-REPORT.md +123 -0
- package/skills/mattpocock/skills/engineering/improve-codebase-architecture/SKILL.md +71 -0
- package/skills/mattpocock/skills/engineering/improve-codebase-architecture/agents/openai.yaml +5 -0
- package/skills/mattpocock/skills/engineering/pr/CREDITS.md +3 -0
- package/skills/mattpocock/skills/engineering/pr/SKILL.md +170 -0
- package/skills/mattpocock/skills/engineering/pr/agents/openai.yaml +3 -0
- package/skills/mattpocock/skills/engineering/prototype/LOGIC.md +67 -0
- package/skills/mattpocock/skills/engineering/prototype/SKILL.md +26 -0
- package/skills/mattpocock/skills/engineering/prototype/UI.md +112 -0
- package/skills/mattpocock/skills/engineering/prototype/agents/openai.yaml +3 -0
- package/skills/mattpocock/skills/engineering/research/SKILL.md +12 -0
- package/skills/mattpocock/skills/engineering/research/agents/openai.yaml +3 -0
- package/skills/mattpocock/skills/engineering/retro/SKILL.md +44 -0
- package/skills/mattpocock/skills/engineering/retro/agents/openai.yaml +5 -0
- package/skills/mattpocock/skills/engineering/setup-matt-pocock-skills/SKILL.md +120 -0
- package/skills/mattpocock/skills/engineering/setup-matt-pocock-skills/agents/openai.yaml +5 -0
- package/skills/mattpocock/skills/engineering/setup-matt-pocock-skills/domain.md +51 -0
- package/skills/mattpocock/skills/engineering/setup-matt-pocock-skills/issue-tracker-github.md +50 -0
- package/skills/mattpocock/skills/engineering/setup-matt-pocock-skills/issue-tracker-gitlab.md +46 -0
- package/skills/mattpocock/skills/engineering/setup-matt-pocock-skills/issue-tracker-local.md +30 -0
- package/skills/mattpocock/skills/engineering/setup-matt-pocock-skills/triage-labels.md +15 -0
- package/skills/mattpocock/skills/engineering/tdd/SKILL.md +38 -0
- package/skills/mattpocock/skills/engineering/tdd/agents/openai.yaml +3 -0
- package/skills/mattpocock/skills/engineering/tdd/mocking.md +59 -0
- package/skills/mattpocock/skills/engineering/tdd/tests.md +77 -0
- package/skills/mattpocock/skills/engineering/to-spec/SKILL.md +75 -0
- package/skills/mattpocock/skills/engineering/to-spec/agents/openai.yaml +5 -0
- package/skills/mattpocock/skills/engineering/to-tickets/SKILL.md +105 -0
- package/skills/mattpocock/skills/engineering/to-tickets/agents/openai.yaml +5 -0
- package/skills/mattpocock/skills/engineering/triage/AGENT-BRIEF.md +207 -0
- package/skills/mattpocock/skills/engineering/triage/OUT-OF-SCOPE.md +105 -0
- package/skills/mattpocock/skills/engineering/triage/SKILL.md +112 -0
- package/skills/mattpocock/skills/engineering/triage/agents/openai.yaml +5 -0
- package/skills/mattpocock/skills/engineering/wayfinder/SKILL.md +128 -0
- package/skills/mattpocock/skills/engineering/wayfinder/agents/openai.yaml +5 -0
- package/skills/mattpocock/skills/engineering/wizard/SKILL.md +44 -0
- package/skills/mattpocock/skills/engineering/wizard/agents/openai.yaml +3 -0
- package/skills/mattpocock/skills/engineering/wizard/template.sh +223 -0
- package/skills/mattpocock/skills/in-progress/README.md +17 -0
- package/skills/mattpocock/skills/in-progress/chief-of-staff/SKILL.md +75 -0
- package/skills/mattpocock/skills/in-progress/chief-of-staff/agents/openai.yaml +5 -0
- package/skills/mattpocock/skills/in-progress/claude-handoff/SKILL.md +18 -0
- package/skills/mattpocock/skills/in-progress/claude-handoff/agents/openai.yaml +5 -0
- package/skills/mattpocock/skills/in-progress/loop-me/SKILL.md +32 -0
- package/skills/mattpocock/skills/in-progress/loop-me/agents/openai.yaml +5 -0
- package/skills/mattpocock/skills/in-progress/setup-ts-deep-modules/SKILL.md +102 -0
- package/skills/mattpocock/skills/in-progress/setup-ts-deep-modules/agents/openai.yaml +5 -0
- package/skills/mattpocock/skills/in-progress/setup-ts-deep-modules/dependency-cruiser.config.cjs +95 -0
- package/skills/mattpocock/skills/in-progress/software-factory/EXAMPLE-TASKS.md +80 -0
- package/skills/mattpocock/skills/in-progress/software-factory/GIT-HOSTS.md +84 -0
- package/skills/mattpocock/skills/in-progress/software-factory/OBSERVABILITY-PLATFORMS.md +75 -0
- package/skills/mattpocock/skills/in-progress/software-factory/RUNNERS.md +94 -0
- package/skills/mattpocock/skills/in-progress/software-factory/SKILL.md +98 -0
- package/skills/mattpocock/skills/in-progress/software-factory/TICKET-TRACKERS.md +85 -0
- package/skills/mattpocock/skills/in-progress/writing-beats/SKILL.md +67 -0
- package/skills/mattpocock/skills/in-progress/writing-beats/agents/openai.yaml +5 -0
- package/skills/mattpocock/skills/in-progress/writing-fragments/SKILL.md +79 -0
- package/skills/mattpocock/skills/in-progress/writing-fragments/agents/openai.yaml +5 -0
- package/skills/mattpocock/skills/in-progress/writing-shape/SKILL.md +79 -0
- package/skills/mattpocock/skills/in-progress/writing-shape/agents/openai.yaml +5 -0
- package/skills/mattpocock/skills/misc/README.md +8 -0
- package/skills/mattpocock/skills/misc/git-guardrails-claude-code/SKILL.md +95 -0
- package/skills/mattpocock/skills/misc/git-guardrails-claude-code/agents/openai.yaml +3 -0
- package/skills/mattpocock/skills/misc/git-guardrails-claude-code/scripts/block-dangerous-git.sh +25 -0
- package/skills/mattpocock/skills/misc/migrate-to-shoehorn/SKILL.md +118 -0
- package/skills/mattpocock/skills/misc/migrate-to-shoehorn/agents/openai.yaml +3 -0
- package/skills/mattpocock/skills/misc/scaffold-exercises/SKILL.md +106 -0
- package/skills/mattpocock/skills/misc/scaffold-exercises/agents/openai.yaml +3 -0
- package/skills/mattpocock/skills/misc/setup-pre-commit/SKILL.md +91 -0
- package/skills/mattpocock/skills/misc/setup-pre-commit/agents/openai.yaml +3 -0
- package/skills/mattpocock/skills/productivity/README.md +20 -0
- package/skills/mattpocock/skills/productivity/grill-me/SKILL.md +7 -0
- package/skills/mattpocock/skills/productivity/grill-me/agents/openai.yaml +5 -0
- package/skills/mattpocock/skills/productivity/grilling/SKILL.md +30 -0
- package/skills/mattpocock/skills/productivity/grilling/agents/openai.yaml +3 -0
- package/skills/mattpocock/skills/productivity/handoff/SKILL.md +16 -0
- package/skills/mattpocock/skills/productivity/handoff/agents/openai.yaml +5 -0
- package/skills/mattpocock/skills/productivity/teach/GLOSSARY-FORMAT.md +35 -0
- package/skills/mattpocock/skills/productivity/teach/LEARNING-RECORD-FORMAT.md +46 -0
- package/skills/mattpocock/skills/productivity/teach/MISSION-FORMAT.md +31 -0
- package/skills/mattpocock/skills/productivity/teach/RESOURCES-FORMAT.md +32 -0
- package/skills/mattpocock/skills/productivity/teach/SKILL.md +140 -0
- package/skills/mattpocock/skills/productivity/teach/agents/openai.yaml +5 -0
- package/skills/mattpocock/skills/productivity/to-questionnaire/SKILL.md +54 -0
- package/skills/mattpocock/skills/productivity/to-questionnaire/agents/openai.yaml +5 -0
- package/skills/mattpocock/skills/productivity/wait-what/SKILL.md +7 -0
- package/skills/mattpocock/skills/productivity/wait-what/agents/openai.yaml +5 -0
- package/skills/mattpocock/skills/productivity/writing-for-agents/SKILL-MECHANICS.md +22 -0
- package/skills/mattpocock/skills/productivity/writing-for-agents/SKILL.md +81 -0
- package/skills/mattpocock/skills/productivity/writing-for-agents/agents/openai.yaml +3 -0
- package/skills/task-agents/operator-development/Agent.md +71 -0
- package/skills/task-agents/operator-development/skills.json +120 -0
- package/skills/task-agents/operator-development/stages.schema.json +532 -0
- package/skills/task-agents/performance-optimization/Agent.md +78 -0
- package/skills/task-agents/performance-optimization/skills.json +64 -0
- package/skills/task-agents/response-protocol.md +35 -0
- package/skills/task-agents/sidebar-contracts.schema.json +4168 -0
- package/skills/task-agents/sidebar-selection.schema.json +971 -0
- package/skills/task-agents/visuals/components.json +283 -0
- package/skills/task-agents/visuals/contracts.schema.json +3628 -0
|
@@ -0,0 +1,1102 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
# ----------------------------------------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2026 Huawei Technologies Co., Ltd.
|
|
5
|
+
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
|
6
|
+
# CANN Open Software License Agreement Version 2.0 (the "License").
|
|
7
|
+
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
|
8
|
+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
|
9
|
+
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
|
10
|
+
# See LICENSE in the root of the software repository for the full text of the License.
|
|
11
|
+
# ----------------------------------------------------------------------------------------------------------
|
|
12
|
+
"""facts_bridge.py — msprof 7 组产物 → verdict.py --scalar 标量生产者
|
|
13
|
+
|
|
14
|
+
设计对齐:
|
|
15
|
+
- 判定侧契约:L0 规则 3 条 + L1 反证 2 条的指标全部 source: scalar 且描述写明
|
|
16
|
+
「调用方换算后提供」——此前全仓无生产者,规则在实践中长期 SKIPPED/不可评估。
|
|
17
|
+
- 本脚本就是那个生产者:读 collection_manifest.json 定位 7 组产物,从
|
|
18
|
+
L2Cache / ArithmeticUtilization / ResourceConflictRatio / OpBasicInfo /
|
|
19
|
+
Memory(PipeUtilization) 提取换算,输出 verdict.py 可直接消费的 --scalar 串。
|
|
20
|
+
- 列名三代兼容:aic_/aiv_/ai_ 前缀逐候选尝试(verdict.py 同款经验);
|
|
21
|
+
三代 msprof 版本的列名漂移是主要风险点,evals 用真实导出 CSV 做 fixture。
|
|
22
|
+
- 峰值换算消费 soc-spec.yaml——GM 带宽标尺有溯源,不再拍脑袋。
|
|
23
|
+
- **npu-compute DB 通道(Roadmap #4)**:npu-compute(950/A5)解包目录自带
|
|
24
|
+
summary.db(7 Section 表 + PcSampling + FieldUnitMap),DB 是 CSV 的同数据
|
|
25
|
+
入库副本(与 msprof DB 双源的「task 级口径差异」不同,可安全互通)——
|
|
26
|
+
逐指标 DB SQL 优先(AVG+NULL-skip 下推),CSV 补位;PcSampling 是 DB 独有
|
|
27
|
+
数据源,本脚本因此成为 top_stall_pct(L0_STALL_DOMINANT)的首个生产者。
|
|
28
|
+
|
|
29
|
+
支持的标量(与规则词汇表一一对应):
|
|
30
|
+
L0: icache_miss_rate / l2_hit_rate / top_stall_pct(PcSampling——npu-compute DB 通道生产)
|
|
31
|
+
L1 反证: mte2_active_bw_pct_of_peak / vec_fp32_ratio / vec_total_cflt_ratio
|
|
32
|
+
L2: task_duration_us / block_dim / physical_cores(soc-spec 解析)
|
|
33
|
+
|
|
34
|
+
用法:
|
|
35
|
+
# msprof 产物(存量路径不变):
|
|
36
|
+
python3 facts_bridge.py --manifest prof/baseline/collection_manifest.json --soc a5 \
|
|
37
|
+
[--kernel-name my_kernel] [--soc-spec ../ops-verdict/references/soc-spec.yaml] \
|
|
38
|
+
[--output scalars.json] [--print-scalar]
|
|
39
|
+
# npu-compute 解包目录(DB 通道;Summary.jsonl 提供 OpInfoSummary):
|
|
40
|
+
python3 facts_bridge.py --manifest <unpacked_dir> --source npu-compute --soc a5 \
|
|
41
|
+
[--db <summary.db>] [--output scalars.json]
|
|
42
|
+
# 显式通道:--source msprof|npu-compute|auto(auto 按目录特征判源);
|
|
43
|
+
# --no-db 禁用一切 DB 读取(纯 CSV 口径)。
|
|
44
|
+
|
|
45
|
+
输出(opstune.facts-bridge/1.1):
|
|
46
|
+
{ "source_tool": "msprof|npu-compute",
|
|
47
|
+
"scalar_str": "l2_hit_rate=96.1,icache_miss_rate=1.2,...",
|
|
48
|
+
"scalars": {...}, "sources": {指标: 文件路径+通道注记},
|
|
49
|
+
"pcsampling": {...top_stall 分布...} | null,
|
|
50
|
+
"missing": [提取失败的指标与原因] }
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
from __future__ import annotations
|
|
54
|
+
|
|
55
|
+
import argparse
|
|
56
|
+
import csv
|
|
57
|
+
import json
|
|
58
|
+
import sys
|
|
59
|
+
from pathlib import Path
|
|
60
|
+
|
|
61
|
+
SCHEMA = "opstune.facts-bridge/1.1"
|
|
62
|
+
|
|
63
|
+
# ---- 列名候选(三代 msprof 列名兼容;逐候选取首个可解析者)----
|
|
64
|
+
ICACHE_COLS = [
|
|
65
|
+
"ai_icache_miss_rate",
|
|
66
|
+
"aic_icache_miss_rate",
|
|
67
|
+
"aiv_icache_miss_rate",
|
|
68
|
+
"icache_miss_rate",
|
|
69
|
+
"ICacheMissRate(%)",
|
|
70
|
+
]
|
|
71
|
+
L2_HIT_COLS = [
|
|
72
|
+
"aiv_total_hit_rate(%)",
|
|
73
|
+
"aic_total_hit_rate(%)",
|
|
74
|
+
"ai_total_hit_rate(%)",
|
|
75
|
+
"total_hit_rate(%)",
|
|
76
|
+
"l2_hit_rate",
|
|
77
|
+
]
|
|
78
|
+
# npu-compute L2Cache 列形态(真实 .npu-rep 实测):只有 read/write 分项 hit_rate,
|
|
79
|
+
# 无 total——按读命中率口径补位(npu-compute 官方 csv_reader 列集核验),
|
|
80
|
+
# sources 注记口径防混比
|
|
81
|
+
L2_HIT_COLS_NPUCOMPUTE = [
|
|
82
|
+
"aiv_read_hit_rate(%)",
|
|
83
|
+
"aic_read_hit_rate(%)",
|
|
84
|
+
]
|
|
85
|
+
VEC_FP32_COLS = ["aiv_vec_fp32_ratio", "ai_vec_fp32_ratio", "vec_fp32_ratio"]
|
|
86
|
+
VEC_CFLT_COLS = [
|
|
87
|
+
"aiv_vec_total_cflt_ratio",
|
|
88
|
+
"ai_vec_total_cflt_ratio",
|
|
89
|
+
"vec_total_cflt_ratio",
|
|
90
|
+
]
|
|
91
|
+
# npu-compute ResourceConflictRatio 无 total 列——stu/ldu/sfu 三个分项和
|
|
92
|
+
# 作为 total 口径补位(与 CSV/DB 双通道同算法,保等价;sources 注记分量和口径)
|
|
93
|
+
VEC_CFLT_PART_COLS = [
|
|
94
|
+
"aiv_vec_stu_cflt_ratio",
|
|
95
|
+
"aiv_vec_ldu_cflt_ratio",
|
|
96
|
+
"aiv_vec_sfu_cflt_ratio",
|
|
97
|
+
]
|
|
98
|
+
MTE2_BW_COLS = [
|
|
99
|
+
"aiv_mte2_active_bw(GB/s)",
|
|
100
|
+
"aic_mte2_active_bw(GB/s)",
|
|
101
|
+
"ai_mte2_active_bw(GB/s)",
|
|
102
|
+
"mte2_active_bw(GB/s)",
|
|
103
|
+
]
|
|
104
|
+
GM_UB_KB_COLS = [
|
|
105
|
+
"GM_to_UB_datas(KB)",
|
|
106
|
+
"gm_to_ub_datas(KB)",
|
|
107
|
+
"read_main_memory_datas(KB)",
|
|
108
|
+
]
|
|
109
|
+
MTE2_RATIO_COLS = ["aiv_mte2_ratio", "aic_mte2_ratio", "ai_mte2_ratio", "mte2_ratio"]
|
|
110
|
+
|
|
111
|
+
# OpBasicInfo(无 block_id 列,含 Op Name 的 per-op 聚合行)
|
|
112
|
+
OPBI_TASK_COLS = ["Task Duration(us)", "Task Duration"]
|
|
113
|
+
OPBI_BLOCKDIM_COLS = ["Block Dim", "BlockDim", "Block DimNum"]
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _first_float(row: dict, cols: list[str]):
|
|
117
|
+
"""按候选列序取首个可解析 float;兼容 0~1 比例与百分数(仅 ratio 类调用方处理)。"""
|
|
118
|
+
for col in cols:
|
|
119
|
+
v = row.get(col)
|
|
120
|
+
if v is None or str(v).strip() in ("", "N/A", "NA", "-", "None"):
|
|
121
|
+
continue
|
|
122
|
+
try:
|
|
123
|
+
return float(str(v).strip().replace("%", ""))
|
|
124
|
+
except ValueError:
|
|
125
|
+
continue
|
|
126
|
+
return None
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def _load_rows(path: Path) -> list[dict]:
|
|
130
|
+
with open(path, encoding="utf-8-sig", errors="replace") as f:
|
|
131
|
+
return list(csv.DictReader(f))
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def find_metric_csv(manifest_dir: Path, metric: str) -> Path | None:
|
|
135
|
+
"""按 manifest 块定位指标 CSV:块 path + rglob 对应 <Metric>.csv 或 op_summary_*.csv。
|
|
136
|
+
|
|
137
|
+
- standard 7 组形态:PROF_<Metric>_*/mindstudio_profiler_output/op_summary_*.csv
|
|
138
|
+
或 msprof op 形态的 op_summary_*.csv(多指标合一份,按块名匹配);
|
|
139
|
+
- 兼容顶层直接导出 <Metric>.csv 的形态(用户从 Insight 导出,如本仓 fixture 真源;
|
|
140
|
+
npu-compute .npu-rep 解包目录同为此形态——Section CSV 顶层平铺)。
|
|
141
|
+
"""
|
|
142
|
+
for cand in sorted(manifest_dir.rglob(f"{metric}.csv")):
|
|
143
|
+
return cand
|
|
144
|
+
for cand in sorted(manifest_dir.rglob("op_summary_*.csv")):
|
|
145
|
+
return cand
|
|
146
|
+
return None
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
# ---- npu-compute DB 通道(Roadmap #4)----------------------------------------
|
|
150
|
+
# summary.db 结构(npu_tools/npu_compute/src/cli/report/summary_sqlite_finalizer.cpp
|
|
151
|
+
# 真源核验):7 个 Section 表(与同名 CSV 同数据,NA→NULL)+ PcSampling(DB 独有)
|
|
152
|
+
# + FieldUnitMap(field_name→unit)。DB 与 CSV 可安全互通(同一次采集的双格式,
|
|
153
|
+
# 与下方 msprof DB 双源的「task 级 vs op 级口径差异」不同)。
|
|
154
|
+
# 等价查询固化在脚本(判定只出自脚本原则:SQL 拼接不进 LLM)。
|
|
155
|
+
|
|
156
|
+
NPUCOMPUTE_DB = "summary.db"
|
|
157
|
+
# PcSampling stall 状态白名单(DDL 语义列,npu-compute pm_sampling_file_validator
|
|
158
|
+
# 核验)——防表结构演进引入非 stall 数值列被当 stall 累计,污染 top_stall
|
|
159
|
+
STALL_COLUMNS = (
|
|
160
|
+
"ibuf_empty",
|
|
161
|
+
"nop_cycles",
|
|
162
|
+
"scoreboard_not_ready",
|
|
163
|
+
"register_bank_conflict",
|
|
164
|
+
"resource_conflict",
|
|
165
|
+
"warp_level_sync",
|
|
166
|
+
"divergence_stack_spill",
|
|
167
|
+
"others",
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def find_npucompute_db(root: Path) -> Path | None:
|
|
172
|
+
"""定位 npu-compute 解包目录的 summary.db(顶层或 collection-* 子目录)。
|
|
173
|
+
|
|
174
|
+
npu-compute 大小写两代产物形态都接受:summary.db / Summary.db,
|
|
175
|
+
Summary.jsonl / summary.jsonl(真实 .npu-rep 两种形态实测)。
|
|
176
|
+
"""
|
|
177
|
+
for name in ("summary.db", "Summary.db"):
|
|
178
|
+
top = root / name
|
|
179
|
+
if top.exists():
|
|
180
|
+
return top
|
|
181
|
+
for pat in (f"*/{name}", f"**/{name}"):
|
|
182
|
+
cands = sorted(root.rglob(pat))
|
|
183
|
+
if cands:
|
|
184
|
+
return cands[0]
|
|
185
|
+
return None
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def detect_source(root: Path) -> str:
|
|
189
|
+
"""通道自动判定:目录特征 → npu-compute / msprof。
|
|
190
|
+
|
|
191
|
+
npu-compute 解包特征:Summary.jsonl/summary.jsonl(OpInfoSummary 承担
|
|
192
|
+
OpBasicInfo 角色)或 summary.db;msprof 特征:PROF_*/ 结构或 OpBasicInfo.csv。
|
|
193
|
+
"""
|
|
194
|
+
for name in ("Summary.jsonl", "summary.jsonl"):
|
|
195
|
+
if (root / name).exists():
|
|
196
|
+
return "npu-compute"
|
|
197
|
+
if list(root.rglob("Summary.jsonl")) or list(root.rglob("summary.jsonl")):
|
|
198
|
+
return "npu-compute"
|
|
199
|
+
if find_npucompute_db(root):
|
|
200
|
+
return "npu-compute"
|
|
201
|
+
return "msprof"
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def open_ro_db(db_path: Path):
|
|
205
|
+
import sqlite3
|
|
206
|
+
|
|
207
|
+
return sqlite3.connect(f"file:{db_path}?mode=ro", uri=True)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def _table_columns(db, table: str) -> set[str]:
|
|
211
|
+
"""实际列集合(PRAGMA 校验)——SQLite 对双引号未知标识符按字符串字面量
|
|
212
|
+
处理(AVG('aiv_total_hit_rate') 合法且返回 0.0,不报错!),必须先验列
|
|
213
|
+
存在再 AVG,否则「列不存在」被静默吞成 0.0 标量(真值污染)。"""
|
|
214
|
+
return {d[1] for d in db.execute(f'PRAGMA table_info("{table}")')}
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def db_column_mean(
|
|
218
|
+
db_path: Path, table: str, cols: list[str]
|
|
219
|
+
) -> tuple[float | None, str | None]:
|
|
220
|
+
"""DB 通道标量:候选列 COALESCE 逐行回退后 AVG(NA→NULL 语义内建)。
|
|
221
|
+
|
|
222
|
+
与 CSV 侧 extract_from_csv 的逐行 _first_float **同语义**——
|
|
223
|
+
此前「候选列逐个 AVG 取首个有值列」是按列选择——同一 Section 表内
|
|
224
|
+
aiv_*/aic_* 部分行有值部分行 NULL 的混排形态(AIC/AIV block 混排报告
|
|
225
|
+
常态)下,DB 侧只统计首个有值列自身的行子集,CSV 侧逐行合并两列,
|
|
226
|
+
双通道标量分叉、sources 注记却都显示「合法等价」)。COALESCE 保持
|
|
227
|
+
候选序逐行回退,聚合语义与 CSV 侧一致。
|
|
228
|
+
返回 (值, 命中列集描述)。表或列不存在返回 (None, None)——调用方按
|
|
229
|
+
missing 降级。
|
|
230
|
+
"""
|
|
231
|
+
try:
|
|
232
|
+
db = open_ro_db(db_path)
|
|
233
|
+
try:
|
|
234
|
+
tables = {
|
|
235
|
+
r[0]
|
|
236
|
+
for r in db.execute(
|
|
237
|
+
"SELECT name FROM sqlite_master WHERE type='table'"
|
|
238
|
+
).fetchall()
|
|
239
|
+
}
|
|
240
|
+
if table not in tables:
|
|
241
|
+
return None, None
|
|
242
|
+
actual = _table_columns(db, table)
|
|
243
|
+
present = [c for c in cols if c in actual]
|
|
244
|
+
if not present:
|
|
245
|
+
return None, None
|
|
246
|
+
if len(present) == 1:
|
|
247
|
+
col = present[0]
|
|
248
|
+
v = db.execute(
|
|
249
|
+
f'SELECT AVG("{col}") FROM "{table}" WHERE "{col}" IS NOT NULL'
|
|
250
|
+
).fetchone()[0]
|
|
251
|
+
hit = col
|
|
252
|
+
else:
|
|
253
|
+
coalesce = ", ".join(f'"{c}"' for c in present)
|
|
254
|
+
v = db.execute(
|
|
255
|
+
f"SELECT AVG(COALESCE({coalesce})) FROM"
|
|
256
|
+
f' "{table}" WHERE COALESCE({coalesce}) IS NOT NULL'
|
|
257
|
+
).fetchone()[0]
|
|
258
|
+
hit = "+".join(present)
|
|
259
|
+
if v is not None:
|
|
260
|
+
return float(v), hit
|
|
261
|
+
return None, None
|
|
262
|
+
finally:
|
|
263
|
+
db.close()
|
|
264
|
+
except Exception: # noqa: BLE001 —— DB 损坏/不可读:降级 CSV,missing 记因
|
|
265
|
+
return None, None
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def db_column_mean_sum(
|
|
269
|
+
db_path: Path, table: str, col_sets: list[list[str]]
|
|
270
|
+
) -> tuple[float | None, list[str]]:
|
|
271
|
+
"""DB 通道分量和口径:候选组内各列均值先取(同组三列须同表同在)再求和。"""
|
|
272
|
+
try:
|
|
273
|
+
db = open_ro_db(db_path)
|
|
274
|
+
try:
|
|
275
|
+
tables = {
|
|
276
|
+
r[0]
|
|
277
|
+
for r in db.execute(
|
|
278
|
+
"SELECT name FROM sqlite_master WHERE type='table'"
|
|
279
|
+
).fetchall()
|
|
280
|
+
}
|
|
281
|
+
if table not in tables:
|
|
282
|
+
return None, []
|
|
283
|
+
actual = _table_columns(db, table)
|
|
284
|
+
for cols in col_sets:
|
|
285
|
+
if not all(c in actual for c in cols):
|
|
286
|
+
continue
|
|
287
|
+
vals = []
|
|
288
|
+
for col in cols:
|
|
289
|
+
v = db.execute(
|
|
290
|
+
f'SELECT AVG("{col}") FROM "{table}" WHERE "{col}" IS NOT NULL'
|
|
291
|
+
).fetchone()[0]
|
|
292
|
+
if v is None:
|
|
293
|
+
vals = []
|
|
294
|
+
break
|
|
295
|
+
vals.append(float(v))
|
|
296
|
+
if vals:
|
|
297
|
+
return sum(vals), cols
|
|
298
|
+
return None, []
|
|
299
|
+
finally:
|
|
300
|
+
db.close()
|
|
301
|
+
except Exception: # noqa: BLE001
|
|
302
|
+
return None, []
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def pcsampling_stall(db_path: Path) -> dict | None:
|
|
306
|
+
"""PcSampling 八状态 stall 分布 → top_stall_pct(L0_STALL_DOMINANT 生产者)。
|
|
307
|
+
|
|
308
|
+
- address 十六进制 ↔ symbolizer.json 定位留给消费方(本层只出分布);
|
|
309
|
+
- 白名单列累计,防表结构演进污染(tool-perf-analysis extract_facts 同款纪律);
|
|
310
|
+
- 无 PcSampling 表(未选 PmSampling Section / SIMD 算子无采样)返回 None——
|
|
311
|
+
如实 missing,不静默造 0。
|
|
312
|
+
"""
|
|
313
|
+
try:
|
|
314
|
+
db = open_ro_db(db_path)
|
|
315
|
+
try:
|
|
316
|
+
tables = {
|
|
317
|
+
r[0]
|
|
318
|
+
for r in db.execute(
|
|
319
|
+
"SELECT name FROM sqlite_master WHERE type='table'"
|
|
320
|
+
).fetchall()
|
|
321
|
+
}
|
|
322
|
+
if "PcSampling" not in tables:
|
|
323
|
+
return None
|
|
324
|
+
cur = db.execute("SELECT * FROM PcSampling")
|
|
325
|
+
cols = [d[0] for d in cur.description]
|
|
326
|
+
rows = cur.fetchall()
|
|
327
|
+
finally:
|
|
328
|
+
db.close()
|
|
329
|
+
except Exception: # noqa: BLE001 —— DB 损坏:missing 降级不崩
|
|
330
|
+
return None
|
|
331
|
+
if not rows:
|
|
332
|
+
return None
|
|
333
|
+
agg = {c: 0.0 for c in STALL_COLUMNS if c in cols}
|
|
334
|
+
if not agg:
|
|
335
|
+
return None
|
|
336
|
+
try:
|
|
337
|
+
for row in rows:
|
|
338
|
+
for c, v in zip(cols, row):
|
|
339
|
+
if c in agg:
|
|
340
|
+
agg[c] += float(v or 0)
|
|
341
|
+
except (TypeError, ValueError):
|
|
342
|
+
return None
|
|
343
|
+
total = sum(agg.values())
|
|
344
|
+
if total <= 0:
|
|
345
|
+
return None
|
|
346
|
+
dist = {
|
|
347
|
+
c: round(v / total * 100, 2)
|
|
348
|
+
for c, v in sorted(agg.items(), key=lambda kv: -kv[1])
|
|
349
|
+
}
|
|
350
|
+
top = max(dist, key=dist.get)
|
|
351
|
+
return {
|
|
352
|
+
"samples_total": int(total),
|
|
353
|
+
"address_rows": len(rows),
|
|
354
|
+
"top_stall": top,
|
|
355
|
+
"top_stall_pct": dist[top],
|
|
356
|
+
"distribution_pct": dist,
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
def load_opinfo_summary(root: Path) -> dict | None:
|
|
361
|
+
"""npu-compute Summary.jsonl 的 OpInfoSummary 行(OpBasicInfo 等价角色)。
|
|
362
|
+
|
|
363
|
+
大小写两代形态都接受(Summary.jsonl / summary.jsonl,真实 .npu-rep 实测)。
|
|
364
|
+
"""
|
|
365
|
+
for cand in (root / "Summary.jsonl", root / "summary.jsonl"):
|
|
366
|
+
if not cand.exists():
|
|
367
|
+
continue
|
|
368
|
+
try:
|
|
369
|
+
for line in cand.read_text(encoding="utf-8").splitlines():
|
|
370
|
+
if not line.strip():
|
|
371
|
+
continue
|
|
372
|
+
d = json.loads(line)
|
|
373
|
+
if d.get("category") == "OpInfoSummary":
|
|
374
|
+
return d
|
|
375
|
+
except (OSError, json.JSONDecodeError):
|
|
376
|
+
continue
|
|
377
|
+
return None
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
# ---- DB 双源:msprof_*.db 与 CSV 等价定位 -----------------------
|
|
381
|
+
# 等价查询固化在脚本(判定只出自脚本原则:SQL 拼接不进 LLM)。
|
|
382
|
+
# 真源核验:msprof 9.0 产物 device_0/sqlite/ai_core_op_summary.db 的 task_time 表
|
|
383
|
+
# (startNs/endNs/duration_time/task_type),op 级 per-kernel 行由 op_summary 语义
|
|
384
|
+
# 承担——DB 路径当前只提供 task_duration 类标量(时间轴),逐核 pipe 类指标
|
|
385
|
+
# 仍走 CSV(msprof 的 per-block 指标只导出 CSV)。
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
def find_metric_db(manifest_dir: Path) -> Path | None:
|
|
389
|
+
"""定位 msprof sqlite 产物(PROF_*/device_*/sqlite/ai_core_op_summary.db 或 msprof_*.db)。"""
|
|
390
|
+
for pat in (
|
|
391
|
+
"**/sqlite/ai_core_op_summary.db",
|
|
392
|
+
"**/ai_core_op_summary.db",
|
|
393
|
+
"msprof_*.db",
|
|
394
|
+
):
|
|
395
|
+
cands = sorted(manifest_dir.rglob(pat))
|
|
396
|
+
if cands:
|
|
397
|
+
return cands[0]
|
|
398
|
+
return None
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
def extract_from_db(db_path: Path, kernel_name: str | None) -> dict:
|
|
402
|
+
"""从 msprof sqlite 提取 task 级标量(DB 双源)。
|
|
403
|
+
|
|
404
|
+
等价查询(与 CSV 路径同口径):
|
|
405
|
+
- task_duration_us:AI Core 计算类 task 的 duration 均值(duration_time
|
|
406
|
+
单位为 ns——真实 msprof 9.0 产物实测核验,start_time 同为 ns;÷1000 转 us)
|
|
407
|
+
- task_count:行数(供 sources 审计)
|
|
408
|
+
口径说明(如实分级):DB task_time 的 AI_CORE 行是 task 级时长,与
|
|
409
|
+
op_summary 的 op 级 Task Duration 聚合层级不同(真实产物实测:8900ns=8.9us
|
|
410
|
+
vs CSV 5.42us,含 SDMA 子事件拆分与 wait 记账差异)——sources 注明
|
|
411
|
+
「DB 口径」,报告消费时不得与 CSV 口径混比(delta_compare 的 HARD 校验
|
|
412
|
+
语义同源)。
|
|
413
|
+
无 Op Name 维度(task_time 表不含 kernel 名)→ 多 kernel 程序 DB 源不产出
|
|
414
|
+
duration 标量(missing 记原因)——比 CSV 侧防护更保守(CSV 有 Op Name 列
|
|
415
|
+
可过滤,DB 侧 msprof 9.0 表结构不可过滤)。
|
|
416
|
+
"""
|
|
417
|
+
out = {}
|
|
418
|
+
try:
|
|
419
|
+
import sqlite3
|
|
420
|
+
|
|
421
|
+
db = sqlite3.connect(f"file:{db_path}?mode=ro", uri=True)
|
|
422
|
+
try:
|
|
423
|
+
tables = {
|
|
424
|
+
r[0]
|
|
425
|
+
for r in db.execute(
|
|
426
|
+
"SELECT name FROM sqlite_master WHERE type='table'"
|
|
427
|
+
).fetchall()
|
|
428
|
+
}
|
|
429
|
+
if "task_time" not in tables:
|
|
430
|
+
return {"error": f"task_time 表不存在(表集合 {sorted(tables)[:8]})"}
|
|
431
|
+
rows = db.execute(
|
|
432
|
+
"SELECT task_type, duration_time FROM task_time"
|
|
433
|
+
).fetchall()
|
|
434
|
+
# 计算类 task:AI_CORE / AI_VECTOR_CORE(排除 EVENT_RECORD / PLACE_HOLDER /
|
|
435
|
+
# SDMA 搬运类行——真实 msprof 9.0 产物实测 task_type 集合核验;
|
|
436
|
+
# CSV 侧 Task Duration 同样只统计计算 op)
|
|
437
|
+
calc = [
|
|
438
|
+
float(d)
|
|
439
|
+
for t, d in rows
|
|
440
|
+
if t
|
|
441
|
+
in ("AI_CORE", "AI_VECTOR_CORE", "AI_CORE_SQE", "AI_VECTOR_CORE_SQE")
|
|
442
|
+
and d not in (None, 0)
|
|
443
|
+
]
|
|
444
|
+
if calc:
|
|
445
|
+
out["task_duration_us"] = round(sum(calc) / len(calc) / 1000.0, 2)
|
|
446
|
+
out["task_count"] = len(calc)
|
|
447
|
+
out["unit_note"] = "duration_time(ns)→us"
|
|
448
|
+
else:
|
|
449
|
+
out["error"] = "无 AI Core 计算类 task 行"
|
|
450
|
+
finally:
|
|
451
|
+
db.close()
|
|
452
|
+
except Exception as e: # noqa: BLE001 —— DB 损坏/表结构漂移:missing 降级不崩
|
|
453
|
+
out = {"error": f"sqlite 读取失败:{e}"}
|
|
454
|
+
return out
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
def extract_from_csv(
|
|
458
|
+
csv_path: Path, cols: list[str], kernel_name: str | None, agg: str = "mean"
|
|
459
|
+
) -> tuple[float | None, int]:
|
|
460
|
+
"""从 CSV 提取候选列聚合值(mean)。有 Op Name 列且多值时按 kernel 过滤
|
|
461
|
+
(与 verdict.py G15 同款防护——bridge 不产出跨 kernel 平均标量)。"""
|
|
462
|
+
rows = _load_rows(csv_path)
|
|
463
|
+
if not rows:
|
|
464
|
+
return None, 0
|
|
465
|
+
if "Op Name" in rows[0]:
|
|
466
|
+
names = {str(r.get("Op Name") or "").strip() for r in rows}
|
|
467
|
+
if len(names) > 1:
|
|
468
|
+
if kernel_name and kernel_name in names:
|
|
469
|
+
rows = [
|
|
470
|
+
r
|
|
471
|
+
for r in rows
|
|
472
|
+
if str(r.get("Op Name") or "").strip() == kernel_name
|
|
473
|
+
]
|
|
474
|
+
else:
|
|
475
|
+
return None, 0 # 混采且无法过滤:不产出(fail silent 到 missing 列表)
|
|
476
|
+
vals = [v for v in (_first_float(r, cols) for r in rows) if v is not None]
|
|
477
|
+
if not vals:
|
|
478
|
+
return None, 0
|
|
479
|
+
if agg == "max":
|
|
480
|
+
return max(vals), len(vals)
|
|
481
|
+
return sum(vals) / len(vals), len(vals)
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
def extract_cflt_parts_from_csv(
|
|
485
|
+
csv_path: Path, col_sets: list[list[str]], kernel_name: str | None
|
|
486
|
+
) -> float | None:
|
|
487
|
+
"""CSV 侧分量和口径:候选组内各列 mean 求和(与 DB 侧 db_column_mean_sum
|
|
488
|
+
同算法——先各列 mean 再求和,保双通道等价)。"""
|
|
489
|
+
rows = _load_rows(csv_path)
|
|
490
|
+
if not rows:
|
|
491
|
+
return None
|
|
492
|
+
if "Op Name" in rows[0]:
|
|
493
|
+
names = {str(r.get("Op Name") or "").strip() for r in rows}
|
|
494
|
+
if len(names) > 1:
|
|
495
|
+
if kernel_name and kernel_name in names:
|
|
496
|
+
rows = [
|
|
497
|
+
r
|
|
498
|
+
for r in rows
|
|
499
|
+
if str(r.get("Op Name") or "").strip() == kernel_name
|
|
500
|
+
]
|
|
501
|
+
else:
|
|
502
|
+
return None
|
|
503
|
+
for cols in col_sets:
|
|
504
|
+
if not all(c in rows[0] for c in cols):
|
|
505
|
+
continue
|
|
506
|
+
vals = []
|
|
507
|
+
for col in cols:
|
|
508
|
+
per_row = [
|
|
509
|
+
v for v in (_first_float(r, [col]) for r in rows) if v is not None
|
|
510
|
+
]
|
|
511
|
+
if not per_row:
|
|
512
|
+
vals = []
|
|
513
|
+
break
|
|
514
|
+
vals.append(sum(per_row) / len(per_row))
|
|
515
|
+
if vals:
|
|
516
|
+
return sum(vals)
|
|
517
|
+
return None
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
def load_soc_spec(path: Path) -> dict:
|
|
521
|
+
import yaml
|
|
522
|
+
|
|
523
|
+
return yaml.safe_load(path.read_text(encoding="utf-8"))
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
def soc_gm_bw_gbps(
|
|
527
|
+
soc_spec: dict, soc: str, sku: str | None
|
|
528
|
+
) -> tuple[float | None, str]:
|
|
529
|
+
"""解析 GM 峰值带宽:优先 SKU 精确值,缺省用 reference(带溯源说明)。"""
|
|
530
|
+
block = soc_spec.get("socs", {}).get(soc)
|
|
531
|
+
if not block:
|
|
532
|
+
return None, f"soc-spec 无 {soc} 条目"
|
|
533
|
+
if sku:
|
|
534
|
+
for s in block.get("skus", []):
|
|
535
|
+
if s.get("sku") == sku:
|
|
536
|
+
# skus 未携带带宽(未标定):仍回退 reference,但注明 SKU 命中
|
|
537
|
+
break
|
|
538
|
+
ref = block.get("reference", {}).get("gm_bw_gbps", {})
|
|
539
|
+
v = ref.get("value")
|
|
540
|
+
note = f"reference {v} GB/s({ref.get('source', '?')})"
|
|
541
|
+
if not ref.get("verified", True):
|
|
542
|
+
note += " 🟡 未实测标定"
|
|
543
|
+
return v, note
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
def main() -> int:
|
|
547
|
+
here = Path(__file__).resolve().parent
|
|
548
|
+
ap = argparse.ArgumentParser(
|
|
549
|
+
description="采集产物 → verdict --scalar 生产者(msprof 7 组 / npu-compute DB 通道)"
|
|
550
|
+
)
|
|
551
|
+
ap.add_argument(
|
|
552
|
+
"--manifest",
|
|
553
|
+
required=True,
|
|
554
|
+
help="collection_manifest.json 路径(或产物根目录——npu-compute 传解包目录)",
|
|
555
|
+
)
|
|
556
|
+
ap.add_argument(
|
|
557
|
+
"--prof-dir",
|
|
558
|
+
"--prof", # 入口文档(SKILL.md)使用的别名
|
|
559
|
+
dest="prof_dir",
|
|
560
|
+
default=None,
|
|
561
|
+
help="产物根目录(manifest 只有相对路径时指定;缺省取 manifest 所在目录)",
|
|
562
|
+
)
|
|
563
|
+
ap.add_argument(
|
|
564
|
+
"--source",
|
|
565
|
+
default="auto",
|
|
566
|
+
choices=["auto", "msprof", "npu-compute"],
|
|
567
|
+
help="产物来源通道:auto 按目录特征判源(Summary.jsonl/summary.db → npu-compute)",
|
|
568
|
+
)
|
|
569
|
+
ap.add_argument("--soc", required=True, help="a2/a3/a5(峰值换算读 soc-spec)")
|
|
570
|
+
ap.add_argument(
|
|
571
|
+
"--kernel-name",
|
|
572
|
+
default=None,
|
|
573
|
+
help="多 kernel CSV 过滤(不产出跨 kernel 平均标量)",
|
|
574
|
+
)
|
|
575
|
+
ap.add_argument(
|
|
576
|
+
"--soc-spec",
|
|
577
|
+
default=str(here.parents[1] / "ops-verdict" / "references" / "soc-spec.yaml"),
|
|
578
|
+
)
|
|
579
|
+
ap.add_argument(
|
|
580
|
+
"--db",
|
|
581
|
+
default=None,
|
|
582
|
+
help="sqlite 产物路径:npu-compute 通道缺省探测 <dir>/summary.db;"
|
|
583
|
+
"msprof 通道缺省探测 PROF_*/sqlite/ai_core_op_summary.db(DB 双源)",
|
|
584
|
+
)
|
|
585
|
+
ap.add_argument(
|
|
586
|
+
"--no-db", action="store_true", help="禁用一切 DB 读取(纯 CSV 口径)"
|
|
587
|
+
)
|
|
588
|
+
ap.add_argument("--output", default=None, help="scalars.json 输出(缺省只打印)")
|
|
589
|
+
ap.add_argument(
|
|
590
|
+
"--print-scalar",
|
|
591
|
+
action="store_true",
|
|
592
|
+
help="stdout 只打印 verdict.py 可直接消费的 --scalar 串(供管道拼接)",
|
|
593
|
+
)
|
|
594
|
+
args = ap.parse_args()
|
|
595
|
+
|
|
596
|
+
manifest_path = Path(args.manifest)
|
|
597
|
+
# 入参二义性按 help 文档口径消解:--manifest 可传
|
|
598
|
+
# manifest 文件或产物根目录——传目录时 root 取该目录本身(取 .parent 会在
|
|
599
|
+
# prof/{baseline,after} 布局下 rglob 命中字母序靠前的另一轮采集,
|
|
600
|
+
# 把「优化后」CSV 当「基线」标量喂给 verdict,结论方向反转);
|
|
601
|
+
# 目录不存在时 fail loud,不静默上移搜索范围。
|
|
602
|
+
if args.prof_dir:
|
|
603
|
+
root = Path(args.prof_dir)
|
|
604
|
+
elif manifest_path.is_dir():
|
|
605
|
+
root = manifest_path
|
|
606
|
+
elif manifest_path.is_file():
|
|
607
|
+
root = manifest_path.parent
|
|
608
|
+
else:
|
|
609
|
+
# 路径不存在(拼错):fail loud——不静默上移到 parent 的 rglob
|
|
610
|
+
print(
|
|
611
|
+
f"ERROR: --manifest 路径不存在(文件或目录): {manifest_path}",
|
|
612
|
+
file=sys.stderr,
|
|
613
|
+
)
|
|
614
|
+
return 1
|
|
615
|
+
if not root.is_dir():
|
|
616
|
+
print(f"ERROR: 产物根目录不存在: {root}", file=sys.stderr)
|
|
617
|
+
return 1
|
|
618
|
+
# manifest 本体只做合法性校验(坏 JSON 应 fail loud);产物定位走 root rglob
|
|
619
|
+
if manifest_path.is_file():
|
|
620
|
+
json.loads(manifest_path.read_text(encoding="utf-8"))
|
|
621
|
+
|
|
622
|
+
# ---- 通道判定(auto 按目录特征;显式指定按用户口径)----
|
|
623
|
+
source_tool = args.source
|
|
624
|
+
if source_tool == "auto":
|
|
625
|
+
source_tool = detect_source(root)
|
|
626
|
+
npu_db_path: Path | None = None
|
|
627
|
+
if source_tool == "npu-compute" and not args.no_db:
|
|
628
|
+
npu_db_path = (
|
|
629
|
+
Path(args.db)
|
|
630
|
+
if args.db and Path(args.db).exists()
|
|
631
|
+
else find_npucompute_db(root)
|
|
632
|
+
)
|
|
633
|
+
if npu_db_path is None:
|
|
634
|
+
# npu-compute 目录无 DB(旧版 .npu-rep / --no-pack 无 sqlite 环境):
|
|
635
|
+
# 如实降级 CSV 通道并注记(DB 增益见 SKILL.md csv_to_db 升级路径)
|
|
636
|
+
print(
|
|
637
|
+
"[warn] npu-compute 目录未见 summary.db——DB 通道降级 CSV(旧版报告可用"
|
|
638
|
+
" csv_to_db.py 升级为 DB 格式)",
|
|
639
|
+
file=sys.stderr,
|
|
640
|
+
)
|
|
641
|
+
|
|
642
|
+
soc_spec = {}
|
|
643
|
+
spec_path = Path(args.soc_spec)
|
|
644
|
+
if spec_path.exists():
|
|
645
|
+
soc_spec = load_soc_spec(spec_path)
|
|
646
|
+
|
|
647
|
+
scalars: dict[str, float] = {}
|
|
648
|
+
sources: dict[str, str] = {}
|
|
649
|
+
missing: list[dict] = []
|
|
650
|
+
|
|
651
|
+
def bridge_db_first(
|
|
652
|
+
table: str,
|
|
653
|
+
db_cols: list[str],
|
|
654
|
+
csv_path: Path | None,
|
|
655
|
+
csv_cols: list[str],
|
|
656
|
+
name: str,
|
|
657
|
+
transform=None,
|
|
658
|
+
note_db: str | None = None,
|
|
659
|
+
note_csv: str | None = None,
|
|
660
|
+
):
|
|
661
|
+
"""npu-compute 通道标量:DB SQL 优先(AVG+NULL-skip 下推),CSV 补位。
|
|
662
|
+
|
|
663
|
+
DB 是 CSV 的同数据入库副本(单次采集双格式),数值口径等价——
|
|
664
|
+
sources 逐指标注记实际通道,报告消费可溯源。
|
|
665
|
+
"""
|
|
666
|
+
if npu_db_path is not None:
|
|
667
|
+
v, col = db_column_mean(npu_db_path, table, db_cols)
|
|
668
|
+
if v is not None:
|
|
669
|
+
if transform:
|
|
670
|
+
v = transform(v)
|
|
671
|
+
if v is not None:
|
|
672
|
+
scalars[name] = round(v, 2)
|
|
673
|
+
sources[name] = f"{npu_db_path}::{table}.{col}{note_db or ''}"
|
|
674
|
+
return
|
|
675
|
+
# CSV 补位(DB 无该表/该列/被 --no-db 禁用)
|
|
676
|
+
if csv_path is not None and Path(csv_path).exists():
|
|
677
|
+
val, _n = extract_from_csv(Path(csv_path), csv_cols, args.kernel_name)
|
|
678
|
+
if val is not None:
|
|
679
|
+
if transform:
|
|
680
|
+
val = transform(val)
|
|
681
|
+
if val is not None:
|
|
682
|
+
scalars[name] = round(val, 2)
|
|
683
|
+
sources[name] = f"{csv_path}{note_csv or ''}"
|
|
684
|
+
return
|
|
685
|
+
missing.append(
|
|
686
|
+
{
|
|
687
|
+
"metric": name,
|
|
688
|
+
"reason": f"列不存在或全空(DB 候选 {db_cols} / CSV 候选 {csv_cols[:3]}…,"
|
|
689
|
+
f"表 {table},CSV {csv_path})",
|
|
690
|
+
}
|
|
691
|
+
)
|
|
692
|
+
|
|
693
|
+
def bridge(
|
|
694
|
+
metric_csv: Path | None,
|
|
695
|
+
cols: list[str],
|
|
696
|
+
name: str,
|
|
697
|
+
agg: str = "mean",
|
|
698
|
+
transform=None,
|
|
699
|
+
):
|
|
700
|
+
"""提取一个标量;失败记 missing(补采闭环 skipped[].missing 的真源)。"""
|
|
701
|
+
if metric_csv is None or not Path(metric_csv).exists():
|
|
702
|
+
missing.append({"metric": name, "reason": f"产物缺失({metric_csv})"})
|
|
703
|
+
return
|
|
704
|
+
val, n = extract_from_csv(Path(metric_csv), cols, args.kernel_name, agg)
|
|
705
|
+
if val is None:
|
|
706
|
+
missing.append(
|
|
707
|
+
{
|
|
708
|
+
"metric": name,
|
|
709
|
+
"reason": f"列不存在或全空(候选列 {cols},文件 {metric_csv})",
|
|
710
|
+
}
|
|
711
|
+
)
|
|
712
|
+
return
|
|
713
|
+
if transform:
|
|
714
|
+
val = transform(val)
|
|
715
|
+
if val is None:
|
|
716
|
+
missing.append({"metric": name, "reason": "换算失败(除零/缺失依赖)"})
|
|
717
|
+
return
|
|
718
|
+
scalars[name] = round(val, 2)
|
|
719
|
+
sources[name] = str(metric_csv)
|
|
720
|
+
|
|
721
|
+
# ---- L0:icache_miss_rate / l2_hit_rate ----
|
|
722
|
+
pipe_csv = find_metric_csv(root, "PipeUtilization")
|
|
723
|
+
l2c_csv = find_metric_csv(root, "L2Cache")
|
|
724
|
+
arith_csv = find_metric_csv(root, "ArithmeticUtilization")
|
|
725
|
+
rcr_csv = find_metric_csv(root, "ResourceConflictRatio")
|
|
726
|
+
# 注:Memory.csv 不作换算源——active_bw 列在 PipeUtilization.csv(三代实测形态),
|
|
727
|
+
# Memory.csv 是通道聚合带宽(main_mem_read/write),口径不同(见下方 L1 反证段)。
|
|
728
|
+
opbi_csv = find_metric_csv(root, "OpBasicInfo")
|
|
729
|
+
|
|
730
|
+
if source_tool == "npu-compute":
|
|
731
|
+
# ---- npu-compute 通道(Roadmap #4):DB SQL 优先,CSV 补位 ----
|
|
732
|
+
# DB 列名为规范化形(单位后缀已拆入 FieldUnitMap);候选序与 CSV 同语义
|
|
733
|
+
# (db_column_mean 用 COALESCE 逐行回退,与 CSV 侧 _first_float 逐行
|
|
734
|
+
# 语义对齐。
|
|
735
|
+
# npu-compute L2Cache 无 total hit_rate 列——read 口径补位(列集真源核验)。
|
|
736
|
+
bridge_db_first(
|
|
737
|
+
"PipeUtilization",
|
|
738
|
+
ICACHE_COLS,
|
|
739
|
+
pipe_csv,
|
|
740
|
+
ICACHE_COLS,
|
|
741
|
+
"icache_miss_rate",
|
|
742
|
+
)
|
|
743
|
+
bridge_db_first(
|
|
744
|
+
"L2Cache",
|
|
745
|
+
[c.replace("(%)", "") for c in L2_HIT_COLS + L2_HIT_COLS_NPUCOMPUTE],
|
|
746
|
+
l2c_csv,
|
|
747
|
+
L2_HIT_COLS + L2_HIT_COLS_NPUCOMPUTE,
|
|
748
|
+
"l2_hit_rate",
|
|
749
|
+
note_csv="(npu-compute 无 total 列时 read_hit_rate 口径补位)",
|
|
750
|
+
)
|
|
751
|
+
bridge_db_first(
|
|
752
|
+
"ArithmeticUtilization",
|
|
753
|
+
VEC_FP32_COLS,
|
|
754
|
+
arith_csv,
|
|
755
|
+
VEC_FP32_COLS,
|
|
756
|
+
"vec_fp32_ratio",
|
|
757
|
+
)
|
|
758
|
+
if "vec_fp32_ratio" in scalars and scalars["vec_fp32_ratio"] <= 1.5:
|
|
759
|
+
scalars["vec_fp32_ratio"] = round(scalars["vec_fp32_ratio"] * 100, 2)
|
|
760
|
+
# vec_total_cflt_ratio:total 列缺失时 stu+ldu+sfu 分量均值和口径
|
|
761
|
+
# (npu-compute ResourceConflictRatio 列集真源核验——无 total 列;
|
|
762
|
+
# 分量和 = total 的成分展开,语义同源,sources 注记口径)
|
|
763
|
+
if npu_db_path is not None:
|
|
764
|
+
v, cols_hit = db_column_mean(
|
|
765
|
+
npu_db_path, "ResourceConflictRatio", VEC_CFLT_COLS
|
|
766
|
+
)
|
|
767
|
+
if v is None:
|
|
768
|
+
v, cols_hit = db_column_mean_sum(
|
|
769
|
+
npu_db_path, "ResourceConflictRatio", [VEC_CFLT_PART_COLS]
|
|
770
|
+
)
|
|
771
|
+
if v is not None:
|
|
772
|
+
v = v # 分量和口径
|
|
773
|
+
note_cflt = (
|
|
774
|
+
"(stu+ldu+sfu 分量均值和口径——npu-compute 无 total 列)"
|
|
775
|
+
)
|
|
776
|
+
else:
|
|
777
|
+
note_cflt = None
|
|
778
|
+
else:
|
|
779
|
+
note_cflt = None
|
|
780
|
+
if v is not None:
|
|
781
|
+
if v <= 1.5:
|
|
782
|
+
v = v * 100
|
|
783
|
+
scalars["vec_total_cflt_ratio"] = round(v, 2)
|
|
784
|
+
# cols_hit:total 命中为 str(COALESCE 命中列集),分量和命中为 list
|
|
785
|
+
suffix = f".{cols_hit[-1]}" if cols_hit else ""
|
|
786
|
+
sources["vec_total_cflt_ratio"] = (
|
|
787
|
+
f"{npu_db_path}::ResourceConflictRatio{suffix}{note_cflt or ''}"
|
|
788
|
+
)
|
|
789
|
+
else:
|
|
790
|
+
missing.append(
|
|
791
|
+
{
|
|
792
|
+
"metric": "vec_total_cflt_ratio",
|
|
793
|
+
"reason": "ResourceConflictRatio 无 total 及分项冲突列"
|
|
794
|
+
f"(候选 {VEC_CFLT_COLS} / {VEC_CFLT_PART_COLS})",
|
|
795
|
+
}
|
|
796
|
+
)
|
|
797
|
+
else:
|
|
798
|
+
# CSV 补位通道:total 列直接候选;缺失时分量和口径(与 DB 侧同算法)
|
|
799
|
+
if rcr_csv is not None and Path(rcr_csv).exists():
|
|
800
|
+
v, _n = extract_from_csv(Path(rcr_csv), VEC_CFLT_COLS, args.kernel_name)
|
|
801
|
+
note_cflt = None
|
|
802
|
+
if v is None:
|
|
803
|
+
v = extract_cflt_parts_from_csv(
|
|
804
|
+
Path(rcr_csv), [VEC_CFLT_PART_COLS], args.kernel_name
|
|
805
|
+
)
|
|
806
|
+
if v is not None:
|
|
807
|
+
note_cflt = (
|
|
808
|
+
"(stu+ldu+sfu 分量均值和口径——npu-compute 无 total 列)"
|
|
809
|
+
)
|
|
810
|
+
if v is not None:
|
|
811
|
+
if v <= 1.5:
|
|
812
|
+
v = v * 100
|
|
813
|
+
scalars["vec_total_cflt_ratio"] = round(v, 2)
|
|
814
|
+
sources["vec_total_cflt_ratio"] = f"{rcr_csv}{note_cflt or ''}"
|
|
815
|
+
else:
|
|
816
|
+
missing.append(
|
|
817
|
+
{
|
|
818
|
+
"metric": "vec_total_cflt_ratio",
|
|
819
|
+
"reason": "ResourceConflictRatio 无 total 及分项冲突列"
|
|
820
|
+
f"(候选 {VEC_CFLT_COLS} / {VEC_CFLT_PART_COLS})",
|
|
821
|
+
}
|
|
822
|
+
)
|
|
823
|
+
else:
|
|
824
|
+
missing.append(
|
|
825
|
+
{
|
|
826
|
+
"metric": "vec_total_cflt_ratio",
|
|
827
|
+
"reason": f"产物缺失({rcr_csv})",
|
|
828
|
+
}
|
|
829
|
+
)
|
|
830
|
+
# task_duration_us / block_dim:Summary.jsonl OpInfoSummary(无 OpBasicInfo)
|
|
831
|
+
opinfo = load_opinfo_summary(root)
|
|
832
|
+
if opinfo:
|
|
833
|
+
td = _first_float(opinfo, OPBI_TASK_COLS)
|
|
834
|
+
bd = _first_float(opinfo, OPBI_BLOCKDIM_COLS)
|
|
835
|
+
if td is not None:
|
|
836
|
+
scalars["task_duration_us"] = round(td, 2)
|
|
837
|
+
sources["task_duration_us"] = f"{root}/Summary.jsonl::OpInfoSummary"
|
|
838
|
+
if bd is not None:
|
|
839
|
+
scalars["block_dim"] = round(bd, 2)
|
|
840
|
+
sources["block_dim"] = f"{root}/Summary.jsonl::OpInfoSummary"
|
|
841
|
+
if td is None:
|
|
842
|
+
missing.append(
|
|
843
|
+
{
|
|
844
|
+
"metric": "task_duration_us",
|
|
845
|
+
"reason": "OpInfoSummary Task Duration(us) 为 null/缺失"
|
|
846
|
+
"(多 kernel 报告形态——逐 op 拆子报告,逐个解包判定)",
|
|
847
|
+
}
|
|
848
|
+
)
|
|
849
|
+
else:
|
|
850
|
+
missing.append(
|
|
851
|
+
{
|
|
852
|
+
"metric": "task_duration_us",
|
|
853
|
+
"reason": "Summary.jsonl OpInfoSummary 缺失(npu-compute 通道)",
|
|
854
|
+
}
|
|
855
|
+
)
|
|
856
|
+
# top_stall_pct:PcSampling(DB 独有)——L0_STALL_DOMINANT 的生产者
|
|
857
|
+
if npu_db_path is not None:
|
|
858
|
+
pcs = pcsampling_stall(npu_db_path)
|
|
859
|
+
if pcs:
|
|
860
|
+
scalars["top_stall_pct"] = pcs["top_stall_pct"]
|
|
861
|
+
sources["top_stall_pct"] = (
|
|
862
|
+
f"{npu_db_path}::PcSampling(DB 独有数据源;CSV 通道不存在该指标)"
|
|
863
|
+
)
|
|
864
|
+
else:
|
|
865
|
+
missing.append(
|
|
866
|
+
{
|
|
867
|
+
"metric": "top_stall_pct",
|
|
868
|
+
"reason": "summary.db 无 PcSampling 表/空表"
|
|
869
|
+
"(未选 PmSampling Section 或 SIMD 算子无 SIMT 采样)",
|
|
870
|
+
}
|
|
871
|
+
)
|
|
872
|
+
else:
|
|
873
|
+
bridge(pipe_csv, ICACHE_COLS, "icache_miss_rate")
|
|
874
|
+
bridge(l2c_csv, L2_HIT_COLS, "l2_hit_rate")
|
|
875
|
+
bridge(arith_csv, VEC_FP32_COLS, "vec_fp32_ratio") # 0~1 比例 → 百分数
|
|
876
|
+
if "vec_fp32_ratio" in scalars and scalars["vec_fp32_ratio"] <= 1.5:
|
|
877
|
+
scalars["vec_fp32_ratio"] = round(scalars["vec_fp32_ratio"] * 100, 2)
|
|
878
|
+
bridge(rcr_csv, VEC_CFLT_COLS, "vec_total_cflt_ratio")
|
|
879
|
+
if "vec_total_cflt_ratio" in scalars and scalars["vec_total_cflt_ratio"] <= 1.5:
|
|
880
|
+
scalars["vec_total_cflt_ratio"] = round(
|
|
881
|
+
scalars["vec_total_cflt_ratio"] * 100, 2
|
|
882
|
+
)
|
|
883
|
+
|
|
884
|
+
# ---- L1 反证:mte2_active_bw_pct_of_peak(active_bw / soc-spec GM 峰值 × 100)----
|
|
885
|
+
# active_bw 列在 PipeUtilization.csv(三代实测形态),不在 Memory.csv——后者是
|
|
886
|
+
# 通道聚合带宽(main_mem_read/write),口径不同不作换算源。
|
|
887
|
+
bw_gbps, bw_note = soc_gm_bw_gbps(soc_spec, args.soc, None)
|
|
888
|
+
|
|
889
|
+
def _pct_of_peak(bw: float) -> float | None:
|
|
890
|
+
return bw / bw_gbps * 100 if bw_gbps else None
|
|
891
|
+
|
|
892
|
+
if source_tool == "npu-compute":
|
|
893
|
+
bridge_db_first(
|
|
894
|
+
"PipeUtilization",
|
|
895
|
+
[c.replace("(GB/s)", "") for c in MTE2_BW_COLS],
|
|
896
|
+
pipe_csv,
|
|
897
|
+
MTE2_BW_COLS,
|
|
898
|
+
"mte2_active_bw_pct_of_peak",
|
|
899
|
+
transform=_pct_of_peak,
|
|
900
|
+
)
|
|
901
|
+
else:
|
|
902
|
+
bridge(
|
|
903
|
+
pipe_csv,
|
|
904
|
+
MTE2_BW_COLS,
|
|
905
|
+
"mte2_active_bw_pct_of_peak",
|
|
906
|
+
agg="mean",
|
|
907
|
+
transform=_pct_of_peak,
|
|
908
|
+
)
|
|
909
|
+
|
|
910
|
+
# ---- L2:task_duration_us / block_dim(OpBasicInfo per-op 行;msprof 通道)----
|
|
911
|
+
# npu-compute 通道在上方 Summary.jsonl 段已完成,此处 msprof 路径行为不变。
|
|
912
|
+
if source_tool != "npu-compute":
|
|
913
|
+
if opbi_csv and Path(opbi_csv).exists():
|
|
914
|
+
rows = _load_rows(Path(opbi_csv))
|
|
915
|
+
op_names = {
|
|
916
|
+
str(r.get("Op Name") or "").strip() for r in rows if r.get("Op Name")
|
|
917
|
+
}
|
|
918
|
+
if args.kernel_name and op_names:
|
|
919
|
+
rows = [
|
|
920
|
+
r
|
|
921
|
+
for r in rows
|
|
922
|
+
if str(r.get("Op Name") or "").strip() == args.kernel_name
|
|
923
|
+
]
|
|
924
|
+
elif len(op_names) > 1:
|
|
925
|
+
# G15 同款防护:多 Op Name 且无 --kernel-name →
|
|
926
|
+
# 不取 rows[0] 张冠李戴,记 missing 待补采
|
|
927
|
+
missing.append(
|
|
928
|
+
{
|
|
929
|
+
"metric": "task_duration_us",
|
|
930
|
+
"reason": f"OpBasicInfo 含多个 Op Name({sorted(op_names)})且未指定 "
|
|
931
|
+
"--kernel-name:不产出张冠李戴标量,请补 --kernel-name 重跑",
|
|
932
|
+
}
|
|
933
|
+
)
|
|
934
|
+
rows = []
|
|
935
|
+
if rows:
|
|
936
|
+
# 指定 kernel 时按其全部行聚合(mean),不取首行
|
|
937
|
+
tds = [
|
|
938
|
+
v
|
|
939
|
+
for v in (_first_float(r, OPBI_TASK_COLS) for r in rows)
|
|
940
|
+
if v is not None
|
|
941
|
+
]
|
|
942
|
+
bds = [
|
|
943
|
+
v
|
|
944
|
+
for v in (_first_float(r, OPBI_BLOCKDIM_COLS) for r in rows)
|
|
945
|
+
if v is not None
|
|
946
|
+
]
|
|
947
|
+
if tds:
|
|
948
|
+
scalars["task_duration_us"] = round(sum(tds) / len(tds), 2)
|
|
949
|
+
sources["task_duration_us"] = str(opbi_csv)
|
|
950
|
+
if bds:
|
|
951
|
+
scalars["block_dim"] = round(sum(bds) / len(bds), 2)
|
|
952
|
+
sources["block_dim"] = str(opbi_csv)
|
|
953
|
+
elif not missing or missing[-1].get("metric") != "task_duration_us":
|
|
954
|
+
missing.append(
|
|
955
|
+
{
|
|
956
|
+
"metric": "task_duration_us",
|
|
957
|
+
"reason": "OpBasicInfo 无匹配行(kernel 过滤后为空)",
|
|
958
|
+
}
|
|
959
|
+
)
|
|
960
|
+
else:
|
|
961
|
+
missing.append(
|
|
962
|
+
{"metric": "task_duration_us", "reason": "OpBasicInfo.csv 缺失"}
|
|
963
|
+
)
|
|
964
|
+
|
|
965
|
+
# ---- P1-6 DB 双源:OpBasicInfo 缺失时 sqlite 补位 task_duration_us ----
|
|
966
|
+
# 等价查询固化在 extract_from_db(判定只出自脚本:SQL 拼接不进 LLM);DB 无
|
|
967
|
+
# kernel 名维度,多 kernel 场景保持 missing(不产出混采标量)。
|
|
968
|
+
# 仅 msprof 通道(npu-compute 的 task_duration 已由 Summary.jsonl 段产出)。
|
|
969
|
+
if (
|
|
970
|
+
source_tool != "npu-compute"
|
|
971
|
+
and "task_duration_us" not in scalars
|
|
972
|
+
and not args.no_db
|
|
973
|
+
):
|
|
974
|
+
db_path = Path(args.db) if args.db else find_metric_db(root)
|
|
975
|
+
if db_path and db_path.exists():
|
|
976
|
+
# G15 同款防护:DB 无 kernel 名维度,指定
|
|
977
|
+
# --kernel-name 时拒绝 DB 补位——不产出跨 kernel 平均标量
|
|
978
|
+
if args.kernel_name:
|
|
979
|
+
db_out = {
|
|
980
|
+
"error": "指定 --kernel-name 时 DB 源不可过滤(无 kernel 名维度)"
|
|
981
|
+
}
|
|
982
|
+
else:
|
|
983
|
+
db_out = extract_from_db(db_path, args.kernel_name)
|
|
984
|
+
if "task_duration_us" in db_out:
|
|
985
|
+
scalars["task_duration_us"] = db_out["task_duration_us"]
|
|
986
|
+
sources["task_duration_us"] = (
|
|
987
|
+
f"{db_path}(sqlite 双源·DB 口径:task 级时长 ≠ op_summary 的"
|
|
988
|
+
f" op 级 Task Duration 聚合,禁止混比;task_count={db_out.get('task_count')},"
|
|
989
|
+
f"{db_out.get('unit_note', '')})"
|
|
990
|
+
)
|
|
991
|
+
elif args.kernel_name:
|
|
992
|
+
missing.append(
|
|
993
|
+
{
|
|
994
|
+
"metric": "task_duration_us",
|
|
995
|
+
"reason": "DB 双源不产出(指定 --kernel-name 时 DB 无 kernel 名维度不可过滤):"
|
|
996
|
+
f"{db_out.get('error', '—')}",
|
|
997
|
+
}
|
|
998
|
+
)
|
|
999
|
+
else:
|
|
1000
|
+
prev = next(
|
|
1001
|
+
(m for m in missing if m["metric"] == "task_duration_us"), None
|
|
1002
|
+
)
|
|
1003
|
+
if prev:
|
|
1004
|
+
prev["reason"] += f";DB 双源亦失败({db_out.get('error', '—')})"
|
|
1005
|
+
|
|
1006
|
+
# ---- physical_cores(soc-spec reference;调用方可用 --scalar 覆写为 SKU 精确值)----
|
|
1007
|
+
# 口径:verdict 的 row_count 是「活跃子块行数」(time_metrics_from_rows 不滤
|
|
1008
|
+
# sub_block_id,Vec/Cube 行都计入)——分母须与实际行集同维:纯 Cube 行集
|
|
1009
|
+
# 按 ai_core_cnt,其余按 vector_core_cnt。
|
|
1010
|
+
def _rows_core_kind(csv_path: Path | None) -> str | None:
|
|
1011
|
+
"""从 PipeUtilization CSV 的 sub_block_id 判行集核型(null=不可判)。
|
|
1012
|
+
|
|
1013
|
+
纯 Cube 行(cube 前缀,忽略大小写)→ "cube";含 Vec 行 → "vector";
|
|
1014
|
+
缺列/无行/未知前缀 → None(调用方回退 AIV 默认,不改变现状行为)。
|
|
1015
|
+
"""
|
|
1016
|
+
if csv_path is None or not Path(csv_path).exists():
|
|
1017
|
+
return None
|
|
1018
|
+
try:
|
|
1019
|
+
rows = _load_rows(Path(csv_path))
|
|
1020
|
+
except Exception:
|
|
1021
|
+
return None
|
|
1022
|
+
if not rows or "sub_block_id" not in rows[0]:
|
|
1023
|
+
return None
|
|
1024
|
+
kinds = set()
|
|
1025
|
+
for r in rows:
|
|
1026
|
+
sb = str(r.get("sub_block_id") or "").strip().lower()
|
|
1027
|
+
if sb.startswith("cube"):
|
|
1028
|
+
kinds.add("cube")
|
|
1029
|
+
elif sb.startswith("vec"):
|
|
1030
|
+
kinds.add("vector")
|
|
1031
|
+
if kinds == {"cube"}:
|
|
1032
|
+
return "cube"
|
|
1033
|
+
if "vector" in kinds:
|
|
1034
|
+
return "vector"
|
|
1035
|
+
return None
|
|
1036
|
+
|
|
1037
|
+
block = soc_spec.get("socs", {}).get(args.soc, {})
|
|
1038
|
+
ref_cores = block.get("reference", {}).get("ai_core_cnt", {}).get("value")
|
|
1039
|
+
vec_cores = block.get("reference", {}).get("vector_core_cnt", {}).get("value")
|
|
1040
|
+
row_kind = _rows_core_kind(pipe_csv)
|
|
1041
|
+
# cube 行集 → 分母取 AIC 数(与活跃 Cube 行同维);其余(vector/不可判)→ AIV 数
|
|
1042
|
+
use_cores = ref_cores if (row_kind == "cube" and ref_cores) else vec_cores
|
|
1043
|
+
use_label = (
|
|
1044
|
+
"AIC(cube 行集同维)"
|
|
1045
|
+
if row_kind == "cube"
|
|
1046
|
+
else "AIV(Vec 行集同维;不可判时的默认)"
|
|
1047
|
+
)
|
|
1048
|
+
if use_cores:
|
|
1049
|
+
scalars["physical_cores"] = float(use_cores)
|
|
1050
|
+
sources["physical_cores"] = (
|
|
1051
|
+
f"soc-spec:{args.soc} reference({vec_cores} AIV / "
|
|
1052
|
+
f"{ref_cores} AIC;行集核型={row_kind or '不可判'} → 取 {use_label};"
|
|
1053
|
+
f"按实际 SKU 覆写可得精确值)"
|
|
1054
|
+
)
|
|
1055
|
+
|
|
1056
|
+
# ---- verdict --scalar 串 ----
|
|
1057
|
+
scalar_str = ",".join(f"{k}={v}" for k, v in scalars.items())
|
|
1058
|
+
pcs_out = pcsampling_stall(npu_db_path) if npu_db_path else None
|
|
1059
|
+
result = {
|
|
1060
|
+
"schema": SCHEMA,
|
|
1061
|
+
"source_tool": source_tool,
|
|
1062
|
+
"soc": args.soc,
|
|
1063
|
+
"kernel_name": args.kernel_name,
|
|
1064
|
+
"gm_bw_gbps": bw_gbps,
|
|
1065
|
+
"gm_bw_source": bw_note,
|
|
1066
|
+
"db_dual_source": "sqlite 备位 task_duration_us(CSV OpBasicInfo 缺失时启用;--no-db 关闭)"
|
|
1067
|
+
if str(sources.get("task_duration_us", "")).endswith(".db")
|
|
1068
|
+
or "(sqlite 双源" in str(sources.get("task_duration_us", ""))
|
|
1069
|
+
else None,
|
|
1070
|
+
"npucompute_db": str(npu_db_path) if npu_db_path else None,
|
|
1071
|
+
"pcsampling": pcs_out,
|
|
1072
|
+
"scalar_str": scalar_str,
|
|
1073
|
+
"scalars": scalars,
|
|
1074
|
+
"sources": sources,
|
|
1075
|
+
"missing": missing,
|
|
1076
|
+
"next": (
|
|
1077
|
+
f"喂判定引擎:python3 ../../ops-verdict/scripts/verdict.py "
|
|
1078
|
+
f"--rules <规则包> --csv <PipeUtilization.csv> --soc {args.soc} "
|
|
1079
|
+
f"--scalar {scalar_str} -o verdict.json"
|
|
1080
|
+
),
|
|
1081
|
+
}
|
|
1082
|
+
if args.output:
|
|
1083
|
+
out = Path(args.output)
|
|
1084
|
+
out.parent.mkdir(parents=True, exist_ok=True)
|
|
1085
|
+
out.write_text(
|
|
1086
|
+
json.dumps(result, indent=2, ensure_ascii=False) + "\n", encoding="utf-8"
|
|
1087
|
+
)
|
|
1088
|
+
print(f"→ {out}")
|
|
1089
|
+
if args.print_scalar:
|
|
1090
|
+
# 管道模式:stdout 只有裸 --scalar 串(human 摘要走 stderr,不污染管道)
|
|
1091
|
+
print(scalar_str)
|
|
1092
|
+
else:
|
|
1093
|
+
print(f"scalars: {scalar_str}")
|
|
1094
|
+
for m in missing:
|
|
1095
|
+
print(f" ⚠ missing: {m['metric']} — {m['reason']}", file=sys.stderr)
|
|
1096
|
+
if not args.print_scalar:
|
|
1097
|
+
print(f"下一步:{result['next']}")
|
|
1098
|
+
return 0
|
|
1099
|
+
|
|
1100
|
+
|
|
1101
|
+
if __name__ == "__main__":
|
|
1102
|
+
sys.exit(main())
|