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,163 @@
|
|
|
1
|
+
# SoftmaxV2 ARA Recompute 模板
|
|
2
|
+
|
|
3
|
+
## 1. 模板用途
|
|
4
|
+
|
|
5
|
+
针对 3D `[A1, R, A0]` 布局、R 超出 UB 容量的 Softmax 场景。将 R 切分为多个 bin,通过三阶段重读 GM(求 max → 求 sum → 输出)完成 Softmax。使用 `NlastReduceSum` 跨 bin 二分折叠和 `UpdateCache` 累加树高效合并局部 sum。
|
|
6
|
+
|
|
7
|
+
## 2. 输入输出布局和 Softmax 轴
|
|
8
|
+
|
|
9
|
+
- 输入 `x`:`[A1, R, A0]`,行优先,Softmax 沿 R 轴计算。
|
|
10
|
+
- 输出 `y`:`[A1, R, A0]`,与输入同 shape、同 dtype。
|
|
11
|
+
- UB 内布局为 `(binAddRFactor, tileA0Len)`,沿 R(bin)逐块处理。
|
|
12
|
+
|
|
13
|
+
## 3. 适用 shape、dtype 和 UB 条件
|
|
14
|
+
|
|
15
|
+
| 条件 | 要求 |
|
|
16
|
+
|------|------|
|
|
17
|
+
| 输入维数 | 3D,A0 > 1 |
|
|
18
|
+
| R 大小 | R 超 UB 单次载入容量 |
|
|
19
|
+
| dtype | FP32、FP16、BF16 |
|
|
20
|
+
| UB 约束 | 双缓冲 xQueue/yQueue + xMax/xSum + cache/temp/reduceSumTemp buffer |
|
|
21
|
+
|
|
22
|
+
## 4. 类名、构造函数和 Init 接口
|
|
23
|
+
|
|
24
|
+
```cpp
|
|
25
|
+
namespace SoftmaxV2Ops;
|
|
26
|
+
|
|
27
|
+
template <typename T1, typename T2>
|
|
28
|
+
class SoftmaxV2ARARecompute : public SoftmaxV2OpsBase {
|
|
29
|
+
public:
|
|
30
|
+
__aicore__ inline SoftmaxV2ARARecompute();
|
|
31
|
+
__aicore__ inline SoftmaxV2ARARecompute(const SoftmaxV2ARARecomputeTilingData* tilingDataIn);
|
|
32
|
+
__aicore__ inline void Init(GM_ADDR x, GM_ADDR y, TPipe* pipeIn);
|
|
33
|
+
__aicore__ inline void Process();
|
|
34
|
+
};
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
- **构造函数**:无参默认,或接收 TilingData 指针。
|
|
38
|
+
- **Init**:初始化 GM/UB buffer,包括 xQueue/yQueue(双缓冲)、xMaxBuf/xSumBuf、cacheBuffer/tempBuffer/reduceSumTempBuffer。
|
|
39
|
+
- **Process**:按 tile 遍历,每 tile 执行三阶段计算。
|
|
40
|
+
|
|
41
|
+
## 5. 对应的 TilingData 和字段说明
|
|
42
|
+
|
|
43
|
+
对应 `SoftmaxV2ARARecomputeTilingData`,定义在 [softmax_v2_tiling_data.h](softmax_v2_tiling_data.template)。
|
|
44
|
+
|
|
45
|
+
| 字段 | 含义 | 单位 |
|
|
46
|
+
|------|------|------|
|
|
47
|
+
| totalRLen / totalA0Len | R/A0 维总长度 | 元素数 |
|
|
48
|
+
| totalTiles | 总 tile 数 = A1 × tileA0Outer | tile |
|
|
49
|
+
| tilesPerCore | 每核 tile 数 | tile |
|
|
50
|
+
| usedCoreNums | 实际使用核数 | 核 |
|
|
51
|
+
| tileA0Outer | A0 方向 tile 总数 | tile |
|
|
52
|
+
| tileA0Len / tileA0Tail | 主块/尾块 A0 长度 | 元素数 |
|
|
53
|
+
| binAddRFactor | R 方向单 bin 长度(默认 128) | 元素数 |
|
|
54
|
+
| binAddRLoop | R 方向完整 bin 数 | bin |
|
|
55
|
+
| binAddRTotalLoop | R 方向 bin 总数 | bin |
|
|
56
|
+
| binAddRTail | R 方向尾 bin 长度 | 元素数 |
|
|
57
|
+
| binAddBasicBlockLoop | 二分树基础块数 | 块 |
|
|
58
|
+
| binAddMainFoldCount | 需折叠块数 | 块 |
|
|
59
|
+
| binAddCacheBufferCount | cache buffer 数量 | 个 |
|
|
60
|
+
| binAddResultCacheID | 最终结果 cache 索引 | 索引 |
|
|
61
|
+
|
|
62
|
+
## 6. Host tiling 参数计算方法
|
|
63
|
+
|
|
64
|
+
使用 [softmax_v2_tiling.h](softmax_v2_tiling.template) 中的 `TilingAraRecompute`:
|
|
65
|
+
|
|
66
|
+
```cpp
|
|
67
|
+
softmax_tiling::CaseShape shape{a1, r, a0, dtypeCode};
|
|
68
|
+
softmax_tiling::PlatformParam plat{ubSize, numBlocks};
|
|
69
|
+
SoftmaxV2ARARecomputeTilingData td;
|
|
70
|
+
int64_t blockDim = softmax_tiling::TilingAraRecompute(shape, plat, td);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
关键计算:
|
|
74
|
+
- `binAddRFactor` = 128(默认)
|
|
75
|
+
- `binAddRTotalLoop` = CeilDiv(R, binAddRFactor)
|
|
76
|
+
- `binAddBasicBlockLoop` = FindNearestPower2(binAddRTotalLoop)
|
|
77
|
+
- `binAddCacheBufferCount` = 64 - clz(binAddBasicBlockLoop)(二分树层数)
|
|
78
|
+
- `binAddResultCacheID` = GetCacheID(binAddBasicBlockLoop - 1)
|
|
79
|
+
|
|
80
|
+
## 7. CopyIn、归约、归一化和 CopyOut 流程
|
|
81
|
+
|
|
82
|
+
三阶段处理,每 tile 独立执行:
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
Process(逐 tile):
|
|
86
|
+
Step 1 — CalcReduceMax:
|
|
87
|
+
for 每个 R bin:
|
|
88
|
+
CopyInX → 逐 A0 列 VF 求 max,与 xMaxLocal 合并
|
|
89
|
+
|
|
90
|
+
Step 2 — CalcReduceSum:
|
|
91
|
+
for basicBlockIdx in [0, binAddBasicBlockLoop):
|
|
92
|
+
a. ProcessMainBlock: CopyIn 主 bin → sub max → exp → 写入 yMain
|
|
93
|
+
b. 若需折叠: ProcessFoldBlock: CopyIn 折叠 bin → sub max → exp → Add 到 yMain
|
|
94
|
+
c. ProcessSummation: NlastReduceSum(yMain) → UpdateCache
|
|
95
|
+
binAddBasicBlockLoop == 0 时: 单 bin 直接处理
|
|
96
|
+
最终: 从 cache[resultCacheID] 拷出 xSum
|
|
97
|
+
|
|
98
|
+
Step 3 — 输出:
|
|
99
|
+
for 每个 R bin:
|
|
100
|
+
CopyInX → CalcOutput(sub max, exp, div sum, Cast)→ CopyOutY
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## 8. NlastReduceSum、bin fold 和 cache 参数
|
|
104
|
+
|
|
105
|
+
### NlastReduceSum
|
|
106
|
+
|
|
107
|
+
`NlastReduceSum` 是跨 R(行)方向对 A0(列)做规约求和的核心函数,实现在 [softmax_v2_base.h](dav310/softmax_v2_base.template) 中:
|
|
108
|
+
|
|
109
|
+
1. **R ≤ 8**:`NlastReduceSumSmallR`,使用 `NlastDichotomyAdd<RSize>` 模板做编译期二分展开。
|
|
110
|
+
- `NlastDichotomyAdd<2>`:基例,2 行 `Add`。
|
|
111
|
+
- 递归展开:`NlastDichotomyAdd<N>` 调用 `NlastDichotomyAdd<(N+1)/2>` 和 `NlastDichotomyAdd<N/2>`。
|
|
112
|
+
- `TailCount` 模板参数:处理尾块不足 8 行时的精确掩码。
|
|
113
|
+
2. **R > 8**:`NlastReduceSumLargeR<TailCount>`,按 8 行分组(COMPRESSION=8)做折叠。
|
|
114
|
+
- `FindNearestPower2(rSize)` 确定 foldPoint。
|
|
115
|
+
- mainFold(8 行折叠)、tailFold(尾块折叠)、unFold(展开)三阶段。
|
|
116
|
+
- 递归调用 `NlastReduceSumSmallR` 做最终归约。
|
|
117
|
+
|
|
118
|
+
### bin fold(MainBlock / FoldBlock 配对)
|
|
119
|
+
|
|
120
|
+
- **ProcessMainBlock**:载入主 bin,`Sub(maxReg)` → `Exp` → 写入 yMain。
|
|
121
|
+
- **ProcessFoldBlock**:载入折叠 bin,`Sub(maxReg)` → `Exp` → `Add` 到 yMain。
|
|
122
|
+
- 配对后一次 `NlastReduceSum`,归约次数减半。
|
|
123
|
+
|
|
124
|
+
### cache 参数
|
|
125
|
+
|
|
126
|
+
- `binAddCacheBufferCount`:二分树层数 + 1,决定 cacheBuffer 大小。
|
|
127
|
+
- `binAddResultCacheID`:`GetCacheID(binAddBasicBlockLoop - 1)`,指向最终合并结果。
|
|
128
|
+
- `UpdateCache`:按 `cacheID` 层级将当前 sum 累加到 cache 对应位置。
|
|
129
|
+
|
|
130
|
+
## 9. 主块、尾块、对齐和数值精度处理
|
|
131
|
+
|
|
132
|
+
- **主块/尾块**:`tileA0Len` 为主块 A0 长度,`tileA0Tail` 为尾块。`binAddRTail` 为 R 方向尾 bin 长度。
|
|
133
|
+
- **折叠尾 bin**:当 `basicBlockIdx == binAddMainFoldCount` 且 `binAddRTail > 0` 且 `binAddRTail != binAddRFactor` 时,折叠块使用 `binAddRTail` 长度。
|
|
134
|
+
- **对齐**:A0 按 `a0TileBase`(FP32=8/FP16=16)对齐,`dstStride` 按 `BLOCK_SIZE`(32B)对齐。
|
|
135
|
+
- **数值精度**:FP16/BF16 通过 `LoadTensorForDtypeT1` 升至 FP32;max/sum 用 FP32 维护;输出 `Cast` 降回。
|
|
136
|
+
|
|
137
|
+
## 10. 独立 Kernel 入口示例
|
|
138
|
+
|
|
139
|
+
```cpp
|
|
140
|
+
#include "softmax_v2_tiling_data.h"
|
|
141
|
+
#include "dav310/softmax_v2_base.h"
|
|
142
|
+
#include "dav310/softmax_v2_ara_recompute.h"
|
|
143
|
+
|
|
144
|
+
using namespace SoftmaxV2Ops;
|
|
145
|
+
|
|
146
|
+
extern "C" __global__ __aicore__ __vector__ void
|
|
147
|
+
softmax_ara_recompute_fp32(GM_ADDR x, GM_ADDR y, SoftmaxV2ARARecomputeTilingData tiling)
|
|
148
|
+
{
|
|
149
|
+
TPipe pipe;
|
|
150
|
+
SoftmaxV2ARARecompute<float, float> op(&tiling);
|
|
151
|
+
op.Init(x, y, &pipe);
|
|
152
|
+
op.Process();
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## 11. 不适用场景和可选替代模板
|
|
157
|
+
|
|
158
|
+
| 不适用场景 | 推荐替代 |
|
|
159
|
+
|-----------|---------|
|
|
160
|
+
| R×tileA0 可载入 UB | [ARA FullLoad](softmax_v2_ara_full_load.md)(无重读) |
|
|
161
|
+
| A0 = 1(2D) | [AR Recompute](softmax_v2_ar_recompute.md) |
|
|
162
|
+
| 需要在线更新(避免 3 次读入) | [ARA Online](softmax_v2_ara_online.md)(2 次读入) |
|
|
163
|
+
| 带宽极度受限 | 评估 FullLoad 是否可用(3× 重读代价高) |
|
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 Huawei Technologies Co., Ltd.
|
|
3
|
+
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
|
4
|
+
* CANN Open Software License Agreement Version 2.0 (the "License").
|
|
5
|
+
* Please refer to the License for details. You may not use this file except in compliance with the License.
|
|
6
|
+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
|
7
|
+
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
|
8
|
+
* See LICENSE in the root of the software repository for the full text of the License.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/*!
|
|
12
|
+
* \file softmax_v2_tiling.h
|
|
13
|
+
* \brief SoftmaxV2 六个模板的 host 侧 tiling 计算(六个独立入口,无统一 selector)。
|
|
14
|
+
*
|
|
15
|
+
* 输入为已经融合后的形状 (a1, r, a0)(softmax 沿 r 轴),以及平台参数。
|
|
16
|
+
* 每个函数填充对应的 packed TilingData,并返回需要的 blockDim(usedCoreNums)。
|
|
17
|
+
*
|
|
18
|
+
* 六个入口互相独立,不返回 TilingKey,不使用模板编号:
|
|
19
|
+
* - TilingArSmallR → SoftmaxV2ArSmallRTilingData → dav310/softmax_v2_ar_small_r.h
|
|
20
|
+
* - TilingArFullLoad → SoftmaxV2ARTilingData → dav310/softmax_v2_ar_full_load.h
|
|
21
|
+
* - TilingArRecompute → SoftmaxV2ArRecomputeTilingData → dav310/softmax_v2_ar_recompute.h
|
|
22
|
+
* - TilingAraFullLoad → SoftmaxV2ARATilingData → dav310/softmax_v2_ara_full_load.h
|
|
23
|
+
* - TilingAraRecompute → SoftmaxV2ARARecomputeTilingData→ dav310/softmax_v2_ara_recompute.h
|
|
24
|
+
* - TilingAraOnline → SoftmaxV2ARAOnlineTilingData → dav310/softmax_v2_ara_online.h
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
#ifndef SOFTMAX_V2_TILING_H
|
|
28
|
+
#define SOFTMAX_V2_TILING_H
|
|
29
|
+
|
|
30
|
+
#include <cstdint>
|
|
31
|
+
#include <cstring>
|
|
32
|
+
#include <algorithm>
|
|
33
|
+
#include "softmax_v2_tiling_data.h"
|
|
34
|
+
|
|
35
|
+
namespace softmax_tiling {
|
|
36
|
+
|
|
37
|
+
// 平台参数(dav-3510 / Ascend950PR):VRegSize=256B 为 constexpr。
|
|
38
|
+
struct PlatformParam {
|
|
39
|
+
int64_t ubSize; // 单核 UB 可用字节数(运行时查询)
|
|
40
|
+
int64_t numBlocks; // AIV 核数(运行时查询)
|
|
41
|
+
int64_t blockSize = 32; // UB block 字节
|
|
42
|
+
int64_t vlFp32 = 64; // 256 / sizeof(float)
|
|
43
|
+
int64_t vlFp16 = 128; // 256 / sizeof(half)
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// 融合后的 case 形状(softmax 沿 r 轴),dtypeCode: 0=FP32,1=FP16,2=BF16。
|
|
47
|
+
struct CaseShape {
|
|
48
|
+
int64_t a1;
|
|
49
|
+
int64_t r;
|
|
50
|
+
int64_t a0;
|
|
51
|
+
int dtypeCode;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
inline int64_t DtypeSize(int dtypeCode) { return dtypeCode == 0 ? 4 : 2; }
|
|
55
|
+
inline bool IsFloat(int dtypeCode) { return dtypeCode == 0; }
|
|
56
|
+
|
|
57
|
+
inline int64_t CeilDiv(int64_t a, int64_t b) { return (a + b - 1) / b; }
|
|
58
|
+
inline int64_t FloorDiv(int64_t a, int64_t b) { return a / b; }
|
|
59
|
+
inline int64_t CeilAlign(int64_t a, int64_t b) { return CeilDiv(a, b) * b; }
|
|
60
|
+
|
|
61
|
+
inline int64_t Gcd(int64_t a, int64_t b)
|
|
62
|
+
{
|
|
63
|
+
a = a < 0 ? -a : a;
|
|
64
|
+
b = b < 0 ? -b : b;
|
|
65
|
+
while (b != 0) {
|
|
66
|
+
int64_t t = b;
|
|
67
|
+
b = a % b;
|
|
68
|
+
a = t;
|
|
69
|
+
}
|
|
70
|
+
return a;
|
|
71
|
+
}
|
|
72
|
+
inline int64_t Lcm(int64_t a, int64_t b)
|
|
73
|
+
{
|
|
74
|
+
int64_t g = Gcd(a, b);
|
|
75
|
+
return (a / g) * b;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
inline int64_t FindNearestPower2(int64_t value)
|
|
79
|
+
{
|
|
80
|
+
if (value <= 1) return 0;
|
|
81
|
+
if (value <= 2) return 1;
|
|
82
|
+
if (value <= 4) return 2;
|
|
83
|
+
int64_t num = value - 1;
|
|
84
|
+
int64_t pow = 63 - __builtin_clzl(static_cast<uint64_t>(num));
|
|
85
|
+
return (1L << pow);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
inline int64_t GetCacheID(int64_t idx)
|
|
89
|
+
{
|
|
90
|
+
return __builtin_popcountll(static_cast<uint64_t>(idx ^ (idx + 1))) - 1;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// ---------------------------------------------------------------------------
|
|
94
|
+
// TilingArSmallR — 对应 SoftmaxV2ArSmallRTilingData
|
|
95
|
+
//
|
|
96
|
+
// 输入:CaseShape (a1, r, a0=1), PlatformParam
|
|
97
|
+
// 适用条件:2D [A1, R],R 极小(FP32≤16 / FP16≤32)
|
|
98
|
+
// 输出:填充 SoftmaxV2ArSmallRTilingData,返回 usedCoreNums
|
|
99
|
+
// ---------------------------------------------------------------------------
|
|
100
|
+
inline int64_t TilingArSmallR(const CaseShape& s, const PlatformParam& p, SoftmaxV2ArSmallRTilingData& td)
|
|
101
|
+
{
|
|
102
|
+
std::memset(&td, 0, sizeof(td));
|
|
103
|
+
const int64_t DATA_BLOCK_COUNT = 16;
|
|
104
|
+
const int64_t FLOAT32_BYTES = 4;
|
|
105
|
+
const int64_t DOUBLE_BUFFER = 2;
|
|
106
|
+
int64_t xDtypeSize = DtypeSize(s.dtypeCode);
|
|
107
|
+
int64_t yDtypeSize = xDtypeSize;
|
|
108
|
+
|
|
109
|
+
int64_t a0New = s.a1; // 转置成 (r, a1)
|
|
110
|
+
int64_t a0TileBase = p.vlFp32;
|
|
111
|
+
int64_t rTileBase = IsFloat(s.dtypeCode) ? DATA_BLOCK_COUNT / 2 : DATA_BLOCK_COUNT;
|
|
112
|
+
int64_t rAligned = CeilDiv(s.r, rTileBase) * rTileBase;
|
|
113
|
+
|
|
114
|
+
int64_t rFactor = rAligned * (xDtypeSize * DOUBLE_BUFFER + yDtypeSize * DOUBLE_BUFFER + FLOAT32_BYTES * DOUBLE_BUFFER);
|
|
115
|
+
int64_t a0TileNumMax = p.ubSize / (a0TileBase * (rFactor + FLOAT32_BYTES));
|
|
116
|
+
|
|
117
|
+
int64_t a0TileNumTmp = CeilDiv(a0New, a0TileBase);
|
|
118
|
+
int64_t a0TileNum = a0TileNumMax < a0TileNumTmp ? a0TileNumMax : a0TileNumTmp;
|
|
119
|
+
int64_t tileA0Len = a0TileNum * a0TileBase;
|
|
120
|
+
int64_t a0Outer = CeilDiv(a0New, tileA0Len);
|
|
121
|
+
int64_t tileA0Tail = a0New - tileA0Len * (a0Outer - 1);
|
|
122
|
+
|
|
123
|
+
int64_t tilesPerCore = CeilDiv(a0Outer, p.numBlocks);
|
|
124
|
+
int64_t usedCoreNums = CeilDiv(a0Outer, tilesPerCore);
|
|
125
|
+
|
|
126
|
+
td.totalTiles = a0Outer;
|
|
127
|
+
td.tilesPerCore = tilesPerCore;
|
|
128
|
+
td.totalRLen = s.r;
|
|
129
|
+
td.totalA0Len = a0New;
|
|
130
|
+
td.tileA0Len = tileA0Len;
|
|
131
|
+
td.tileA0Tail = tileA0Tail;
|
|
132
|
+
td.rTileBase = rTileBase;
|
|
133
|
+
td.rAligned = rAligned;
|
|
134
|
+
return usedCoreNums;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// ---------------------------------------------------------------------------
|
|
138
|
+
// TilingArFullLoad — 对应 SoftmaxV2ARTilingData
|
|
139
|
+
//
|
|
140
|
+
// 输入:CaseShape (a1, r, a0=1), PlatformParam
|
|
141
|
+
// 适用条件:2D [A1, R],R 可整段载入 UB
|
|
142
|
+
// 输出:填充 SoftmaxV2ARTilingData,返回 usedCoreNums
|
|
143
|
+
// ---------------------------------------------------------------------------
|
|
144
|
+
inline int64_t TilingArFullLoad(const CaseShape& s, const PlatformParam& p, SoftmaxV2ARTilingData& td)
|
|
145
|
+
{
|
|
146
|
+
std::memset(&td, 0, sizeof(td));
|
|
147
|
+
const int64_t FLOAT32_BYTES = 4;
|
|
148
|
+
const int64_t DOUBLE_BUFFER = 2;
|
|
149
|
+
const int64_t UB_RESERVED_BYTE = 1024;
|
|
150
|
+
const int64_t BINARY_TMP_LOCAL_SHAPE = 512;
|
|
151
|
+
int64_t xDtypeSize = DtypeSize(s.dtypeCode);
|
|
152
|
+
int64_t yDtypeSize = xDtypeSize;
|
|
153
|
+
|
|
154
|
+
int64_t rAligned = CeilAlign(s.r, p.blockSize / xDtypeSize);
|
|
155
|
+
int64_t ubFactor = (p.ubSize - UB_RESERVED_BYTE - BINARY_TMP_LOCAL_SHAPE) /
|
|
156
|
+
(rAligned * FLOAT32_BYTES + DOUBLE_BUFFER * rAligned * xDtypeSize +
|
|
157
|
+
DOUBLE_BUFFER * rAligned * yDtypeSize);
|
|
158
|
+
int64_t rLoopCount = CeilDiv(rAligned, p.vlFp32);
|
|
159
|
+
int64_t aBlockFactor = CeilDiv(s.a1, p.numBlocks);
|
|
160
|
+
int64_t usedCoreNums = CeilDiv(s.a1, aBlockFactor);
|
|
161
|
+
ubFactor = ubFactor < aBlockFactor ? ubFactor : aBlockFactor;
|
|
162
|
+
|
|
163
|
+
td.a = s.a1;
|
|
164
|
+
td.r = s.r;
|
|
165
|
+
td.rAligned = rAligned;
|
|
166
|
+
td.aBlockFactor = aBlockFactor;
|
|
167
|
+
td.rLoopCount = rLoopCount;
|
|
168
|
+
td.ubFactor = ubFactor;
|
|
169
|
+
return usedCoreNums;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// ---------------------------------------------------------------------------
|
|
173
|
+
// TilingArRecompute — 对应 SoftmaxV2ArRecomputeTilingData
|
|
174
|
+
//
|
|
175
|
+
// 输入:CaseShape (a1, r, a0=1), PlatformParam
|
|
176
|
+
// 适用条件:2D [A1, R],R 超出 UB
|
|
177
|
+
// 输出:填充 SoftmaxV2ArRecomputeTilingData,返回 usedCoreNums
|
|
178
|
+
// ---------------------------------------------------------------------------
|
|
179
|
+
inline int64_t TilingArRecompute(const CaseShape& s, const PlatformParam& p, SoftmaxV2ArRecomputeTilingData& td)
|
|
180
|
+
{
|
|
181
|
+
std::memset(&td, 0, sizeof(td));
|
|
182
|
+
const int64_t AR_RECOMPUTE_MAX_BUFFER_BTYES = 32;
|
|
183
|
+
const int64_t AR_RECOMPUTE_SUM_BUFFER_BTYES = 32;
|
|
184
|
+
const int64_t AR_RECOMPUTE_BINARY_CACHE_BTYES = 2048;
|
|
185
|
+
const int64_t TRIPLE_BUFFER = 3;
|
|
186
|
+
const int64_t DOUBLE_BUFFER = 2;
|
|
187
|
+
int64_t xDtypeSize = DtypeSize(s.dtypeCode);
|
|
188
|
+
int64_t yDtypeSize = xDtypeSize;
|
|
189
|
+
|
|
190
|
+
int64_t ubFlexible = p.ubSize - AR_RECOMPUTE_MAX_BUFFER_BTYES - AR_RECOMPUTE_SUM_BUFFER_BTYES -
|
|
191
|
+
AR_RECOMPUTE_BINARY_CACHE_BTYES;
|
|
192
|
+
int64_t baseFactor = xDtypeSize * TRIPLE_BUFFER + yDtypeSize * DOUBLE_BUFFER + 4;
|
|
193
|
+
|
|
194
|
+
int64_t aPerCore = CeilDiv(s.a1, p.numBlocks);
|
|
195
|
+
int64_t usedCoreNums = CeilDiv(s.a1, aPerCore);
|
|
196
|
+
|
|
197
|
+
int64_t ubFactorTmp = ubFlexible / baseFactor;
|
|
198
|
+
int64_t lcm = Lcm(p.blockSize, Lcm(p.blockSize / xDtypeSize, p.blockSize / yDtypeSize));
|
|
199
|
+
int64_t ubFactor = std::min<int64_t>(s.r, (ubFactorTmp / lcm) * lcm);
|
|
200
|
+
int64_t aLoopCountCeil = CeilDiv(s.r, ubFactor);
|
|
201
|
+
int64_t aLoopCountFloor = FloorDiv(s.r, ubFactor);
|
|
202
|
+
int64_t ubFactorTail = s.r - ubFactor * aLoopCountFloor;
|
|
203
|
+
|
|
204
|
+
int64_t basicBlockLoop = FindNearestPower2(aLoopCountCeil);
|
|
205
|
+
int64_t mainFoldCount = aLoopCountFloor - basicBlockLoop;
|
|
206
|
+
|
|
207
|
+
td.a = s.a1;
|
|
208
|
+
td.r = s.r;
|
|
209
|
+
td.ubFactor = ubFactor;
|
|
210
|
+
td.ubFactorTail = ubFactorTail;
|
|
211
|
+
td.aBlockFactor = aPerCore;
|
|
212
|
+
td.aLoopCountCeil = aLoopCountCeil;
|
|
213
|
+
td.basicBlockLoop = basicBlockLoop;
|
|
214
|
+
td.mainFoldCount = mainFoldCount;
|
|
215
|
+
return usedCoreNums;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// ---------------------------------------------------------------------------
|
|
219
|
+
// TilingAraFullLoad — 对应 SoftmaxV2ARATilingData
|
|
220
|
+
//
|
|
221
|
+
// 输入:CaseShape (a1, r, a0), PlatformParam
|
|
222
|
+
// 适用条件:3D [A1, R, A0],R×A0_tile 可载入 UB
|
|
223
|
+
// 输出:填充 SoftmaxV2ARATilingData,返回 usedCoreNums
|
|
224
|
+
// ---------------------------------------------------------------------------
|
|
225
|
+
inline int64_t TilingAraFullLoad(const CaseShape& s, const PlatformParam& p, SoftmaxV2ARATilingData& td)
|
|
226
|
+
{
|
|
227
|
+
std::memset(&td, 0, sizeof(td));
|
|
228
|
+
const int64_t FLOAT32_BYTES = 4;
|
|
229
|
+
const int64_t DOUBLE_BUFFER = 2;
|
|
230
|
+
const int64_t CONST_EIGHT = 8;
|
|
231
|
+
int64_t xDtypeSize = DtypeSize(s.dtypeCode);
|
|
232
|
+
|
|
233
|
+
int64_t a0TileBase = IsFloat(s.dtypeCode) ? p.vlFp32 : p.vlFp16;
|
|
234
|
+
int64_t factorMax = p.ubSize /
|
|
235
|
+
((xDtypeSize * DOUBLE_BUFFER + FLOAT32_BYTES * DOUBLE_BUFFER + FLOAT32_BYTES) * s.r +
|
|
236
|
+
FLOAT32_BYTES + FLOAT32_BYTES) /
|
|
237
|
+
a0TileBase;
|
|
238
|
+
|
|
239
|
+
int64_t a0FactorMax = CeilDiv(s.a0, a0TileBase);
|
|
240
|
+
int64_t totalTilesMax = s.a1 * a0FactorMax;
|
|
241
|
+
int64_t a0InnerMax = CeilDiv(totalTilesMax, p.numBlocks);
|
|
242
|
+
int64_t a0Inner = a0InnerMax < factorMax ? a0InnerMax : factorMax;
|
|
243
|
+
a0Inner = a0Inner < a0FactorMax ? a0Inner : a0FactorMax;
|
|
244
|
+
|
|
245
|
+
int64_t tileA0Len = a0Inner * a0TileBase;
|
|
246
|
+
int64_t a0Outer = CeilDiv(s.a0, tileA0Len);
|
|
247
|
+
int64_t tileA0Tail = s.a0 - tileA0Len * (a0Outer - 1);
|
|
248
|
+
int64_t a1Inner = 1;
|
|
249
|
+
|
|
250
|
+
int64_t totalTiles = s.a1 * a0Outer;
|
|
251
|
+
int64_t tilesPerCore = CeilDiv(totalTiles, p.numBlocks);
|
|
252
|
+
int64_t usedCoreNums = CeilDiv(totalTiles, tilesPerCore);
|
|
253
|
+
|
|
254
|
+
td.totalTiles = totalTiles;
|
|
255
|
+
td.tilesPerCore = tilesPerCore;
|
|
256
|
+
td.usedCoreNums = usedCoreNums;
|
|
257
|
+
td.totalA1Len = s.a1;
|
|
258
|
+
td.totalRLen = s.r;
|
|
259
|
+
td.totalA0Len = s.a0;
|
|
260
|
+
td.a1Outer = s.a1;
|
|
261
|
+
td.a0Outer = a0Outer;
|
|
262
|
+
td.tileA1Len = a1Inner;
|
|
263
|
+
td.tileA1Tail = s.a1;
|
|
264
|
+
td.tileA0Len = tileA0Len;
|
|
265
|
+
td.tileA0Tail = tileA0Tail;
|
|
266
|
+
|
|
267
|
+
if (s.r <= CONST_EIGHT) {
|
|
268
|
+
return usedCoreNums;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// BinaryAddTiling
|
|
272
|
+
int64_t binaryAddQuotient = (1L << (63 - __builtin_clzl(static_cast<uint64_t>(s.r - 1))));
|
|
273
|
+
int64_t binaryAddNum = binaryAddQuotient / CONST_EIGHT;
|
|
274
|
+
int64_t binaryAddK = 0;
|
|
275
|
+
int64_t binaryAddLast = 0;
|
|
276
|
+
int64_t curBinaryAddNum = 1;
|
|
277
|
+
while (curBinaryAddNum < binaryAddNum) {
|
|
278
|
+
binaryAddK++;
|
|
279
|
+
curBinaryAddNum *= 4;
|
|
280
|
+
}
|
|
281
|
+
if (curBinaryAddNum == binaryAddNum * 2) {
|
|
282
|
+
binaryAddK -= 1;
|
|
283
|
+
binaryAddLast = 1;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
uint16_t remainderLoopCount = (uint16_t)((s.r - binaryAddQuotient + CONST_EIGHT - 1) / CONST_EIGHT);
|
|
287
|
+
uint16_t quotientLoopCount = (uint16_t)((binaryAddQuotient / CONST_EIGHT) - remainderLoopCount);
|
|
288
|
+
uint32_t remainderOffset = (uint32_t)(binaryAddQuotient * tileA0Len);
|
|
289
|
+
uint32_t baseLineOffset = (uint32_t)(CONST_EIGHT * tileA0Len);
|
|
290
|
+
uint16_t binaryAddInnerLoop = (uint16_t)(binaryAddQuotient / CONST_EIGHT);
|
|
291
|
+
uint32_t validNumInXUb = (uint32_t)(s.r * tileA0Len);
|
|
292
|
+
uint16_t remainderTailCount = (uint16_t)((s.r - binaryAddQuotient) - (int64_t)(remainderLoopCount - 1) * CONST_EIGHT);
|
|
293
|
+
uint32_t quotientTailOffset = (uint32_t)((int64_t)(remainderLoopCount - 1) * baseLineOffset);
|
|
294
|
+
uint32_t remainderTailOffset = quotientTailOffset + remainderOffset;
|
|
295
|
+
auto pick = [&](uint16_t row, int64_t off) -> uint32_t {
|
|
296
|
+
return (row > remainderTailCount) ? validNumInXUb : (uint32_t)(remainderTailOffset + off * tileA0Len);
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
td.binaryAddK = (uint16_t)binaryAddK;
|
|
300
|
+
td.binaryAddLast = (uint16_t)binaryAddLast;
|
|
301
|
+
td.binaryAddInnerLoop = binaryAddInnerLoop;
|
|
302
|
+
td.remainderLoopCount = remainderLoopCount;
|
|
303
|
+
td.quotientLoopCount = quotientLoopCount;
|
|
304
|
+
td.remainderTailCount = remainderTailCount;
|
|
305
|
+
td.remainderOffset = remainderOffset;
|
|
306
|
+
td.baseLineOffset = baseLineOffset;
|
|
307
|
+
td.validNumInXUb = validNumInXUb;
|
|
308
|
+
td.quotientTailOffset = quotientTailOffset;
|
|
309
|
+
td.remainderTailOffset = remainderTailOffset;
|
|
310
|
+
td.remainderTailOffset0 = pick(0, 0);
|
|
311
|
+
td.remainderTailOffset1 = pick(1, 1);
|
|
312
|
+
td.remainderTailOffset2 = pick(2, 2);
|
|
313
|
+
td.remainderTailOffset3 = pick(3, 3);
|
|
314
|
+
td.remainderTailOffset4 = pick(4, 4);
|
|
315
|
+
td.remainderTailOffset5 = pick(5, 5);
|
|
316
|
+
td.remainderTailOffset6 = pick(6, 6);
|
|
317
|
+
td.remainderTailOffset7 = pick(7, 7);
|
|
318
|
+
return usedCoreNums;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// ---------------------------------------------------------------------------
|
|
322
|
+
// TilingAraRecompute — 对应 SoftmaxV2ARARecomputeTilingData
|
|
323
|
+
//
|
|
324
|
+
// 输入:CaseShape (a1, r, a0), PlatformParam
|
|
325
|
+
// 适用条件:3D [A1, R, A0],R 超出 UB
|
|
326
|
+
// 输出:填充 SoftmaxV2ARARecomputeTilingData,返回 usedCoreNums
|
|
327
|
+
// ---------------------------------------------------------------------------
|
|
328
|
+
inline int64_t TilingAraRecompute(const CaseShape& s, const PlatformParam& p, SoftmaxV2ARARecomputeTilingData& td)
|
|
329
|
+
{
|
|
330
|
+
std::memset(&td, 0, sizeof(td));
|
|
331
|
+
const int64_t FLOAT32_BYTES = 4;
|
|
332
|
+
const int64_t DOUBLE_BUFFER = 2;
|
|
333
|
+
const int64_t FP32_BLOCK_ALIGN_NUM = 8;
|
|
334
|
+
const int64_t FP16_BLOCK_ALIGN_NUM = 16;
|
|
335
|
+
const int64_t DEFAULT_BIN_ADD_R_FACTOR = 128;
|
|
336
|
+
const int64_t UB_COMPUTE_FACTOR = 11;
|
|
337
|
+
int64_t xDtypeSize = DtypeSize(s.dtypeCode);
|
|
338
|
+
|
|
339
|
+
// ComputeBinaryAddParams
|
|
340
|
+
int64_t binAddRFactor = DEFAULT_BIN_ADD_R_FACTOR;
|
|
341
|
+
int64_t binAddRLoop = s.r / binAddRFactor;
|
|
342
|
+
int64_t binAddRTotalLoop = CeilDiv(s.r, binAddRFactor);
|
|
343
|
+
int64_t binAddRTail = s.r - (binAddRTotalLoop - 1) * binAddRFactor;
|
|
344
|
+
int64_t binAddBasicBlockLoop =
|
|
345
|
+
binAddRTotalLoop > 1 ? (1L << (63 - __builtin_clzl(static_cast<uint64_t>(binAddRTotalLoop - 1)))) : 0;
|
|
346
|
+
int64_t mainFoldCount = binAddRLoop - binAddBasicBlockLoop;
|
|
347
|
+
int64_t binAddCacheBufferCount;
|
|
348
|
+
int64_t binAddResultCacheID;
|
|
349
|
+
if (binAddBasicBlockLoop == 0) {
|
|
350
|
+
binAddCacheBufferCount = 1;
|
|
351
|
+
binAddResultCacheID = 0;
|
|
352
|
+
} else {
|
|
353
|
+
binAddCacheBufferCount = 64 - __builtin_clzl(static_cast<uint64_t>(binAddBasicBlockLoop));
|
|
354
|
+
binAddResultCacheID = GetCacheID(binAddBasicBlockLoop - 1);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
int64_t a0TileBase = IsFloat(s.dtypeCode) ? FP32_BLOCK_ALIGN_NUM : FP16_BLOCK_ALIGN_NUM;
|
|
358
|
+
int64_t factorMax = p.ubSize / a0TileBase /
|
|
359
|
+
(binAddRFactor * DOUBLE_BUFFER * (FLOAT32_BYTES + xDtypeSize) +
|
|
360
|
+
FLOAT32_BYTES * (UB_COMPUTE_FACTOR + binAddCacheBufferCount));
|
|
361
|
+
|
|
362
|
+
int64_t a0FactorMax = CeilDiv(s.a0, a0TileBase);
|
|
363
|
+
int64_t totalTilesMax = s.a1 * a0FactorMax;
|
|
364
|
+
int64_t a0InnerMax = CeilDiv(totalTilesMax, p.numBlocks);
|
|
365
|
+
int64_t a0Inner = a0InnerMax < factorMax ? a0InnerMax : factorMax;
|
|
366
|
+
a0Inner = a0Inner < a0FactorMax ? a0Inner : a0FactorMax;
|
|
367
|
+
|
|
368
|
+
int64_t tileA0Len = a0Inner * a0TileBase;
|
|
369
|
+
int64_t a0Outer = CeilDiv(s.a0, tileA0Len);
|
|
370
|
+
int64_t tileA0Tail = s.a0 - tileA0Len * (a0Outer - 1);
|
|
371
|
+
|
|
372
|
+
int64_t totalTiles = s.a1 * a0Outer;
|
|
373
|
+
int64_t tilesPerCore = CeilDiv(totalTiles, p.numBlocks);
|
|
374
|
+
int64_t usedCoreNums = CeilDiv(totalTiles, tilesPerCore);
|
|
375
|
+
|
|
376
|
+
td.totalRLen = s.r;
|
|
377
|
+
td.totalA0Len = s.a0;
|
|
378
|
+
td.totalTiles = totalTiles;
|
|
379
|
+
td.tilesPerCore = tilesPerCore;
|
|
380
|
+
td.usedCoreNums = usedCoreNums;
|
|
381
|
+
td.tileA0Outer = a0Outer;
|
|
382
|
+
td.tileA0Len = tileA0Len;
|
|
383
|
+
td.tileA0Tail = tileA0Tail;
|
|
384
|
+
td.binAddRFactor = binAddRFactor;
|
|
385
|
+
td.binAddRLoop = binAddRLoop;
|
|
386
|
+
td.binAddRTotalLoop = binAddRTotalLoop;
|
|
387
|
+
td.binAddRTail = binAddRTail;
|
|
388
|
+
td.binAddBasicBlockLoop = binAddBasicBlockLoop;
|
|
389
|
+
td.binAddMainFoldCount = mainFoldCount;
|
|
390
|
+
td.binAddCacheBufferCount = binAddCacheBufferCount;
|
|
391
|
+
td.binAddResultCacheID = binAddResultCacheID;
|
|
392
|
+
return usedCoreNums;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// ---------------------------------------------------------------------------
|
|
396
|
+
// TilingAraOnline — 对应 SoftmaxV2ARAOnlineTilingData
|
|
397
|
+
//
|
|
398
|
+
// 输入:CaseShape (a1, r, a0), PlatformParam
|
|
399
|
+
// 适用条件:3D [A1, R, A0],沿 R 分 chunk 在线更新 running max / running sum
|
|
400
|
+
// 输出:填充 SoftmaxV2ARAOnlineTilingData,返回 usedCoreNums
|
|
401
|
+
// ---------------------------------------------------------------------------
|
|
402
|
+
inline int64_t TilingAraOnline(const CaseShape& s, const PlatformParam& p, SoftmaxV2ARAOnlineTilingData& td)
|
|
403
|
+
{
|
|
404
|
+
std::memset(&td, 0, sizeof(td));
|
|
405
|
+
const int64_t FLOAT32_BYTES = 4;
|
|
406
|
+
const int64_t DOUBLE_BUFFER = 2;
|
|
407
|
+
const int64_t FP32_BLOCK_ALIGN_NUM = 8;
|
|
408
|
+
const int64_t FP16_BLOCK_ALIGN_NUM = 16;
|
|
409
|
+
const int64_t DEFAULT_R_CHUNK_FACTOR = 128;
|
|
410
|
+
int64_t xDtypeSize = DtypeSize(s.dtypeCode);
|
|
411
|
+
|
|
412
|
+
int64_t rChunkFactor = DEFAULT_R_CHUNK_FACTOR;
|
|
413
|
+
if (rChunkFactor > s.r) {
|
|
414
|
+
rChunkFactor = s.r;
|
|
415
|
+
}
|
|
416
|
+
int64_t rChunkTotalLoop = CeilDiv(s.r, rChunkFactor);
|
|
417
|
+
int64_t rChunkTail = s.r - (rChunkTotalLoop - 1) * rChunkFactor;
|
|
418
|
+
|
|
419
|
+
int64_t a0TileBase = IsFloat(s.dtypeCode) ? FP32_BLOCK_ALIGN_NUM : FP16_BLOCK_ALIGN_NUM;
|
|
420
|
+
int64_t bytesPerA0Col = DOUBLE_BUFFER * rChunkFactor * xDtypeSize +
|
|
421
|
+
DOUBLE_BUFFER * rChunkFactor * FLOAT32_BYTES + FLOAT32_BYTES + FLOAT32_BYTES;
|
|
422
|
+
int64_t factorMax = p.ubSize / a0TileBase / bytesPerA0Col;
|
|
423
|
+
if (factorMax < 1) {
|
|
424
|
+
factorMax = 1;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
int64_t a0FactorMax = CeilDiv(s.a0, a0TileBase);
|
|
428
|
+
int64_t totalTilesMax = s.a1 * a0FactorMax;
|
|
429
|
+
int64_t a0InnerMax = CeilDiv(totalTilesMax, p.numBlocks);
|
|
430
|
+
int64_t a0Inner = a0InnerMax < factorMax ? a0InnerMax : factorMax;
|
|
431
|
+
a0Inner = a0Inner < a0FactorMax ? a0Inner : a0FactorMax;
|
|
432
|
+
if (a0Inner < 1) {
|
|
433
|
+
a0Inner = 1;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
int64_t tileA0Len = a0Inner * a0TileBase;
|
|
437
|
+
int64_t a0Outer = CeilDiv(s.a0, tileA0Len);
|
|
438
|
+
int64_t tileA0Tail = s.a0 - tileA0Len * (a0Outer - 1);
|
|
439
|
+
|
|
440
|
+
int64_t totalTiles = s.a1 * a0Outer;
|
|
441
|
+
int64_t tilesPerCore = CeilDiv(totalTiles, p.numBlocks);
|
|
442
|
+
int64_t usedCoreNums = CeilDiv(totalTiles, tilesPerCore);
|
|
443
|
+
|
|
444
|
+
td.totalRLen = s.r;
|
|
445
|
+
td.totalA0Len = s.a0;
|
|
446
|
+
td.totalTiles = totalTiles;
|
|
447
|
+
td.tilesPerCore = tilesPerCore;
|
|
448
|
+
td.usedCoreNums = usedCoreNums;
|
|
449
|
+
td.tileA0Outer = a0Outer;
|
|
450
|
+
td.tileA0Len = tileA0Len;
|
|
451
|
+
td.tileA0Tail = tileA0Tail;
|
|
452
|
+
td.rChunkFactor = rChunkFactor;
|
|
453
|
+
td.rChunkTotalLoop = rChunkTotalLoop;
|
|
454
|
+
td.rChunkTail = rChunkTail;
|
|
455
|
+
return usedCoreNums;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
} // namespace softmax_tiling
|
|
459
|
+
|
|
460
|
+
#endif // SOFTMAX_V2_TILING_H
|