Commit a6305cb
authored
Arm backend: Add CMSIS Pack build infrastructure (#19942)
Adds the PyTorch::ExecuTorch CMSIS Pack build pipeline: PDSC template,
per-operator component generator, kernel-registration generator,
source-collection driver, top-level pack-build script, the production
GitHub Actions build workflow, and a local test harness for the
consumer-build smoke.
All changes are confined to backends/arm/cmsis_pack/ and
backends/arm/scripts/cmsis_pack/. No code outside the cmsis_pack
folder is modified.
## Pack contents
- Runtime, Kernel Utils, Kernel Registration umbrella components.
- 171 per-op Portable operator components.
- 9 per-op Quantized operator components.
- 16 per-op Cortex-M operator components. The ARM::CMSIS-NN
dependency is auto-attached only to ops that route through
CMSIS-NN (q/dq and softmax stay pure-CPU; the 13 quantized_*
operators add `<require condition="CMSIS-NN"/>`).
- Ethos-U Backend for Cortex-M (bare-metal).
The Runtime component ships a pack-local patched copy of
`runtime/platform/default/minimal.cpp` (under
`backends/arm/cmsis_pack/contributions/runtime/platform/default/`).
The patched copy marks each `et_pal_*` fallback with `ET_WEAK`
directly on the definition. Relying on attribute inheritance from
the (weak-via-ET_INTERNAL_PLATFORM_WEAKNESS) declaration in
`platform.h` does not produce weak symbols on GCC 13/14/15 or
armclang 6.24, so a downstream client that supplies its own
`et_pal_*` override hits a multi-def link error against the fallback
unless the fallback definition is marked weak directly. The upstream
file is not modified; copy_sources.sh overlays the patched copy onto
the staged pack tree.
## Codegen
- generate_components.py walks the kernel/operator source trees and
emits one CMSIS pack component per op_*.cpp under three
categories: Portable, Quantized, Cortex-M. The Cortex-M scan
detects CMSIS-NN dependency per file via include + symbol pattern
scan, so q/dq components stay free of the CMSIS-NN dep.
- generate_register_all_kernels.py walks the portable / quantized /
cortex_m operator yamls, extracts kernel signatures from the
matching .cpp sources, and emits one
#ifdef RTE_ML_EXECUTORCH_OP_<CATEGORY>_<NAME>-guarded
Kernel(...) registration per overload. Cortex-M kernels are
forward-declared inside a `cortex_m::native` namespace block
(with using aliases for Tensor / ScalarType / Int64ArrayRef /
KernelRuntimeContext, mirroring cortex_m_ops_common.h but
without pulling in arm_nn_types.h) and invoked via
cortex_m::native::<short>(...). ATen and quantized_decomposed
kernels remain in torch::executor::native.
- For cortex_m::quantize_per_tensor.out and
cortex_m::dequantize_per_tensor.out the generated trampoline
accepts either the declared 7 args or 8 args and routes the
`out` slot via stack[stack.size()-1], so AOT pipelines that
emit an optional out_dtype EValue do not require kernel
recompilation.
## Local test harness
- backends/arm/cmsis_pack/test/validate_pack.py — structural
validation of a built .pack archive (PDSC well-formed, file refs
resolve to real entries, no leaked Python sources, runtime +
RegisterAllKernels.cpp present).
- backends/arm/cmsis_pack/test/smoke/ — minimal csolution consumer
project plus a run.sh driver that builds the pack, validates it,
and runs csolution + cbuild against the freshly built pack
inside the avh-mlops-licensed-community Docker image. No
compiler flags are hand-curated in the script; the
cmsis-toolbox cdefault.yml plus the PDSC drive everything.
## Workflow
.github/workflows/build-cmsis-pack.yml runs the pack build only:
cross-compile ExecuTorch headers, run build_pack.sh, upload the
artifact, and (on non-prerelease release events) attach the .pack
to the GitHub Release. Structural validation and consumer-build
smoke run locally via the scripts under
backends/arm/cmsis_pack/test/.
## Follow-up items (not in this CL)
1. executorch_config.yml is parsed but unused by
generate_components.py; annotate as documentation or drive
generation from it.
2. Add a coverage test that compares
generate_register_all_kernels.py output against the union of
functions.yaml / quantized.yaml / cortex_m operators.yaml.
3. PDSC template <repository> URL hard-codes pytorch/executorch.
4. Wire validate_pack.py + smoke/run.sh into the CI workflow
once the runner image carries vcpkg + the AVH-MLOps toolset.
5. Extend the csolution smoke project to also exercise a Cortex-M
per-op component.
6. Cortex-A / Linux-userspace Ethos-U backend variant: add as a
second component once the userspace driver headers are
vendorable in-pack.
7. Gate std::random_device use in op_rand / op_randn /
op_native_dropout behind a bare-metal-aware define plus an
et_pal_random_u32() PAL hook, so consumers selecting those
per-op components do not hit unresolved libstdc++
_M_getval / _M_init / _M_fini at link time.
Original author: Matthias Hertel <matthias.hertel@arm.com>
Change-Id: Ide967ae0a24293d9f24b76961db92eb1f064655d
Signed-off-by: Matthias Hertel <matthias.hertel@arm.com>
cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils
@Sebastian-Larsson @robell @rascani
Signed-off-by: Matthias Hertel <matthias.hertel@arm.com>1 parent 0dbaed4 commit a6305cb
18 files changed
Lines changed: 3076 additions & 0 deletions
File tree
- .github/workflows
- backends/arm/cmsis_pack
- config
- contributions
- add
- Documentation
- armclang_shims/sys
- runtime/platform/default
- scripts
- templates
- test
- smoke
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
0 commit comments