pypto-case-matmul-2d

pypto-case-matmul-2d is a skill for Claude Code, Codex from mindspore-ai/akg. It costs 34 tokens per session (1,380 once invoked), scanned A, original, Apache-2.0.

An example of a two-dimensional matrix multiplication kernel using loop-based blocks and separate handling for leftover rows. Matrix multiplication combines rows and columns of number grids to produce a new grid.

In plain words
What is it for?
Use it as a pattern for writing a PyPTO matrix multiplication kernel with M-dimension batching, loop control, and tail processing.
Why use it?
It shows how to process input whose size is not an exact multiple of the chosen block size, so the final partial block is not skipped.

Skill for Claude CodeCodex

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

Good fit Use it as a pattern for writing a PyPTO matrix multiplication kernel with M-dimension batching, loop control, and tail processing.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/mindspore-ai/akg/pypto-case-matmul-2d
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 pypto-case-matmul-2d
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 pypto-case-matmul-2d

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

Your own site · 80×15
<a href="https://agentmods.dev/skills/mindspore-ai/akg/pypto-case-matmul-2d"><img src="https://agentmods.dev/badge/skills/mindspore-ai/akg/pypto-case-matmul-2d.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 34 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,380 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.00034 $0.01380
Opus 5 $0.00017 $0.00690
Sonnet 5 $0.00007 $0.00276
Haiku 4.5 $0.00003 $0.00138

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

Security

Grade A, and why

pypto-case-matmul-2d 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 11d 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/pypto/cases/pypto-case-matmul-2d/SKILL.md · 103 lines

How it starts

The opening of the file, as written. The whole thing — 103 lines — stays where its author put it; the contents beside it link to each section on GitHub.

模式 B:Matmul + Loop(含尾部处理)

def ceil_div(a, b):
    return (a + b - 1) // b

def create_matmul_kernel(m, k, n):
    # 先在 loop_count 空间选中段,再反推 BASIC_BATCH
    # 当 loop 范围约为 1~128 时,默认先试 16/32
    TARGET_LOOP_COUNT = 16
    BASIC_BATCH = ceil_div(m, TARGET_LOOP_COUNT)

    full_iterations = m // BASIC_BATCH
    tail = m % BASIC_BATCH
    tail_offset = full_iterations * BASIC_BATCH

    @pypto.frontend.jit(runtime_options=..., debug_options=...)
    def kernel(
        a: pypto.Tensor((m, k), pypto.DT_FP32),
        b: pypto.Tensor((k, n), pypto.DT_FP32),
    ) -> pypto.Tensor((m, n), pypto.DT_FP32):
        pypto.set_cube_tile_shapes([128, 128], [32, 128], [256, 256], True, False)
        c = pypto.tensor([m, n], pypto.DT_FP32)

        for idx in pypto.loop(0, full_iterations, 1, name="LOOP_M", idx_name="idx"):
            offset = idx * BASIC_BATCH
            a_chunk = pypto.view(a, [BASIC_BATCH, k], [offset, 0])
            c_chunk = pypto.matmul(a_chunk, b, pypto.DT_FP32)
            pypto.assemble(c_chunk, [offset, 0], c)

        if tail > 0:
            a_tail = pypto.view(a, [tail, k], [tail_offset, 0])
            c_tail = pypto.matmul(a_tail, b, pypto.DT_FP32)
            pypto.assemble(c_tail, [tail_offset, 0], c)

        return c
    return kernel

forward:assert → contiguous → 读 shape → 调 kernel

3D 输入 + 2D B:forward 中计算 nm = N * MA.reshape(nm, K) → 将 nm 传入工厂函数(不要分别传 N、M):

def forward(self, A, B):
    N, M, K = A.shape
    nm = N * M
    A_2d = A.reshape(nm, K)
    result_2d = create_matmul_kernel(nm, K, L)(A_2d, B)
    return result_2d.reshape(N, M, L)

Matmul + Bias(Linear)两阶段写法

linear = matmul + bias 不要把 add 直接塞在 cube 阶段。matmul 是 cube op,add/expand_clone 是 vec op,必须显式切换 tile。

def create_linear_kernel(m, k, n):
    @pypto.frontend.jit(runtime_options=..., debug_options=...)
    def kernel(
        x: pypto.Tensor((m, k), pypto.DT_FP32),
        w: pypto.Tensor((k, n), pypto.DT_FP32),
        b_row: pypto.Tensor((1, n), pypto.DT_FP32),   # forward 中 b.reshape(1, -1)
    ) -> pypto.Tensor((m, n), pypto.DT_FP32):
        # Phase 1: cube matmul
        pypto.set_cube_tile_shapes([128, 128], [32, 128], [256, 256], True, False)
        mm = pypto.tensor([m, n], pypto.DT_FP32)
        for idx in pypto.loop(0, full_iterations, 1, name="LOOP_M", idx_name="idx"):
            off = idx * BASIC_BATCH
            x_chunk = pypto.view(x, [BASIC_BATCH, k], [off, 0])
            y_chunk = pypto.matmul(x_chunk, w, pypto.DT_FP32)
            pypto.assemble(y_chunk, [off, 0], mm)

        # Phase 2: vec bias add
        pypto.set_vec_tile_shapes(1, n)
        b_full = pypto.expand_clone(b_row, [m, n])   # 单轴广播
        out = pypto.add(mm, b_full)
        return out
    return kernel

Read the full file on GitHub · 103 lines

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. 11d ago First seen · 103 lines · 34 tokens per session scan A d0595874aaad

Subscribe to this mod's changes

pypto-case-matmul-2d is a skill published in the GitHub repository mindspore-ai/akg (259 stars, last pushed 1mo ago), licensed Apache-2.0. It adds 34 tokens to every session and 1,380 once invoked, about $0.0002 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

pypto-case-matmul-2d

A documented example of 2D matrix multiplication using loop blocking over the M dimension and handling leftover elements. Matrix multiplication combines rows and columns of number grids to produce a new grid.

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

pypto-case-reduction-sum

A small example of summing values along one axis of a three-dimensional array while keeping the original number of dimensions.

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

instrument-data-to-allotrope

Convert laboratory instrument output files (PDF, CSV, Excel, TXT) to Allotrope Simple Model (ASM) JSON format or flattened 2D CSV. Use this skill when scientists need to standardize instrument data for LIMS systems, data lakes, or downstream analysis. Supports auto-detection of instrument types. Outputs include full…

anthropics/knowledge-work-plugins · 123 tokens

exploratory-data-analysis

Perform bounded, local exploratory analysis of explicitly supported scientific files. Use for redacted CSV/TSV/JSON profiles; optional NumPy, HDF5, FASTA/FASTQ, and basic image metadata inspection; missingness/leakage audits; outlier and transformation sensitivity; and rigorous EDA report scaffolds. Other domain…

K-Dense-AI/scientific-agent-skills · 83 tokens

matlab

Build, review, migrate, and safely plan MATLAB or GNU Octave numerical workflows, including arrays, tabular/time data, tests, projects, graphics, MAT files, and explicit Python interoperability.

K-Dense-AI/scientific-agent-skills · 42 tokens

phylogenetics

Build and analyze phylogenetic trees using MAFFT (multiple alignment), IQ-TREE 2 (maximum likelihood), and FastTree (fast NJ/ML). Visualize with ETE3 or FigTree. For evolutionary analysis, microbial genomics, viral phylodynamics, protein family analysis, and molecular clock studies.

K-Dense-AI/scientific-agent-skills · 68 tokens