Guides AscendC Tensor API operator development on Ascend 950/DAV_3510: route contracts, layout/memory budgets, build, precision, performance, and troubleshooting.
Ships in ops-direct-invoke-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
本 Skill 是 Ascend C 直调工作流中的 Tensor API 实现路线权威源,不是独立工作流,也不新增 PM、Agent、workflow 模板或 harness 状态。用户明确要求 Tensor API 时,需求清单记录用户原话与路线来源,并固定 implementation_route=tensor_api_custom;该路线为硬约束,不由 Blaze 优先选型改写。
后续只验证该路线是否可行;不得静默切换到 Blaze 或原生 AscendC。若 API、ABI、Layout、内存或同步无法闭合,输出 unsupported 与证据,由用户决定下一步。
路径约定:
project_root: <project-root>
operator_root: <project-root>/operators/<operator_name>/
design_path: operators/<operator_name>/docs/DESIGN.md
plan_path: operators/<operator_name>/docs/PLAN.md
execution_record_path: operators/<operator_name>/docs/EXECUTION_RECORD.md
本地手册或官方样例缺失时运行 ensure_docs.py:主工作区 ~/asc-devkit 在 master 上时自动 clone 或 fast-forward;若被其他分支占用(如 vendor 头锁定的 feature 分支)或与 master 历史分叉,脚本自动维护独立的 master 浅镜像 ~/asc-devkit-master 提供手册与样例,不修改主工作区。输出 JSON 的 selected_root 即当前事实源根目录。仓库 dirty 或 origin 不匹配时阻断,不强制覆盖。
除 asc-devkit 外,可按 source-map.md 检索本地官方源码仓 ~/ops-tensor、~/ops-nn、~/ops-transformer、~/cann-samples。在 skill 根目录运行 ensure_sources.py 记录各仓 commit 与可用性;这些仓只读,脚本不 clone、不 fetch、不修改。asc-devkit 手册与头文件仍是 API/ABI/Layout 权威源;源码仓只用于算法结构、tiling、边界处理和组件架构参考,引用前必须完成 source-map 的路线审计。
事实源优先级固定为:asc-devkit 手册与 Tensor API 头文件 > asc-devkit 07_tensor_api/ 官方样例
(Tensor API 调用形态的第一参考)> 本地源码仓的算法/tiling/边界参考。官方样例不可用时,
本地源码仓不能替代其 API 事实源地位,只能提供工程结构参考。
源码仓注册表和 required_paths 的唯一机器事实源是 scripts/sources.yaml;ensure_sources.py --check-map references/source-map.md 用于检查 Markdown 引用与注册表一致。
以下三类联调/评测高频问题的既有结论,先记结论、细节再查对应 reference。
先看误差量级区分两类问题:实现 bug 的 MERE 通常是 1e-11e1 量级,硬件舍入极限是 1e-61e-5 量级,先看量级再选排障路径。再按证据强度排障:① 官方 kernel 对照实验(官方 torch_npu matmul 跑同数据同判定,再 bit 级对比输出,一致即数值等价);② 控制变量变体实验(从现有数据切 K/M/N 派生真子集,注意验证切片后 shape 真的变了);③ 拟合 σ(段数) 模型(σ≈2.6e-6×sqrt(K段数),K段数=ceil(K/128),mmad k=256 会被拆成 2×128,K 链长度物理不可减);④ 位置基数效应(超标数=位置数×超标率,大 M×N case 更容易撞逐点门限);⑤ 纯 Cube 修复死路表(树状累加受 L0C 单 tile 限制、split-K GM 中转走 hf32 丢 5 位尾数引入更大误差、拆双链 σ 不减等,勿重复尝试)。详见 precision-model.md。
这是 L1 容量超限(A5 L1 总预算 512KB,8 槽 × 列片尺寸可能达到 576KB 超出);失败模式是全挂 + 超时而非明确报错,极难定位。预防:构建期容量预算门禁(CMake 检查 槽数×列片尺寸×dtype ≤ 预算×安全利用率,实证 459KB/87.6% 可行),超限硬失败。另注意 B 槽位跨 expert 场景必须区分 expert 维度否则数值错配。详见 design-guidance.md §4、performance-patterns.md §4。
分层验证:build.sh --run-mode=sim 覆盖全部内核代码编译;cmake -D<OP>_DEMO_ONLY=ON -DCMAKE_ASC_RUN_MODE=npu 覆盖 kernel+host 侧 ASC 编译面(绕开 torch 依赖);torch extension 的 C++ 部分设计为纯 Python.h 入口壳,版本敏感代码收敛在 kernel 侧;远程真机完成完整链路验证;补充环境矩阵意识——torch_npu 只能在系统 CANN 环境跑。详见 verification-and-debug.md。
| 请求目的 | 执行 |
|---|---|
| 明确要求从零完整开发算子 | Step 1 → Step 2 → Step 3 → Step 4 |
| 明确要求设计或方案分析,不实施 | Step 1 → Step 2 → Step 3 |
| 咨询、解释、评审、排障、能力查询 | 只读取相关 references |
不要按调用者身份增加模式。发现已有 DESIGN/PLAN 时,不得仅因此进入 Step 4;direct invoke Developer 直接消费相同 DESIGN/PLAN,本 Skill 的 Step 4 只属于完整四步开发流程。
算子的全部计算步骤必须在 device 侧单一 Kernel 中完成。Host 侧只负责数据准备、物理布局转换、Tiling 计算、Kernel launch 和结果搬运。
不得通过把非核心计算步骤排除到 Host 侧来缩小 API 覆盖性判定范围。若单一 Kernel、数据驻留或同步形态是用户硬约束,Step 2/3 不得降低该约束。
在 skill 根目录运行 scripts/ensure_docs.py 确保 Tensor API 手册与样例可用(输出 JSON 的 selected_root 为事实源根目录);需要固定文档版本时传入 --asc-devkit-ref。随后创建 operator_root。不预先实现公式、Tiling、Golden 或固定工程。文档或样例缺失且无法自动获取时保持 Step 1 blocked。
用户未特别指定时,operator/demo 工程默认采用 asc-devkit 07_tensor_api/ 官方样例同构结构:CMakeLists.txt、<op_name>.asc、data_utils.h、README 与 scripts/{gen_data.py,verify_result.py};仅用户明确要求或宿主工程已有约束时才拆分 .cpp 入口。CMake 使用 LANGUAGES ASC CXX 构建单个 demo,并在配置期硬检查:run mode 只允许 npu 或 sim,目标架构必须是 dav-3510,不满足直接 FATAL。
按需求语义只读调查 Tensor API:候选 API、Pattern、Copy/Mmad、C API 辅助能力、物理数据与 ABI 事实。只生成 Investigation,不修改源码、不启动构建。
需要官方实现参考时,先按 source-map.md 与算法 archetype 路由检索本地源码仓;ops-nn/ops-transformer 中的非 Tensor API 实现只能作为算法/tiling/边界参考,不能直接推断为 Tensor API 支持。
需要 API 语义、A5 平台边界、历史排障或优化经验时,按 knowledge-integration.md 查询 ~/cannbot-knowledge。查询仅返回候选摘要;采用结论前必须读完整卡片并记录卡片路径、status、来源与平台。
查询时先固定 --platform 950;精确 API 名使用 --match literal,能力描述或现象使用短词组和
--match text。
依据需求和 Investigation 生成 DESIGN 与 PLAN,覆盖逻辑接口、API 分工、数据流、Layout、内存预算、尾块、同步 owner、ABI crosswalk、构建合同、Golden 合同、性能基线和验证 checkpoint。若一次补充调查后仍缺决定性事实,保持 blocked,不生成最终 DESIGN/PLAN。
只在完整四步流程中执行当前 operator_root 的 DESIGN/PLAN。实施期间持续更新 PLAN 的执行记录;不得重新选择 API 路线、改变接口/ABI、切换备选或扩大支持域。
| 问题域 | 文档 |
|---|---|
| API 分工、数据流、Layout、内存预算 | references/api-dataflow-layout.md |
| NPU 执行模型、存储层级与 Tensor API 概念 | references/npu-execution-model.md |
| Tensor API 公开 API、Pattern、Copy/Mmad 与 Routing | references/tensor-api-reference.md |
| Kernel 端到端骨架(三形态、地址空间、最小可编译 skeleton) | references/kernel-skeleton.md |
| C API 辅助能力签名(初始化/同步/锁/原子/缓存) | references/c-api-primitives.md |
| 官方样例路由与检索规则 | references/sample-router.md |
| 本地官方源码仓与 L3 算子映射 | references/source-map.md |
| cannbot-knowledge 检索与证据采用 | references/knowledge-integration.md |
| Cube 收缩 / 量化 / GroupedMatmul epilogue | references/algorithm-archetypes/contraction-quant-epilogue.md |
| 卷积 / 空间采样 / filter 梯度 | references/algorithm-archetypes/convolution-spatial.md |
| 行归约 / 归一化 / 动态量化 / 融合 | references/algorithm-archetypes/vector-reduction-normalization.md |
| 索引 / Scatter / Hash / 前缀重排 | references/algorithm-archetypes/index-scatter-hash.md |
| TopK / 排序 / 去重 / 变长输出 | references/algorithm-archetypes/sort-select-compaction.md |
| 任意 ND 布局变换 | references/algorithm-archetypes/layout-transform.md |
| Experimental Reg Vector 与 move/move_mask/mem_bar | references/experimental-reg-vector.md |
| 同步、事件、生命周期与输出 writer | references/sync-and-lifecycle.md |
| 构建、工具链、自带头文件与 CMake | references/build-and-toolchain.md |
| 文档与样例自动获取 | scripts/ensure_docs.py |
| DESIGN 合同模板 | references/kernel-design/design-template.md |
| DESIGN 模板填写指导 | references/kernel-design/design-guidance.md |
| PLAN 与实施合同模板 | references/kernel-design/plan-template.md |
| Launcher、逻辑物理转换与证据隔离 | references/launcher/launcher-development.md |
| Golden 生成与精度对比(参考实现、ABI 解码、误差门 vs bit 级) | references/golden-generation.md |
| Cube 精度模型、排障、边界语义与低精度/量化选型 | references/precision-model.md |
| Cube/Matmul 性能瓶颈地图、递进优化序列与优化模式 | references/performance-patterns.md |
| 寄存器驻留 Vector 高性能、VF 优化与 Scalar 优化 | references/vector-performance-patterns.md |
| 融合算子设计(AIC/AIV 混合、CV 融合 UB 直通) | references/fusion-design.md |
| Tiling 决策树与多核切分 | references/tiling-strategy.md |
| 性能基线、峰值参数、瓶颈定位、达标线与优化建议 | references/performance-analysis.md |
| 参考算子阶梯路由(金标准四算子) | references/reference-operator-map.md |
| 无真机验证、环境矩阵、调试与排障 | references/verification-and-debug.md |
| 功能精度、性能与代码检视清单 | references/review-checklist.md |
每个开发问题保留原始问题,而非只保留最终经验。EXECUTION_RECORD 或等价记录逐项写明:
issue_id
original_problem
observed_signal_and_command
first_failed_boundary: build | abi | layout | sync | precision | performance
classification: actual_failure | preflight_risk | environment_blocked
root_cause_and_evidence
fix_or_recovery
positive_regression
remaining_boundary
skill_promotion: reusable | operator_local | none
若 skill_promotion=reusable,在当前任务验收后按 cannbot-knowledge 贡献流程将问题蒸馏为
Runbook/Optimization 知识卡;本 Skill 不直接回写知识仓,只保留执行记录和候选素材。
编译、静态检查和 CPU Golden 只能证明对应层级。设备结论必须来自真实设备路径,并记录 sandbox/device_visible、设备节点、SoC/架构、命令、返回码和输出。没有同合同 baseline 时性能写 NOT_EVALUATED。
evals/evals.json (opens in a new tab)references/algorithm-archetypes/contraction-quant-epilogue.md (opens in a new tab)references/algorithm-archetypes/convolution-spatial.md (opens in a new tab)references/algorithm-archetypes/index-scatter-hash.md (opens in a new tab)references/algorithm-archetypes/layout-transform.md (opens in a new tab)references/algorithm-archetypes/sort-select-compaction.md (opens in a new tab)references/algorithm-archetypes/vector-reduction-normalization.md (opens in a new tab)references/api-dataflow-layout.md (opens in a new tab)references/build-and-toolchain.md (opens in a new tab)references/c-api-primitives.md (opens in a new tab)references/experimental-reg-vector.md (opens in a new tab)references/fusion-design.md (opens in a new tab)references/golden-generation.md (opens in a new tab)references/kernel-design/design-guidance.md (opens in a new tab)references/kernel-design/design-template.md (opens in a new tab)references/kernel-design/plan-template.md (opens in a new tab)references/kernel-skeleton.md (opens in a new tab)references/knowledge-integration.md (opens in a new tab)references/launcher/launcher-development.md (opens in a new tab)references/npu-execution-model.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
25 skills in this plugin
/ascendc-api-best-practicesAscend C API 使用最佳实践。提供算术、归约、数据搬运、Buffer管理、精度转换、通信接口等 API 的正确用法和限制说明。触发:用户询问具体 API 用法(如"DataCopy 怎么用"、"ReadNbi 怎么用")、遇到 API 参数错误或限制报错(如 repeatTimes、对齐问题)、需要查看 API 最佳实践或避坑指南、算子性能疑似受标量访问/单元素读写影响时。/ascendc-blaze-best-practice在 Ascend 950 / DAV_3510 平台上,基于 Blaze/tensor_api 开发 Basic、Batch、Grouped、Quantized、MX 等 MatMul 类算子或相关的融合算子时使用。不适用于纯 Vector 算子或 A2/A3 平台。/ascendc-blaze-migration评估并将 ops-nn、ops-transformer 等仓中 Ascend 950 / DAV_3510 的 AscendC Kernel 分支等价迁移到 ops-tensor Blaze/Tensor API。适用于 CMCT、CGMCT、单体或自定义分层 Kernel,以及 Cube、Vector、MIX、高阶 Matmul、手工 Buffer、数据搬运、自定义调度、VF 和同步路径;在隔离迁移工程中串行完成迁移合同冻结、Blaze 开发、验证资产生成、原始基线、Blaze 验收和双仓本地提交交付。/ascendc-code-reviewAscend C 代码检视技能。触发:检视代码、检视 PR、检查是否有问题、快速检视。支持文件检视、PR 检视、快速定向检视、设计一致性检查。自动识别代码侧别、提取适用条例、执行假设检验驱动的逐条检视。/ascendc-crash-debugAscend C 算子卡死/崩溃/内存错误调试路由技能。用于处理程序无法运行完或执行异常崩溃的场景:(1) 程序卡死/挂起/超时,Kernel 无响应,(2) 程序崩溃(Segmentation Fault、Abort),(3) Buffer 冲突/死锁导致的核心挂起,(4) 需要解析 plog 日志定位卡死/崩溃位置,(5) 偶发崩溃/结果异常(怀疑内存越界踩踏),需要主动检测内存错误。触发关键词:卡死、挂起、超时、崩溃、hang、crash、deadlock、Segmentation Fault、Abort、Kernel hang、内存越界、plog、memcheck、内存检查、内存错误、偶发崩溃、aic error、非法读写。/ascendc-direct-invoke-templateKernel直调工程模板,用于创建 Ascend C Kernel 直调工程项目。提供经过验证的 Vector 样例工程(add_custom)、Blaze Matmul 工程模板(纯 Matmul / 融合 / MX 量化 / GroupMatmul)和 Kirin Vector 模板。触发:当用户需要创建 Kernel 直调工程、学习 Ascend C 编程、快速原型验证、或提及"Kernel直调"、"<<<>>>内核调用"、"Blaze Matmul"、"matmul 模板"时使用本 skill。/ops-direct-invoke-skills:ascendc-tensor-api-best-practicefrom ops-direct-invoke-skills
npx claudepluginhub hicann/cannbot-skills --plugin ops-direct-invoke-skillsOther plugins' skills for the same job