Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx skills add mindspore-ai/akg --skill triton-ascend-performance-improvementgit clone --depth 1 https://github.com/mindspore-ai/akgWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/mindspore-ai/akg/triton-ascend-performance-improvement)<a href="https://agentmods.dev/skills/mindspore-ai/akg/triton-ascend-performance-improvement"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/triton-ascend-performance-improvement/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/skills/mindspore-ai/akg/triton-ascend-performance-improvement"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/triton-ascend-performance-improvement.svg" alt="Reviewed on agentmods" width="80" height="20"></a>- NVIDIA SkillSpector pass
What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00067 | $0.01126 |
| Opus 5.5 | $0.00027 | $0.00450 |
| Sonnet 5.5 | $0.00013 | $0.00225 |
| Haiku 4.5 | $0.00007 | $0.00113 |
Grade A, and why
triton-ascend-performance-improvement scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3mo ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 88 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Tile 尺寸选择方法
tile 尺寸需满足硬件存储约束(具体容量参考传入的硬件信息文档):
CUBE 路径 (matmul / tl.dot):tile 必须能放入 L0A/L0B/L0C
- 计算公式:
BLOCK_M × BLOCK_K × sizeof(dtype) ≤ L0A 容量 - fp32 占用是 fp16 的 2 倍,需相应缩小 tile
- K 维度按 512B 对齐可提升带宽利用率
VEC 路径 (elementwise / reduce):所有活跃 tensor 需放入 UB
- 计算公式:
BLOCK_SIZE × sizeof(dtype) × 活跃tensor数 × multi_buffer系数 ≤ UB 容量 - 编译器 auto-multi-buffer 会将占用增至 2~3 倍
- kernel 中间变量(如
tl.where产生的临时缓冲)也占用 UB
调优策略:从较大 tile 开始尝试,遇到 ub overflow / cbuf overflow 编译错误时逐级缩小。配合 @triton.autotune 自动选优。
内存加载优化
在 tl.load 时直接应用 mask 和填充值,而非先无条件加载再用 tl.where 筛选:
# 次优:先加载再 where(多一次中间操作,可能触发 vsel 编译错误)
tile = tl.zeros([BLOCK_SIZE], dtype=tl.float32)
tile = tl.where(mask, tl.load(ptr + offsets), 0.0)
# 推荐:直接在 load 时应用 mask
tile = tl.load(ptr + offsets, mask=mask, other=0.0)
隐式广播替代显式展开
需要将低维 tensor 广播到高维时,用维度扩展([:, None])利用 Triton 的隐式广播,避免 tl.broadcast_to 创建临时矩阵:
# 次优:显式展开为完整矩阵
a_broadcast = tl.broadcast_to(a_tile[:, None], (BLOCK_M, BLOCK_N))
c_tile = a_broadcast * b_tile
# 推荐:隐式广播
c_tile = a_tile[:, None] * b_tile
Reduction 最佳实践
- 标量累加器:每个核心用
core_sum = 0.0局部累加,避免 tensor 索引问题 - 单次原子写入:循环结束后
tl.atomic_add(out_ptr, core_sum)一次写入 - 避免 host 端 permute:非最后维度 reduce 直接在 kernel 内用多维索引
Host 端预计算 stride
在 host 端预先计算 tensor 的 stride 并作为参数传入 kernel,而非在 kernel 内部计算,可以减少传参错误并辅助编译器优化:
# host 端
stride_am, stride_ak = A.stride(0), A.stride(1)
kernel[grid](A_ptr, ..., stride_am, stride_ak, ...)
多 Pass 合并为单 Pass
当算子对同一数据进行多次独立遍历时(如 softmax 的 max→exp_sum→normalize,或 topk 的多次扫描),应合并为单次遍历。每减少一次 HBM 读取,理论上可获得等比例加速。多 pass 合并对归约维度较小(能放入单个 BLOCK)的场景效果最佳。
Strided 访问模式重构
当算子涉及非连续的 strided 访问(如需要访问相邻元素的配对计算),应重构数据加载策略:
- 改为按语义分组处理,使相关元素落在同一 block 内
- 避免
flat_idx % D+ 跨 stride 的随机访问 - 连续加载后在块内处理配对关系,利用数据局部性
Ascend 硬件对非连续访问有显著性能惩罚,重构后性能差距可达数倍至数十倍。
Normalization 两阶段优于单 Pass
对于 LayerNorm/RMSNorm 类算子,两阶段方案(第一遍统计 mean/var,第二遍归一化)通常优于单 pass(在线统计)。 原因:单 pass 循环体内活跃 tensor 增多,UB 压力增大,编译器流水线优化效率下降。实测中 2-pass 比单 pass 快约 20%。
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 3mo ago First seen · 88 lines · 67 tokens per session scan A afe73dc7f4eb
triton-ascend-performance-improvement is a skill published in the GitHub repository mindspore-ai/akg (269 stars, last pushed today), licensed Apache-2.0. It adds 67 tokens to every session and 1,126 once invoked, about $0.0003 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.
triton-ascend-performance-improvement compared with skills from other repositories
| Mod | Type | Stars | Last push | Licence | Scan | Tokens | Works with |
|---|---|---|---|---|---|---|---|
| triton-ascend-performance-improvementmindspore-ai/akg | Skill | 269 | today | Apache-2.0 | A | 67 | Claude Code, Codex |
| automatic-stateful-prompt-improvercuriositech/windags-skills | Skill | 21 | 6d ago | none | A | 102 | Claude Code |
| agent-platform-model-registrygoogle/skills | Skill | 25k | today | Apache-2.0 | A | 60 | Claude Code, Codex |
| llm-evaluationsickn33/agentic-awesome-skills | Skill | 51k | today | MIT | A | 25 | Claude Code |
| google-cloud-solution-agentic-analytics-spark-knowledge-cataloggoogle/skills | Skill | 25k | today | Apache-2.0 | A | 132 | Claude Code, Codex |
| training-checkwanshuiyin/Auto-claude-code-research-in-sleep | Skill | 20k | yesterday | MIT | A | 35 | Claude Code |
| tao-run-inference-serviceNVIDIA/skills | Skill | 4.3k | today | Apache-2.0 | A | 92 | Claude Code |