Triton Operator Code Review logo

Triton Operator Code Review

Organization
Ascend
triton-operator-code-review

静态检视 Triton 算子代码质量(Host+Device 侧),面向 Ascend NPU。发现潜在 bug、API 误用和性能隐患。仅关注静态代码分析。关键词:code review、代码检视、静态分析。

Overview

PublisherAscend
Repositoryagent-skills
Skill nametriton-operator-code-review
Stars
54
Forks
4
Bundled files
5
LicenseMulanPSL-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 5 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by Ascend on GitHub. Read the source before you install it.

Installation

Install the Triton Operator Code Review AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/Ascend/agent-skills/tree/master/skills/triton-operator-code-review
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Ascend/agent-skills.git /tmp/agent-skills
mkdir -p .claude/skills
cp -r /tmp/agent-skills/skills/triton-operator-code-review .claude/skills/triton-operator-code-review
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Triton Operator Code Review in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Triton Operator Code Review on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Triton Operator Code Review is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Triton 算子静态代码检视(Ascend NPU)

检视原则

  • Ascend 特有约束优先:聚焦硬件差异,不检查 Triton 通用知识
  • Mask 零容错:Ascend 对越界访问零容忍

严重性分级

级别含义典型问题
P0必定崩溃或错误结果Mask 遗漏、核类型错配、Atomic 循环死锁
P1高概率精度/功能问题归约未升精度、Softmax 未减 max
P2性能/可维护性冗余访存、BLOCK 未对齐

参考资源加载

阶段加载不要加载
Phase 1: Host 侧ascend-triton-api-constraints.mddtype-matrix
Phase 2: Device 侧ascend-api-dtype-matrix.mdtest-patterns
逐项核对code-review-checklist.md—
参考官方实现ascend-test-patterns.md—
确认 API 签名/参数triton-api-reference.md—

加载触发:需要确认某个 tl/libdevice API 的签名、参数或可用数据类型时,完整阅读 triton-api-reference.md。

检视工作流

Phase 1: Host 侧

检查项识别方式级别
硬编码核数grid = (20,) 等字面量P0
核类型错配含 tl.dot 的 kernel 用了 num_vectorcoreP0
矩阵乘法退化为逐元素无 tl.dot,用 Vector Core 逐元素乘加实现 matmul/GEMVP0
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。

Phase 2: Device 侧

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 — AssertionError
  • ❌ val = tensor[i] — AssertionError
  • ❌ tensor[i:j] 切片 — 编译错误

代码模式:

  • ❌ for ... : tl.atomic_cas/or/xor/and/xchg(...) — 可能死锁(P0)
  • ❌ 多核 kernel 中使用 tl.atomic_add 返回值(P0)
  • ❌ kernel 内 import numpy(P0)
  • ⚠️ tensor[i].item() 在 Host 热路径 — 触发 CPU-NPU 同步(P2)
  • ⚠️ 归约类算子存在多个 for ... : tl.load(x_ptr + ...) 循环 — 双 pass 反模式(P1)
  • ⚠️ Post-dot 操作未用 tl.parallel(bind_sub_block=True) — tl.dot 后有逐元素操作但无并行分片(P2)
  • ⚠️ 整数类型转换溢出 — tl.cast 到 int8/int16 未指定 overflow_mode(P1)

Phase 3: 性能隐患(P2)

  • 同一 ptr 多次 tl.load → 冗余 GM 访问
  • tl.arange(0, N) * stride(stride > 1)→ 非连续访存
  • pid 直接映射 block 无循环 → 负载不均
  • kernel 内对辅助张量(cos/sin 等)使用 broadcast stride 计算偏移(b * stride0 + n * stride1 + ...)→ 建议改为 host 侧 expand+contiguous,统一 row * D + col 偏移
  • 归约类算子 weight/bias 未预展开,kernel 内用 weight_ptr + ch_idx gather → 建议 host 侧展开为连续布局

反模式清单(NEVER)

Host

  • ❌ 硬编码核数 / 矩阵乘法用 num_vectorcore / BLOCK_SIZE 非 tl.constexpr
  • ❌ 矩阵乘法(含 GEMV)用 Vector Core 逐元素乘加实现——必须用 tl.dot + AI Core

Device

  • ❌ tl.load/tl.store 无 mask / tl.dot 输入 int32/int16/int64 / dot_scaled
  • ❌ atomic_or/xor/and/xchg/cas 在 for 循环内 / kernel 内第三方库
  • ❌ FP16/BF16 归约不升 FP32 / Softmax 不减 max
  • ❌ 整数截断 cast 未指定 overflow_mode
  • ❌ for/while 循环内 return / break — Triton 结构化控制流不支持 early exit(含子函数中的 return)
  • ❌ tensor[i] 索引操作(读取/赋值/切片)— 用 tl.where / tl.gather / tl.extract_slice 替代

输出

按 code-review-report-template.md 格式输出报告。

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Triton Operator Code Review AI skill do?

静态检视 Triton 算子代码质量(Host+Device 侧),面向 Ascend NPU。发现潜在 bug、API 误用和性能隐患。仅关注静态代码分析。关键词:code review、代码检视、静态分析。

Why use Triton Operator Code Review on TypingMind?

Because you install it once and use it with any model. Triton Operator Code Review is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Triton Operator Code Review in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/Ascend/agent-skills/tree/master/skills/triton-operator-code-review. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Triton Operator Code Review?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Triton Operator Code Review?

As many as you like. As long as a model supports skills, you can use Triton Operator Code Review with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Triton Operator Code Review AI skill free?

Yes. It is published on GitHub by Ascend under the MulanPSL-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇