triton-ascend-case-index-histogram

triton-ascend-case-index-histogram is a skill for Claude Code, Codex from mindspore-ai/akg. It costs 79 tokens per session (948 once invoked), scanned A, original, Apache-2.0.

An optimization pattern for histogram counting, which records how often each value appears. It sorts the input first, then uses binary search to find each value's range.

In plain words
What is it for?
Use it for large histogram-style tasks, such as counting expert IDs in an index array with hundreds of thousands of elements.
Why use it?
Checking every element against every possible category creates too many comparisons for large inputs. Sorting and searching reduces the amount of repeated work.

Skill for Claude CodeCodex

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

Good fit Use it for large histogram-style tasks, such as counting expert IDs in an index array with hundreds of thousands of elements.

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

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

Your own site · 80×15
<a href="https://agentmods.dev/skills/mindspore-ai/akg/triton-ascend-case-index-histogram"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/triton-ascend-case-index-histogram.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 79 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 948 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.00079 $0.00948
Opus 5 $0.00039 $0.00474
Sonnet 5 $0.00016 $0.00190
Haiku 4.5 $0.00008 $0.00095

Measured 12d ago against content hash be1e094a293d, 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-case-index-histogram 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 12d 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/cases/triton-ascend-case-index-histogram/SKILL.md · 97 lines

What it actually says

Histogram 直方图统计优化案例

任务特征

  • 操作类型:直方图统计,统计每个专家ID出现的次数
  • 数据尺寸:输入索引(65536, 8),专家数量365
  • 特点:需要优化算法复杂度,从O(n×m)降至O(n log n + m log n)

优化 1:预排序 + 二分查找

错误:简单方式:遍历统计 O(n×m)

count = 0
for i in range(total_elements):  # 524288次迭代
    val = tl.load(indices_ptr + i)
    if val == expert_idx:
        count += 1

问题:复杂度O(n×m) = 524288 × 365 ≈ 1.9亿次操作

正确:优化方式:预排序+二分查找 O(n log n + m log n)

# 预排序:O(n log n)
indices_flat = indices.flatten().to(torch.float32)
sorted_indices, _ = torch.sort(indices_flat)

# Triton kernel内二分查找:每个expert执行O(log n)
@triton.jit
def histogram_kernel(sorted_indices_ptr, splits_ptr, total_elements):
    expert_idx = tl.program_id(0)
    expert_id = expert_idx.to(tl.float32)
    
    # 二分查找下界(O(log n),约19次迭代)
    left, right = 0, total_elements - 1
    start_pos = total_elements
    while left <= right:
        mid = (left + right) // 2
        mid_val = tl.load(sorted_indices_ptr + mid)
        if mid_val < expert_id:
            left = mid + 1
        else:
            if mid_val == expert_id:
                start_pos = tl.minimum(start_pos, mid)
            right = mid - 1
    
    # 二分查找上界(类似逻辑)
    # ...
    count = end_pos - start_pos + 1

性能对比

  • 遍历统计:1.9亿次操作
  • 预排序+二分查找:约1000万次操作
  • 性能提升:约19倍

优化 2:Float32 类型转换(Vec Core加速)

错误:简单方式:直接使用 int32

indices_flat = indices.flatten()  # int32
sorted_indices, _ = torch.sort(indices_flat)  # 可能调用AI CPU

问题:可能回退到AI CPU排序,性能较差

正确:优化方式:转换为 float32

indices_flat = indices.flatten().to(torch.float32)  # 转换为float32
sorted_indices, _ = torch.sort(indices_flat)  # 调用Vec Core排序

优化内容

  • Ascend芯片包含AI Core、Vec Core、AI CPU
  • Vec Core对float32类型的排序操作有专门优化,支持SIMD并行
  • int32排序可能回退到AI CPU,性能较差
  • 索引值范围远小于float32精度范围(2^23),转换不会损失精度

总结

  1. [算法优化] 对于统计类操作,应优先考虑预排序+二分查找,将O(n×m)复杂度降至O(n log n + m log n)
  2. [底层接口优化] 在Ascend平台上,对于大规模排序,应使用float32类型调用Vec Core硬件加速
  3. 365个专家的二分查找可以并行执行,每个线程块独立处理一个专家
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. 12d ago First seen · 97 lines · 79 tokens per session scan A be1e094a293d

Subscribe to this mod's changes

triton-ascend-case-index-histogram is a skill published in the GitHub repository mindspore-ai/akg (259 stars, last pushed 1mo ago), licensed Apache-2.0. It adds 79 tokens to every session and 948 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-08-30.

Related

Other skills, from other repositories