Skip to content
Skills Library
Programming · Building & coding

cortex-m

/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.

Repository
executorch ↗
Licence
BSD-3-Clause
Last repository change
27.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 27.10.2026, without references to retired models or APIs.

Licence

BSD-3-Clause, otwarta.

What it does and when to use it

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.

Original author description

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.

How it works

  1. Architecture
  2. Pipeline
  3. Key Files
  4. Testing
  5. Adding a New Op
Original SKILL.md headings · 87 lines, 331 words
SKILL.md preview
---
name: cortex-m
description: 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.
---

# 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 (`prepare_pt2e` / `convert_pt2e`), then `CortexMPassManager` rewrites quantized ops to `cortex_m::` equivalents.

```python
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(),
    transform_passes=CortexMPassManager(),
)
et_program = edge.to_executorch()
```

In tests, `CortexMTester` wraps this pipeline:

```python
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/cortex_m/passes/cortex_m_pass_manager.py` | `CortexMPassManager` — rewrites ATen ops → `cortex_m::` ops |
| `backends/cortex_m/test/tester.py` | `CortexMTester` — test harness with `test_dialect()` and `test_implementation()` |
| `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):**
```bash
./examples/arm/setup.sh --i-agree-to-the-contained-eula
source ./examples/arm/arm-scratch/setup_path.sh
```

**Run all tests:**
```bash
source ./examples/arm/arm-scratch/setup_path.sh
pytest backends/cortex_m/test/
```

`test_dialect_*` tests verify graph correctness (pure Python, no toolchain needed).
`test_implementation_*` tests verify numerical accuracy on the Corstone-300 FVP (requires toolchain on PATH).

**Baremetal build:**
```bash
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.test_dialect()` (graph correctness) and `test_implementation()` (numerical accuracy on FVP)

Versions

The database has no other skills named cortex-m.

Database snapshot: 13.11.2026 · package version ecb1ff74d7fb (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 96cortex-mcp-project
    Use when working on the Cortex MCP server repo.
  • 100cmsis-dsp-integration
    Use when integrating, configuring, or debugging CMSIS-DSP, ARM math functions, FFT, filters, fixed-point DSP, vector math, or Cortex-M signal processing
  • 100cortex-run
    ONLY load this skill when the user explicitly types $cortex-run or /cortex-run. NEVER load this skill from auto-routing hooks or keyword matching. For auto-routed prompts, use snowflake-cortex-code:cortex-router instead.
  • 100stm32-baremetal
    Use when scaffolding STM32 firmware without HAL, CMSIS-only clock/RCC config, STM32F4/H7 bring-up, or building with arm-none-eabi-gcc for Cortex-M. Not for the startup file: use baremetal-startup.
  • 96cortex-mcp
    Use when usás Cortex (MCP) para buscar o guardar notas.
  • 100cortex-evolve
    Save knowledge to the cortex vault. Use when the user says "存到 cortex", "記一下", "save to cortex", "記到筆記", "cortex evolve", or when the session-suggest hook recommends saving content. Handles Notes and Projects.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.