Generates Triton kernel code for Ascend NPU operators from design documents or direct requirements, including tiling strategies and basic correctness tests.
Ships in external-gitcode-ascend-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.
计算逻辑 → Tiling 策略 → 代码实现。顺序不可颠倒。
tl.tanh / tl.erf / tl.sqrt — 推荐,性能最优tl.math.tanh / tl.math.erf — 备选triton.language.extra.ascend.libdevice / triton.language.extra.libdevice — 以上找不到时| 阶段 | 必须加载 | 不要加载 |
|---|---|---|
| 设计 Tiling | hardware-architecture.md | templates.md |
| 生成 Kernel | templates.md | hardware-architecture.md |
| 查找 API 签名 | triton-api-reference.md | — |
MANDATORY:对应阶段前完整阅读上述文件,不设行数限制。
加载触发:需要确认某个 tl/libdevice API 的签名或参数时,完整阅读 triton-api-reference.md。
提取数学公式、输入输出规格、约束条件。用伪代码描述计算过程,必须与用户确认。
输入依赖:若已有设计文档(design skill 产出),按其 Tiling 策略实现;若无,则在此设计。
核间切分两原则:
grid = 物理核数(get_npu_aicore_num() 或 get_npu_vectorcore_num())core_num = get_npu_aicore_num()
grid = (core_num,)
# kernel 内:
pid = tl.program_id(0)
num_core = tl.num_programs(0)
blocks_per_core = tl.cdiv(total_blocks, num_core)
for block_idx in range(pid * blocks_per_core, min(...)):
...
UB 空间:安全 BLOCK_SIZE = (196608 - 32) / (缓冲区数 × dtype大小) × 0.8
按算子类型选择模板(详见 templates.md):
| 算子类型 | 核心类型 | 模板 |
|---|---|---|
| 归约类 | vector core | 模板 1 |
| GEMM/注意力 | AI core | 模板 2,6 |
| 激活/损失/索引/MoE/后处理 | vector core | 模板 3-5,7-8 |
| 卷积 | AI core | 模板 9 |
生成一个基本正确性测试(单 shape × 单 dtype 的 smoke test),确保 kernel 可编译运行且结果正确。全面的精度验证由 precision-eval skill 负责。
tl.dot + pad B 到 BLOCK_N=16,禁止用 Vector Core 逐行算内积tl.sum(x, 1) 在 UB 内完成统计和归一化,见模板 1for/while 循环内 return / break — Triton IR 结构化控制流不支持 early exit,编译必报错。替代:while + 布尔标志,或 tl.where masktensor[i] 索引操作(读取/赋值/切片)— Triton tensor 不支持 Python 风格下标。替代:tl.where 赋值、tl.gather 读取、tl.extract_slice 切片| 陷阱 | 症状 | 解决 |
|---|---|---|
| 计算逻辑错 | 输出不符预期 | 伪代码描述并确认 |
| UB 溢出 | "ub overflow" | 减小 BLOCK_SIZE |
| coreDim 超限 | "coreDim > UINT16_MAX" | 增大 BLOCK_SIZE 或设 TRITON_ALL_BLOCKS_PARALLEL=1 |
| 精度损失 | FP16 不准确 | 归约前升 FP32 |
| 索引不够 | D-cache 报错 | 超大 shape 用 int64 |
| 归约类算子慢 5x+ | aiv_scalar > 80% | 单 pass:一次 load + tl.sum(x, 1) UB 内全计算 |
| 大矩阵 L2 缓存颠簸 | GEMM 吞吐低于预期 | 对角线调度(task_m_idx = block_idx % NUM_BLOCKS_M),见模板 2 |
必须使用 Triton kernel 完成核心计算,严禁以下行为:
What SKILL.md sets; muted values are Claude Code's defaults
/external-gitcode-ascend-skills:external-gitcode-ascend-triton-operator-code-genfrom external-gitcode-ascend-skills
npx claudepluginhub ascend-ai-coding/awesome-ascend-skills --plugin external-gitcode-ascend-skills91 skills in this plugin
/external-gitcode-ascend-analyse-coverage分析测试覆盖率盲区,生成覆盖率分析报告/external-gitcode-ascend-arxiv-recommendation-npu自动化推荐系统论文发现流水线。抓取 arxiv 推荐论文,检测源码,生成待迁移任务清单,由 npu-model-migration skill 完成 NPU 适配。/external-gitcode-ascend-ascendc-operator-code-gen根据设计文档生成 AscendC 算子完整代码实现并完成框架适配。TRIGGER when: 设计文档已完成,需要生成 op_host/op_kernel 代码、注册到 PyTorch 框架、编译测试。关键词:代码生成、op_host、op_kernel、tiling、kernel、框架适配、算子注册。Other plugins' skills for the same job