Guides connecting existing Ascend operator projects to PyTorch via PTA (PyTorch Adapter) interfaces. Routes between kernel-direct and aclnn-registry approaches based on project structure.
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 只负责给已能跑通的算子工程加 PyTorch 接入层。算子工程按调用形态分两类,PTA 接口的做法完全不同且不可混用,因此先判定路线,再执行对应子流程。
.run 包已就绪)source set_env.sh(ASCEND_HOME_PATH 已设置)按证据判定,优先看工程里有什么文件、导出了什么符号:
| 证据(任一命中) | 路线 |
|---|---|
kernel 源码里有 <<<...>>> 调用;有 .asc / .cce kernel 文件;CMake 直接编译 kernel 源码;已有 op_extension/ 或 TORCH_LIBRARY_FRAGMENT(npu, ...) | 路线 A:kernel 直调 |
有 op_host/ OpDef(OP_ADD(...))+ op_host/op_api/aclnn_<op>.h;build.sh 产出 custom_opp_<arch>.run;libcust_opapi.so 导出 aclnnXxxGetWorkspaceSize / aclnnXxx;工程里没有 <<<>>> | 路线 B:aclnn 注册 |
取证命令(在算子工程根执行):
grep -rn '<<<' --include='*.asc' --include='*.cpp' --include='*.cce' . | head # 命中 → 路线 A
ls op_host/ op_host/op_api/ 2>/dev/null # 有 OpDef + aclnn_*.h → 路线 B
nm -D $ASCEND_CUSTOM_OPP_PATH/../../lib64/libcust_opapi.so 2>/dev/null | grep aclnn | head
判定规则:
ops/ascendc-direct-invoke-template 或 ops/ascendc-registry-invoke-template,不要在这里硬造 PTA 层TORCH_LIBRARY / torch.ops.npu / stream(true) / .so 加载 → 倾向路线 A;EXEC_NPU_CMD_V1 / xops / NpuExtension / torchair converter / torch_npu.xxx → 倾向路线 B;仍需向用户确认后再进入| 路线 | 适用工程 | 子流程文件 |
|---|---|---|
| A:kernel 直调 | Ascend C <<<>>> 直调工程 | routes/direct-invoke.md(Step 0–6) |
| B:aclnn 注册 | aclnn 注册算子工程(.run + libcust_opapi.so) | routes/aclnn-registry.md(Step 0–8) |
routes/*.mdtemplates/direct-invoke/ + references/direct-invoke/,路线 B 用 templates/aclnn/ + references/aclnn/stream(true) / CMake 那套搬进 aclnn 路线会丢掉入 queue 语义,把 aclnn 的 EXEC_NPU_CMD_V1 搬进直调路线会因找不到 kernel 符号而链接失败references/ 只在排查问题或需要完整映射表时按需读,不预读| 路线 A:kernel 直调 | 路线 B:aclnn 注册 | |
|---|---|---|
| 产物 | libxxx_ops.so,torch.ops.load_library 加载 | xops wheel,import xops 加载 |
| 构建 | CMake,编译 .asc kernel | setup.py + NpuExtension,不编译 kernel |
| 下发 | 函数调用 kernel + stream(true) 手动清 queue | EXEC_NPU_CMD_V1 → RunOpApiV2 入 queue |
| 命名空间 | torch.ops.npu.xxx | torch.ops.custom.xxx / torch_npu.xxx |
| 图模式 | aclgraph(NPUGraph / make_graphed_callables),无 GE 入图 | torchair FX→GE converter → GE op_type |
| 共性 | 都必须注册 Meta backend(torch.compile / fx 追踪必需);都不写 autograd 反向 | 同左 |
| 资源 | 路径 | 说明 |
|---|---|---|
| 路线 A 子流程 | routes/direct-invoke.md | TORCH_LIBRARY 对接 Step 0–6 |
| 路线 B 子流程 | routes/aclnn-registry.md | xops wheel + dlsym Step 0–8 |
| 路线 A 模板 | templates/direct-invoke/ | ops_template.h、torch_template.cpp、register_template.cpp、CMakeLists_template.cmake |
| 路线 B 模板 | templates/aclnn/ | setup.py、package_init.py、converter_*.py、csrc/*(ops_common.{h,cpp} 原样复制勿改) |
| 路线 A 参考 | references/direct-invoke/anti_patterns.md、operation_checklist.md、troubleshooting.md | stream 反模式、适配清单、踩坑 |
| 路线 B 参考 | references/aclnn/schema_mapping.md、ops_common_internals.md、troubleshooting.md | schema/OpDef/aclnn 对齐、样板内部机制、踩坑 |
ops/ascendc-direct-invoke-templateops/ascendc-registry-invoke-templateops/ascendc-registry-invoke-to-direct-invokeops/ascendc-mc2-best-practiceevals/evals.json (opens in a new tab)references/aclnn/ops_common_internals.md (opens in a new tab)references/aclnn/schema_mapping.md (opens in a new tab)references/aclnn/troubleshooting.md (opens in a new tab)references/direct-invoke/anti_patterns.md (opens in a new tab)references/direct-invoke/operation_checklist.md (opens in a new tab)references/direct-invoke/troubleshooting.md (opens in a new tab)routes/aclnn-registry.md (opens in a new tab)routes/direct-invoke.md (opens in a new tab)templates/aclnn/converter_init.py (opens in a new tab)templates/aclnn/converter_op.py (opens in a new tab)templates/aclnn/csrc/op_impl.cpp (opens in a new tab)templates/aclnn/csrc/ops_common.cpp (opens in a new tab)templates/aclnn/csrc/ops_common.h (opens in a new tab)templates/aclnn/csrc/ops_def_registration.cpp (opens in a new tab)templates/aclnn/package_init.py (opens in a new tab)templates/aclnn/setup.py (opens in a new tab)templates/direct-invoke/CMakeLists_template.cmake (opens in a new tab)templates/direct-invoke/ops_template.h (opens in a new tab)templates/direct-invoke/register_template.cpp (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
ascend, pytorch-adapter, npu, operator-extension, torch-library
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 验收和双仓本地提交交付。/ops-direct-invoke-skills:torch-ascendc-op-extensionfrom ops-direct-invoke-skills
npx claudepluginhub hicann/cannbot-skills --plugin ops-direct-invoke-skills2 plugins ship this exact skill · first indexed Oct 20, 2026
Other plugins' skills for the same job