triton-cuda-matmul

triton-cuda-matmul is a skill for Claude Code, Codex from mindspore-ai/akg. It costs 73 tokens per session (2,601 once invoked), scanned A, original, Apache-2.0.

A guide to speeding up matrix multiplication, including ordinary, batched, and linear-layer operations, on CUDA GPUs. It covers tiling, shared-memory caching, and Tensor Cores, specialized GPU units for matrix calculations.

In plain words
What is it for?
Use it when implementing Triton kernels for GEMM, batched matrix multiplication, or fully connected layers.
Why use it?
Matrix multiplication often dominates the runtime of machine-learning models. The guide helps choose block layouts and hardware features that suit the matrix size.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it when implementing Triton kernels for GEMM, batched matrix multiplication, or fully connected layers.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/mindspore-ai/akg/triton-cuda-matmul
Install

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.

Any agent
npx skills add mindspore-ai/akg --skill triton-cuda-matmul
Clone the repo
git clone --depth 1 https://github.com/mindspore-ai/akg

Made for: Claude Code, Codex.

Wrote 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.

agentmods badge for triton-cuda-matmul

README.md
[![agentmods](https://agentmods.dev/badge/skills/mindspore-ai/akg/triton-cuda-matmul/github.svg)](https://agentmods.dev/skills/mindspore-ai/akg/triton-cuda-matmul)
Your own site
<a href="https://agentmods.dev/skills/mindspore-ai/akg/triton-cuda-matmul"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/triton-cuda-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.

agentmods 80×15 button for triton-cuda-matmul

Your own site · 80×15
<a href="https://agentmods.dev/skills/mindspore-ai/akg/triton-cuda-matmul"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/triton-cuda-matmul.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 73 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,601 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

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.

ModelPer sessionOnce invoked
Fable 5.1 $0.00073 $0.02601
Opus 5 $0.00036 $0.01300
Sonnet 5 $0.00015 $0.00520
Haiku 4.5 $0.00007 $0.00260

Measured 8d ago against content hash b50f6e6ed4f5, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-11, from the pricing page.

Security

Grade A, and why

triton-cuda-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 8d 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.

akg_agents/python/akg_agents/op/resources/skills/triton-cuda/guides/triton-cuda-matmul/SKILL.md · 258 lines

How it starts

The opening of the file, as written. The whole thing — 258 lines — stays where its author put it; the contents beside it link to each section on GitHub.

MatMul 算子优化

适用于矩阵乘法及相关运算

CUDA GPU MatMul 优化核心

Tensor Core 利用

  • Ampere (A100): 支持 FP16, BF16, TF32, INT8 Tensor Core
  • Hopper (H100): 额外支持 FP8, wgmma 指令
  • 关键: tl.dot(a, b, allow_tf32=True) 启用 TF32 Tensor Core

分块配置建议

常用配置(2 的幂次):

配置 BLOCK_M BLOCK_N BLOCK_K num_warps num_stages 适用场景
小矩阵 64 64 32 4 4 M, N < 1024
中矩阵 128 128 32 4 3 M, N < 4096
大矩阵 128 256 64 8 3 M, N >= 4096
高 K 64 128 64 4 4 K 很大

标准 MatMul Kernel(使用 block_ptr)

@triton.jit
def matmul_kernel(
    a_ptr, b_ptr, c_ptr,
    M, N, K,
    stride_am, stride_ak,
    stride_bk, stride_bn,
    stride_cm, stride_cn,
    BLOCK_SIZE_M: tl.constexpr,
    BLOCK_SIZE_N: tl.constexpr,
    BLOCK_SIZE_K: tl.constexpr,
):
    pid = tl.program_id(0)
    num_pid_m = tl.cdiv(M, BLOCK_SIZE_M)
    num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)
    
    # 2D 索引计算
    pid_m = pid // num_pid_n
    pid_n = pid % num_pid_n
    
    # 创建 block pointers
    a_block_ptr = tl.make_block_ptr(
        base=a_ptr,
        shape=(M, K),
        strides=(stride_am, stride_ak),
        offsets=(pid_m * BLOCK_SIZE_M, 0),
        block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_K),
        order=(1, 0)
    )
    
    b_block_ptr = tl.make_block_ptr(
        base=b_ptr,
        shape=(K, N),
        strides=(stride_bk, stride_bn),
        offsets=(0, pid_n * BLOCK_SIZE_N),
        block_shape=(BLOCK_SIZE_K, BLOCK_SIZE_N),
        order=(1, 0)
    )
    
    # 使用 float32 累加器
    accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)
    
    # K 维度循环
    for k in range(0, K, BLOCK_SIZE_K):
        a = tl.load(a_block_ptr, boundary_check=(0, 1))
        b = tl.load(b_block_ptr, boundary_check=(0, 1))
        accumulator += tl.dot(a, b)
        
        # 移动 block pointers
        a_block_ptr = tl.advance(a_block_ptr, (0, BLOCK_SIZE_K))
        b_block_ptr = tl.advance(b_block_ptr, (BLOCK_SIZE_K, 0))
    
    # 存储结果(需显式转换类型,匹配输出 dtype)
    c = accumulator.to(c_ptr.dtype.element_ty)
    c_block_ptr = tl.make_block_ptr(
        base=c_ptr,
        shape=(M, N),
        strides=(stride_cm, stride_cn),
        offsets=(pid_m * BLOCK_SIZE_M, pid_n * BLOCK_SIZE_N),
        block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_N),
        order=(1, 0)
    )
    tl.store(c_block_ptr, c, boundary_check=(0, 1))

Read the full file on GitHub · 258 lines

Changes

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.

  1. 8d ago First seen · 258 lines · 73 tokens per session scan A b50f6e6ed4f5

Subscribe to this mod's changes

triton-cuda-matmul is a skill published in the GitHub repository mindspore-ai/akg (259 stars, last pushed 1mo ago), licensed Apache-2.0. It adds 73 tokens to every session and 2,601 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-09-03.