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-cuda-grid-configgit 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-cuda-grid-config)<a href="https://agentmods.dev/skills/mindspore-ai/akg/triton-cuda-grid-config"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/triton-cuda-grid-config/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-cuda-grid-config"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/triton-cuda-grid-config.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.00065 | $0.01986 |
| Opus 5 | $0.00032 | $0.00993 |
| Sonnet 5 | $0.00013 | $0.00397 |
| Haiku 4.5 | $0.00006 | $0.00199 |
Grade A, and why
triton-cuda-grid-config 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.
How it starts
The opening of the file, as written. The whole thing — 271 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Grid 配置策略
Grid 配置是 Triton Kernel 启动的关键。本文档提供 Triton CUDA 的 Grid 配置策略和大 shape 处理方案。
1. Grid 设置规范
维度格式
- Grid 必须是 tuple 类型,最多 3 维
- 支持的格式:
(x,),(x, y),(x, y, z)
# 正确
grid = (100,)
grid = (100, 200)
grid = (100, 200, 50)
# 错误
grid = 100 # 必须是 tuple
grid = [100, 200] # 必须是 tuple,不能是 list
使用 lambda(autotune 场景)
当使用 autotune 时,grid 必须使用 lambda:
# autotune 时必须使用 lambda
grid = lambda meta: (triton.cdiv(M, meta['BLOCK_SIZE_M']) * triton.cdiv(N, meta['BLOCK_SIZE_N']),)
# 非 autotune 时可以直接计算
grid = (triton.cdiv(n_elements, BLOCK_SIZE),)
2. 1D Grid 配置
Element-wise 算子
最常见的配置方式:每个 block 处理 BLOCK_SIZE 个元素。
n_elements = input_tensor.numel()
BLOCK_SIZE = 1024
grid = (triton.cdiv(n_elements, BLOCK_SIZE),)
kernel[grid](input_tensor, output_tensor, n_elements, BLOCK_SIZE=BLOCK_SIZE)
逐行处理(Reduce 类算子)
每个 block 处理一行或多行:
n_rows, n_cols = x.shape
BLOCK_SIZE = triton.next_power_of_2(n_cols)
# 方式 1:每行一个 block
grid = (n_rows,)
# 方式 2:限制并行度(grid stride loop)
num_programs = min(n_rows, 65535)
grid = (num_programs,)
3. 2D Grid 配置
MatMul 类算子
使用 2D Grid 进行行列双向并行:
BLOCK_M, BLOCK_N = 128, 256
grid_m = triton.cdiv(M, BLOCK_M)
grid_n = triton.cdiv(N, BLOCK_N)
# 方式 1:2D Grid
grid = (grid_m, grid_n)
# 方式 2:1D Grid(更灵活,支持 Grouped Ordering)
grid = (grid_m * grid_n,)
1D vs 2D Grid
| 特性 | 1D Grid | 2D Grid |
|---|---|---|
| 灵活性 | 高(支持 Grouped Ordering) | 低 |
| 代码复杂度 | 需要手动计算 pid_m, pid_n | 直接获取 |
| L2 缓存优化 | 容易实现 | 不易实现 |
| 推荐场景 | MatMul(需要缓存优化) | 简单 2D 算子 |
推荐: 对于 MatMul 类算子,使用 1D Grid + Grouped Ordering。
4. 大 Shape 处理:Grid Stride Loop
问题描述
CUDA GPU 对 grid 大小也有限制(通常 2^31 - 1 per dimension),但更重要的是,过大的 grid 会导致:
- 启动开销增加
- 资源浪费(每个 block 只处理少量数据)
Grid Stride Loop 方案
每个 block 通过循环处理多个数据块:
@triton.jit
def grid_stride_kernel(
input_ptr, output_ptr, n_elements,
BLOCK_SIZE: tl.constexpr,
):
pid = tl.program_id(0)
num_pids = tl.num_programs(0)
# Grid stride loop
for block_start in range(pid * BLOCK_SIZE, n_elements, num_pids * BLOCK_SIZE):
offsets = block_start + tl.arange(0, BLOCK_SIZE)
mask = offsets < n_elements
data = tl.load(input_ptr + offsets, mask=mask)
result = compute(data)
tl.store(output_ptr + offsets, result, mask=mask)
# 限制 grid 大小
MAX_GRID = 65535
num_blocks = min(triton.cdiv(n_elements, BLOCK_SIZE), MAX_GRID)
grid = (num_blocks,)
grid_stride_kernel[grid](input_tensor, output_tensor, n_elements, BLOCK_SIZE=1024)
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.
- 9d ago First seen · 271 lines · 65 tokens per session scan A 65e250d09b03
triton-cuda-grid-config is a skill published in the GitHub repository mindspore-ai/akg (259 stars, last pushed 1mo ago), licensed Apache-2.0. It adds 65 tokens to every session and 1,986 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.
Other skills, from other repositories
hatch3r-ai-feature
Eval-driven development workflow for shipping AI features — write eval before prompt, measure, iterate, ship with caching + cost telemetry + model fallback + hallucination SLI.
AI Integration Specialist
Integrate AI tools and APIs into business workflows and applications.
triton-cuda-reduce
A guide to writing CUDA GPU code that combines many values into results such as sums, averages, maximums, and minimums. It also covers softmax, layer normalization, and log-softmax.
triton-cuda-attention
An implementation guide for attention operations in Triton on CUDA, with a complete Flash Attention example and changes for causal, grouped-query, multi-query, and rotary-position variants.
AI Integration Specialist
Integrate AI tools and APIs into business workflows and applications.
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…