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-case-matmul-swizzle2dgit 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-case-matmul-swizzle2d)<a href="https://agentmods.dev/skills/mindspore-ai/akg/triton-ascend-case-matmul-swizzle2d"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/triton-ascend-case-matmul-swizzle2d/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-case-matmul-swizzle2d"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/triton-ascend-case-matmul-swizzle2d.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.00088 | $0.01017 |
| Opus 5 | $0.00044 | $0.00508 |
| Sonnet 5 | $0.00018 | $0.00203 |
| Haiku 4.5 | $0.00009 | $0.00102 |
Grade A, and why
triton-ascend-case-matmul-swizzle2d 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 13d 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 — 96 lines — stays where its author put it; the contents beside it link to each section on GitHub.
矩阵乘法 Swizzle2D 优化案例
任务特征
- 操作类型:矩阵乘法 A[M, K] @ B[K, N] = C[M, N]
- 数据尺寸:A[2048, 7168] @ B[7168, 16384] = C[2048, 16384]
- 特点:计算密集型,核心分配策略对缓存命中率和负载均衡影响显著
优化 1:固定核心数启动(最重要!)
错误:错误:启动所有块
grid = (NUM_BLOCKS_M * NUM_BLOCKS_N,) # 启动1024个程序
正确:正确:固定核心数启动
num_cores = 20 # Ascend 910B4有20个AI Core
@triton.jit
def matmul_kernel(..., num_cores: tl.constexpr):
pid = tl.program_id(axis=0) # 0~19
NUM_BLOCKS = NUM_BLOCKS_M * NUM_BLOCKS_N
# 每个核心循环处理多个块
for block_idx in range(pid, NUM_BLOCKS, num_cores):
# 处理块...
pass
matmul_kernel[(num_cores,)](...) # grid=(20,)
核心要点:Ascend NPU必须使用固定核心数启动,每个核心循环处理多个块。
优化 2:Swizzle2D 块重排
@triton.jit
def matmul_kernel_swizzle2d(..., GROUP_SIZE: tl.constexpr, DIRECTION: tl.constexpr):
for block_idx in range(pid, NUM_BLOCKS, num_cores):
block_m = block_idx // NUM_BLOCKS_N
block_n = block_idx % NUM_BLOCKS_N
if DIRECTION == 0: # M≥N: 行优先分组
task_m_idx, task_n_idx = tl.swizzle2d(
block_m, block_n, NUM_BLOCKS_M, NUM_BLOCKS_N, GROUP_SIZE
)
else: # M<N: 列优先分组(手动实现)
size_gj = GROUP_SIZE * NUM_BLOCKS_M
group_id = block_idx // size_gj
off_n = group_id * GROUP_SIZE
cur_size_g = tl.minimum(NUM_BLOCKS_N - off_n, GROUP_SIZE)
local_ij = block_idx % size_gj
task_m_idx = local_ij // cur_size_g
task_n_idx = off_n + local_ij % cur_size_g
优化内容
- Swizzle2D通过GROUP_SIZE将块按组重排,组内块共享数据
- GROUP_SIZE推荐值为4,可通过autotune搜索[1,2,3,4,5,8]
优化 3:矩阵形状自适应
DIRECTION = 1 if m < n else 0 # M<N列优先, M≥N行优先
- M≥N时:行优先分组,减少mat_a重复加载
- M<N时:列优先分组,减少mat_b重复加载
优化 4:分块大小选择
# float16/bfloat16
BLOCK_M, BLOCK_K, BLOCK_N = 128, 256, 256
# float32
BLOCK_M, BLOCK_K, BLOCK_N = 128, 128, 128
总结
- 固定核心数启动:
grid=(20,),每个核心循环处理多个块 - Swizzle2D 重排:通过块分组提升缓存局部性
- 自适应分组方向:根据M/N比例选择行优先或列优先
- 合适的分块大小:根据数据类型和缓存容量选择
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.
- 13d ago First seen · 96 lines · 88 tokens per session scan A 9278a8853a73
triton-ascend-case-matmul-swizzle2d is a skill published in the GitHub repository mindspore-ai/akg (259 stars, last pushed 1mo ago), licensed Apache-2.0. It adds 88 tokens to every session and 1,017 once invoked, about $0.0004 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-08-30.
Other skills, from other repositories
text-transformer
Text encoding, decoding, and transformation utilities - Base64, URL, HTML, hashing, case conversion, and string manipulation.
triton-ascend-case-reduction-amin-atomic
A case study for optimizing amin reductions with atomic operations when the non-reduced dimension is small and the reduced dimension is very large. An amin reduction finds the smallest value.
triton-ascend-case-matmul-large-k
A case study for optimizing matrix multiplication when the shared K dimension is much larger than the output dimensions. It uses Split-K to divide that dimension across cores, then combines the partial results.
triton-ascend-case-elemwise-concat
A guide to combining slicing and concatenation operations in Triton Ascend kernels, which are GPU programs. It describes loading only needed data and calculating joined indexes without a separate concatenation step.
triton-ascend-case-index-histogram
A case study for speeding up histogram calculations, which count how many values fall into each group or range.
triton-ascend-case-matmul-swizzle2d
A case study for optimizing matrix multiplication in Triton on Ascend hardware using 2D block swizzling and a fixed number of cores.