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-ascend-case-index-histogramgit 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-ascend-case-index-histogram)<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.
<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>- 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.00079 | $0.00948 |
| Opus 5 | $0.00039 | $0.00474 |
| Sonnet 5 | $0.00016 | $0.00190 |
| Haiku 4.5 | $0.00008 | $0.00095 |
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.
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),转换不会损失精度
总结
- [算法优化] 对于统计类操作,应优先考虑预排序+二分查找,将O(n×m)复杂度降至O(n log n + m log n)
- [底层接口优化] 在Ascend平台上,对于大规模排序,应使用float32类型调用Vec Core硬件加速
- 365个专家的二分查找可以并行执行,每个线程块独立处理一个专家
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.
- 12d ago First seen · 97 lines · 79 tokens per session scan A be1e094a293d
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.
Other skills, from other repositories
text-transformer
Text encoding, decoding, and transformation utilities - Base64, URL, HTML, hashing, case conversion, and string manipulation.
triton-ascend-case-reduction-amin-atomic
A case study for optimizing amin reductions with atomic operations when the non-reduced dimension is small and the reduced dimension is very large. An amin reduction finds the smallest value.
triton-ascend-case-matmul-large-k
A case study for optimizing matrix multiplication when the shared K dimension is much larger than the output dimensions. It uses Split-K to divide that dimension across cores, then combines the partial results.
triton-ascend-case-elemwise-concat
A guide to combining slicing and concatenation operations in Triton Ascend kernels, which are GPU programs. It describes loading only needed data and calculating joined indexes without a separate concatenation step.
triton-ascend-case-index-histogram
A case study for speeding up histogram calculations, which count how many values fall into each group or range.
triton-ascend-case-matmul-swizzle2d
A case study for optimizing matrix multiplication in Triton on Ascend hardware using 2D block swizzling and a fixed number of cores.