본문으로 건너뛰기
cccskills
무료GitHub에 공개

add-new-op

Add new operators to MNN through a staged workflow covering data definitions, output shapes, computation, and tests. It prioritizes combining existing operators, with CPU implementations and additional hardware backends used when needed.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

원문원문 설명 보기

为 MNN 框架新增算子。包含 Schema 定义、形状计算、几何计算、后端实现、单元测试的完整 TDD 流程。分 5 步执行,每步有独立测试标准。

설치 방법 보기

이럴 때 유용합니다

  • Adding a new operator to MNN
  • Implementing output shape calculations
  • Combining existing operators for new operations
  • Extending operators to additional hardware backends

포함된 파일(6)

  • SKILL.md5.9 KB
  • step1-schema.md6.3 KB
  • step2-shape.md4.7 KB
  • step3-compute.md9.3 KB
  • step4-test.md6.5 KB
  • step5-optimize.md6.8 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

MNN 新增算子 SKILL

触发条件:当用户请求为 MNN 添加/实现一个新的算子时触发。常见表述包括:"添加xxx算子"、"实现xxx op"、"支持xxx操作"等。

概述

本 SKILL 指导 AI Agent 为 MNN 框架新增算子支持。采用 TDD(测试驱动)模式,每一步都有明确的测试标准。

核心原则

优先级顺序:几何计算 > 后端实现

  • 几何计算:如果新算子可以通过已有算子的拆解、组合实现,优先用几何计算,不需要为每个后端单独实现
  • 后端实现:如果算子无法拆解,或性能敏感需要原生实现,则添加后端实现

注意事项

严禁访问以下目录:schema/private/ 和 source/internal/,包含内部私有代码,不得读取、修改或引用。

名字必须等于真实物理量:新增或修改任何后端算子 / kernel 代码时,变量、字段、宏名指代的必须是代码里真正装的那个量——blockSize 是"块内元素数"还是"每行块数"、step 是元素数还是字节数、shape 门禁的自变量是通道数还是 tile 数。名字骗人不会报错(编译、对拍、单测都过),但后续基于它写的阈值、门控、分档会一起错。写完对着实际索引 / 指针算术复核一遍,不符就改名。


核心文件清单

目录/文件作用何时修改
schema/default/MNN.fbs算子类型和参数定义(开源版)每个新算子都需要;内部仓库实际生成走 schema/private/,计划开源发布的算子两份都要改,详见 step1-schema.md §1.5
schema/default/CaffeOps.fbsCaffe 框架算子参数有参数时
schema/default/TensorflowOp.fbsTF 框架算子参数有参数时
source/shape/Shape*.cpp形状(维度)计算输出形状与输入不同时
source/geometry/Geometry*.cpp几何计算(算子拆解)优先实现
source/backend/cpu/CPU*.cpp/.hppCPU 后端实现无法几何拆解时
source/backend/metal/Metal*.cpp/.hpp/.metalMetal 后端实现扩展到 Metal
source/backend/opencl/execution/*.cpp/.h/.clOpenCL 后端实现扩展到 OpenCL
source/backend/vulkan/image/execution/Vulkan*.cpp/.hppVulkan 后端实现扩展到 Vulkan
source/backend/cuda/execution/*.cu/.cuhCUDA 后端实现扩展到 CUDA
include/MNN/expr/ExprCreator.hpp表达式 API 函数需要用户可调用时
test/op/*Test.cpp单元测试每个新算子都需要
tools/script/register.py注册脚本添加 shape/geometry/backend 后运行

分步流程总览

┌──────────────────────────────────────────────────────────┐
│  步骤 1: Schema 定义 (step1-schema.md)                    │
│  输入: 算子名称、语义、输入输出定义                          │
│  输出: MNN.fbs 中的 OpType + 可选的参数 table              │
│  测试: flatc 编译通过                                      │
├──────────────────────────────────────────────────────────┤
│  步骤 2: 形状计算 (step2-shape.md)                        │
│  输入: 算子的输入输出维度关系                                │
│  输出: source/shape/Shape*.cpp                             │
│  测试: register.py 运行成功 + cmake 编译通过               │
├──────────────────────────────────────────────────────────┤
│  步骤 3: 几何计算或 CPU 实现 (step3-compute.md)            │
│  输入: 算子的计算逻辑                                      │
│  输出: Geometry*.cpp 或 CPU*.cpp                           │
│  测试: register.py + 编译通过                              │
├──────────────────────────────────────────────────────────┤
│  步骤 4: 单元测试 (step4-test.md)                         │
│  输入: 算子的预期行为                                      │
│  输出: test/op/*Test.cpp                                  │
│  测试: ./run_test.out op/MyOp 全部通过                     │
├──────────────────────────────────────────────────────────┤
│  步骤 5: 扩展后端与优化 (step5-optimize.md)                │
│  输入: 步骤 4 通过                                        │
│  输出: Metal/OpenCL/Vulkan/CUDA 实现                      │
│  测试: 各后端单元测试通过                                   │
└──────────────────────────────────────────────────────────┘

步骤选择指南

情况需要执行的步骤
输出形状与输入完全一致,可几何拆解1 → 3(几何) → 4
输出形状与输入不同,可几何拆解1 → 2 → 3(几何) → 4
输出形状与输入不同,需要后端实现1 → 2 → 3(CPU) → 4 → 5
输出形状与输入完全一致,需要后端实现1 → 3(CPU) → 4 → 5

开始执行

现在请打开 skills/add-new-op/step1-schema.md,开始步骤 1。

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

bugfix

무료

Triage incorrect MNN outputs and regressions by matching symptoms to focused debugging guides. Use backend comparisons, minimal reproductions, and controlled experiments to investigate memory issues, quantization, concurrency, numeric limits, caches, and inconsistent results across runs.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Investigating garbled or degraded MNN output
  • Comparing results across execution backends
  • Tracking regressions after optimization changes
alibaba/MNN1.6만2026년 10월 20일 업데이트

cpu

무료

Find the right workflow for MNN CPU work, from investigating slow execution to implementing calculation routines and planning tests. Compare ARM, x86_64, and RISC-V backend structures before choosing the relevant guidance.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Choosing where to start an MNN CPU performance investigation
  • Finding guidance for CPU kernel implementation
  • Comparing ARM, x86_64, and RISC-V backend structures
alibaba/MNN1.6만2026년 10월 20일 업데이트

Develop or port CPU kernels, the low-level calculation routines used by MNN. Follow staged implementation guidance, check data layout agreements, register functions, and verify correctness across processor instruction sets and numerical precision settings.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Implementing or porting an MNN CPU kernel
  • Adding support for a processor instruction set
  • Changing packed data layouts or tile sizes
alibaba/MNN1.6만2026년 10월 20일 업데이트

Find why MNN CPU inference is slow by examining threads, scheduling, memory layout, and the processor instruction path actually used. Operator-level measurements and comparisons with other inference frameworks help identify which layer needs improvement across ARM, x86_64, and RISC-V.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Investigate slow CPU operators or LLM inference
  • Diagnose thread count and memory usage anomalies
  • Locate the cause of a performance regression
alibaba/MNN1.6만2026년 10월 20일 업데이트

Optimize and troubleshoot MNN's Hexagon DSP backend, which runs computation on a dedicated processor. The workflow uses device measurements to identify bottlenecks, compare v79 and v81 architectures, verify correctness, and investigate crashes or memory usage.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Finding bottlenecks in Hexagon operators
  • Checking changes on v79 and v81 devices
  • Investigating cDSP crashes and device disconnects
alibaba/MNN1.6만2026년 10월 20일 업데이트

Guide MNN Metal backend development and optimization, from finding performance bottlenecks to changing GPU computation, combining operators, and adjusting execution scheduling. A task-based document index directs work toward relevant implementation rules, benchmarks, and correctness checks.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Finding bottlenecks in Metal inference
  • Adding or modifying Metal kernels
  • Combining operators into one GPU dispatch
alibaba/MNN1.6만2026년 10월 20일 업데이트

alibaba의 스킬 모두 보기

이 스킬의 문제 신고