用途:这是 Executorch 中面向 Cortex-M(CMSIS-NN)的后端,用于构建、测试或开发该后端,以及为 Cortex-M 导出模型。它不是 delegate 后端,没有 partitioner,而是在图级别用自定义算子和图变换把 ATen 量化算子替换为 CMSIS-NN 等价实现。
主要能力:采用标准 PT2E 量化流程(prepare_pt2e / convert_pt2e),随后由 CortexMPassManager 将量化算子重写为 cortex_m:: 等价算子。关键文件包括 quantizer/quantizer.py(CortexMQuantizer)、passes/cortex_m_pass_manager.py(CortexMPassManager)、test/tester.py(CortexMTester)、ops/operators.py(Python 算子定义与参考实现)以及 ops/operators.yaml(C++ kernel 注册 schema)。C++ kernel 调用 CMSIS-NN API,位于 backends/cortex_m/ops/ 下。
使用方式:导出时先量化再导出,然后调用 to_edge_transform_and_lower,传入 cortex_m_edge_compile_config() 与 CortexMPassManager(),最后 to_executorch()。测试中可用 CortexMTester 串联 quantize().export().to_edge().run_passes().to_executorch()。运行 test_implementation 测试需先配置工具链:./examples/arm/setup.sh --i-agree-to-the-contained-eula 与 source ./examples/arm/arm-scratch/setup_path.sh,然后 pytest backends/cortex_m/test/。裸机构建使用 backends/cortex_m/test/build_test_runner.sh。
适用场景:开发或调试 Cortex-M 后端、运行 Cortex-M 测试、为 Cortex-M 导出模型,以及新增算子(定义 schema、meta 函数与参考实现,编写 C++ kernel,注册 .out kernel,添加重写 pass,并用 test_dialect 与 test_implementation 验证)。
限制:test_dialect_* 仅验证图正确性,纯 Python 无需工具链;test_implementation_* 在 Corstone-300 FVP 上验证数值精度,需要工具链在 PATH 中。后端配置要求 linear 与激活必须存活到 to_edge,否则 lowering 失败或静默回退到 portable float kernel。其他收费、平台与效果信息暂未提供。