triton-cuda-basics

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

A beginner guide to writing Triton kernels for CUDA GPUs. It explains how GPU programs split data into blocks and use memory and threads to run work in parallel.

In plain words
What is it for?
Use it when generating or learning basic Triton CUDA kernel code, including kernel definitions, launch grids, masked loads, and stores.
Why use it?
It gives a consistent structure for writing kernels and helps avoid confusion about program IDs, grids, blocks, memory, and boundaries.

Skill for Claude CodeCodex

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

Good fit Use it when generating or learning basic Triton CUDA kernel code, including kernel definitions, launch grids, masked loads, and stores.

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

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

Your own site · 80×15
<a href="https://agentmods.dev/skills/mindspore-ai/akg/triton-cuda-basics"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/triton-cuda-basics.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 64 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,797 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.00064 $0.01797
Opus 5 $0.00032 $0.00898
Sonnet 5 $0.00013 $0.00359
Haiku 4.5 $0.00006 $0.00180

Measured 7d ago against content hash 8d424034bcd8, 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-basics 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 7d 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-basics/SKILL.md · 179 lines

How it starts

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

Triton CUDA 编程基础

1. 核心概念

内核 (Kernel)

  • 定义: 使用 @triton.jit 装饰的 Python 函数,编译后在 GPU 上并行执行
  • 特点: 每个内核实例处理数据的一个子集,通过程序 ID 区分

网格 (Grid) 与块 (Block)

  • 网格: 内核启动时的并行维度配置,如 (num_blocks_x, num_blocks_y)
  • : 每个程序实例处理的数据块大小,如 BLOCK_SIZE = 1024
  • 关系: grid_size = ceil(total_elements / block_size)

内存层次

  • 全局内存 (Global Memory): 主内存(HBM),所有程序可访问,延迟高,带宽大
  • 共享内存 (Shared Memory): SM 内共享,延迟低,容量有限(通常 48-164 KB/SM)
  • 寄存器 (Registers): 每个线程私有,最快访问

CUDA GPU 架构要点

  • SM (Streaming Multiprocessor): GPU 基本计算单元
  • Warp: 32 个线程为一组并行执行
  • Tensor Core: 专用矩阵计算单元(Ampere/Hopper 架构)

2. 标准内核结构(五步模式)

所有 Triton 内核都遵循相同的五步结构模式:

@triton.jit
def standard_kernel(
    output_ptr, input_ptr, n_elements, 
    BLOCK_SIZE: tl.constexpr,
):
    # 1. 获取程序 ID 和计算偏移
    pid = tl.program_id(0)
    offsets = pid * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)
    
    # 2. 创建边界掩码
    mask = offsets < n_elements
    
    # 3. 加载数据
    data = tl.load(input_ptr + offsets, mask=mask)
    
    # 4. 执行计算
    result = compute_function(data)
    
    # 5. 存储结果
    tl.store(output_ptr + offsets, result, mask=mask)

3. 内核启动方式

函数形式

def launch_kernel(input_tensor, output_tensor):
    BLOCK_SIZE = 1024  
    grid = (triton.cdiv(input_tensor.numel(), BLOCK_SIZE),)
    
    kernel[grid](
        output_tensor, input_tensor, input_tensor.numel(),
        BLOCK_SIZE=BLOCK_SIZE,
    )

ModelNew 类格式(推荐)

class ModelNew(torch.nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, input_tensor):
        output_tensor = torch.empty_like(input_tensor)
        BLOCK_SIZE = 1024  
        grid = (triton.cdiv(input_tensor.numel(), BLOCK_SIZE),)
        
        kernel[grid](
            output_tensor, input_tensor, input_tensor.numel(),
            BLOCK_SIZE=BLOCK_SIZE,
        )
        return output_tensor

4. 边界处理

使用 mask 处理边界

# 基本边界检查
offsets = pid * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)
mask = offsets < n_elements
data = tl.load(ptr + offsets, mask=mask, other=0.0)

Read the full file on GitHub · 179 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. 7d ago First seen · 179 lines · 64 tokens per session scan A 8d424034bcd8

Subscribe to this mod's changes

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