triton-ascend-elementwise-reduce-fused

triton-ascend-elementwise-reduce-fused is a skill for Claude Code, Codex from mindspore-ai/akg. It costs 189 tokens per session (805 once invoked), scanned A, original, Apache-2.0.

A guide for writing Triton kernels that combine per-element calculations with a reduction, such as adding or averaging values into a smaller result. Triton is a language for writing GPU kernels.

In plain words
What is it for?
Use it to implement fused GPU kernels for losses and other operations that transform tensor elements and then sum or average them.
Why use it?
Keeping both stages together can avoid storing an intermediate result and can support operations such as loss calculations. The guide explains the calculation pattern and its reduction steps.

Skill for Claude CodeCodex

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

Good fit Use it to implement fused GPU kernels for losses and other operations that transform tensor elements and then sum or average them.

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

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

Your own site · 80×15
<a href="https://agentmods.dev/skills/mindspore-ai/akg/triton-ascend-elementwise-reduce-fused"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/triton-ascend-elementwise-reduce-fused.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 189 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 805 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.00189 $0.00805
Opus 5 $0.00095 $0.00402
Sonnet 5 $0.00038 $0.00161
Haiku 4.5 $0.00019 $0.00081

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

Security

Grade A, and why

triton-ascend-elementwise-reduce-fused 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-ascend/guides/triton-ascend-elementwise-reduce-fused/SKILL.md · 62 lines

What it actually says

Elementwise + Reduce 融合算子指南

适用于先逐元素计算、再全局归约的复合算子(损失函数等)

计算模式

这类算子的通用流程:

  1. Elementwise 阶段:对输入张量逐元素执行变换(如差值、平方、clamp、log 等)
  2. Reduce 阶段:对变换结果做全局归约(sum / mean),得到标量或低维输出

融合 Kernel 写法

将 elementwise 计算和局部归约放在同一个 kernel 中,避免中间结果写回 GM:

@triton.jit
def fused_loss_kernel(
    pred_ptr, target_ptr, output_ptr,
    n_elements,
    BLOCK_SIZE: tl.constexpr, CORE_NUM: tl.constexpr,
):
    pid = tl.program_id(0)
    num_blocks = tl.cdiv(n_elements, BLOCK_SIZE)
    local_sum = tl.zeros((1,), dtype=tl.float32)

    for block_id in range(pid, num_blocks, CORE_NUM):
        offsets = block_id * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)
        mask = offsets < n_elements
        pred = tl.load(pred_ptr + offsets, mask=mask, other=0.0)
        target = tl.load(target_ptr + offsets, mask=mask, other=0.0)

        # Elementwise 阶段
        diff = pred - target
        loss_elem = diff * diff  # MSELoss 为例

        # 块内归约
        local_sum += tl.sum(loss_elem, axis=0)

    # 跨块归约
    tl.atomic_add(output_ptr, local_sum / n_elements)

关键要点

  1. 单 kernel 融合:elementwise 变换和归约在同一 kernel 完成,中间结果仅存在于寄存器/UB 中
  2. 原子操作汇总:多个 program 的局部结果通过 tl.atomic_add 汇聚到全局输出
  3. reduction 参数:注意 PyTorch 损失函数的 reduction 参数('mean'/'sum'/'none'),'none' 时退化为纯 elementwise
  4. 使用 VEC_CORE_NUM:此类算子不涉及 tl.dot,使用向量核心
  5. 数值稳定性:中间计算用 float32,避免半精度溢出
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 · 62 lines · 189 tokens per session scan A 08350d3e623d

Subscribe to this mod's changes

triton-ascend-elementwise-reduce-fused is a skill published in the GitHub repository mindspore-ai/akg (259 stars, last pushed 1mo ago), licensed Apache-2.0. It adds 189 tokens to every session and 805 once invoked, about $0.0009 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.