triton-ascend-case-elemwise-broadcast-3d

triton-ascend-case-elemwise-broadcast-3d is a skill for Claude Code, Codex from mindspore-ai/akg. It costs 78 tokens per session (787 once invoked), scanned A, original, Apache-2.0.

An optimization pattern for 3D broadcast division, where one tensor's values are repeated across selected dimensions. It first expands the repeated values and then reshapes the work into a simpler 2D form.

In plain words
What is it for?
Use it for Triton on Ascend when dividing a large 3D tensor by values broadcast across axes, especially when the last dimension is below about 20.
Why use it?
Broadcasting across a very small last dimension can produce poor vector processing. Splitting the work into two stages improves how the data is processed.

Skill for Claude CodeCodex

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

Good fit Use it for Triton on Ascend when dividing a large 3D tensor by values broadcast across axes, especially when the last dimension is below about 20.

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

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

Your own site · 80×15
<a href="https://agentmods.dev/skills/mindspore-ai/akg/triton-ascend-case-elemwise-broadcast-3d"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/triton-ascend-case-elemwise-broadcast-3d.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 78 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 787 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.00078 $0.00787
Opus 5 $0.00039 $0.00394
Sonnet 5 $0.00016 $0.00157
Haiku 4.5 $0.00008 $0.00079

Measured 12d ago against content hash 08080ca50969, 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-case-elemwise-broadcast-3d 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-elemwise-broadcast-3d/SKILL.md · 73 lines

What it actually says

跨轴 3D Broadcast 优化案例

任务特征

  • 操作类型:跨轴broadcast,broadcast第一、三根轴
  • 数据尺寸:(65536, 128, 16) / (1, 128, 1)
  • 特点:第一维很大,第三维很小,属于跨轴broadcast

优化:两阶段 Kernel 策略

当跨轴broadcast中最后一维特别小时(如W=16),如果直接处理会导致向量化效果差。

阶段1:Broadcast Kernel(多核并行)

# 先将(1, H, 1) broadcast到(1, H, W)
input2_broadcast = torch.empty(1, H, W, dtype=input2.dtype, device=input2.device)

grid_broadcast = lambda meta: (meta['NUM_H_CORES'],)
broadcast_kernel_parallel[grid_broadcast](
    input2, input2_broadcast,
    input2.stride(1),
    input2_broadcast.stride(1), input2_broadcast.stride(2),
    H=H, W=W,
)

阶段2:Division Kernel(Reshape为2D)

# 将3D问题转换为2D处理
input1_flat = input1.reshape(B, HW).contiguous()  # (B, HxW)
input2_flat = input2_broadcast.reshape(1, HW).contiguous()  # (1, HxW)
output_flat = torch.empty(B, HW, dtype=input1.dtype, device=input1.device)

grid_div = lambda meta: (meta['NUM_CORES'],)
div_flatten_kernel[grid_div](
    input1_flat, input2_flat, output_flat,
    B, HW,
    input1_flat.stride(0), input1_flat.stride(1),
    input2_flat.stride(1),
    output_flat.stride(0), output_flat.stride(1),
)

优化内容

  1. 第一阶段kernel:先将需要broadcast的维度展开,沿H维度映射到多核并行处理
  2. 第二阶段kernel:将3D reshape为2D,把第一维(B)映射到多核,核内对HW维度切分(SUB_HW=512),向量化维度大大提升

这种方法通过预先broadcast+reshape,避免了最后一维过小导致的向量化效率问题。

通用优化方案

连续broadcast(相邻维度)

通过reshape将相邻维度合并为一维,转换为单轴broadcast。

跨轴broadcast(不相邻维度)

  • 第一维映射到多核上实现并行
  • 核内对其他维度按需进行切分

总结

当跨轴broadcast中最后一维特别小时,采用两阶段kernel:先broadcast展开+reshape为2D,再进行标准的多核并行处理,提升向量化效率。

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 · 73 lines · 78 tokens per session scan A 08080ca50969

Subscribe to this mod's changes

triton-ascend-case-elemwise-broadcast-3d is a skill published in the GitHub repository mindspore-ai/akg (259 stars, last pushed 1mo ago), licensed Apache-2.0. It adds 78 tokens to every session and 787 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.