triton-cuda-patterns

triton-cuda-patterns is a skill for Claude Code, Codex from mindspore-ai/akg. It costs 70 tokens per session (1,789 once invoked), scanned A, original, Apache-2.0.

A set of standard Triton CUDA programming patterns for vector operations, reductions, and matrix multiplication. It provides reusable structures for indexing, masked memory access, aggregation, and tiled computation.

In plain words
What is it for?
Use it to identify whether an operation is element-wise, a reduction, or a matrix multiplication, then adapt the matching kernel pattern.
Why use it?
Starting GPU kernels from scratch makes common indexing and boundary mistakes easy to repeat. These templates give a clear structure for the three main kinds of tensor work.

Skill for Claude CodeCodex

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

Good fit Use it to identify whether an operation is element-wise, a reduction, or a matrix multiplication, then adapt the matching kernel pattern.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/mindspore-ai/akg/triton-cuda-patterns
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-patterns
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-patterns

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

Your own site · 80×15
<a href="https://agentmods.dev/skills/mindspore-ai/akg/triton-cuda-patterns"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/triton-cuda-patterns.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 70 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,789 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.00070 $0.01789
Opus 5 $0.00035 $0.00894
Sonnet 5 $0.00014 $0.00358
Haiku 4.5 $0.00007 $0.00179

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

Security

Grade A, and why

triton-cuda-patterns 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.

akg_agents/python/akg_agents/op/resources/skills/triton-cuda/guides/triton-cuda-patterns/SKILL.md · 194 lines

How it starts

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

Triton CUDA 编程模式

3.1 向量操作模式

适用于元素级运算:加法、乘法、激活函数等。

标准代码结构

@triton.jit
def vector_add_kernel(a_ptr, b_ptr, c_ptr, n_elements, BLOCK_SIZE: tl.constexpr):
    pid = tl.program_id(0)
    offsets = pid * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)
    mask = offsets < n_elements
    
    a = tl.load(a_ptr + offsets, mask=mask)
    b = tl.load(b_ptr + offsets, mask=mask)
    c = a + b
    
    tl.store(c_ptr + offsets, c, mask=mask)

适用算子

  • 算术运算: add, mul, sub, div
  • 激活函数: relu, sigmoid, tanh(需用 tl.extra.cuda.libdevice.tanh), gelu
  • 数学函数: exp, log, sqrt, pow

关键要点

  • 使用一维索引和偏移
  • 边界处理用 mask
  • 简单直接的数据流:加载 → 计算 → 存储

3.2 归约模式

适用于求和、最大值、最小值等聚合操作。

标准代码结构

@triton.jit
def reduction_kernel(input_ptr, output_ptr, n_elements, BLOCK_SIZE: tl.constexpr):
    pid = tl.program_id(0)
    offsets = pid * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)
    mask = offsets < n_elements
    
    # 加载数据
    data = tl.load(input_ptr + offsets, mask=mask, other=0.0)
    
    # 块内归约
    block_sum = tl.sum(data, axis=0)
    
    # 原子操作写回全局内存
    tl.atomic_add(output_ptr, block_sum)

适用算子

  • 基础归约: sum, mean, max, min
  • 归一化: softmax, logsoftmax, layernorm, batchnorm
  • 统计: variance, std

关键要点

  • 块内归约:使用 tl.sum, tl.max
  • 原子操作:使用 tl.atomic_add 等写回全局内存
  • 数值稳定性:减去最大值防止溢出(见 triton-cuda-reduce)

3.3 矩阵乘法模式

适用于矩阵乘法等多维块计算。

标准代码结构

@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,
):
    # 获取程序 ID
    pid_m = tl.program_id(0)
    pid_n = tl.program_id(1)

    # 初始化累加器
    accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)

    # K 维度循环
    for k in range(0, K, BLOCK_SIZE_K):
        # 创建块指针
        a_block_ptr = tl.make_block_ptr(
            base=a_ptr, shape=(M, K), strides=(stride_am, stride_ak),
            offsets=(pid_m * BLOCK_SIZE_M, k),
            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=(k, pid_n * BLOCK_SIZE_N),
            block_shape=(BLOCK_SIZE_K, BLOCK_SIZE_N), order=(1, 0)
        )

        # 加载数据块
        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)

    # 存储结果(需显式转换类型,匹配输出 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 · 194 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. 9d ago First seen · 194 lines · 70 tokens per session scan A bccd4d792cfd

Subscribe to this mod's changes

triton-cuda-patterns is a skill published in the GitHub repository mindspore-ai/akg (259 stars, last pushed 1mo ago), licensed Apache-2.0. It adds 70 tokens to every session and 1,789 once invoked, about $0.0003 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.

Related

Other skills, from other repositories

agent-platform-rag-engine-management

Manage and query Agent Platform RAG Engine Corpora and retrieve grounded contexts using the Google GenAI SDK. Use when listing RAG corpora or files, inspecting a corpus, retrieving contexts, or generating content grounded in a RAG corpus. Do not use for standard database queries (use SQL/Spanner skills), Google…

google/skills · 85 tokens

agent-platform-model-registry

Agent Platform Model Registry Management. Use when you need to upload, list, describe, update, or delete machine learning models (and their versions) in the Agent Platform Model Registry. Don't use for model training, model deployment to endpoints, or managing non-Agent Platform models.

google/skills · 60 tokens

foundry-config-setup

Resolve missing setup caused by a hardcoded Foundry project endpoint or model in a sample. Use when a sample fails because it uses a placeholder/hardcoded projectendpoint (for example "https://your-project.services.ai.azure.com") or a hardcoded model instead of reading them from the environment.

microsoft/agent-framework · 65 tokens

google-cloud-solution-agentic-analytics-spark-knowledge-catalog

Discovers requirements and generates guidance to design and deploy a governed, secure agentic-analytics solution for data that's distributed across Google Cloud, other cloud providers, or on-premises. Data that's outside Google Cloud (such as data from Databricks, Snowflake, Salesforce, SAP, or Oracle systems) is…

google/skills · 138 tokens

training-check

Interactively monitor training metrics from the current Codex session, periodically checking WandB or fallback logs for NaN, divergence, plateaus, and broken runs.

wanshuiyin/Auto-claude-code-research-in-sleep · 35 tokens

nemo-automodel-launcher-config

Configure NeMo AutoModel job launches for interactive runs, Slurm clusters, and SkyPilot cloud execution.

NVIDIA/skills · 30 tokens