Triton Operator Performance Optim logo

Triton Operator Performance Optim

Organization
Ascend
triton-operator-performance-optim

优化 Ascend NPU 亲和的 Triton 算子性能。解决 UB 溢出、提高 Cube 利用率、Tiling 策略设计。关键词:性能优化、performance optimization、tiling、UB。

Overview

PublisherAscend
Repositoryagent-skills
Skill nametriton-operator-performance-optim
Stars
54
Forks
4
Bundled files
2
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.

  • 2 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 Performance Optim 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-performance-optim
  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-performance-optim .claude/skills/triton-operator-performance-optim
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Triton Operator Performance Optim 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 Performance Optim 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 Performance Optim 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)

底线(不可突破)

  1. 精度:优化后 rtol=1e-3, atol=1e-3 对齐 PyTorch-NPU。不通过则回退。
  2. 泛化性:支持原有所有输入形状和 dtype,不能 hardcode 特定尺寸。

性能比定义:Ratio = torch_npu 耗时 / Triton 耗时(耗时倒数)。Ratio > 1.0 表示 Triton 更快。

优先级:正确性 > 泛化性 > 性能。

优化工作流

Phase 0: 算法审视

优化前先审视算法本身。低效算法再优化也有先天不足。

Phase 1: 分层评估

  1. 快速筛选:time.time() 测端到端(覆盖小/中/大),达标则完成
  2. 精确诊断:不达标时用 msprof 测 kernel 侧耗时,定位真正瓶颈

Phase 2: 瓶颈优化

瓶颈优化重点
Memory-Bound向量化访存、UB 缓存复用、算子融合
Compute-BoundCube 适配、Block 尺寸调优
Latency-Bound增大并行度、减少同步

基础四板斧(按顺序):Block/Grid Size → 连续访存 → UB 复用 → 编译时常量

加载:optimization-patterns.md, ascend-terminology.md

Phase 3: 硬件特化

  • Cube:BLOCK_M/N/K 为 16 倍数,累加器 FP32
  • UB:缓冲区总大小 < 192KB,单值缓冲区 32B 对齐
  • Grid:1D Grid ≤ 物理核数,核内循环处理多行
  • 对角线调度:大矩阵(BLOCK_THRESHOLD 以上)使用对角线 Grid 调度提升 L2 缓存命中率
  • 多 Vector Core:post-dot 操作使用 tl.parallel(bind_sub_block=True) 分配到 2 个 vector cores

加载:triton-ascend-api.md, tiling-strategies.md, triton-api-reference.md

Phase 4: 高级优化(按需)

算子融合、Double Buffer(tl.multibuffer(tensor, 2) 或 tl.compile_hint(tensor, "multi_buffer", 2))

Phase 5: 验证(MANDATORY)

精度 + 泛化性 + 性能 + 端到端回归

反模式清单(NEVER)

  • ❌ 仅凭单一规模数据做优化决策
  • ❌ 端到端不达标时直接优化 kernel(应先 msprof 确认瓶颈)
  • ❌ 为性能牺牲精度 / hardcode 破坏泛化性
  • ❌ FP16 直接归约 / 非 16 倍数 BLOCK 做矩阵乘
  • ❌ BLOCK_SIZE 超 UB(192KB)/ 非连续访存
  • ❌ 热路径用 tensor.item()(触发 CPU-NPU 同步)
  • ❌ 循环内用 if 分支修改变量(Triton 编译为 masked 操作,灾难性性能下降)
  • ❌ 2D Tiling 只算数据 buffer 的 UB(必须包含 offset/mask/index 数组)
  • ❌ 用预计算的 offset tensor 做 2D broadcasting(触发编译器 addptr 多用户 assertion)
  • ❌ kernel 内用 broadcast stride 访问辅助张量(cos/sin 等),应改为 host 侧 expand+contiguous。expand 额外内存 < 非连续访存的性能损失
  • ❌ 归约类算子用双 pass(多次 load 同一数据分别算统计量和归一化)——应单 pass,一次 load 后 UB 内全计算,详见踩坑 8
  • ❌ msprof 对比时两个 kernel 同名——msprof 按 OP Type 聚合,同名会混在一起
  • ❌ 大矩阵不用对角线调度(L2 缓存颠簸,BLOCK_THRESHOLD 以上必须启用)

检查清单

  • 精度对齐 PyTorch-NPU(rtol=1e-3, atol=1e-3)
  • 非对齐维度和边界通过
  • 性能测试覆盖小/中/大
  • grid ≤ 物理核数,BLOCK_SIZE 为编译时常量
  • 缓冲区 < 192KB,所有 load/store 有 Mask
  • 归约升 FP32,矩阵乘 BLOCK 为 16 倍数
  • 归约类算子是否单 pass(D ≤ UB 时必须)

常见瓶颈速查

msprof 指标瓶颈典型优化
aiv_scalar > 80%Scalar Bound检查双 pass / 逐行循环+tl.where 累加,改单 pass
aiv_mte2 > 50%Memory Bound连续访存、expand+contiguous、增大 BLOCK
aiv_vec > 50%Compute Bound算法优化、减少冗余计算
aic_cube_ratio < 50%Cube 利用率低检查对齐(512B/元素大小)、BLOCK 是否 16 倍数、用 compile_hint('dot_pad_only_k')

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 Performance Optim AI skill do?

优化 Ascend NPU 亲和的 Triton 算子性能。解决 UB 溢出、提高 Cube 利用率、Tiling 策略设计。关键词:性能优化、performance optimization、tiling、UB。

Why use Triton Operator Performance Optim on TypingMind?

Because you install it once and use it with any model. Triton Operator Performance Optim 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 Performance Optim in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/Ascend/agent-skills/tree/master/skills/triton-operator-performance-optim. 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 Performance Optim?

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 Performance Optim?

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

Is the Triton Operator Performance Optim 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 👇