pytorch/executorch · Archived

cortex-m

Build, test, or develop the Cortex-M (CMSIS-NN) backend. Use when working on backends/cortex_m/, running Cortex-M tests, or exporting models for Cortex-M targets.

First seen Jul 3, 2026

Installation

$ npx skills add pytorch/executorch --skill cortex-m

Stronger alternatives

This repository is archived — consider an actively maintained alternative.

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from pytorch/executorch.

npx skills add pytorch/executorch

Browse all from pytorch/executorch

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Repository health

Stars 5.0K
License LICENSE
Default branch main
Open issues 930
Status Archived

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 3,579 B
  • docs SUMMARY.md 178 B

History

  1. First seen on skills.sh
  2. First recorded snapshot · 5 installs

SKILL.md

Cortex-M (CMSIS-NN) Backend

Architecture

Not a delegate backend — no partitioner. Custom ops and graph passes replace ATen quantized ops with CMSIS-NN equivalents at the graph level.

Pipeline

Uses standard PT2E quantization (preparept2e / convertpt2e), then CortexMPassManager rewrites quantized ops to cortex_m:: equivalents.

from executorch.backends.cortex_m.quantizer.quantizer import CortexMQuantizer
from executorch.backends.cortex_m.passes.cortex_m_pass_manager import CortexMPassManager
from executorch.backends.cortex_m.edge_compile_config import cortex_m_edge_compile_config
from torch.export import export
from torchao.quantization.pt2e.quantize_pt2e import convert_pt2e, prepare_pt2e
from executorch.exir import to_edge_transform_and_lower

quantizer = CortexMQuantizer()
captured = export(model, example_inputs).module()
prepared = prepare_pt2e(captured, quantizer)
prepared(*example_inputs)  # calibration
quantized = convert_pt2e(prepared)

exported = export(quantized, example_inputs)
# The backend's own config: linear and the activations must survive to_edge or the
# lowering either fails or silently falls back to portable float kernels.
edge = to_edge_transform_and_lower(
    exported,
    compile_config=cortex_m_edge_compile_config(),
)
edge._edge_programs["forward"] = CortexMPassManager(
    edge.exported_program(), CortexMPassManager.pass_list
).transform()
et_program = edge.to_executorch()

In tests, CortexMTester wraps this pipeline:

from executorch.backends.cortex_m.test.tester import CortexMTester

tester = CortexMTester(model, example_inputs)
tester.quantize().export().to_edge().run_passes().to_executorch()

Key Files

File Purpose
backends/cortex_m/quantizer/quantizer.py CortexMQuantizer — quantizes model for CMSIS-NN
backends/cortexm/passes/cortexmpassmanager.py CortexMPassManager — rewrites ATen ops → cortex_m:: ops
backends/cortex_m/test/tester.py CortexMTester — test harness with testdialect() and testimplementation()
backends/cortex_m/ops/operators.py Python op definitions and reference implementations (cortex_m:: namespace)
backends/cortex_m/ops/operators.yaml C++ kernel registration schemas (used by build system)

C++ kernels calling CMSIS-NN APIs live under backends/cortex_m/ops/.

Testing

Toolchain setup (required for test_implementation tests):

./examples/arm/setup.sh --i-agree-to-the-contained-eula
source ./examples/arm/arm-scratch/setup_path.sh

Run all tests:

source ./examples/arm/arm-scratch/setup_path.sh
pytest backends/cortex_m/test/

testdialect tests verify graph correctness (pure Python, no toolchain needed). testimplementation tests verify numerical accuracy on the Corstone-300 FVP (requires toolchain on PATH).

Baremetal build:

backends/cortex_m/test/build_test_runner.sh

Adding a New Op

  1. Define the op schema, meta function, and reference implementation in operators.py
  2. Write the C++ kernel in backends/cortex_m/ops/ calling CMSIS-NN APIs
  3. Register the .out kernel in operators.yaml
  4. Add a pass to rewrite the ATen op → cortex_m:: op
  5. Test with CortexMTester.testdialect() (graph correctness) and testimplementation() (numerical accuracy on FVP)