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-examples-torchgit 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-examples-torch)<a href="https://agentmods.dev/skills/mindspore-ai/akg/triton-cuda-examples-torch"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/triton-cuda-examples-torch/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-examples-torch"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/triton-cuda-examples-torch.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.00071 | $0.03340 |
| Opus 5 | $0.00036 | $0.01670 |
| Sonnet 5 | $0.00014 | $0.00668 |
| Haiku 4.5 | $0.00007 | $0.00334 |
Grade A, and why
triton-cuda-examples-torch 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.
How it starts
The opening of the file, as written. The whole thing — 389 lines — stays where its author put it; the contents beside it link to each section on GitHub.
PyTorch + Triton CUDA 示例代码
本 Skill 包含完整的可运行示例代码,展示如何在 PyTorch 中使用 Triton CUDA 编写高性能 kernel。
示例列表
1. Vector Add(向量加法)
算子类型: Element-wise 关键点:
- 最简单的 Triton kernel 示例
- 一维索引和 mask
- 标准五步模式
import torch
import triton
import triton.language as tl
@triton.jit
def add_kernel(x_ptr, y_ptr, output_ptr, n_elements, BLOCK_SIZE: tl.constexpr):
"""Triton 向量相加内核,每个程序处理 BLOCK_SIZE 个元素"""
pid = tl.program_id(axis=0)
block_start = pid * BLOCK_SIZE
offsets = block_start + tl.arange(0, BLOCK_SIZE)
mask = offsets < n_elements
x = tl.load(x_ptr + offsets, mask=mask)
y = tl.load(y_ptr + offsets, mask=mask)
output = x + y
tl.store(output_ptr + offsets, output, mask=mask)
class ModelNew(torch.nn.Module):
def __init__(self):
super().__init__()
def forward(self, x: torch.Tensor, y: torch.Tensor):
output = torch.empty_like(x)
n_elements = output.numel()
grid = lambda meta: (triton.cdiv(n_elements, meta['BLOCK_SIZE']),)
add_kernel[grid](x, y, output, n_elements, BLOCK_SIZE=1024)
return output
2. Softmax
算子类型: Reduce 关键点:
- 数值稳定化(减去最大值)
- 逐行处理,grid stride loop
tl.range和tl.num_programs配合使用
import torch
import triton
import triton.language as tl
@triton.jit
def softmax_kernel(output_ptr, input_ptr, input_row_stride, output_row_stride,
n_rows, n_cols, BLOCK_SIZE: tl.constexpr):
row_start = tl.program_id(0)
row_step = tl.num_programs(0)
for row_idx in tl.range(row_start, n_rows, row_step):
row_start_ptr = input_ptr + row_idx * input_row_stride
col_offsets = tl.arange(0, BLOCK_SIZE)
input_ptrs = row_start_ptr + col_offsets
mask = col_offsets < n_cols
row = tl.load(input_ptrs, mask=mask, other=-float('inf'))
# 数值稳定性
row_minus_max = row - tl.max(row, axis=0)
numerator = tl.exp(row_minus_max)
denominator = tl.sum(numerator, axis=0)
softmax_output = numerator / denominator
output_row_start_ptr = output_ptr + row_idx * output_row_stride
output_ptrs = output_row_start_ptr + col_offsets
tl.store(output_ptrs, softmax_output, mask=mask)
class ModelNew(torch.nn.Module):
def __init__(self):
super().__init__()
def forward(self, x):
n_rows, n_cols = x.shape
BLOCK_SIZE = triton.next_power_of_2(n_cols)
y = torch.empty_like(x)
num_programs = min(32, n_rows)
softmax_kernel[(num_programs, 1, 1)](
y, x, x.stride(0), y.stride(0), n_rows, n_cols, BLOCK_SIZE
)
return y
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.
- 7d ago First seen · 389 lines · 71 tokens per session scan A 85cf68ece137
triton-cuda-examples-torch is a skill published in the GitHub repository mindspore-ai/akg (259 stars, last pushed 1mo ago), licensed Apache-2.0. It adds 71 tokens to every session and 3,340 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.
Other skills, from other repositories
triton-cuda-examples-torch
A set of complete examples showing how Triton CUDA kernels work inside PyTorch, including vector addition, matrix multiplication, layer normalization, and softmax.
triton-ascend-examples-mindspore
Integration examples for using Triton Ascend kernels inside MindSpore, a machine-learning framework. They show how to register a custom operation and pass tensors in and out.
pypto-case-norm-batchnorm
A worked example of BatchNorm, a machine-learning step that normalizes values in groups, for three-dimensional data. It demonstrates reducing dimensions, summing across several axes, and copying values across expanded dimensions.
pypto-case-loss-crossentropy
An example of implementing cross-entropy loss, a calculation commonly used to measure classification errors. It covers multiple inputs, tiled processing, softmax, selecting target values, summing, and producing one scalar result.
pypto-case-norm-layernorm
A PyPTO example showing how LayerNorm normalises values across a two-dimensional input using a loop. LayerNorm is a machine-learning operation that rescales values to help a model process them consistently.
pypto-case-elemwise-gelu
A PyPTO example for applying the GELU activation function element by element to a one-dimensional array. It demonstrates flattening, a hand-written formula without tanh, and operator use.