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-matmulgit 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-matmul)<a href="https://agentmods.dev/skills/mindspore-ai/akg/triton-ascend-matmul"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/triton-ascend-matmul/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-matmul"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/triton-ascend-matmul.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.00162 | $0.01700 |
| Opus 5 | $0.00081 | $0.00850 |
| Sonnet 5 | $0.00032 | $0.00340 |
| Haiku 4.5 | $0.00016 | $0.00170 |
Grade A, and why
triton-ascend-matmul 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 9d 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 — 148 lines — stays where its author put it; the contents beside it link to each section on GitHub.
MatMul 算子优化
适用于矩阵乘法及相关运算
核心数选择(硬约束)
- 涉及
tl.dot/ 矩阵乘法运算 → 必须使用 CUBE_CORE_NUM - 混合运算(先 matmul 再 elementwise 后处理)→ CUBE_CORE_NUM
- 纯 elementwise / 标量运算 → VEC_CORE_NUM
使用 VEC_CORE_NUM 启动 matmul kernel 会导致数值结果错误。
Tile Size 限制(硬件约束)
MatMul 数据走 L0A/L0B/L0C,tile 大小受硬件存储容量限制,超出会导致 ub overflow / cbuf overflow 编译错误。
约束公式(具体容量参考目标硬件信息文档):
- L0A:
BLOCK_M × BLOCK_K × sizeof(dtype) ≤ L0A容量 - L0B:
BLOCK_K × BLOCK_N × sizeof(dtype) ≤ L0B容量 - L0C:
BLOCK_M × BLOCK_N × sizeof(acc_dtype) ≤ L0C容量
遇 ub overflow / cbuf overflow → 缩小 BLOCK_M, BLOCK_N 或 BLOCK_K
Ascend 后端切分优化
关键原则: 充分发挥带宽,算子行宽为 512B 的整数倍。
以 fp16/bf16 为例(每个元素 2 字节):
切分配置(根据转置情况)
-
A、B 都不转置
- 分块行宽分别为 K0 和 N0
- 推荐: M0=128, K0=256, N0=256
-
A 不转置,B 转置
- 分块行宽都是 K0
- 推荐: K0=256, M0 和 N0 影响较小
-
A、B 都转置
- 分块行宽分别为 M0 和 K0
- 推荐: M0=256, K0=256, N0=128
-
A 转置,B 不转置
- 分块行宽分别为 M0 和 N0
- 注意: 左右矩阵均无法同时满足 512B 的整数倍,需根据实际情况调整
为什么是 512B?
- 512B = 256 个 fp16/bf16 元素(256 × 2 字节)
- NPU 的最佳带宽对齐
- 确保每次内存访问充分利用带宽
固定核心数启动
MatMul 算子使用 CUBE核心数(矩阵计算核心)。
关键: 使用 grid=(num_cores,) 而非 (NUM_BLOCKS,)
@triton.jit
def matmul_kernel(
a_ptr, b_ptr, c_ptr,
M, N, K,
num_cores: tl.constexpr,
BLOCK_M: tl.constexpr,
BLOCK_N: tl.constexpr,
BLOCK_K: tl.constexpr,
):
# 关键:使用固定核心数启动,每个核心处理多个块
pid = tl.program_id(0) # 核心ID: 0~num_cores-1
NUM_BLOCKS_M = triton.cdiv(M, BLOCK_M)
NUM_BLOCKS_N = triton.cdiv(N, BLOCK_N)
NUM_BLOCKS = NUM_BLOCKS_M * NUM_BLOCKS_N
# 每个核心循环处理多个块
for block_idx in range(pid, NUM_BLOCKS, num_cores):
# 计算当前块的2D索引
block_m = block_idx // NUM_BLOCKS_N
block_n = block_idx % NUM_BLOCKS_N
# 初始化累加器
accumulator = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.float32)
# K维度循环
for k in range(0, K, BLOCK_K):
# 加载A块
a_offset = (block_m * BLOCK_M + tl.arange(0, BLOCK_M))[:, None] * K + \
(k + tl.arange(0, BLOCK_K))[None, :]
a_mask = (block_m * BLOCK_M + tl.arange(0, BLOCK_M))[:, None] < M
a = tl.load(a_ptr + a_offset, mask=a_mask, other=0.0)
# 加载B块
b_offset = (k + tl.arange(0, BLOCK_K))[:, None] * N + \
(block_n * BLOCK_N + tl.arange(0, BLOCK_N))[None, :]
b_mask = (block_n * BLOCK_N + tl.arange(0, BLOCK_N))[None, :] < N
b = tl.load(b_ptr + b_offset, mask=b_mask, other=0.0)
# 矩阵乘累加
accumulator += tl.dot(a, b)
# 存储结果
c_offset = (block_m * BLOCK_M + tl.arange(0, BLOCK_M))[:, None] * N + \
(block_n * BLOCK_N + tl.arange(0, BLOCK_N))[None, :]
c_mask = ((block_m * BLOCK_M + tl.arange(0, BLOCK_M))[:, None] < M) & \
((block_n * BLOCK_N + tl.arange(0, BLOCK_N))[None, :] < N)
tl.store(c_ptr + c_offset, accumulator, mask=c_mask)
class ModelNew(torch.nn.Module):
def __init__(self):
super().__init__()
try:
self.CUBE_CORE_NUM = torch_npu.npu.npu_config.get_device_limit(0).get("cube_core_num", 20)
except:
self.CUBE_CORE_NUM = 20
def forward(self, a, b):
M, K = a.shape
K2, N = b.shape
assert K == K2
c = torch.empty((M, N), device=a.device, dtype=a.dtype)
num_cores = self.CUBE_CORE_NUM
BLOCK_M, BLOCK_N, BLOCK_K = 128, 256, 256
matmul_kernel[(num_cores,)](
a, b, c, M, N, K, num_cores,
BLOCK_M, BLOCK_N, BLOCK_K
)
return c
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.
- 9d ago First seen · 148 lines · 162 tokens per session scan A 4b90502e8803
triton-ascend-matmul is a skill published in the GitHub repository mindspore-ai/akg (259 stars, last pushed 1mo ago), licensed Apache-2.0. It adds 162 tokens to every session and 1,700 once invoked, about $0.0008 per session on Opus 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.
Other skills, from other repositories
fs-notebook-tabs
A computer-science capstone: an on-device ML keyboard that predicts next words privately — problem, method, evaluation, and defense answers. Built as a decision-grade coursework defense deck for professor, defense committee.
implementing-llms-litgpt
Implements and trains LLMs using Lightning AI's LitGPT with 20+ pretrained architectures (Llama, Gemma, Phi, Qwen, Mistral). Use when need clean model implementations, educational understanding of architectures, or production fine-tuning with LoRA/QLoRA. Single-file implementations, no abstraction layers.
nanogpt
Educational GPT implementation in 300 lines. Reproduces GPT-2 (124M) on OpenWebText. Clean, hackable code for learning transformers. By Andrej Karpathy. Perfect for understanding GPT architecture from scratch. Train on Shakespeare (CPU) or OpenWebText (multi-GPU).
rwkv-architecture
RNN+Transformer hybrid with O(n) inference. Linear time, infinite context, no KV cache. Train like GPT (parallel), infer like RNN (sequential). Linux Foundation AI project. Production at Windows, Office, NeMo. RWKV-7 (March 2025). Models up to 14B parameters.
lesson-quiz
Test a learner on a single Claude Code tutorial lesson (01-10) with 10 questions, scoring answers and flagging weak spots. Use before, during, or after a lesson. Don't use for whole-tutorial assessment or explaining a topic instead of testing it.
kaggle-learner
This skill should be used when the user asks to "learn from Kaggle", "study Kaggle solutions", "analyze Kaggle competitions", or mentions Kaggle competition URLs. Provides access to extracted knowledge from winning Kaggle solutions across NLP, CV, time series, tabular, and multimodal domains.