triton-cuda-memory

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

A guide to improving how Triton CUDA kernels read and arrange data in GPU memory. It covers shared memory, continuous access, avoiding bank conflicts, and data layouts.

In plain words
What is it for?
Use it when writing or tuning Triton kernels that process large datasets or are limited by global-memory speed.
Why use it?
Poor memory access can leave a GPU waiting instead of computing. This guide helps identify and reduce memory bandwidth bottlenecks.

Skill for Claude CodeCodex

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

Good fit Use it when writing or tuning Triton kernels that process large datasets or are limited by global-memory speed.

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

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

Your own site · 80×15
<a href="https://agentmods.dev/skills/mindspore-ai/akg/triton-cuda-memory"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/triton-cuda-memory.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 66 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,085 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.00066 $0.02085
Opus 5 $0.00033 $0.01043
Sonnet 5 $0.00013 $0.00417
Haiku 4.5 $0.00007 $0.00209

Measured 9d ago against content hash 5f84e9e00afc, 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-memory 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-memory/SKILL.md · 245 lines

How it starts

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

内存访问优化

内存访问是 GPU 性能的关键瓶颈。本文档提供 Triton CUDA 的内存访问优化策略。


1. GPU 内存层次

内存带宽和延迟

内存类型 带宽 (A100) 延迟 容量
寄存器 ~19 TB/s 1 cycle 256 KB/SM
共享内存 ~19 TB/s ~20 cycles 164 KB/SM
L2 缓存 ~5 TB/s ~100 cycles 40 MB
全局内存 (HBM) ~2 TB/s ~400 cycles 40/80 GB

优化原则

  • 减少全局内存访问: 利用共享内存和寄存器
  • 合并访问 (Coalesced Access): 同一 warp 内线程访问连续地址
  • 提高 L2 缓存命中率: 通过 Grouped Ordering 等技术

2. 合并访问 (Coalesced Access)

什么是合并访问?

当同一 warp 中的 32 个线程访问连续的内存地址时,GPU 可以将这些请求合并为一次或少量内存事务,大幅提高带宽利用率。

# 正确:合并访问(连续地址)
@triton.jit
def coalesced_kernel(input_ptr, output_ptr, n, BLOCK_SIZE: tl.constexpr):
    pid = tl.program_id(0)
    offsets = pid * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)  # 连续偏移
    mask = offsets < n
    data = tl.load(input_ptr + offsets, mask=mask)
    tl.store(output_ptr + offsets, data, mask=mask)

# 错误:非合并访问(跳跃地址)
@triton.jit
def strided_kernel(input_ptr, output_ptr, n, stride, BLOCK_SIZE: tl.constexpr):
    pid = tl.program_id(0)
    offsets = pid * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)
    # 每个线程跳跃 stride 个元素,导致非合并访问
    strided_offsets = offsets * stride
    mask = strided_offsets < n
    data = tl.load(input_ptr + strided_offsets, mask=mask)

3. 块大小选择策略

调优原则

  • 平衡并行度与资源占用,避免过大或过小
  • BLOCK_SIZE 常用值:128, 256, 512, 1024
  • 过小:并行度不足,无法充分利用 warp
  • 过大:寄存器/共享内存溢出,occupancy 下降

推荐设置

  • Element-wise 算子:BLOCK_SIZE = 1024 或 512
  • Reduce 算子:BLOCK_SIZE = triton.next_power_of_2(n_cols)
  • MatMul 算子:BLOCK_M = 128, BLOCK_N = 128, BLOCK_K = 32-64

4. 2D 数据内存访问优化

优先使用 tl.make_block_ptr

对于 2D 数据(如矩阵),优先使用 tl.make_block_ptr 配合 boundary_check,可自动优化内存合并。

@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_M: tl.constexpr,
    BLOCK_N: tl.constexpr,
    BLOCK_K: tl.constexpr,
):
    pid_m = tl.program_id(0)
    pid_n = tl.program_id(1)
    
    # 创建 2D Block Pointer
    A_block_ptr = tl.make_block_ptr(
        base=A_ptr,
        shape=(M, K),
        strides=(stride_am, stride_ak),
        offsets=(pid_m * BLOCK_M, 0),
        block_shape=(BLOCK_M, BLOCK_K),
        order=(1, 0),  # Row-major
    )
    
    # 使用 boundary_check 自动处理边界
    a = tl.load(A_block_ptr, boundary_check=(0, 1))

Read the full file on GitHub · 245 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 · 245 lines · 66 tokens per session scan A 5f84e9e00afc

Subscribe to this mod's changes

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