Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 100 additions & 29 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# SPDX-License-Identifier: Apache-2.0
#
# CI for the three-step flow (cbuild setup, create_ai_layer.py, cbuild)
# followed by an FVP run, with each of the three toolchains.
# followed by an FVP run that checks the generated face against the host
# reference, with each of the three toolchains.
name: Build and Run

on:
Expand All @@ -17,11 +18,77 @@ env:
TARGET: SSE-320-U85

jobs:
# Step 1 and 2 of the flow, once: the AI layer is the same for every
# toolchain and both target-types. The model data (ai_layer/model_pte.c) is
# generated here rather than committed; the job also renders the host's
# fake-quant reference image of the boot demo for the FVP check below.
export:
name: Create the AI layer
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v7

- name: Install tools
uses: ARM-software/cmsis-actions/vcpkg@v1

# cbuild setup of CMSIS-Toolbox 2.15 configures the CMake project, which
# probes the solution's compiler (AC6).
- name: Activate Arm tool license
uses: ARM-software/cmsis-actions/armlm@v1

- name: Cache packs
uses: actions/cache@v6
with:
key: cmsis-packs-${{ hashFiles('*.csolution.yml') }}
path: /home/runner/.cache/arm/packs

# torch + executorch is a multi-gigabyte install and otherwise dominates
# the job. Keyed on the requirements files so a pin change rebuilds it.
- name: Cache model-export venv
uses: actions/cache@v6
with:
key: venv-${{ runner.os }}-${{ hashFiles('requirements*.txt', 'setup_venv.py') }}
path: .venv

- name: Cache pico-faces checkpoints
uses: actions/cache@v6
with:
key: pico-faces-${{ hashFiles('setup_venv.py') }}
path: model/pico_faces

- name: Create model-export venv and fetch the checkpoints
run: ./setup_venv.sh

# The committed AI layer lists ai_layer/model_pte.c, which only step 2
# generates, and csolution refuses a layer whose files are missing. An
# empty placeholder lets step 1 run; create_ai_layer.py overwrites it.
- name: Generate the MLOps information
run: |
touch ai_layer/model_pte.c
cbuild setup ${SOLUTION}.csolution.yml --active ${TARGET} --packs

- name: Create the AI layer
run: python3 create_ai_layer.py ${SOLUTION}.cbuild-mlops.yml

- name: Render the host reference of the boot demo
run: python3 model/verify_export.py --stage fakequant --seed 3 --class 1 --w 4 --k 4 --out reference/pf_fakequant.png

- name: Upload the AI layer
uses: actions/upload-artifact@v4
with:
name: ai-layer
path: |
ai_layer/
reference/

# Full build plus an FVP run, once per toolchain. Linux only: the FVP needs
# an Arm user-based license, so matrixing this across hosts is not cheap.
build-and-run:
name: Build and run on Corstone-320 (${{ matrix.toolchain }})
runs-on: ubuntu-latest
needs: export

strategy:
fail-fast: false
Expand All @@ -32,6 +99,11 @@ jobs:
- name: Checkout repo
uses: actions/checkout@v7

- name: Download the AI layer
uses: actions/download-artifact@v4
with:
name: ai-layer

- name: Install tools
uses: ARM-software/cmsis-actions/vcpkg@v1

Expand All @@ -41,7 +113,8 @@ jobs:
# The FVP loads the runner's libpython3.11, whose standard library is
# not where that build's prefix says; the model then dies at start-up
# with "Fatal Python error: init_fs_encoding". PYTHONHOME (set on the
# FVP step only) points it at a complete Python 3.11.
# FVP step only) points it at a complete Python 3.11, which also runs
# the image comparison.
- name: Set up Python 3.11 for the FVP
uses: actions/setup-python@v5
with:
Expand All @@ -53,25 +126,8 @@ jobs:
key: cmsis-packs-${{ hashFiles('*.csolution.yml') }}
path: /home/runner/.cache/arm/packs

# torch + executorch is a multi-gigabyte install and otherwise dominates
# the job. Keyed on the requirements files so a pin change rebuilds it.
- name: Cache model-export venv
uses: actions/cache@v6
with:
key: venv-${{ runner.os }}-${{ hashFiles('requirements*.txt', 'setup_venv.py') }}
path: .venv

- name: Create model-export venv
run: ./setup_venv.sh

- name: Generate the MLOps information
run: cbuild setup ${SOLUTION}.csolution.yml --active ${TARGET} --packs

- name: Create the AI layer
run: python3 create_ai_layer.py ${SOLUTION}.cbuild-mlops.yml

- name: Build
run: cbuild ${SOLUTION}.csolution.yml --active ${TARGET} --toolchain ${{ matrix.toolchain }}
run: cbuild ${SOLUTION}.csolution.yml --active ${TARGET} --toolchain ${{ matrix.toolchain }} --packs

- name: Run on the FVP
env:
Expand All @@ -80,7 +136,7 @@ jobs:
IMAGE=$(find out -name "${SOLUTION}.axf" -o -name "${SOLUTION}.elf" | head -1)
echo "Running ${IMAGE}"
# stdio is retargeted to semihosting, so the output arrives on the
# FVP's own stdout.
# FVP's own stdout; the application ends the simulation itself.
FVP_Corstone_SSE-320 \
-f board/Corstone-320/fvp_config.txt \
-a "${IMAGE}" \
Expand All @@ -90,23 +146,33 @@ jobs:
echo "Checking simulation output"
grep -q "Test_result: PASS" fvp_stdout.log

# The run writes the generated image to out/fvp_image.bin through
# semihosting; it has to match what the quantized graphs compute on the
# host (the NPU's integer arithmetic differs from the fake-quant graphs
# only by rounding).
- name: Compare the image with the host reference
run: |
python -m pip install --quiet numpy pillow
python model/verify_export.py --compare out/fvp_image.bin reference/pf_fakequant.png --min-psnr 35

- name: Upload artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: corstone-320-${{ matrix.toolchain }}
path: |
fvp_stdout.log
out/fvp_image.bin
out/fvp_result.txt
out/**/*.axf
out/**/*.elf
ai_layer/

# The same solution for the Alif Ensemble E8 DevKit (target-type DevKit-E8),
# once per toolchain. Build only: the hardware is not in CI. The shipped
# ai_layer/ is used, so no venv is needed.
# once per toolchain. Build only: the hardware is not in CI.
build-devkit-e8:
name: Build for the Alif Ensemble E8 DevKit (${{ matrix.toolchain }})
runs-on: ubuntu-latest
needs: export

strategy:
fail-fast: false
Expand All @@ -117,6 +183,11 @@ jobs:
- name: Checkout repo
uses: actions/checkout@v7

- name: Download the AI layer
uses: actions/download-artifact@v4
with:
name: ai-layer

- name: Install tools
uses: ARM-software/cmsis-actions/vcpkg@v1

Expand All @@ -126,14 +197,11 @@ jobs:
- name: Cache packs
uses: actions/cache@v6
with:
key: cmsis-packs
key: cmsis-packs-${{ hashFiles('*.csolution.yml') }}
path: /home/runner/.cache/arm/packs

- name: Generate the MLOps information
run: cbuild setup ${SOLUTION}.csolution.yml --active DevKit-E8 --packs

- name: Build
run: cbuild ${SOLUTION}.csolution.yml --active DevKit-E8 --toolchain ${{ matrix.toolchain }}
run: cbuild ${SOLUTION}.csolution.yml --active DevKit-E8 --toolchain ${{ matrix.toolchain }} --packs

- name: Upload artifacts
if: always()
Expand All @@ -142,6 +210,7 @@ jobs:
name: devkit-e8-${{ matrix.toolchain }}
path: |
out/**/*.axf
out/**/*.elf
out/**/*.hex

# The export flow must work on all three host OSes -- that is the point of a
Expand Down Expand Up @@ -186,6 +255,8 @@ jobs:
# No cbuild-mlops.yml without cbuild; importing the script checks
# that it parses under this interpreter.
"${PY}" -c "import create_ai_layer; print('create_ai_layer.py OK')"
# The checkpoints setup_venv.py downloaded load on this host.
"${PY}" -c "import sys; sys.path.insert(0, 'model'); import model; model.load_checkpoint(); print('checkpoints OK')"

- name: Report resolved versions
shell: bash
Expand Down
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
__pycache__/
*.pyc

# The exported ExecuTorch program. create_ai_layer.py writes it next to the
# generated AI layer; the C array in ai_layer/model_pte.c is what gets built.
# The exported ExecuTorch program and its C array. create_ai_layer.py writes
# both into the generated AI layer; at ~2.8 MB (a ~14 MB C source) they are
# regenerated by "Create AI layer" rather than committed. The clayer and the
# headers next to them are committed.
*.pte
ai_layer/model_pte.c

# The pico-faces checkpoints setup_venv.py downloads (see PICO_FACES_FILES).
model/pico_faces/

# CMSIS-Toolbox build outputs. RTE/ is tracked in full: the layers' configuration
# files and the per-context RTE/_<build>_<target>/ headers the toolbox writes.
Expand Down
10 changes: 7 additions & 3 deletions .vscode.d/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
{
"label": "Create AI layer",
"detail": "Export model/model.py for the NPU in cmsis-executorch.cbuild-mlops.yml and write ai_layer/ (run a CMSIS build or 'cbuild setup' first)",
"detail": "Export model/model.py (pico-faces) for the NPU in cmsis-executorch.cbuild-mlops.yml and write ai_layer/ (run a CMSIS build or 'cbuild setup' first; takes a few minutes)",
"type": "shell",
"command": "python3",
"args": ["create_ai_layer.py", "cmsis-executorch.cbuild-mlops.yml"],
Expand All @@ -43,12 +43,14 @@
},
{
"label": "Alif: Install M55_HP debug stubs (DevKit-E8, single core configuration)",
"detail": "Programs the ATOC/MRAM stubs with Alif SETOOLS so J-Link can load and debug the M55_HP core. Overwrites build/config/M55_HP_mram_cfg.json and build/images/M55_HP_mram_stub.bin in the SETOOLS tree, then runs app-gen-toc and app-write-mram; stops at the first failing step. Set SW4 to SEUART, set 'alif.setools.root' in your VS Code settings.",
"detail": "Programs the ATOC/MRAM stubs with Alif SETOOLS so J-Link can load and debug the M55_HP core. Selects the DevKit-E8's part in SETOOLS first (E8 AE822FA0E5597LS0, revision A0): app-gen-toc writes it into the ATOC, and the Secure Enclave does not boot an ATOC built for another part. The part and revision are written into SETOOLS' utils/global-cfg.db before tools-config runs, because tools-config refuses to start while another project's 'tools-config -p' without '-r' has left a revision the part does not have ('Revision is invalid!'). Overwrites build/config/M55_HP_mram_cfg.json and build/images/M55_HP_mram_stub.bin in the SETOOLS tree, then runs app-gen-toc and app-write-mram; stops at the first failing step. Set SW4 to SEUART, set 'alif.setools.root' in your VS Code settings.",
"type": "shell",
"command": [
"cp './.alif/M55_HP_mram_cfg.json' '${config:alif.setools.root}/build/config/M55_HP_mram_cfg.json' &&",
"cp './.alif/M55_HP_mram_stub.bin' '${config:alif.setools.root}/build/images/M55_HP_mram_stub.bin' &&",
"cd '${config:alif.setools.root}' &&",
"sed -i.bak -E -e 's|(\"Part#\": *\")[^\"]*|\\1E8 (AE822FA0E5597LS0) - 5.5 MRAM / 9.75 SRAM|' -e 's|(\"Revision\": *\")[^\"]*|\\1A0|' utils/global-cfg.db &&",
"./tools-config -p 'E8 (AE822FA0E5597LS0) - 5.5 MRAM / 9.75 SRAM' -r A0 &&",
"./app-gen-toc -f 'build/config/M55_HP_mram_cfg.json' &&",
"./app-write-mram -p ${input:discoverCOM}"
],
Expand All @@ -57,6 +59,8 @@
"cp './.alif/M55_HP_mram_cfg.json' '${config:alif.setools.root}/build/config/M55_HP_mram_cfg.json'; if (-not $?) { exit 1 };",
"cp './.alif/M55_HP_mram_stub.bin' '${config:alif.setools.root}/build/images/M55_HP_mram_stub.bin'; if (-not $?) { exit 1 };",
"cd '${config:alif.setools.root}'; if (-not $?) { exit 1 };",
"(Get-Content utils/global-cfg.db -Raw) -replace '(\\x22Part#\\x22:\\s*\\x22)[^\\x22]*', '$1E8 (AE822FA0E5597LS0) - 5.5 MRAM / 9.75 SRAM' -replace '(\\x22Revision\\x22:\\s*\\x22)[^\\x22]*', '$1A0' | Set-Content utils/global-cfg.db -NoNewline; if (-not $?) { exit 1 };",
"./tools-config -p 'E8 (AE822FA0E5597LS0) - 5.5 MRAM / 9.75 SRAM' -r A0; if (-not $?) { exit 1 };",
"./app-gen-toc -f 'build/config/M55_HP_mram_cfg.json'; if (-not $?) { exit 1 };",
"./app-write-mram -p ${input:discoverCOM}"
],
Expand Down Expand Up @@ -112,7 +116,7 @@
{
"id": "setupPythonVersion",
"type": "promptString",
"description": "Python version for uv (>=3.10,<3.15), e.g. 3.12 or 3.12.10",
"description": "Python version for uv (>=3.10,<3.14), e.g. 3.12 or 3.12.10",
"default": "3.12"
}
]
Expand Down
Loading
Loading