ops-tune-workbench-plugin 0.0.0-stage → 0.0.1-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE.md +14 -0
- package/README.md +39 -2
- package/cordis.patch.yml +20 -0
- package/lib/client.js +4253 -0
- package/lib/host.js +2518 -0
- package/package.json +53 -4
- package/skills/tool-ops-tune/INSTALL.md +52 -0
- package/skills/tool-ops-tune/README.md +167 -0
- package/skills/tool-ops-tune/SKILL.md +93 -0
- package/skills/tool-ops-tune/agent/AGENTS.md +195 -0
- package/skills/tool-ops-tune/agent/agents/perf-implementer.md +68 -0
- package/skills/tool-ops-tune/agent/agents/perf-reviewer.md +86 -0
- package/skills/tool-ops-tune/agent/workflows/task-prompts.md +362 -0
- package/skills/tool-ops-tune/agent/workflows/troubleshooting.md +43 -0
- package/skills/tool-ops-tune/docs/figures/opstune-architecture.png +0 -0
- package/skills/tool-ops-tune/docs/figures/opstune-architecture.svg +253 -0
- package/skills/tool-ops-tune/docs/ops-tune-design.md +404 -0
- package/skills/tool-ops-tune/docs//347/224/250/344/276/213/346/236/204/345/273/272.md +714 -0
- package/skills/tool-ops-tune/docs//347/237/245/350/257/206/345/272/223/350/247/204/350/214/203.md +103 -0
- package/skills/tool-ops-tune/evals/evals.json +242 -0
- package/skills/tool-ops-tune/ops-collect/SKILL.md +146 -0
- package/skills/tool-ops-tune/ops-collect/references/tool-routing.md +86 -0
- package/skills/tool-ops-tune/ops-collect/scripts/collect_board.sh +444 -0
- package/skills/tool-ops-tune/ops-collect/scripts/collect_cases.py +368 -0
- package/skills/tool-ops-tune/ops-collect/scripts/collect_sim.sh +134 -0
- package/skills/tool-ops-tune/ops-collect/scripts/csv_to_db.py +314 -0
- package/skills/tool-ops-tune/ops-collect/scripts/db_bench.py +545 -0
- package/skills/tool-ops-tune/ops-collect/scripts/facts_bridge.py +1063 -0
- package/skills/tool-ops-tune/ops-collect/scripts/isolation_test.py +454 -0
- package/skills/tool-ops-tune/ops-collect/scripts/jsonl_to_cases.py +163 -0
- package/skills/tool-ops-tune/ops-family/SKILL.md +76 -0
- package/skills/tool-ops-tune/ops-family/references/broadcast/advanced_tiling.md +92 -0
- package/skills/tool-ops-tune/ops-family/references/broadcast/broadcast_design.md +160 -0
- package/skills/tool-ops-tune/ops-family/references/broadcast/code/broadcast_add_kernel.cpp +126 -0
- package/skills/tool-ops-tune/ops-family/references/broadcast/code/broadcast_add_tiling.cpp +144 -0
- package/skills/tool-ops-tune/ops-family/references/broadcast/code/broadcast_tiling_common.h +401 -0
- package/skills/tool-ops-tune/ops-family/references/broadcast/code/onedim_add_kernel.cpp +107 -0
- package/skills/tool-ops-tune/ops-family/references/broadcast/code/onedim_add_tiling.cpp +64 -0
- package/skills/tool-ops-tune/ops-family/references/broadcast/datacopypad_design.md +46 -0
- package/skills/tool-ops-tune/ops-family/references/broadcast/guide.md +14 -0
- package/skills/tool-ops-tune/ops-family/references/broadcast/nddma_design.md +53 -0
- package/skills/tool-ops-tune/ops-family/references/broadcast/onedim_design.md +114 -0
- package/skills/tool-ops-tune/ops-family/references/broadcast/ub_broadcast_design.md +67 -0
- package/skills/tool-ops-tune/ops-family/references/common/datacopy_optimization_design.md +351 -0
- package/skills/tool-ops-tune/ops-family/references/common/index.md +9 -0
- package/skills/tool-ops-tune/ops-family/references/common/tail_block_design.md +268 -0
- package/skills/tool-ops-tune/ops-family/references/common/timing_harness/index.md +38 -0
- package/skills/tool-ops-tune/ops-family/references/common/timing_harness/timing_harness_aclrt_event.cpp +199 -0
- package/skills/tool-ops-tune/ops-family/references/common/timing_harness/timing_harness_torch_event.py +130 -0
- package/skills/tool-ops-tune/ops-family/references/common/ub_resident_design.md +342 -0
- package/skills/tool-ops-tune/ops-family/references/conversion/guide.md +69 -0
- package/skills/tool-ops-tune/ops-family/references/conversion/index.md +4 -0
- package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_base.template +81 -0
- package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_big_dim.template +217 -0
- package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_cut_one_axis.template +336 -0
- package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_cut_two_axis.template +781 -0
- package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_n_last.template +340 -0
- package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_small_shape.template +321 -0
- package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_tensor_move.template +102 -0
- package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_transdata_5hd.template +480 -0
- package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_transdata_5hd_021axis.template +533 -0
- package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_with_gather.template +688 -0
- package/skills/tool-ops-tune/ops-family/references/conversion/templates/transpose_tiling_data.template +192 -0
- package/skills/tool-ops-tune/ops-family/references/conversion/transpose_big_dim.md +220 -0
- package/skills/tool-ops-tune/ops-family/references/conversion/transpose_cut_one_axis.md +175 -0
- package/skills/tool-ops-tune/ops-family/references/conversion/transpose_cut_two_axis.md +177 -0
- package/skills/tool-ops-tune/ops-family/references/conversion/transpose_fusion_design.md +398 -0
- package/skills/tool-ops-tune/ops-family/references/conversion/transpose_gather.md +191 -0
- package/skills/tool-ops-tune/ops-family/references/conversion/transpose_n_last.md +276 -0
- package/skills/tool-ops-tune/ops-family/references/conversion/transpose_small_shape.md +315 -0
- package/skills/tool-ops-tune/ops-family/references/conversion/transpose_tensor_move.md +203 -0
- package/skills/tool-ops-tune/ops-family/references/conversion/transpose_tiling_data.md +176 -0
- package/skills/tool-ops-tune/ops-family/references/conversion/transpose_vconv_021.md +206 -0
- package/skills/tool-ops-tune/ops-family/references/conversion/transpose_vconv_5hd.md +179 -0
- package/skills/tool-ops-tune/ops-family/references/elementwise/double_buffer_design.md +288 -0
- package/skills/tool-ops-tune/ops-family/references/elementwise/guide.md +46 -0
- package/skills/tool-ops-tune/ops-family/references/elementwise/index.md +10 -0
- package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/CMakeLists.txt +131 -0
- package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/README.md +55 -0
- package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_extension/add_custom_torch.cpp +80 -0
- package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_extension/ops.h +23 -0
- package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_extension/register.cpp +30 -0
- package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_host/add_custom.asc +149 -0
- package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_host/data_utils.h +97 -0
- package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_kernel/add_custom_kernel.asc +136 -0
- package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_kernel/add_custom_tiling.h +31 -0
- package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/run.sh +86 -0
- package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/scripts/gen_data.py +70 -0
- package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/scripts/golden.py +34 -0
- package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/scripts/test_torch.py +99 -0
- package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/scripts/verify_result.py +56 -0
- package/skills/tool-ops-tune/ops-family/references/elementwise/templates/usage_guide.md +61 -0
- package/skills/tool-ops-tune/ops-family/references/elementwise/vector_efficiency_design.md +203 -0
- package/skills/tool-ops-tune/ops-family/references/fa/fa_mixed_kernel_design.md +174 -0
- package/skills/tool-ops-tune/ops-family/references/fa/fa_roofline_design.md +141 -0
- package/skills/tool-ops-tune/ops-family/references/fa/guide.md +87 -0
- package/skills/tool-ops-tune/ops-family/references/knowledge_gaps.json +56 -0
- package/skills/tool-ops-tune/ops-family/references/matmul/best-practices-guide.md +14 -0
- package/skills/tool-ops-tune/ops-family/references/matmul/fullload_design.md +344 -0
- package/skills/tool-ops-tune/ops-family/references/matmul/guide.md +52 -0
- package/skills/tool-ops-tune/ops-family/references/matmul/mte2_preload_design.md +320 -0
- package/skills/tool-ops-tune/ops-family/references/matmul/pingpong_design.md +254 -0
- package/skills/tool-ops-tune/ops-family/references/matmul/scale_coalescing_design.md +282 -0
- package/skills/tool-ops-tune/ops-family/references/matmul/streamk_design.md +374 -0
- package/skills/tool-ops-tune/ops-family/references/matmul/swat_design.md +423 -0
- package/skills/tool-ops-tune/ops-family/references/matmul/templates/matmul_basic_blaze.template +165 -0
- package/skills/tool-ops-tune/ops-family/references/matmul/templates/usage_guide.md +29 -0
- package/skills/tool-ops-tune/ops-family/references/mc2/best-practices-guide.md +43 -0
- package/skills/tool-ops-tune/ops-family/references/mc2/guide.md +42 -0
- package/skills/tool-ops-tune/ops-family/references/mc2/local_matmul_design.md +130 -0
- package/skills/tool-ops-tune/ops-family/references/mc2/pipeline_balancing_design.md +502 -0
- package/skills/tool-ops-tune/ops-family/references/reduce/guide.md +178 -0
- package/skills/tool-ops-tune/ops-family/references/reduce/templates/dav310/kernel_utils.template +75 -0
- package/skills/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_ar_full_load.template +429 -0
- package/skills/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_ar_recompute.template +485 -0
- package/skills/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_ar_small_r.template +348 -0
- package/skills/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_ara_full_load.template +574 -0
- package/skills/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_ara_online.template +324 -0
- package/skills/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_ara_recompute.template +436 -0
- package/skills/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_base.template +950 -0
- package/skills/tool-ops-tune/ops-family/references/reduce/templates/fused_attention_online_softmax_design.md +428 -0
- package/skills/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_ar_full_load.md +137 -0
- package/skills/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_ar_recompute.md +135 -0
- package/skills/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_ar_small_r.md +122 -0
- package/skills/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_ara_full_load.md +144 -0
- package/skills/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_ara_online.md +185 -0
- package/skills/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_ara_recompute.md +163 -0
- package/skills/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_tiling.template +460 -0
- package/skills/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_tiling_data.template +278 -0
- package/skills/tool-ops-tune/ops-family/references/reduce/templates/state_resident_design.md +337 -0
- package/skills/tool-ops-tune/ops-family/references/reduce/templates/usage_guide.md +253 -0
- package/skills/tool-ops-tune/ops-family/references/scalar/coding_principles.md +476 -0
- package/skills/tool-ops-tune/ops-family/references/scalar/conv_scalar.md +163 -0
- package/skills/tool-ops-tune/ops-family/references/scalar/guide.md +30 -0
- package/skills/tool-ops-tune/ops-family/references/simt/guide.md +91 -0
- package/skills/tool-ops-tune/ops-family/references/simt/optimization-guide.md +110 -0
- package/skills/tool-ops-tune/ops-family/references/sort/guide.md +83 -0
- package/skills/tool-ops-tune/ops-family/references/sort/radix_sort.md +354 -0
- package/skills/tool-ops-tune/ops-family/scripts/family_asset_audit.py +68 -0
- package/skills/tool-ops-tune/ops-family/scripts/tiling_candidates.py +419 -0
- package/skills/tool-ops-tune/ops-mechanism/SKILL.md +23 -0
- package/skills/tool-ops-tune/ops-mechanism/cases/ascendc/case_groupedmatmul_pipeline.md +23 -0
- package/skills/tool-ops-tune/ops-mechanism/cases/ascendc/case_triton_atomic_revert.md +19 -0
- package/skills/tool-ops-tune/ops-mechanism/cases/mc2/case_mc2_fusion.md +19 -0
- package/skills/tool-ops-tune/ops-mechanism/references/optimize/api-usage.md +70 -0
- package/skills/tool-ops-tune/ops-mechanism/references/optimize/ascendc-regbase-vf.md +45 -0
- package/skills/tool-ops-tune/ops-mechanism/references/optimize/ascendc-tiling.md +51 -0
- package/skills/tool-ops-tune/ops-mechanism/references/optimize/data-copy.md +67 -0
- package/skills/tool-ops-tune/ops-mechanism/references/optimize/index.md +45 -0
- package/skills/tool-ops-tune/ops-mechanism/references/optimize/mc2-balancing.md +77 -0
- package/skills/tool-ops-tune/ops-mechanism/references/optimize/mc2.md +103 -0
- package/skills/tool-ops-tune/ops-mechanism/references/optimize/memory-hierarchy.md +40 -0
- package/skills/tool-ops-tune/ops-mechanism/references/optimize/pipeline.md +95 -0
- package/skills/tool-ops-tune/ops-mechanism/scripts/case_backfill.py +170 -0
- package/skills/tool-ops-tune/ops-mechanism/scripts/log_gap.py +145 -0
- package/skills/tool-ops-tune/ops-mechanism/scripts/mc2_search.py +367 -0
- package/skills/tool-ops-tune/ops-report/SKILL.md +77 -0
- package/skills/tool-ops-tune/ops-verdict/evals/run_evals.py +837 -0
- package/skills/tool-ops-tune/ops-verdict/evals/smoke/install-hooks.sh +65 -0
- package/skills/tool-ops-tune/ops-verdict/evals/smoke/run_smoke.sh +405 -0
- package/skills/tool-ops-tune/ops-verdict/fixtures/core_tail_a5.csv +25 -0
- package/skills/tool-ops-tune/ops-verdict/fixtures/few_cores_a5.csv +5 -0
- package/skills/tool-ops-tune/ops-verdict/fixtures/mte2_bound_a2.csv +17 -0
- package/skills/tool-ops-tune/ops-verdict/fixtures/multi_kernel_mix_a5.csv +7 -0
- package/skills/tool-ops-tune/ops-verdict/fixtures/no_bound_a5.csv +9 -0
- package/skills/tool-ops-tune/ops-verdict/fixtures/serial_no_overlap_a2.csv +9 -0
- package/skills/tool-ops-tune/ops-verdict/fixtures/vec_bound_a5.csv +9 -0
- package/skills/tool-ops-tune/ops-verdict/references/io-contracts.md +94 -0
- package/skills/tool-ops-tune/ops-verdict/references/rule-schema.md +130 -0
- package/skills/tool-ops-tune/ops-verdict/references/scope-schema.md +61 -0
- package/skills/tool-ops-tune/ops-verdict/references/soc-spec.yaml +140 -0
- package/skills/tool-ops-tune/ops-verdict/rules/L0-instruction.yaml +67 -0
- package/skills/tool-ops-tune/ops-verdict/rules/L1-single-core.yaml +316 -0
- package/skills/tool-ops-tune/ops-verdict/rules/L2-inter-core.yaml +173 -0
- package/skills/tool-ops-tune/ops-verdict/rules/L3-inter-card.yaml +156 -0
- package/skills/tool-ops-tune/ops-verdict/scripts/batch_pipeline.py +444 -0
- package/skills/tool-ops-tune/ops-verdict/scripts/calibrate.py +249 -0
- package/skills/tool-ops-tune/ops-verdict/scripts/delta_compare.py +244 -0
- package/skills/tool-ops-tune/ops-verdict/scripts/render_html.py +274 -0
- package/skills/tool-ops-tune/ops-verdict/scripts/snapshot.py +200 -0
- package/skills/tool-ops-tune/ops-verdict/scripts/trace_bubble.py +331 -0
- package/skills/tool-ops-tune/ops-verdict/scripts/verdict.py +1072 -0
- package/skills/tool-ops-tune/scripts/diff_audit.py +281 -0
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
# 模板使用指南
|
|
2
|
+
|
|
3
|
+
本文件说明如何将 `templates/` 下的 SoftmaxV2 Kernel 模板集成到实际算子项目中。
|
|
4
|
+
|
|
5
|
+
## 0. 模板文件格式与使用约定
|
|
6
|
+
|
|
7
|
+
`templates/` 下的所有源码模板均以 `.template` 为后缀(如 `softmax_v2_base.template`)。这些是**参考模板**,不是可直接编译的源码。
|
|
8
|
+
|
|
9
|
+
**使用时必须将 `.template` 重命名/复制为对应的 `.h`(或 `.cpp`)文件**,否则最终工程里的 `#include` 引用的是 `.h`,代码不易读也无法编译。转换规则很简单,去掉 `.template` 后缀并按文件头 `\file` 注释中标注的名字落地:
|
|
10
|
+
|
|
11
|
+
| 模板文件 | 转换后落地文件 |
|
|
12
|
+
|----------|---------------|
|
|
13
|
+
| `dav310/softmax_v2_base.template` | `dav310/softmax_v2_base.h` |
|
|
14
|
+
| `dav310/softmax_v2_ar_small_r.template` | `dav310/softmax_v2_ar_small_r.h` |
|
|
15
|
+
| `dav310/softmax_v2_ar_full_load.template` | `dav310/softmax_v2_ar_full_load.h` |
|
|
16
|
+
| `dav310/softmax_v2_ar_recompute.template` | `dav310/softmax_v2_ar_recompute.h` |
|
|
17
|
+
| `dav310/softmax_v2_ara_full_load.template` | `dav310/softmax_v2_ara_full_load.h` |
|
|
18
|
+
| `dav310/softmax_v2_ara_recompute.template` | `dav310/softmax_v2_ara_recompute.h` |
|
|
19
|
+
| `dav310/softmax_v2_ara_online.template` | `dav310/softmax_v2_ara_online.h` |
|
|
20
|
+
| `dav310/kernel_utils.template` | `dav310/kernel_utils.h` |
|
|
21
|
+
| `softmax_v2_tiling_data.template` | `softmax_v2_tiling_data.h` |
|
|
22
|
+
| `softmax_v2_tiling.template` | `softmax_v2_tiling.h` |
|
|
23
|
+
|
|
24
|
+
转换命令示例(保留目录结构):
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# 在 templates/ 目录下,把所有 .template 复制成同名 .h 到工程目录
|
|
28
|
+
find . -name '*.template' | while read f; do
|
|
29
|
+
cp "$f" "${f%.template}.h"
|
|
30
|
+
done
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
> **架构目录说明**:Kernel 模板位于 `dav310/` 子目录(对应目标架构 `dav-3510`/Ascend950),`kernel_utils.template` 也在 `dav310/` 下,与其它 Kernel 模板同级。
|
|
34
|
+
|
|
35
|
+
## 1. 文件清单
|
|
36
|
+
|
|
37
|
+
### Kernel 文件(7 个,均在 `dav310/` 下)
|
|
38
|
+
|
|
39
|
+
| 模板文件 | 转换后 | 作用 |
|
|
40
|
+
|----------|--------|------|
|
|
41
|
+
| `dav310/softmax_v2_base.template` | `softmax_v2_base.h` | 公共基类 `SoftmaxV2OpsBase`:CastTrait、VF 工具、CopyIn/Out、NlastReduceSum、UpdateCache 等 |
|
|
42
|
+
| `dav310/softmax_v2_ar_small_r.template` | `softmax_v2_ar_small_r.h` | AR-SmallR:`SoftmaxV2ArSmallR<Tx,Ty>`,R 极小转置向量化 |
|
|
43
|
+
| `dav310/softmax_v2_ar_full_load.template` | `softmax_v2_ar_full_load.h` | AR-FullLoad:`SoftmaxV2AR<T_in,T_out>`,R 全量载入 UB |
|
|
44
|
+
| `dav310/softmax_v2_ar_recompute.template` | `softmax_v2_ar_recompute.h` | AR-Recompute:`SoftmaxV2ArRecompute<Tx,Ty>`,R 超 UB 三阶段重读 |
|
|
45
|
+
| `dav310/softmax_v2_ara_full_load.template` | `softmax_v2_ara_full_load.h` | ARA-FullLoad:`SoftmaxV2ARA<T1,T2>`,3D R 全量载入 |
|
|
46
|
+
| `dav310/softmax_v2_ara_recompute.template` | `softmax_v2_ara_recompute.h` | ARA-Recompute:`SoftmaxV2ARARecompute<T1,T2>`,3D R 超 UB |
|
|
47
|
+
| `dav310/softmax_v2_ara_online.template` | `softmax_v2_ara_online.h` | ARA-Online:`SoftmaxV2ARAOnline<T1,T2>`,3D 在线 max/sum |
|
|
48
|
+
|
|
49
|
+
### 公共依赖(3 个)
|
|
50
|
+
|
|
51
|
+
| 模板文件 | 转换后 | 作用 |
|
|
52
|
+
|----------|--------|------|
|
|
53
|
+
| `softmax_v2_tiling_data.template` | `softmax_v2_tiling_data.h` | 六套 TilingData 结构体定义(packed),host/device 共用 |
|
|
54
|
+
| `softmax_v2_tiling.template` | `softmax_v2_tiling.h` | 六个独立 Host tiling 计算函数 |
|
|
55
|
+
| `dav310/kernel_utils.template` | `dav310/kernel_utils.h` | Device 侧工具模板(CeilDiv、CeilAlign、FloorDiv、Aligned 等) |
|
|
56
|
+
|
|
57
|
+
## 2. 六类可独立选择的模板
|
|
58
|
+
|
|
59
|
+
每个模板可独立选择、独立包含和独立实例化,不使用 TilingKey、templateCode 或统一模板分发器。
|
|
60
|
+
|
|
61
|
+
| 模板 | 类名 | TilingData | Tiling 函数 | 构造方式 |
|
|
62
|
+
|------|------|-----------|------------|---------|
|
|
63
|
+
| AR-SmallR | `SoftmaxV2ArSmallR` | `SoftmaxV2ArSmallRTilingData` | `TilingArSmallR` | AR 系:构造传 `TPipe*` |
|
|
64
|
+
| AR-FullLoad | `SoftmaxV2AR` | `SoftmaxV2ARTilingData` | `TilingArFullLoad` | AR 系:构造传 `TPipe*` |
|
|
65
|
+
| AR-Recompute | `SoftmaxV2ArRecompute` | `SoftmaxV2ArRecomputeTilingData` | `TilingArRecompute` | AR 系:构造传 `TPipe*` |
|
|
66
|
+
| ARA-FullLoad | `SoftmaxV2ARA` | `SoftmaxV2ARATilingData` | `TilingAraFullLoad` | ARA 系:构造传 TilingData* |
|
|
67
|
+
| ARA-Recompute | `SoftmaxV2ARARecompute` | `SoftmaxV2ARARecomputeTilingData` | `TilingAraRecompute` | ARA 系:构造传 TilingData* |
|
|
68
|
+
| ARA-Online | `SoftmaxV2ARAOnline` | `SoftmaxV2ARAOnlineTilingData` | `TilingAraOnline` | ARA 系:构造传 TilingData* |
|
|
69
|
+
|
|
70
|
+
## 3. 每个模板的最小依赖集合
|
|
71
|
+
|
|
72
|
+
> 下面的依赖关系均以**转换后的 `.h`** 描述。集成前请先按第 0 节把 `.template` 落地为 `.h`。
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
具体模板(如 dav310/softmax_v2_ar_small_r.h)
|
|
76
|
+
├── dav310/softmax_v2_base.h(按实际依赖)
|
|
77
|
+
│ └── dav310/kernel_utils.h(同目录)
|
|
78
|
+
├── softmax_v2_tiling_data.h
|
|
79
|
+
└── CANN SDK headers(kernel_tiling/kernel_tiling.h, kernel_operator.h, op_kernel/platform_util.h)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
使用者不需要包含其他不相关模板。每个模板显式选择,不依赖模板注册表或自动路由。
|
|
83
|
+
|
|
84
|
+
## 4. 如何显式选择一个模板
|
|
85
|
+
|
|
86
|
+
在 kernel 入口文件中 `#include` 需要的模板头文件和 TilingData 头文件:
|
|
87
|
+
|
|
88
|
+
```cpp
|
|
89
|
+
#include "softmax_v2_tiling_data.h"
|
|
90
|
+
#include "dav310/softmax_v2_base.h"
|
|
91
|
+
#include "dav310/softmax_v2_ar_full_load.h" // 只包含需要的模板
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## 5. 如何构造对应的 TilingData
|
|
95
|
+
|
|
96
|
+
在 Host 侧使用 `softmax_v2_tiling.h` 中的对应函数:
|
|
97
|
+
|
|
98
|
+
```cpp
|
|
99
|
+
#include "softmax_v2_tiling.h"
|
|
100
|
+
|
|
101
|
+
softmax_tiling::PlatformParam plat;
|
|
102
|
+
// 运行时查询平台参数
|
|
103
|
+
plat.ubSize = static_cast<int64_t>(ubSize);
|
|
104
|
+
plat.numBlocks = static_cast<int64_t>(coreNumAiv);
|
|
105
|
+
|
|
106
|
+
softmax_tiling::CaseShape shape;
|
|
107
|
+
shape.a1 = a1; shape.r = r; shape.a0 = a0; shape.dtypeCode = 0; // 0=FP32, 1=FP16, 2=BF16
|
|
108
|
+
|
|
109
|
+
SoftmaxV2ARTilingData td;
|
|
110
|
+
int64_t blockDim = softmax_tiling::TilingArFullLoad(shape, plat, td);
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## 6. 如何实例化类并调用 Process
|
|
114
|
+
|
|
115
|
+
### AR 系模板(构造传 `TPipe*`,Init 传 TilingData 指针)
|
|
116
|
+
|
|
117
|
+
```cpp
|
|
118
|
+
TPipe pipe;
|
|
119
|
+
SoftmaxV2AR<float, float> op(&pipe); // 构造传 TPipe*
|
|
120
|
+
op.Init(x, y, &tiling); // Init 传 TilingData*
|
|
121
|
+
op.Process();
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### ARA 系模板(构造传 TilingData 指针,Init 传 `TPipe*`)
|
|
125
|
+
|
|
126
|
+
```cpp
|
|
127
|
+
TPipe pipe;
|
|
128
|
+
SoftmaxV2ARA<float, float> op(&tiling); // 构造传 TilingData*
|
|
129
|
+
op.Init(x, y, &pipe); // Init 传 TPipe*
|
|
130
|
+
op.Process();
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
> **注意**:AR 和 ARA 系的构造/Init 参数顺序不同,不能混用。
|
|
134
|
+
|
|
135
|
+
## 7. FP32、FP16、BF16 实例化方法
|
|
136
|
+
|
|
137
|
+
```cpp
|
|
138
|
+
// FP32
|
|
139
|
+
SoftmaxV2AR<float, float> op_fp32(&pipe);
|
|
140
|
+
// FP16
|
|
141
|
+
SoftmaxV2AR<half, half> op_fp16(&pipe);
|
|
142
|
+
// BF16
|
|
143
|
+
SoftmaxV2AR<bfloat16_t, bfloat16_t> op_bf16(&pipe);
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
输入输出 dtype 必须一致(`Tx == Ty`)。内部计算始终在 FP32 进行。
|
|
147
|
+
|
|
148
|
+
## 8. MicroAPI、`__vector__`、CANN SDK include 和目标架构要求
|
|
149
|
+
|
|
150
|
+
- **MicroAPI**:所有模板使用 `AscendC::MicroAPI::RegTensor`、`MaskReg` 等 VF 类型,需 `__VEC_SCOPE__` 作用域。
|
|
151
|
+
- **`__vector__`**:Kernel 入口需标注 `__global__ __aicore__ __vector__`,纯 AIV/Vector 核。
|
|
152
|
+
- **CANN SDK include**:
|
|
153
|
+
- `kernel_tiling/kernel_tiling.h` — TilingData 基础设施
|
|
154
|
+
- `kernel_operator.h` — AscendC 高层 API 和 MicroAPI
|
|
155
|
+
- `op_kernel/platform_util.h` — 平台工具
|
|
156
|
+
- **目标架构**:`dav-3510`(Ascend950),VRegSize=256B,VL_FP32=64。
|
|
157
|
+
|
|
158
|
+
## 9. 构建方式
|
|
159
|
+
|
|
160
|
+
### 方式一:ASC 语言单 .asc 文件(host + kernel 同一翻译单元)
|
|
161
|
+
|
|
162
|
+
参考源工程 `softmax.asc`,host main 与 kernel 入口写在同一个 `.asc` 文件中,一趟 ASC 编译,`<<<blockDim, nullptr, stream>>>` 直调。
|
|
163
|
+
|
|
164
|
+
关键 CMakeLists.txt 配置:
|
|
165
|
+
|
|
166
|
+
```cmake
|
|
167
|
+
set(CMAKE_ASC_ARCHITECTURES "dav-3510" CACHE STRING "")
|
|
168
|
+
find_package(ASC REQUIRED)
|
|
169
|
+
project(softmax LANGUAGES ASC CXX)
|
|
170
|
+
|
|
171
|
+
add_executable(softmax softmax.asc)
|
|
172
|
+
target_include_directories(softmax PRIVATE
|
|
173
|
+
${CMAKE_CURRENT_SOURCE_DIR}/op_kernel
|
|
174
|
+
${CMAKE_CURRENT_SOURCE_DIR}/op_host
|
|
175
|
+
)
|
|
176
|
+
target_compile_options(softmax PRIVATE
|
|
177
|
+
$<$<COMPILE_LANGUAGE:ASC>:-dc>
|
|
178
|
+
$<$<COMPILE_LANGUAGE:ASC>:--npu-arch=${CMAKE_ASC_ARCHITECTURES}>
|
|
179
|
+
)
|
|
180
|
+
target_link_options(softmax PRIVATE
|
|
181
|
+
--npu-arch=${CMAKE_ASC_ARCHITECTURES}
|
|
182
|
+
)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### 方式二:`ascendc_library(kernellaunch)` 框架
|
|
186
|
+
|
|
187
|
+
```cmake
|
|
188
|
+
set(ASCEND_KERNEL_LAUNCH_ONLY ON)
|
|
189
|
+
include(${ASCENDC_CMAKE_DIR}/ascendc.cmake)
|
|
190
|
+
ascendc_library(ascendc_kernels_npu STATIC op_kernel/softmax_kernel.cpp)
|
|
191
|
+
ascendc_include_directories(ascendc_kernels_npu PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/op_kernel)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Host 侧通过 `ACLRT_LAUNCH_KERNEL` 调用。
|
|
195
|
+
|
|
196
|
+
## 10. 构建注意事项
|
|
197
|
+
|
|
198
|
+
### `-dc` 和 device link `--npu-arch`
|
|
199
|
+
|
|
200
|
+
dav310 头文件使用 `AscendC::MicroAPI::RegTensor` 等 reg_compute 类型,仅在 device arch 下声明。单 .asc 编译时需:
|
|
201
|
+
|
|
202
|
+
1. **`-dc`**:生成可重定位 device 代码。
|
|
203
|
+
2. **`--npu-arch=dav-3510`**:device 编译和链接阶段均需显式指定架构,否则默认落到 `dav-m100` 导致 device 符号无法解析。
|
|
204
|
+
3. **`__ASC_NPU_HOST__` 守卫**:host pass 需打开 `__ASC_NPU_HOST__` 使 reg_compute 类型在 host pass 可见;device pass 不打开,避免污染向量 intrinsic 类型映射。源码内用 `#ifndef __NPU_ARCH__` / `#define __ASC_NPU_HOST__` 守卫实现按 pass 限定。
|
|
205
|
+
|
|
206
|
+
### VF fusion
|
|
207
|
+
|
|
208
|
+
`--cce-simd-vf-fusion` 选项控制 VF 融合模式(`true`/`false`),按需开启。
|
|
209
|
+
|
|
210
|
+
### 两种方式的选择
|
|
211
|
+
|
|
212
|
+
- **单 .asc**:适合快速验证和直调场景,host+kernel 同一翻译单元。
|
|
213
|
+
- **`ascendc_library`**:适合正式算子工程,自动生成 `aclrtlaunch_*.h`。
|
|
214
|
+
|
|
215
|
+
> 两种方式均可使用,不存在"禁止使用 `add_executable + .asc`"的限制。关键是正确配置 `-dc`、`--npu-arch` 和 include 路径。
|
|
216
|
+
|
|
217
|
+
## 11. 参考模板与完整可运行工程之间的边界
|
|
218
|
+
|
|
219
|
+
`templates/` 目录提供的是**参考模板**:
|
|
220
|
+
|
|
221
|
+
- **包含**:7 个 Kernel 模板(`dav310/*.template`)、公共 TilingData 定义、Host tiling 参考实现、`dav310/kernel_utils.template`、文档。集成前按第 0 节将 `.template` 转成 `.h`/`.cpp`。
|
|
222
|
+
- **不包含**:完整的 CMakeLists.txt、`.asc` 入口文件、数据生成/验证脚本、input/output I/O 工具。
|
|
223
|
+
- 完整可运行工程参考:`softmaxNewKernel/` 源工程(含 `softmax.asc`、`CMakeLists.txt`、`data_utils.h`)。
|
|
224
|
+
|
|
225
|
+
集成时需自行编写:
|
|
226
|
+
1. Kernel 入口(`.asc` 或 `.cpp`),按本文档第 4-6 节的方式实例化模板。
|
|
227
|
+
2. Host main 或 op_host,调用 `softmax_v2_tiling.h` 中的 tiling 函数。
|
|
228
|
+
3. CMakeLists.txt,按本文档第 9 节的方式配置构建。
|
|
229
|
+
4. 数据 I/O 工具(如 `data_utils.h`)。
|
|
230
|
+
|
|
231
|
+
## 12. 常见编译问题
|
|
232
|
+
|
|
233
|
+
### 问题 1:MicroAPI 类型找不到
|
|
234
|
+
|
|
235
|
+
**现象**:`error: no template named 'RegTensor'` 或 `error: 'MicroAPI' has not been declared`
|
|
236
|
+
|
|
237
|
+
**根因**:reg_compute 类型仅在 device arch 下声明,host pass 不可见。
|
|
238
|
+
|
|
239
|
+
**解决**:在 include 之前添加 `__ASC_NPU_HOST__` 守卫(见第 10 节),或使用 `ascendc_library(kernellaunch)` 框架。
|
|
240
|
+
|
|
241
|
+
### 问题 2:device 链接符号未定义
|
|
242
|
+
|
|
243
|
+
**现象**:链接阶段报 device 符号无法解析。
|
|
244
|
+
|
|
245
|
+
**根因**:`--npu-arch` 未在链接阶段指定,默认架构不匹配。
|
|
246
|
+
|
|
247
|
+
**解决**:`target_link_options` 中添加 `--npu-arch=dav-3510`。
|
|
248
|
+
|
|
249
|
+
### 问题 3:compile_commands.json 不存在
|
|
250
|
+
|
|
251
|
+
**现象**:`error: No such file or directory: 'compile_commands.json'`
|
|
252
|
+
|
|
253
|
+
**解决**:`export CMAKE_EXPORT_COMPILE_COMMANDS=ON` 后在同一 shell 执行 cmake 和 make。
|