triton-ascend-example-softmax

triton-ascend-example-softmax is a skill for Claude Code, Codex from mindspore-ai/akg. It costs 77 tokens per session (796 once invoked), scanned A, original, Apache-2.0.

A complete example of implementing softmax in Triton for Ascend hardware. Softmax turns a group of numbers into values that add up to one, often for selecting or weighting options in machine-learning models.

In plain words
What is it for?
Use it when generating or adapting softmax and other reduction kernels that process data in chunks and accumulate results.
Why use it?
It provides a reference for the multiple passes needed to find the maximum, calculate the exponential sum, and normalize the result safely.

Skill for Claude CodeCodex

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

Good fit Use it when generating or adapting softmax and other reduction kernels that process data in chunks and accumulate results.

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

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

Your own site · 80×15
<a href="https://agentmods.dev/skills/mindspore-ai/akg/triton-ascend-example-softmax"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/triton-ascend-example-softmax.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 77 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 796 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.00077 $0.00796
Opus 5 $0.00039 $0.00398
Sonnet 5 $0.00015 $0.00159
Haiku 4.5 $0.00008 $0.00080

Measured 7d ago against content hash 21037dc1fb5a, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-11, from the pricing page.

Security

Grade A, and why

triton-ascend-example-softmax 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-ascend/examples/triton-ascend-example-softmax/SKILL.md · 82 lines

What it actually says

Softmax — Triton Ascend 实现示例

import torch
import triton
import triton.language as tl


@triton.jit
def softmax_kernel(
    X_ptr, Y_ptr,
    B: tl.constexpr, N: tl.constexpr,
    stride_xb: tl.constexpr, stride_xn: tl.constexpr,
    stride_yb: tl.constexpr, stride_yn: tl.constexpr,
    BLOCK_SIZE_N: tl.constexpr, CORE_NUM: tl.constexpr,
):
    pid = tl.program_id(0)
    for b in range(pid, B, CORE_NUM):
        # Phase 1: max
        max_val = -float('inf')
        for off in range(0, N, BLOCK_SIZE_N):
            n_off = off + tl.arange(0, BLOCK_SIZE_N)
            mask = n_off < N
            x = tl.load(X_ptr + b * stride_xb + n_off * stride_xn,
                        mask=mask, other=-float('inf'))
            max_val = tl.maximum(max_val, tl.max(x, axis=0))

        # Phase 2: sum(exp(x - max))
        sum_val = 0.0
        for off in range(0, N, BLOCK_SIZE_N):
            n_off = off + tl.arange(0, BLOCK_SIZE_N)
            mask = n_off < N
            x = tl.load(X_ptr + b * stride_xb + n_off * stride_xn,
                        mask=mask, other=0.0)
            exp_x = tl.math.exp(x - max_val)
            sum_val += tl.sum(exp_x, axis=0).to(tl.float32)

        # Phase 3: normalize
        for off in range(0, N, BLOCK_SIZE_N):
            n_off = off + tl.arange(0, BLOCK_SIZE_N)
            mask = n_off < N
            x = tl.load(X_ptr + b * stride_xb + n_off * stride_xn,
                        mask=mask, other=0.0)
            result = tl.math.exp(x - max_val) / sum_val
            tl.store(Y_ptr + b * stride_yb + n_off * stride_yn,
                     result, mask=mask)


class ModelNew(torch.nn.Module):
    def __init__(self):
        super().__init__()
        try:
            self.VEC_CORE_NUM = torch_npu.npu.npu_config.get_device_limit(0).get("vector_core_num", 40)
        except:
            self.VEC_CORE_NUM = 40

    def forward(self, x):
        if not x.is_contiguous():
            x = x.contiguous()
        B, N = x.shape
        y = torch.empty_like(x)
        BLOCK_SIZE_N = 4096
        grid = (self.VEC_CORE_NUM,)
        softmax_kernel[grid](
            x, y, B, N,
            x.stride(0), x.stride(1), y.stride(0), y.stride(1),
            BLOCK_SIZE_N=BLOCK_SIZE_N, CORE_NUM=self.VEC_CORE_NUM)
        return y
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 · 82 lines · 77 tokens per session scan A 21037dc1fb5a

Subscribe to this mod's changes

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

Related

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.

wenyi-li/awesome-agent-kernel-skills · 71 tokens

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.

wenyi-li/awesome-agent-kernel-skills · 75 tokens

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.

wenyi-li/awesome-agent-kernel-skills · 41 tokens

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.

wenyi-li/awesome-agent-kernel-skills · 37 tokens

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.

wenyi-li/awesome-agent-kernel-skills · 42 tokens

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.

wenyi-li/awesome-agent-kernel-skills · 40 tokens