Reviews Triton operator code for Ascend NPU, checking for bugs, API misuse, and performance issues. Focuses on static analysis with Ascend-specific constraints.
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.
| 级别 | 含义 | 典型问题 |
|---|---|---|
| P0 | 必定崩溃或错误结果 | Mask 遗漏、核类型错配、Atomic 循环死锁 |
| P1 | 高概率精度/功能问题 | 归约未升精度、Softmax 未减 max |
| P2 | 性能/可维护性 | 冗余访存、BLOCK 未对齐 |
| 阶段 | 加载 | 不要加载 |
|---|---|---|
| Phase 1: Host 侧 | ascend-triton-api-constraints.md | dtype-matrix |
| Phase 2: Device 侧 | ascend-api-dtype-matrix.md | test-patterns |
| 逐项核对 | code-review-checklist.md | — |
| 参考官方实现 | ascend-test-patterns.md | — |
| 确认 API 签名/参数 | triton-api-reference.md | — |
加载触发:需要确认某个 tl/libdevice API 的签名、参数或可用数据类型时,完整阅读 triton-api-reference.md。
| 检查项 | 识别方式 | 级别 |
|---|---|---|
| 硬编码核数 | grid = (20,) 等字面量 | P0 |
| 核类型错配 | 含 tl.dot 的 kernel 用了 num_vectorcore | P0 |
| 矩阵乘法退化为逐元素 | 无 tl.dot,用 Vector Core 逐元素乘加实现 matmul/GEMV | P0 |
BLOCK_SIZE 非 tl.constexpr | 声明检查 | P1 |
| 矩阵运算 BLOCK 非 16 倍数 | 数值检查 | P2 |
核类型:含 tl.dot → AI Core (num_aicore);逐元素/归约/激活 → Vector Core (num_vectorcore)。注意:矩阵乘法类算子(含 GEMV)必须用 tl.dot + AI Core,Cube Core 吞吐远高于 Vector Core。
Mask 完整性(P0):所有 tl.load/tl.store 必须有 mask= 或使用 make_block_ptr。
数据类型(P0-P1):tl.dot 输入仅支持 int8/fp16/fp32/bf16;dot_scaled 有条件支持(bf16/fp16 lhs/rhs, int8 scale, fp32 out);permute/trans 不支持 int64。
精度处理(P1):FP16/BF16 归约前 .to(tl.float32);Softmax 必须减 max。
归约类算子单 pass 检查(P1):GroupNorm/LayerNorm/RMSNorm 等算子,检查是否对同一数据多次 load(先算统计量,再 load 做归一化)。当 D ≤ UB 时应单 pass:一次 load 后 tl.sum(x, 1) 在 UB 内完成全部计算。双 pass 可慢 5x。
控制流(P0):Triton IR 使用 MLIR 结构化控制流(scf.for/scf.while),不支持 early exit。
for/while 循环内 return — 编译错误:"Cannot have return statements inside while or for"(包括子函数中的 return)for 循环内 break — 编译错误:"unsupported AST node type: Break"Tensor 索引(P0):Triton tensor 不支持 Python 风格 [] 下标操作。
tensor[i] = val — AssertionErrorval = tensor[i] — AssertionErrortensor[i:j] 切片 — 编译错误代码模式:
for ... : tl.atomic_cas/or/xor/and/xchg(...) — 可能死锁(P0)tl.atomic_add 返回值(P0)import numpy(P0)tensor[i].item() 在 Host 热路径 — 触发 CPU-NPU 同步(P2)for ... : tl.load(x_ptr + ...) 循环 — 双 pass 反模式(P1)tl.parallel(bind_sub_block=True) — tl.dot 后有逐元素操作但无并行分片(P2)tl.cast 到 int8/int16 未指定 overflow_mode(P1)tl.load → 冗余 GM 访问tl.arange(0, N) * stride(stride > 1)→ 非连续访存pid 直接映射 block 无循环 → 负载不均b * stride0 + n * stride1 + ...)→ 建议改为 host 侧 expand+contiguous,统一 row * D + col 偏移weight_ptr + ch_idx gather → 建议 host 侧展开为连续布局num_vectorcore / BLOCK_SIZE 非 tl.constexprtl.dot + AI Coretl.load/tl.store 无 mask / tl.dot 输入 int32/int16/int64 / dot_scaledatomic_or/xor/and/xchg/cas 在 for 循环内 / kernel 内第三方库overflow_modefor/while 循环内 return / break — Triton 结构化控制流不支持 early exit(含子函数中的 return)tensor[i] 索引操作(读取/赋值/切片)— 用 tl.where / tl.gather / tl.extract_slice 替代按 code-review-report-template.md 格式输出报告。
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/external-gitcode-ascend-skills:external-gitcode-ascend-triton-operator-code-reviewfrom 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